diff --git a/src/layer/batchnorm.cpp b/src/layer/batchnorm.cpp index 387c11242..636293faf 100644 --- a/src/layer/batchnorm.cpp +++ b/src/layer/batchnorm.cpp @@ -60,7 +60,7 @@ int BatchNorm::load_model(const ModelBin& mb) for (int i=0; i(sqrt(var_data[i] + eps)); a_data[i] = bias_data[i] - slope_data[i] * mean_data[i] / sqrt_var; b_data[i] = slope_data[i] / sqrt_var; } diff --git a/src/layer/normalize.cpp b/src/layer/normalize.cpp index c84041726..bf34cceaa 100644 --- a/src/layer/normalize.cpp +++ b/src/layer/normalize.cpp @@ -86,7 +86,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float a; if (eps_mode == 0) // caffe/mxnet { - a = 1.f / sqrt(ssum + eps); + a = static_cast(1.f / sqrt(ssum + eps)); } else if (eps_mode == 1) // pytorch { @@ -94,7 +94,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const } else //if (eps_mode == 2) // tensorflow { - a = 1.f / sqrt(std::max(ssum, eps)); + a = static_cast(1.f / sqrt(std::max(ssum, eps))); } if (channel_shared) @@ -146,7 +146,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float a; if (eps_mode == 0) // caffe/mxnet { - a = 1.f / sqrt(ssum + eps); + a = static_cast(1.f / sqrt(ssum + eps)); } else if (eps_mode == 1) // pytorch { @@ -154,7 +154,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const } else //if (eps_mode == 2) // tensorflow { - a = 1.f / sqrt(std::max(ssum, eps)); + a = static_cast(1.f / sqrt(std::max(ssum, eps))); } float scale = a * (channel_shared ? scale_data[0] : scale_data[q]); @@ -193,7 +193,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float a; if (eps_mode == 0) // caffe/mxnet { - a = 1.f / sqrt(ssum + eps); + a = static_cast(1.f / sqrt(ssum + eps)); } else if (eps_mode == 1) // pytorch { @@ -201,7 +201,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const } else //if (eps_mode == 2) // tensorflow { - a = 1.f / sqrt(std::max(ssum, eps)); + a = static_cast(1.f / sqrt(std::max(ssum, eps))); } square_sum_blob[i] = a * scale; @@ -233,7 +233,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float a; if (eps_mode == 0) // caffe/mxnet { - a = 1.f / sqrt(ssum + eps); + a = static_cast(1.f / sqrt(ssum + eps)); } else if (eps_mode == 1) // pytorch { @@ -241,7 +241,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const } else //if (eps_mode == 2) // tensorflow { - a = 1.f / sqrt(std::max(ssum, eps)); + a = static_cast(1.f / sqrt(std::max(ssum, eps))); } square_sum_blob[i] = a; diff --git a/src/layer/padding.cpp b/src/layer/padding.cpp index fc751616e..66e715f14 100644 --- a/src/layer/padding.cpp +++ b/src/layer/padding.cpp @@ -298,7 +298,7 @@ int Padding::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) c return -100; if (elemsize == 1) - copy_make_border_image(bottom_blob, top_blob, 0, left, type, value); + copy_make_border_image(bottom_blob, top_blob, 0, left, type, static_cast(value)); else if (elemsize == 4) copy_make_border_image(bottom_blob, top_blob, 0, left, type, value); @@ -314,7 +314,7 @@ int Padding::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) c return -100; if (elemsize == 1) - copy_make_border_image(bottom_blob, top_blob, top, left, type, value); + copy_make_border_image(bottom_blob, top_blob, top, left, type, static_cast(value)); else if (elemsize == 4) copy_make_border_image(bottom_blob, top_blob, top, left, type, value); @@ -334,7 +334,7 @@ int Padding::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) c Mat borderm = top_blob.channel(q); if (elemsize == 1) - copy_make_border_image(m, borderm, top, left, type, value); + copy_make_border_image(m, borderm, top, left, type, static_cast(value)); else if (elemsize == 4) copy_make_border_image(m, borderm, top, left, type, value); } @@ -386,7 +386,7 @@ int Padding::forward(const std::vector& bottom_blobs, std::vector& top return -100; if (elemsize == 1) - copy_make_border_image(bottom_blob, top_blob, 0, _left, type, value); + copy_make_border_image(bottom_blob, top_blob, 0, _left, type, static_cast(value)); else if (elemsize == 4) copy_make_border_image(bottom_blob, top_blob, 0, _left, type, value); @@ -402,7 +402,7 @@ int Padding::forward(const std::vector& bottom_blobs, std::vector& top return -100; if (elemsize == 1) - copy_make_border_image(bottom_blob, top_blob, _top, _left, type, value); + copy_make_border_image(bottom_blob, top_blob, _top, _left, type, static_cast(value)); else if (elemsize == 4) copy_make_border_image(bottom_blob, top_blob, _top, _left, type, value); @@ -422,7 +422,7 @@ int Padding::forward(const std::vector& bottom_blobs, std::vector& top Mat borderm = top_blob.channel(q); if (elemsize == 1) - copy_make_border_image(m, borderm, _top, _left, type, value); + copy_make_border_image(m, borderm, _top, _left, type, static_cast(value)); else if (elemsize == 4) copy_make_border_image(m, borderm, _top, _left, type, value); } diff --git a/src/layer/priorbox.cpp b/src/layer/priorbox.cpp index 39f8aa45f..edbc888de 100644 --- a/src/layer/priorbox.cpp +++ b/src/layer/priorbox.cpp @@ -101,7 +101,7 @@ int PriorBox::forward(const std::vector& bottom_blobs, std::vector& to float size = min_sizes[0]; for (int p = 1; p < num_ratios; p++) { - float ratio = sqrt(aspect_ratios[p]); + float ratio = static_cast(sqrt(aspect_ratios[p])); float cw = size * h / w * ratio / 2; float ch = size / ratio / 2; @@ -141,13 +141,13 @@ int PriorBox::forward(const std::vector& bottom_blobs, std::vector& to { step_w = (float)image_w / w; if (step_mmdetection) - step_w = ceil((float)image_w / w); + step_w = static_cast(ceil((float)image_w / w)); } if (step_h == -233) { step_h = (float)image_h / h; if (step_mmdetection) - step_h = ceil((float)image_h / h); + step_h = static_cast(ceil((float)image_h / h)); } int num_min_size = min_sizes.w; @@ -200,7 +200,7 @@ int PriorBox::forward(const std::vector& bottom_blobs, std::vector& to float max_size = max_sizes[k]; // max size box - box_w = box_h = sqrt(min_size * max_size); + box_w = box_h = static_cast(sqrt(min_size * max_size)); box[0] = (center_x - box_w * 0.5f) / image_w; box[1] = (center_y - box_h * 0.5f) / image_h; @@ -215,8 +215,8 @@ int PriorBox::forward(const std::vector& bottom_blobs, std::vector& to { float ar = aspect_ratios[p]; - box_w = min_size * sqrt(ar); - box_h = min_size / sqrt(ar); + box_w = static_cast(min_size * sqrt(ar)); + box_h = static_cast(min_size / sqrt(ar)); box[0] = (center_x - box_w * 0.5f) / image_w; box[1] = (center_y - box_h * 0.5f) / image_h; diff --git a/src/layer/requantize.cpp b/src/layer/requantize.cpp index 9f51d5237..8114d99f8 100644 --- a/src/layer/requantize.cpp +++ b/src/layer/requantize.cpp @@ -29,7 +29,7 @@ Requantize::Requantize() static inline signed char float2int8(float v) { - int int32 = round(v); + int int32 = static_cast(round(v)); if (int32 > 127) return 127; if (int32 < -127) return -127; return (signed char)int32; diff --git a/src/mat_pixel.cpp b/src/mat_pixel.cpp index fbe01f361..0752d1049 100644 --- a/src/mat_pixel.cpp +++ b/src/mat_pixel.cpp @@ -717,7 +717,7 @@ static int from_rgb2gray(const unsigned char* rgb, int w, int h, int stride, Mat #endif // __ARM_NEON for (; remain>0; remain--) { - *ptr = (rgb[0] * R2Y + rgb[1] * G2Y + rgb[2] * B2Y) >> Y_shift; + *ptr = static_cast((rgb[0] * R2Y + rgb[1] * G2Y + rgb[2] * B2Y) >> Y_shift); rgb += 3; ptr++; @@ -874,7 +874,7 @@ static int from_bgr2gray(const unsigned char* bgr, int w, int h, int stride, Mat #endif // __ARM_NEON for (; remain>0; remain--) { - *ptr = (bgr[2] * R2Y + bgr[1] * G2Y + bgr[0] * B2Y) >> Y_shift; + *ptr = static_cast((bgr[2] * R2Y + bgr[1] * G2Y + bgr[0] * B2Y) >> Y_shift); bgr += 3; ptr++; @@ -1428,7 +1428,7 @@ static int from_rgba2gray(const unsigned char* rgba, int w, int h, int stride, M #endif // __ARM_NEON for (; remain>0; remain--) { - *ptr = (rgba[0] * R2Y + rgba[1] * G2Y + rgba[2] * B2Y) >> Y_shift; + *ptr = static_cast((rgba[0] * R2Y + rgba[1] * G2Y + rgba[2] * B2Y) >> Y_shift); rgba += 4; ptr++; diff --git a/src/mat_pixel_resize.cpp b/src/mat_pixel_resize.cpp index 79afc334e..1290043bf 100644 --- a/src/mat_pixel_resize.cpp +++ b/src/mat_pixel_resize.cpp @@ -71,7 +71,7 @@ void resize_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstr for (int dx = 0; dx < w; dx++) { fx = (float)((dx + 0.5) * scale_x - 0.5); - sx = floor(fx); + sx = static_cast(floor(fx)); fx -= sx; if (sx < 0) @@ -97,7 +97,7 @@ void resize_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstr for (int dy = 0; dy < h; dy++) { fy = (float)((dy + 0.5) * scale_y - 0.5); - sy = floor(fy); + sy = static_cast(floor(fy)); fy -= sy; if (sy < 0) @@ -326,7 +326,7 @@ void resize_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstr for (int dx = 0; dx < w; dx++) { fx = (float)((dx + 0.5) * scale_x - 0.5); - sx = floor(fx); + sx = static_cast(floor(fx)); fx -= sx; if (sx < 0) @@ -352,7 +352,7 @@ void resize_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstr for (int dy = 0; dy < h; dy++) { fy = (float)((dy + 0.5) * scale_y - 0.5); - sy = floor(fy); + sy = static_cast(floor(fy)); fy -= sy; if (sy < 0) @@ -636,7 +636,7 @@ void resize_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstr for (int dx = 0; dx < w; dx++) { fx = (float)((dx + 0.5) * scale_x - 0.5); - sx = floor(fx); + sx = static_cast(floor(fx)); fx -= sx; if (sx < 0) @@ -662,7 +662,7 @@ void resize_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstr for (int dy = 0; dy < h; dy++) { fy = (float)((dy + 0.5) * scale_y - 0.5); - sy = floor(fy); + sy = static_cast(floor(fy)); fy -= sy; if (sy < 0) @@ -957,7 +957,7 @@ void resize_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstr for (int dx = 0; dx < w; dx++) { fx = (float)((dx + 0.5) * scale_x - 0.5); - sx = floor(fx); + sx = static_cast(floor(fx)); fx -= sx; if (sx < 0) @@ -983,7 +983,7 @@ void resize_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstr for (int dy = 0; dy < h; dy++) { fy = (float)((dy + 0.5) * scale_y - 0.5); - sy = floor(fy); + sy = static_cast(floor(fy)); fy -= sy; if (sy < 0) diff --git a/src/modelbin.cpp b/src/modelbin.cpp index 95d67bd70..51c35e2eb 100644 --- a/src/modelbin.cpp +++ b/src/modelbin.cpp @@ -77,7 +77,7 @@ Mat ModelBinFromDataReader::load(int w, int type) const if (flag_struct.tag == 0x01306B47) { // half-precision data - int align_data_size = alignSize(w * sizeof(unsigned short), 4); + size_t align_data_size = alignSize(w * sizeof(unsigned short), 4); std::vector float16_weights; float16_weights.resize(align_data_size); nread = dr.read(float16_weights.data(), align_data_size); @@ -92,7 +92,7 @@ Mat ModelBinFromDataReader::load(int w, int type) const else if (flag_struct.tag == 0x000D4B38) { // int8 data - int align_data_size = alignSize(w, 4); + size_t align_data_size = alignSize(w, 4); std::vector int8_weights; int8_weights.resize(align_data_size); nread = dr.read(int8_weights.data(), align_data_size); @@ -142,7 +142,7 @@ Mat ModelBinFromDataReader::load(int w, int type) const return Mat(); } - int align_weight_data_size = alignSize(w * sizeof(unsigned char), 4); + size_t align_weight_data_size = alignSize(w * sizeof(unsigned char), 4); std::vector index_array; index_array.resize(align_weight_data_size); nread = dr.read(index_array.data(), align_weight_data_size);