From 76f6e253bb5263deb4abc7c2996c42353329e15d Mon Sep 17 00:00:00 2001 From: HinGwenWoong Date: Sat, 7 May 2022 10:35:22 +0800 Subject: [PATCH] [Fix] ncnn [-Wreturn-type] and improve mutex `if` (#431) * Fix make ncnn [-Wreturn-type] * Fix lint --- .../ncnn/ops/constantofshape/constantofshape.cpp | 7 +++---- csrc/backend_ops/ncnn/ops/expand/expand.cpp | 16 ++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/csrc/backend_ops/ncnn/ops/constantofshape/constantofshape.cpp b/csrc/backend_ops/ncnn/ops/constantofshape/constantofshape.cpp index 486ede415..b865db7b2 100755 --- a/csrc/backend_ops/ncnn/ops/constantofshape/constantofshape.cpp +++ b/csrc/backend_ops/ncnn/ops/constantofshape/constantofshape.cpp @@ -29,8 +29,7 @@ int ConstantOfShape::forward(const Mat& bottom_blob, Mat& top_blob, const Option if (top_blob.empty()) return -100; top_blob.fill(val); return 0; - } - if (dims == 2) { + } else if (dims == 2) { int h = (int)(shape_ptr[0] + 0.5); int w = (int)(shape_ptr[1] + 0.5); size_t elemsize = sizeof(val); @@ -38,8 +37,7 @@ int ConstantOfShape::forward(const Mat& bottom_blob, Mat& top_blob, const Option if (top_blob.empty()) return -100; top_blob.fill(val); return 0; - } - if (dims == 3) { + } else if (dims == 3) { int channels = (int)(shape_ptr[0] + 0.5); int h = (int)(shape_ptr[1] + 0.5); int w = (int)(shape_ptr[2] + 0.5); @@ -49,6 +47,7 @@ int ConstantOfShape::forward(const Mat& bottom_blob, Mat& top_blob, const Option top_blob.fill(val); return 0; } + return -1; } } // namespace mmdeploy diff --git a/csrc/backend_ops/ncnn/ops/expand/expand.cpp b/csrc/backend_ops/ncnn/ops/expand/expand.cpp index 044717a32..be3d75a24 100755 --- a/csrc/backend_ops/ncnn/ops/expand/expand.cpp +++ b/csrc/backend_ops/ncnn/ops/expand/expand.cpp @@ -46,8 +46,7 @@ int Expand::forward(const std::vector& bottom_blobs, std::vector& top_ return -100; } return 0; - } - if (bottom_blob.dims == 1 && shape_blob.w == 2) { + } else if (bottom_blob.dims == 1 && shape_blob.w == 2) { int shape_0 = (int)(shape_blob[0] + 0.5); int shape_1 = (int)(shape_blob[1] + 0.5); if (bottom_blob.w != shape_1 && bottom_blob.w != 1 && shape_1 != 1) { @@ -78,8 +77,7 @@ int Expand::forward(const std::vector& bottom_blobs, std::vector& top_ return -100; } return 0; - } - if (bottom_blob.dims == 1 && shape_blob.w == 3) { + } else if (bottom_blob.dims == 1 && shape_blob.w == 3) { int shape_0 = (int)(shape_blob[0] + 0.5); int shape_1 = (int)(shape_blob[1] + 0.5); int shape_2 = (int)(shape_blob[2] + 0.5); @@ -112,8 +110,7 @@ int Expand::forward(const std::vector& bottom_blobs, std::vector& top_ return -100; } return 0; - } - if (bottom_blob.dims == 2 && shape_blob.w == 2) { + } else if (bottom_blob.dims == 2 && shape_blob.w == 2) { int shape_0 = (int)(shape_blob[0] + 0.5); int shape_1 = (int)(shape_blob[1] + 0.5); if (bottom_blob.w != shape_1 && bottom_blob.w != 1 && shape_1 != 1) { @@ -160,8 +157,7 @@ int Expand::forward(const std::vector& bottom_blobs, std::vector& top_ return -100; } return 0; - } - if (bottom_blob.dims == 2 && shape_blob.w == 3) { + } else if (bottom_blob.dims == 2 && shape_blob.w == 3) { int shape_0 = (int)(shape_blob[0] + 0.5); int shape_1 = (int)(shape_blob[1] + 0.5); int shape_2 = (int)(shape_blob[2] + 0.5); @@ -219,8 +215,7 @@ int Expand::forward(const std::vector& bottom_blobs, std::vector& top_ return -100; } return 0; - } - if (bottom_blob.dims == 3 && shape_blob.w == 3) { + } else if (bottom_blob.dims == 3 && shape_blob.w == 3) { int shape_0 = (int)(shape_blob[0] + 0.5); int shape_1 = (int)(shape_blob[1] + 0.5); int shape_2 = (int)(shape_blob[2] + 0.5); @@ -332,6 +327,7 @@ int Expand::forward(const std::vector& bottom_blobs, std::vector& top_ } fprintf(stderr, "Layer: Expand, bottom_blob.dims: %d, shape_blob.w: %d\n", bottom_blob.dims, shape_blob.w); + return -1; } } // namespace mmdeploy