Skip to content

Commit 195a4dd

Browse files
committed
Fixed compile warning due to default cast
1 parent bc24712 commit 195a4dd

5 files changed

Lines changed: 44 additions & 40 deletions

File tree

benchmark/benchncnn.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tencent is pleased to support the open source community by making ncnn available.
1+
// Tencent is pleased to support the open source community by making ncnn available.
22
//
33
// Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
44
//
@@ -12,6 +12,10 @@
1212
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
// specific language governing permissions and limitations under the License.
1414

15+
#ifdef _WIN32
16+
#define _CRT_SECURE_NO_WARNINGS
17+
#endif
18+
1519
#include <float.h>
1620
#include <stdio.h>
1721
#include <string.h>

src/layer/roialign.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tencent is pleased to support the open source community by making ncnn available.
1+
// Tencent is pleased to support the open source community by making ncnn available.
22
//
33
// Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
44
//
@@ -44,9 +44,9 @@ int ROIAlign::load_param(const ParamDict& pd)
4444

4545
static inline float bilinear_interpolate(const float* ptr, int w, int h, float x, float y)
4646
{
47-
int x0 = x;
47+
int x0 = (int)x;
4848
int x1 = x0 + 1;
49-
int y0 = y;
49+
int y0 = (int)y;
5050
int y1 = y0 + 1;
5151

5252
float a0 = x1 - x;
@@ -143,8 +143,8 @@ int ROIAlign::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to
143143
hend = std::min(std::max(hend, 0.f), (float)h);
144144
wend = std::min(std::max(wend, 0.f), (float)w);
145145

146-
int bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart);
147-
int bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart);
146+
int bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart));
147+
int bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart));
148148

149149
bool is_empty = (hend <= hstart) || (wend <= wstart);
150150
int area = bin_grid_h * bin_grid_w;
@@ -175,10 +175,10 @@ int ROIAlign::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to
175175
else if (version == 1)
176176
{
177177
// the version in detectron 2
178-
int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_h / pooled_height);
179-
int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_w / pooled_width);
178+
int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_h / pooled_height));
179+
int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_w / pooled_width));
180180

181-
const float count = std::max(roi_bin_grid_h * roi_bin_grid_w, 1);
181+
const float count = (float)std::max(roi_bin_grid_h * roi_bin_grid_w, 1);
182182

183183
#pragma omp parallel for num_threads(opt.num_threads)
184184
for (int q = 0; q < channels; q++)

src/layer/x86/roialign_x86.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tencent is pleased to support the open source community by making ncnn available.
1+
// Tencent is pleased to support the open source community by making ncnn available.
22
//
33
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
44
//
@@ -116,7 +116,7 @@ void detectron2_pre_calc_for_bilinear_interpolate(
116116

117117
T ly = y - y_low;
118118
T lx = x - x_low;
119-
T hy = 1. - ly, hx = 1. - lx;
119+
T hy = (T)(1. - ly), hx = (T)(1. - lx);
120120
T w1 = hy * hx, w2 = hy * lx, w3 = ly * hx, w4 = ly * lx;
121121

122122
// save weights and indices
@@ -163,8 +163,8 @@ void original_pre_calc_for_bilinear_interpolate(
163163
hend = std::min(std::max(hend, 0.f), (float)height);
164164
wend = std::min(std::max(wend, 0.f), (float)width);
165165

166-
int bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart);
167-
int bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart);
166+
int bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart));
167+
int bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart));
168168

169169
for (int by = 0; by < bin_grid_h; by++)
170170
{
@@ -173,9 +173,9 @@ void original_pre_calc_for_bilinear_interpolate(
173173
for (int bx = 0; bx < bin_grid_w; bx++)
174174
{
175175
float x = wstart + (bx + 0.5f) * bin_size_w / (float)bin_grid_w;
176-
int x0 = x;
176+
int x0 = (int)x;
177177
int x1 = x0 + 1;
178-
int y0 = y;
178+
int y0 = (int)y;
179179
int y1 = y0 + 1;
180180

181181
float a0 = x1 - x;
@@ -261,8 +261,8 @@ int ROIAlign_x86::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>
261261
if (version == 0)
262262
{
263263
// original version
264-
int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height);
265-
int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width);
264+
int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height));
265+
int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width));
266266
std::vector<PreCalc<float> > pre_calc(
267267
roi_bin_grid_h * roi_bin_grid_w * pooled_width * pooled_height);
268268
original_pre_calc_for_bilinear_interpolate(
@@ -301,8 +301,8 @@ int ROIAlign_x86::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>
301301
hend = std::min(std::max(hend, 0.f), (float)height);
302302
wend = std::min(std::max(wend, 0.f), (float)width);
303303

304-
int bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart);
305-
int bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart);
304+
int bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart));
305+
int bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart));
306306

307307
bool is_empty = (hend <= hstart) || (wend <= wstart);
308308
int area = bin_grid_h * bin_grid_w;
@@ -327,10 +327,10 @@ int ROIAlign_x86::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>
327327
else if (version == 1)
328328
{
329329
// the version in detectron 2
330-
int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height);
331-
int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width);
330+
int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height));
331+
int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width));
332332

