Skip to content

Commit

Permalink
fix less c++11
Browse files Browse the repository at this point in the history
  • Loading branch information
Baiyuetribe committed Jan 13, 2025
1 parent 0a3aa28 commit 3ac68cd
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-x64-cpu-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
- "!tools/pnnx/**"
- "examples/**"
pull_request:
# branches: [master]
branches: [master]
paths:
- ".github/workflows/linux-x64-cpu-gcc.yml"
- "toolchains/host-c.gcc.toolchain.cmake"
Expand Down
93 changes: 73 additions & 20 deletions tests/test_flip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,61 @@
#include "layer.h"
#include "testutil.h"

static int test_flip(const ncnn::Mat& a, std::vector<int> axis)
// 为兼容低于c++11弃用如下实现
// ncnn::Mat axis_mat(axis.size());
// for (size_t i = 0; i < axis.size(); i++)
// {
// axis_mat[i] = axis[i];
// }
static ncnn::Mat IntArrayMat(int a0)
{
ncnn::Mat m(1);
int* p = m;
p[0] = a0;
return m;
}

static ncnn::Mat IntArrayMat(int a0, int a1)
{
ncnn::Mat m(2);
int* p = m;
p[0] = a0;
p[1] = a1;
return m;
}

static ncnn::Mat IntArrayMat(int a0, int a1, int a2)
{
ncnn::Mat m(3);
int* p = m;
p[0] = a0;
p[1] = a1;
p[2] = a2;
return m;
}

static ncnn::Mat IntArrayMat(int a0, int a1, int a2, int a3)
{
ncnn::Mat m(4);
int* p = m;
p[0] = a0;
p[1] = a1;
p[2] = a2;
p[3] = a3;
return m;
}

static int test_flip(const ncnn::Mat& a, const ncnn::Mat& axis)
{
ncnn::Mat axis_mat(axis.size());
for (size_t i = 0; i < axis.size(); i++)
{
axis_mat[i] = axis[i];
}
ncnn::ParamDict pd;
pd.set(0, axis_mat); // axis
pd.set(0, axis);

std::vector<ncnn::Mat> weights(0);

int ret = test_layer("Flip", pd, weights, a);
if (ret != 0)
{
fprintf(stderr, "test_flip failed a.dims=%d a=(%d %d %d) axis=", a.dims, a.w, a.h, a.c);
fprintf(stderr, "test_flip failed a.dims=%d a=(%d %d %d) axis_w=%d", a.dims, a.w, a.h, a.c, axis.w);
}

return ret;
Expand All @@ -39,38 +78,52 @@ static int test_flip(const ncnn::Mat& a, std::vector<int> axis)
static int test_flip_0()
{
return 0
|| test_flip(RandomMat(3, 2, 6, 7), {0})
|| test_flip(RandomMat(3, 2, 6, 7), {0, 1})
|| test_flip(RandomMat(3, 2, 6, 7), {0, 2})
|| test_flip(RandomMat(3, 2, 6, 7), {0, 3});
|| test_flip(RandomMat(2, 3, 4, 5), IntArrayMat(0))
|| test_flip(RandomMat(3, 2, 4, 5), IntArrayMat(1))
|| test_flip(RandomMat(4, 3, 2, 5), IntArrayMat(2))
|| test_flip(RandomMat(2, 3, 1, 5), IntArrayMat(3))
|| test_flip(RandomMat(6, 3, 4, 5), IntArrayMat(0, 1))
|| test_flip(RandomMat(2, 3, 1, 6), IntArrayMat(0, 2))
|| test_flip(RandomMat(5, 1, 2, 5), IntArrayMat(0, 3))
|| test_flip(RandomMat(5, 2, 1, 5), IntArrayMat(1, 2))
|| test_flip(RandomMat(4, 5, 2, 3), IntArrayMat(1, 3))
|| test_flip(RandomMat(2, 6, 4, 5), IntArrayMat(2, 3))
|| test_flip(RandomMat(6, 1, 4, 5), IntArrayMat(0, 1, 2))
|| test_flip(RandomMat(5, 2, 1, 5), IntArrayMat(0, 1, 3))
|| test_flip(RandomMat(4, 3, 3, 5), IntArrayMat(0, 2, 3))
|| test_flip(RandomMat(4, 3, 4, 5), IntArrayMat(1, 2, 3))
|| test_flip(RandomMat(6, 3, 3, 2), IntArrayMat(0, 1, 2, 3));
}

static int test_flip_1()
{
return 0
|| test_flip(RandomMat(2, 3, 5), {0})
|| test_flip(RandomMat(4, 2, 5), {0, 1})
|| test_flip(RandomMat(3, 4, 2), {0, 1, 2});
|| test_flip(RandomMat(2, 3, 5), IntArrayMat(0))
|| test_flip(RandomMat(3, 3, 5), IntArrayMat(1))
|| test_flip(RandomMat(4, 3, 5), IntArrayMat(2))
|| test_flip(RandomMat(3, 1, 5), IntArrayMat(0, 1))
|| test_flip(RandomMat(3, 2, 5), IntArrayMat(0, 2))
|| test_flip(RandomMat(3, 3, 4), IntArrayMat(1, 2))
|| test_flip(RandomMat(4, 3, 2), IntArrayMat(0, 1, 2));
}

static int test_flip_2()
{
return 0
|| test_flip(RandomMat(8, 2), {-2})
|| test_flip(RandomMat(16, 3), {-2, -1});
|| test_flip(RandomMat(8, 2), IntArrayMat(-2))
|| test_flip(RandomMat(16, 3), IntArrayMat(-1))
|| test_flip(RandomMat(7, 2), IntArrayMat(-2, -1));
}

static int test_flip_3()
{
return 0
|| test_flip(RandomMat(16), {-1})
|| test_flip(RandomMat(32), {0});
|| test_flip(RandomMat(18), IntArrayMat(-1));
}

int main()
{
SRAND(7767517);

return 0
|| test_flip_0()
|| test_flip_1()
Expand Down

0 comments on commit 3ac68cd

Please sign in to comment.