Skip to content

Commit c5b2a23

Browse files
committed
Added assertions and other check for new matrix types in cudaarithm.
1 parent 5c73969 commit c5b2a23

14 files changed

+80
-44
lines changed

modules/cudaarithm/src/cuda/absdiff_mat.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace
135135
void absDiffMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int)
136136
{
137137
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
138-
static const func_t funcs[] =
138+
static const func_t funcs[CV_DEPTH_MAX] =
139139
{
140140
absDiffMat_v1<uchar>,
141141
absDiffMat_v1<schar>,

modules/cudaarithm/src/cuda/absdiff_scalar.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace
9595
void absDiffScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int)
9696
{
9797
typedef void (*func_t)(const GpuMat& src, cv::Scalar val, GpuMat& dst, Stream& stream);
98-
static const func_t funcs[7][4] =
98+
static const func_t funcs[CV_DEPTH_MAX][4] =
9999
{
100100
{
101101
absDiffScalarImpl<uchar, float>, absDiffScalarImpl<uchar2, float>, absDiffScalarImpl<uchar3, float>, absDiffScalarImpl<uchar4, float>

modules/cudaarithm/src/cuda/cmp_scalar.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void cmpScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const G
217217
const int depth = src.depth();
218218
const int cn = src.channels();
219219

220-
CV_DbgAssert( depth <= CV_64F && cn <= 4 );
220+
CV_Assert( depth <= CV_64F && cn <= 4 );
221221

222222
funcs[depth][cmpop][cn - 1](src, val, dst, stream);
223223
}

modules/cudaarithm/src/cuda/div_mat.cu

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace
120120
void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int)
121121
{
122122
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, const GpuMat& dst, double scale, Stream& stream);
123-
static const func_t funcs[7][7] =
123+
static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] =
124124
{
125125
{
126126
divMatImpl<uchar, float, uchar>,
@@ -190,8 +190,6 @@ void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&,
190190
const int sdepth = src1.depth();
191191
const int ddepth = dst.depth();
192192

193-
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F );
194-
195193
GpuMat src1_ = src1.reshape(1);
196194
GpuMat src2_ = src2.reshape(1);
197195
GpuMat dst_ = dst.reshape(1);

modules/cudaarithm/src/cuda/minmax.cu

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace
8787
void cv::cuda::findMinMax(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
8888
{
8989
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream);
90-
static const func_t funcs[] =
90+
static const func_t funcs[CV_DEPTH_MAX] =
9191
{
9292
minMaxImpl<uchar, int>,
9393
minMaxImpl<schar, int>,
@@ -110,6 +110,8 @@ void cv::cuda::findMinMax(InputArray _src, OutputArray _dst, InputArray _mask, S
110110
GpuMat dst = getOutputMat(_dst, 1, 2, dst_depth, stream);
111111

112112
const func_t func = funcs[src.depth()];
113+
CV_Assert(func);
114+
113115
func(src, mask, dst, stream);
114116

115117
syncOutput(dst, _dst, stream);
@@ -158,7 +160,7 @@ namespace
158160
void cv::cuda::device::findMaxAbs(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
159161
{
160162
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream);
161-
static const func_t funcs[] =
163+
static const func_t funcs[CV_DEPTH_MAX] =
162164
{
163165
findMaxAbsImpl<uchar, int>,
164166
findMaxAbsImpl<schar, int>,
@@ -181,6 +183,8 @@ void cv::cuda::device::findMaxAbs(InputArray _src, OutputArray _dst, InputArray
181183
GpuMat dst = getOutputMat(_dst, 1, 1, dst_depth, stream);
182184

183185
const func_t func = funcs[src.depth()];
186+
CV_Assert(func);
187+
184188
func(src, mask, dst, stream);
185189

186190
syncOutput(dst, _dst, stream);

modules/cudaarithm/src/cuda/minmax_mat.cu

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace
127127
void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int op)
128128
{
129129
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
130-
static const func_t funcs_v1[2][7] =
130+
static const func_t funcs_v1[2][CV_DEPTH_MAX] =
131131
{
132132
{
133133
minMaxMat_v1<minimum, uchar>,
@@ -161,8 +161,6 @@ void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat
161161

162162
const int depth = src1.depth();
163163

164-
CV_DbgAssert( depth <= CV_64F );
165-
166164
GpuMat src1_ = src1.reshape(1);
167165
GpuMat src2_ = src2.reshape(1);
168166
GpuMat dst_ = dst.reshape(1);
@@ -191,6 +189,7 @@ void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat
191189
}
192190

193191
const func_t func = funcs_v1[op][depth];
192+
CV_Assert(func);
194193

195194
func(src1_, src2_, dst_, stream);
196195
}
@@ -209,8 +208,10 @@ namespace
209208

210209
void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int op)
211210
{
211+
CV_DbgAssert( src.channels() == 1 );
212+
212213
typedef void (*func_t)(const GpuMat& src, double value, GpuMat& dst, Stream& stream);
213-
static const func_t funcs[2][7] =
214+
static const func_t funcs[2][CV_DEPTH_MAX] =
214215
{
215216
{
216217
minMaxScalar<minimum, uchar>,
@@ -232,12 +233,10 @@ void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const
232233
}
233234
};
234235

235-
const int depth = src.depth();
236-
237-
CV_DbgAssert( depth <= CV_64F );
238-
CV_DbgAssert( src.channels() == 1 );
236+
auto f = funcs[op][src.depth()];
237+
CV_Assert(f);
239238

240-
funcs[op][depth](src, value[0], dst, stream);
239+
f(src, value[0], dst, stream);
241240
}
242241

243242
#endif

modules/cudaarithm/src/cuda/minmaxloc.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace
7575
void cv::cuda::findMinMaxLoc(InputArray _src, OutputArray _minMaxVals, OutputArray _loc, InputArray _mask, Stream& stream)
7676
{
7777
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _valBuf, GpuMat& _locBuf, Stream& stream);
78-
static const func_t funcs[] =
78+
static const func_t funcs[CV_DEPTH_MAX] =
7979
{
8080
minMaxLocImpl<uchar, int>,
8181
minMaxLocImpl<schar, int>,
@@ -99,6 +99,7 @@ void cv::cuda::findMinMaxLoc(InputArray _src, OutputArray _minMaxVals, OutputArr
9999
GpuMat locBuf(pool.getAllocator());
100100

101101
const func_t func = funcs[src_depth];
102+
CV_Assert(func);
102103
func(src, mask, valBuf, locBuf, stream);
103104

104105
GpuMat minMaxVals = valBuf.colRange(0, 1);

modules/cudaarithm/src/cuda/norm.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace
161161
void cv::cuda::device::normL2(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
162162
{
163163
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream);
164-
static const func_t funcs[] =
164+
static const func_t funcs[CV_DEPTH_MAX] =
165165
{
166166
normL2Impl<uchar, double>,
167167
normL2Impl<schar, double>,
@@ -181,6 +181,7 @@ void cv::cuda::device::normL2(InputArray _src, OutputArray _dst, InputArray _mas
181181
GpuMat dst = getOutputMat(_dst, 1, 1, CV_64FC1, stream);
182182

183183
const func_t func = funcs[src.depth()];
184+
CV_Assert(func);
184185
func(src, mask, dst, stream);
185186

186187
syncOutput(dst, _dst, stream);

modules/cudaarithm/src/cuda/normalize.cu

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b,
219219
typedef void (*func_minmax_t)(const GpuMat& _src, GpuMat& _dst, double a, double b, const GpuMat& mask, Stream& stream);
220220
typedef void (*func_norm_t)(const GpuMat& _src, GpuMat& _dst, double a, int normType, const GpuMat& mask, Stream& stream);
221221

222-
static const func_minmax_t funcs_minmax[] =
222+
static const func_minmax_t funcs_minmax[CV_DEPTH_MAX] =
223223
{
224224
normalizeMinMax<uchar, float, float>,
225225
normalizeMinMax<schar, float, float>,
@@ -230,7 +230,7 @@ void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b,
230230
normalizeMinMax<double, double, double>
231231
};
232232

233-
static const func_norm_t funcs_norm[] =
233+
static const func_norm_t funcs_norm[CV_DEPTH_MAX] =
234234
{
235235
normalizeNorm<uchar, float, float>,
236236
normalizeNorm<schar, float, float>,
@@ -273,11 +273,13 @@ void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b,
273273
if (normType == NORM_MINMAX)
274274
{
275275
const func_minmax_t func = funcs_minmax[src_depth];
276+
CV_Assert(func);
276277
func(src, dst, a, b, mask, stream);
277278
}
278279
else
279280
{
280281
const func_norm_t func = funcs_norm[src_depth];
282+
CV_Assert(func);
281283
func(src, dst, a, normType, mask, stream);
282284
}
283285

modules/cudaarithm/src/cuda/reduce.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void cv::cuda::reduce(InputArray _src, OutputArray _dst, int dim, int reduceOp,
142142
if (dim == 0)
143143
{
144144
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream);
145-
static const func_t funcs[7][7] =
145+
static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] =
146146
{
147147
{
148148
reduceToRowImpl<uchar, int, uchar>,
@@ -220,7 +220,7 @@ void cv::cuda::reduce(InputArray _src, OutputArray _dst, int dim, int reduceOp,
220220
else
221221
{
222222
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream);
223-
static const func_t funcs[7][7] =
223+
static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] =
224224
{
225225
{
226226
reduceToColumnImpl<uchar, int, uchar>,

0 commit comments

Comments
 (0)