forked from jiuyuan/InfiniTensor
58 lines
1.9 KiB
C++
58 lines
1.9 KiB
C++
#include "core/graph.h"
|
|
#include "core/kernel.h"
|
|
#include "core/runtime.h"
|
|
#include "operators/reshape.h"
|
|
|
|
#include "test.h"
|
|
|
|
namespace infini {
|
|
|
|
TEST(Reshape, ShapeInference) {
|
|
Runtime runtime = NativeCpuRuntimeObj::getInstance();
|
|
{
|
|
Graph g = make_ref<GraphObj>(runtime);
|
|
Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32);
|
|
auto op = g->addOp<ReshapeObj>(i, nullptr, Shape{3, 2, 4, 3});
|
|
EXPECT_EQ(op->getOutput()->getDims(), (Shape{3, 2, 4, 3}));
|
|
}
|
|
}
|
|
TEST(Flatten, ShapeInference) {
|
|
Runtime runtime = NativeCpuRuntimeObj::getInstance();
|
|
{
|
|
Graph g = make_ref<GraphObj>(runtime);
|
|
Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32);
|
|
auto op = g->addOp<FlattenObj>(i, nullptr, 1);
|
|
EXPECT_EQ(op->getOutput()->getDims(), (Shape{2, 36}));
|
|
}
|
|
{
|
|
Graph g = make_ref<GraphObj>(runtime);
|
|
Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32);
|
|
auto op = g->addOp<FlattenObj>(i, nullptr, 0);
|
|
EXPECT_EQ(op->getOutput()->getDims(), (Shape{1, 72}));
|
|
}
|
|
{
|
|
Graph g = make_ref<GraphObj>(runtime);
|
|
Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32);
|
|
auto op = g->addOp<FlattenObj>(i, nullptr, -1);
|
|
EXPECT_EQ(op->getOutput()->getDims(), (Shape{18, 4}));
|
|
}
|
|
{
|
|
Graph g = make_ref<GraphObj>(runtime);
|
|
Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32);
|
|
auto op = g->addOp<FlattenObj>(i, nullptr, -2);
|
|
EXPECT_EQ(op->getOutput()->getDims(), (Shape{6, 12}));
|
|
}
|
|
}
|
|
|
|
TEST(Identity, ShapeInference) {
|
|
Runtime runtime = NativeCpuRuntimeObj::getInstance();
|
|
{
|
|
Graph g = make_ref<GraphObj>(runtime);
|
|
Tensor i = g->addTensor({2, 3, 3, 4}, DataType::Float32);
|
|
auto op = g->addOp<IdentityObj>(i, nullptr);
|
|
EXPECT_EQ(op->getOutput()->getDims(), (Shape{2, 3, 3, 4}));
|
|
}
|
|
}
|
|
|
|
} // namespace infini
|