Skip to content

Commit

Permalink
Fixed compile warning due to default cast
Browse files Browse the repository at this point in the history
  • Loading branch information
fawdlstty committed Oct 13, 2020
1 parent bc24712 commit 195a4dd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
6 changes: 5 additions & 1 deletion benchmark/benchncnn.cpp
@@ -1,4 +1,4 @@
// Tencent is pleased to support the open source community by making ncnn available.
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
//
Expand All @@ -12,6 +12,10 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <float.h>
#include <stdio.h>
#include <string.h>
Expand Down
16 changes: 8 additions & 8 deletions src/layer/roialign.cpp
@@ -1,4 +1,4 @@
// Tencent is pleased to support the open source community by making ncnn available.
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
//
Expand Down Expand Up @@ -44,9 +44,9 @@ int ROIAlign::load_param(const ParamDict& pd)

static inline float bilinear_interpolate(const float* ptr, int w, int h, float x, float y)
{
int x0 = x;
int x0 = (int)x;
int x1 = x0 + 1;
int y0 = y;
int y0 = (int)y;
int y1 = y0 + 1;

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

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

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

const float count = std::max(roi_bin_grid_h * roi_bin_grid_w, 1);
const float count = (float)std::max(roi_bin_grid_h * roi_bin_grid_w, 1);

#pragma omp parallel for num_threads(opt.num_threads)
for (int q = 0; q < channels; q++)
Expand Down
26 changes: 13 additions & 13 deletions src/layer/x86/roialign_x86.cpp
@@ -1,4 +1,4 @@
// Tencent is pleased to support the open source community by making ncnn available.
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
Expand Down Expand Up @@ -116,7 +116,7 @@ void detectron2_pre_calc_for_bilinear_interpolate(

T ly = y - y_low;
T lx = x - x_low;
T hy = 1. - ly, hx = 1. - lx;
T hy = (T)(1. - ly), hx = (T)(1. - lx);
T w1 = hy * hx, w2 = hy * lx, w3 = ly * hx, w4 = ly * lx;

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

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

for (int by = 0; by < bin_grid_h; by++)
{
Expand All @@ -173,9 +173,9 @@ void original_pre_calc_for_bilinear_interpolate(
for (int bx = 0; bx < bin_grid_w; bx++)
{
float x = wstart + (bx + 0.5f) * bin_size_w / (float)bin_grid_w;
int x0 = x;
int x0 = (int)x;
int x1 = x0 + 1;
int y0 = y;
int y0 = (int)y;
int y1 = y0 + 1;

float a0 = x1 - x;
Expand Down Expand Up @@ -261,8 +261,8 @@ int ROIAlign_x86::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>
if (version == 0)
{
// original version
int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height);
int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width);
int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height));
int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width));
std::vector<PreCalc<float> > pre_calc(
roi_bin_grid_h * roi_bin_grid_w * pooled_width * pooled_height);
original_pre_calc_for_bilinear_interpolate(
Expand Down Expand Up @@ -301,8 +301,8 @@ int ROIAlign_x86::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>
hend = std::min(std::max(hend, 0.f), (float)height);
wend = std::min(std::max(wend, 0.f), (float)width);

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

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

const float count = std::max(roi_bin_grid_h * roi_bin_grid_w, 1);
const float count = (float)std::max(roi_bin_grid_h * roi_bin_grid_w, 1);

std::vector<PreCalc<float> > pre_calc(
roi_bin_grid_h * roi_bin_grid_w * pooled_width * pooled_height);
Expand Down
24 changes: 12 additions & 12 deletions src/mat_pixel_affine.cpp
@@ -1,4 +1,4 @@
// Tencent is pleased to support the open source community by making ncnn available.
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
Expand Down Expand Up @@ -60,7 +60,7 @@ void get_affine_transform(const float* points_from, const float* points_to, int
ma[1][1] = ma[0][0];
ma[2][1] = ma[1][2] = -ma[0][3];
ma[3][1] = ma[1][3] = ma[2][0] = ma[0][2];
ma[2][2] = ma[3][3] = num_point;
ma[2][2] = ma[3][3] = (float)num_point;
ma[3][0] = ma[0][3];

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

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

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

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

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

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

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

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

dst0 += 4;
Expand Down
12 changes: 6 additions & 6 deletions tools/mxnet/mxnet2ncnn.cpp
@@ -1,4 +1,4 @@
// Tencent is pleased to support the open source community by making ncnn available.
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
//
Expand Down Expand Up @@ -176,7 +176,7 @@ std::vector<int> MXNetNode::attr_ai(const char* key) const
int i = 0;
int c = 0;
int nconsumed = 0;
int nscan = sscanf(it->second.c_str() + c, "%*[\[(,]%d%n", &i, &nconsumed);
int nscan = sscanf(it->second.c_str() + c, "%*[\\[(,]%d%n", &i, &nconsumed);
if (nscan != 1)
{
// (None
Expand Down Expand Up @@ -261,9 +261,9 @@ bool MXNetNode::has_weight(int i) const

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

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

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

for (int i = 0; i < (int)(*params).size(); i++)
for (int j = 0; j < (int)(*params).size(); j++)
{
const MXNetParam& p = (*params)[i];
const MXNetParam& p = (*params)[j];
if (p.name != name)
continue;

Expand Down

0 comments on commit 195a4dd

Please sign in to comment.