MCPcopy Create free account
hub / github.com/alibaba/MNN / run

Method run

test/op/StridedSliceTest.cpp:18–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16public:
17 virtual ~StridedSliceTest() = default;
18 virtual bool run(int precision) {
19 auto input = _Input({1, 3, 2, 3}, NCHW);
20 auto begin = _Input({4}, NCHW);
21 auto end = _Input({4}, NCHW);
22 auto strided = _Input({4}, NCHW);
23 const float input_data[] = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
24 memcpy(input->writeMap<float>(), input_data, 18 * sizeof(float));
25 const int begin_data[] = {0, 0, 0, 0};
26 memcpy(begin->writeMap<int>(), begin_data, 4 * sizeof(int));
27 const int end_data[] = {1, 2, 2, 3};
28 memcpy(end->writeMap<int>(), end_data, 4 * sizeof(int));
29 const int stride_data[] = {1, 1, 1, 1};
30 memcpy(strided->writeMap<int>(), stride_data, 4 * sizeof(int));
31 // 1. all mask = 0
32 auto output_1 = _StridedSlice(input, begin, end, strided, 0, 0, 0, 0, 0);
33 const std::vector<int> expectedShape_1 = {1, 2, 2, 3};
34 const std::vector<float> expectedOutput_1 = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
35 if (!checkVector<int>(output_1->getInfo()->dim.data(), expectedShape_1.data(), expectedShape_1.size(), 0) ||
36 !checkVector<float>(output_1->readMap<float>(), expectedOutput_1.data(), expectedOutput_1.size(), 0.01)) {
37 MNN_ERROR("stridedslice (all mask=0) test failed!\n");
38 return false;
39 }
40 // 2. ellipsisMask = 2
41 auto output_2 = _StridedSlice(input, begin, end, strided, 0, 0, 2, 0, 0);
42 const std::vector<int> expectedShape_2 = {1, 3, 2, 3};
43 const std::vector<float> expectedOutput_2 = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
44 if (!checkVector<int>(output_2->getInfo()->dim.data(), expectedShape_2.data(), expectedShape_2.size(), 0) ||
45 !checkVector<float>(output_2->readMap<float>(), expectedOutput_2.data(), expectedOutput_2.size(), 0.01)) {
46 MNN_ERROR("stridedslice (ellipsisMask=2) test failed!\n");
47 return false;
48 }
49 // 3. newAxisMask = 2
50 auto output_3 = _StridedSlice(input, begin, end, strided, 0, 0, 0, 2, 0);
51 const std::vector<int> expectedShape_3 = {1, 1, 2, 2, 3};
52 const std::vector<float> expectedOutput_3 = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
53 if (!checkVector<int>(output_3->getInfo()->dim.data(), expectedShape_3.data(), expectedShape_3.size(), 0) ||
54 !checkVector<float>(output_3->readMap<float>(), expectedOutput_3.data(), expectedOutput_3.size(), 0.01)) {
55 MNN_ERROR("stridedslice (newAxisMask=2) test failed!\n");
56 return false;
57 }
58 // 4. shrinkAxisMask = 2
59 auto output_4 = _StridedSlice(input, begin, end, strided, 0, 0, 0, 0, 2);
60 const std::vector<int> expectedShape_4 = {1, 2, 3};
61 const std::vector<float> expectedOutput_4 = {1, 1, 1, 2, 2, 2};
62 if (!checkVector<int>(output_4->getInfo()->dim.data(), expectedShape_4.data(), expectedShape_4.size(), 0) ||
63 !checkVector<float>(output_4->readMap<float>(), expectedOutput_4.data(), expectedOutput_4.size(), 0.01)) {
64 MNN_ERROR("stridedslice (shrinkAxisMask=2) test failed!\n");
65 return false;
66 }
67 // 5. ellipsisMask = 2, shrinkAxisMask = 8(0b01000)
68 auto output_5 = _StridedSlice(input, begin, end, strided, 0, 0, 2, 0, 8);
69 const std::vector<int> expectedShape_5 = {1, 3, 2};
70 const std::vector<float> expectedOutput_5 = {1, 2, 3, 4, 5, 6};
71 if (!checkVector<int>(output_5->getInfo()->dim.data(), expectedShape_5.data(), expectedShape_5.size(), 0) ||
72 !checkVector<float>(output_5->readMap<float>(), expectedOutput_5.data(), expectedOutput_5.size(), 0.01)) {
73 MNN_ERROR("stridedslice (ellipsisMask=2, shrinkAxisMask=8) test failed!\n");
74 return false;
75 }

Callers

nothing calls this directly

Calls 6

_InputFunction · 0.85
_StridedSliceFunction · 0.85
dataMethod · 0.45
getInfoMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected