#include "core/graph.h" #include "core/kernel.h" #include "core/runtime.h" #include "operators/reduce.h" #include "test.h" namespace infini { template void testShapeInference() { Runtime runtime = NativeCpuRuntimeObj::getInstance(); { Graph g = make_ref(runtime); Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32); auto op = g->addOp(i, nullptr, std::nullopt, true); EXPECT_EQ(op->getOutput()->getDims(), (Shape{1, 1, 1, 1})); } { Graph g = make_ref(runtime); Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32); auto op = g->addOp(i, nullptr, vector{1, 3}, true); EXPECT_EQ(op->getOutput()->getDims(), (Shape{2, 1, 3, 1})); } { Graph g = make_ref(runtime); Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32); auto op = g->addOp(i, nullptr, vector{-3, 3}, true); EXPECT_EQ(op->getOutput()->getDims(), (Shape{2, 1, 3, 1})); } { Graph g = make_ref(runtime); Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32); auto op = g->addOp(i, nullptr, std::nullopt, false); EXPECT_EQ(op->getOutput()->getDims(), (Shape{1})); } { Graph g = make_ref(runtime); Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32); auto op = g->addOp(i, nullptr, vector{1, 3}, false); EXPECT_EQ(op->getOutput()->getDims(), (Shape{2, 3})); } { Graph g = make_ref(runtime); Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32); auto op = g->addOp(i, nullptr, vector{-3, 3}, false); EXPECT_EQ(op->getOutput()->getDims(), (Shape{2, 3})); } } TEST(ReduceMean, ShapeInference) { testShapeInference(); testShapeInference(); } } // namespace infini