@@ -62,7 +62,7 @@ TEST(Broadcast, ScalarTo2D_2x3) {
6262 std::vector<float > golden = {
6363 2 .25f , 2 .25f , 2 .25f , 2 .25f , 2 .25f , 2 .25f ,
6464 };
65- std::vector<int32_t > shape = {3 , 2 };
65+ std::vector<uint32_t > shape = {3 , 2 };
6666
6767 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
6868 in_data.size () * sizeof (float )));
@@ -93,7 +93,7 @@ TEST(Broadcast, 1DTo2D) {
9393 std::vector<float > golden = {
9494 1 .f , 2 .f , 3 .f , 1 .f , 2 .f , 3 .f ,
9595 };
96- std::vector<int32_t > shape = {3 , 2 };
96+ std::vector<uint32_t > shape = {3 , 2 };
9797
9898 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
9999 in_data.size () * sizeof (float )));
@@ -125,7 +125,7 @@ TEST(Broadcast, 1DTo2D_WithDims0) {
125125 1 .f , 2 .f ,
126126 1 .f , 2 .f ,
127127 };
128- std::vector<int32_t > shape = {2 , 2 };
128+ std::vector<uint32_t > shape = {2 , 2 };
129129 std::vector<int32_t > dimensions = {0 };
130130
131131 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
@@ -158,7 +158,7 @@ TEST(Broadcast, 1DTo2D_WithDims1) {
158158 1 .f , 1 .f ,
159159 2 .f , 2 .f ,
160160 };
161- std::vector<int32_t > shape = {2 , 2 };
161+ std::vector<uint32_t > shape = {2 , 2 };
162162 std::vector<int32_t > dimensions = {1 };
163163
164164 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
@@ -170,6 +170,44 @@ TEST(Broadcast, 1DTo2D_WithDims1) {
170170 CheckResult (graph, golden, output_tensor);
171171}
172172
173+ TEST (Broadcast, 1DTo2D_WithDimsMinus2) {
174+ auto ctx = tim::vx::Context::Create ();
175+ auto graph = ctx->CreateGraph ();
176+
177+ tim::vx::ShapeType input_shape ({3 });
178+ tim::vx::ShapeType output_shape ({3 , 2 });
179+ tim::vx::TensorSpec input_spec (tim::vx::DataType::FLOAT32, input_shape,
180+ tim::vx::TensorAttribute::INPUT);
181+ tim::vx::TensorSpec output_spec (tim::vx::DataType::FLOAT32, output_shape,
182+ tim::vx::TensorAttribute::OUTPUT);
183+
184+ auto input_tensor = graph->CreateTensor (input_spec);
185+ auto output_tensor = graph->CreateTensor (output_spec);
186+
187+ std::vector<float > in_data = {
188+ 1 .f , 2 .f , 3 .f
189+ };
190+ std::vector<float > golden = {
191+ 1 .f , 2 .f , 3 .f ,
192+ 1 .f , 2 .f , 3 .f
193+ };
194+ std::vector<uint32_t > shape = {3 , 2 };
195+ std::vector<int32_t > dimensions = {-2 };
196+ EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
197+ in_data.size () * sizeof (float )));
198+
199+ auto op = graph->CreateOperation <tim::vx::ops::Broadcast>(shape, dimensions);
200+ (*op).BindInputs ({input_tensor}).BindOutputs ({output_tensor});
201+
202+
203+ EXPECT_TRUE (graph->Compile ());
204+ EXPECT_TRUE (graph->Run ());
205+
206+ std::vector<float > output (golden.size ());
207+ EXPECT_TRUE (output_tensor->CopyDataFromTensor (output.data ()));
208+ EXPECT_EQ (golden, output);
209+ }
210+
173211TEST (Broadcast, 1DTo3D_WithDims0) {
174212 auto ctx = tim::vx::Context::Create ();
175213 auto graph = ctx->CreateGraph ();
@@ -190,7 +228,7 @@ TEST(Broadcast, 1DTo3D_WithDims0) {
190228 std::vector<float > golden = {
191229 1 .f , 2 .f , 1 .f , 2 .f , 1 .f , 2 .f , 1 .f , 2 .f ,
192230 };
193- std::vector<int32_t > shape = {2 , 2 , 2 };
231+ std::vector<uint32_t > shape = {2 , 2 , 2 };
194232 std::vector<int32_t > dimensions = {0 };
195233
196234 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
@@ -222,7 +260,7 @@ TEST(Broadcast, 1DTo3D_WithDims1) {
222260 std::vector<float > golden = {
223261 1 .f , 1 .f , 2 .f , 2 .f , 1 .f , 1 .f , 2 .f , 2 .f ,
224262 };
225- std::vector<int32_t > shape = {2 , 2 , 2 };
263+ std::vector<uint32_t > shape = {2 , 2 , 2 };
226264 std::vector<int32_t > dimensions = {1 };
227265
228266 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
@@ -254,7 +292,7 @@ TEST(Broadcast, 1DTo3D_WithDims2) {
254292 std::vector<float > golden = {
255293 1 .f , 1 .f , 1 .f , 1 .f , 2 .f , 2 .f , 2 .f , 2 .f ,
256294 };
257- std::vector<int32_t > shape = {2 , 2 , 2 };
295+ std::vector<uint32_t > shape = {2 , 2 , 2 };
258296 std::vector<int32_t > dimensions = {2 };
259297
260298 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
@@ -286,7 +324,7 @@ TEST(Broadcast, 2DTo3D_WithDims02) {
286324 std::vector<float > golden = {
287325 1 .f , 5 .f , 1 .f , 5 .f , 2 .f , 6 .f , 2 .f , 6 .f ,
288326 };
289- std::vector<int32_t > shape = {2 , 2 , 2 };
327+ std::vector<uint32_t > shape = {2 , 2 , 2 };
290328 std::vector<int32_t > dimensions = {0 , 2 };
291329
292330 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
@@ -318,7 +356,7 @@ TEST(Broadcast, 2DTo3D_WithDims12) {
318356 std::vector<float > golden = {
319357 1 .f , 1 .f , 5 .f , 5 .f , 2 .f , 2 .f , 6 .f , 6 .f ,
320358 };
321- std::vector<int32_t > shape = {2 , 2 , 2 };
359+ std::vector<uint32_t > shape = {2 , 2 , 2 };
322360 std::vector<int32_t > dimensions = {1 , 2 };
323361
324362 EXPECT_TRUE (input_tensor->CopyDataToTensor (in_data.data (),
0 commit comments