1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
8
// https://opensource.org/licenses/BSD-3-Clause
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
17
static int test_expanddims(const ncnn::Mat& a, int expand_w, int expand_h, int expand_d, int expand_c)
25
std::vector<ncnn::Mat> weights(0);
27
int ret = test_layer("ExpandDims", pd, weights, a);
30
fprintf(stderr, "test_expanddims failed a.dims=%d a=(%d %d %d %d) expand_w=%d expand_h=%d expand_d=%d expand_c=%d\n", a.dims, a.w, a.h, a.d, a.c, expand_w, expand_h, expand_d, expand_c);
36
static ncnn::Mat IntArrayMat(int a0)
44
static ncnn::Mat IntArrayMat(int a0, int a1)
53
static ncnn::Mat IntArrayMat(int a0, int a1, int a2)
63
static ncnn::Mat IntArrayMat(int a0, int a1, int a2, int a3)
74
static void print_int_array(const ncnn::Mat& a)
79
for (int i = 0; i < a.w; i++)
81
fprintf(stderr, " %d", pa[i]);
83
fprintf(stderr, " ]");
86
static int test_expanddims_axes(const ncnn::Mat& a, const ncnn::Mat& axes)
91
std::vector<ncnn::Mat> weights(0);
93
int ret = test_layer("ExpandDims", pd, weights, a);
96
fprintf(stderr, "test_expanddims_axes failed a.dims=%d a=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c);
97
fprintf(stderr, " axes=");
98
print_int_array(axes);
99
fprintf(stderr, "\n");
105
static int test_expanddims_all_params(const ncnn::Mat& a)
108
|| test_expanddims(a, 0, 0, 0, 0)
109
|| test_expanddims(a, 0, 0, 0, 1)
110
|| test_expanddims(a, 0, 0, 1, 0)
111
|| test_expanddims(a, 0, 0, 1, 1)
112
|| test_expanddims(a, 0, 1, 0, 0)
113
|| test_expanddims(a, 0, 1, 0, 1)
114
|| test_expanddims(a, 0, 1, 1, 0)
115
|| test_expanddims(a, 0, 1, 1, 1)
116
|| test_expanddims(a, 1, 0, 0, 0)
117
|| test_expanddims(a, 1, 0, 0, 1)
118
|| test_expanddims(a, 1, 0, 1, 0)
119
|| test_expanddims(a, 1, 0, 1, 1)
120
|| test_expanddims(a, 1, 1, 0, 0)
121
|| test_expanddims(a, 1, 1, 0, 1)
122
|| test_expanddims(a, 1, 1, 1, 0)
123
|| test_expanddims(a, 1, 1, 1, 1)
125
|| test_expanddims_axes(a, IntArrayMat(0))
126
|| test_expanddims_axes(a, IntArrayMat(1))
127
|| test_expanddims_axes(a, IntArrayMat(2))
128
|| test_expanddims_axes(a, IntArrayMat(3))
129
|| test_expanddims_axes(a, IntArrayMat(0, 1))
130
|| test_expanddims_axes(a, IntArrayMat(0, 2))
131
|| test_expanddims_axes(a, IntArrayMat(0, 3))
132
|| test_expanddims_axes(a, IntArrayMat(1, 2))
133
|| test_expanddims_axes(a, IntArrayMat(1, 3))
134
|| test_expanddims_axes(a, IntArrayMat(2, 3))
135
|| test_expanddims_axes(a, IntArrayMat(0, 1, 2))
136
|| test_expanddims_axes(a, IntArrayMat(0, 1, 3))
137
|| test_expanddims_axes(a, IntArrayMat(0, 2, 3))
138
|| test_expanddims_axes(a, IntArrayMat(1, 2, 3))
139
|| test_expanddims_axes(a, IntArrayMat(0, 1, 2, 3));
142
static int test_expanddims_0()
145
|| test_expanddims_all_params(RandomMat(3, 12, 16))
146
|| test_expanddims_all_params(RandomMat(3, 1, 16))
147
|| test_expanddims_all_params(RandomMat(1, 33, 15))
148
|| test_expanddims_all_params(RandomMat(1, 14, 1))
149
|| test_expanddims_all_params(RandomMat(12, 13, 1))
150
|| test_expanddims_all_params(RandomMat(1, 1, 1));
153
static int test_expanddims_1()
156
|| test_expanddims_all_params(RandomMat(14, 16))
157
|| test_expanddims_all_params(RandomMat(1, 14))
158
|| test_expanddims_all_params(RandomMat(11, 1))
159
|| test_expanddims_all_params(RandomMat(1, 1));
162
static int test_expanddims_2()
165
|| test_expanddims_all_params(RandomMat(120))
166
|| test_expanddims_all_params(RandomMat(1));
173
return test_expanddims_0() || test_expanddims_1() || test_expanddims_2();