333-
const float count = std::max(roi_bin_grid_h * roi_bin_grid_w, 1);
333+
const float count = (float)std::max(roi_bin_grid_h * roi_bin_grid_w, 1);
334334

335335
std::vector<PreCalc<float> > pre_calc(
336336
roi_bin_grid_h * roi_bin_grid_w * pooled_width * pooled_height);

src/mat_pixel_affine.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tencent is pleased to support the open source community by making ncnn available.
1+
// Tencent is pleased to support the open source community by making ncnn available.
22
//
33
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
44
//
@@ -60,7 +60,7 @@ void get_affine_transform(const float* points_from, const float* points_to, int
6060
ma[1][1] = ma[0][0];
6161
ma[2][1] = ma[1][2] = -ma[0][3];
6262
ma[3][1] = ma[1][3] = ma[2][0] = ma[0][2];
63-
ma[2][2] = ma[3][3] = num_point;
63+
ma[2][2] = ma[3][3] = (float)num_point;
6464
ma[3][0] = ma[0][3];
6565

6666
// MM = inv(A) * B
@@ -208,7 +208,7 @@ void warpaffine_bilinear_c1(const unsigned char* src, int srcw, int srch, int sr
208208
const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx;
209209
const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx + 1;
210210

211-
*dst0 = (*a0 * (1.f - fx) + *a1 * fx) * (1.f - fy) + (*b0 * (1.f - fx) + *b1 * fx) * fy;
211+
*dst0 = (unsigned char)((*a0 * (1.f - fx) + *a1 * fx) * (1.f - fy) + (*b0 * (1.f - fx) + *b1 * fx) * fy);
212212
}
213213

214214
dst0 += 1;
@@ -257,8 +257,8 @@ void warpaffine_bilinear_c2(const unsigned char* src, int srcw, int srch, int sr
257257
const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx * 2;
258258
const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx * 2 + 2;
259259

260-
dst0[0] = (a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy;
261-
dst0[1] = (a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy;
260+
dst0[0] = (unsigned char)((a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy);
261+
dst0[1] = (unsigned char)((a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy);
262262
}
263263

264264
dst0 += 2;
@@ -308,9 +308,9 @@ void warpaffine_bilinear_c3(const unsigned char* src, int srcw, int srch, int sr
308308
const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx * 3;
309309
const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx * 3 + 3;
310310

311-
dst0[0] = (a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy;
312-
dst0[1] = (a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy;
313-
dst0[2] = (a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy;
311+
dst0[0] = (unsigned char)((a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy);
312+
dst0[1] = (unsigned char)((a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy);
313+
dst0[2] = (unsigned char)((a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy);
314314
}
315315

316316
dst0 += 3;
@@ -361,10 +361,10 @@ void warpaffine_bilinear_c4(const unsigned char* src, int srcw, int srch, int sr
361361
const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx * 4;
362362
const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx * 4 + 4;
363363

364-
dst0[0] = (a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy;
365-
dst0[1] = (a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy;
366-
dst0[2] = (a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy;
367-
dst0[3] = (a0[3] * (1.f - fx) + a1[3] * fx) * (1.f - fy) + (b0[3] * (1.f - fx) + b1[3] * fx) * fy;
364+
dst0[0] = (unsigned char)((a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy);
365+
dst0[1] = (unsigned char)((a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy);
366+
dst0[2] = (unsigned char)((a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy);
367+
dst0[3] = (unsigned char)((a0[3] * (1.f - fx) + a1[3] * fx) * (1.f - fy) + (b0[3] * (1.f - fx) + b1[3] * fx) * fy);
368368
}
369369

370370
dst0 += 4;

tools/mxnet/mxnet2ncnn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tencent is pleased to support the open source community by making ncnn available.
1+
// Tencent is pleased to support the open source community by making ncnn available.
22
//
33
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
44
//
@@ -176,7 +176,7 @@ std::vector<int> MXNetNode::attr_ai(const char* key) const
176176
int i = 0;
177177
int c = 0;
178178
int nconsumed = 0;
179-
int nscan = sscanf(it->second.c_str() + c, "%*[\[(,]%d%n", &i, &nconsumed);
179+
int nscan = sscanf(it->second.c_str() + c, "%*[\\[(,]%d%n", &i, &nconsumed);
180180
if (nscan != 1)
181181
{
182182
// (None
@@ -261,9 +261,9 @@ bool MXNetNode::has_weight(int i) const
261261

262262
const std::string& name = (*nodes)[weights[i]].name;
263263

264-
for (int i = 0; i < (int)(*params).size(); i++)
264+
for (int j = 0; j < (int)(*params).size(); j++)
265265
{
266-
const MXNetParam& p = (*params)[i];
266+
const MXNetParam& p = (*params)[j];
267267
if (p.name == name)
268268
return true;
269269
}
@@ -278,9 +278,9 @@ std::vector<float> MXNetNode::weight(int i, int init_len) const
278278

279279
const std::string& name = (*nodes)[weights[i]].name;
280280

281-
for (int i = 0; i < (int)(*params).size(); i++)
281+
for (int j = 0; j < (int)(*params).size(); j++)
282282
{
283-
const MXNetParam& p = (*params)[i];
283+
const MXNetParam& p = (*params)[j];
284284
if (p.name != name)
285285
continue;
286286

0 commit comments

Comments
 (0)