Added Ceil & unit test (#381)
* Added Ceil & unit test * Added Round & Unit test
This commit is contained in:
parent
7a8ae32f73
commit
eab0d807a6
|
|
@ -82,6 +82,10 @@ namespace ops {
|
||||||
*
|
*
|
||||||
* returns the largest integer less than or equal to a given number.
|
* returns the largest integer less than or equal to a given number.
|
||||||
*
|
*
|
||||||
|
* ## Ceil
|
||||||
|
*
|
||||||
|
* returns the largest integer more than or equal to a given number.
|
||||||
|
*
|
||||||
* ## Cast
|
* ## Cast
|
||||||
*
|
*
|
||||||
* Change the format from input tensor to output tensor. This operation ignores
|
* Change the format from input tensor to output tensor. This operation ignores
|
||||||
|
|
@ -101,6 +105,8 @@ DECLARE_SIMPLE_OP(Rsqrt)
|
||||||
DECLARE_SIMPLE_OP(Square)
|
DECLARE_SIMPLE_OP(Square)
|
||||||
DECLARE_SIMPLE_OP(LogicalNot)
|
DECLARE_SIMPLE_OP(LogicalNot)
|
||||||
DECLARE_SIMPLE_OP(Floor)
|
DECLARE_SIMPLE_OP(Floor)
|
||||||
|
DECLARE_SIMPLE_OP(Ceil)
|
||||||
|
DECLARE_SIMPLE_OP(Round)
|
||||||
DECLARE_SIMPLE_OP(Cast)
|
DECLARE_SIMPLE_OP(Cast)
|
||||||
|
|
||||||
#undef DECLARE_SIMPLE_OP
|
#undef DECLARE_SIMPLE_OP
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ DEFINE_SIMPLE_OP(Rsqrt, VSI_NN_OP_RSQRT)
|
||||||
DEFINE_SIMPLE_OP(Square, VSI_NN_OP_SQUARE)
|
DEFINE_SIMPLE_OP(Square, VSI_NN_OP_SQUARE)
|
||||||
DEFINE_SIMPLE_OP(LogicalNot, VSI_NN_OP_LOGICAL_NOT)
|
DEFINE_SIMPLE_OP(LogicalNot, VSI_NN_OP_LOGICAL_NOT)
|
||||||
DEFINE_SIMPLE_OP(Floor, VSI_NN_OP_FLOOR)
|
DEFINE_SIMPLE_OP(Floor, VSI_NN_OP_FLOOR)
|
||||||
|
DEFINE_SIMPLE_OP(Ceil, VSI_NN_OP_CEIL)
|
||||||
|
DEFINE_SIMPLE_OP(Round, VSI_NN_OP_ROUND)
|
||||||
DEFINE_SIMPLE_OP(Cast, VSI_NN_OP_CAST)
|
DEFINE_SIMPLE_OP(Cast, VSI_NN_OP_CAST)
|
||||||
|
|
||||||
#undef DEFINE_SIMPLE_OP
|
#undef DEFINE_SIMPLE_OP
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,66 @@ TEST(Floor, shape_5_1_fp32) {
|
||||||
EXPECT_EQ(golden, output);
|
EXPECT_EQ(golden, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Round, shape_15_1_fp32) {
|
||||||
|
auto ctx = tim::vx::Context::Create();
|
||||||
|
auto graph = ctx->CreateGraph();
|
||||||
|
|
||||||
|
tim::vx::ShapeType io_shape({15, 1});
|
||||||
|
tim::vx::TensorSpec input_spec(tim::vx::DataType::FLOAT32,
|
||||||
|
io_shape, tim::vx::TensorAttribute::INPUT);
|
||||||
|
tim::vx::TensorSpec output_spec(tim::vx::DataType::FLOAT32,
|
||||||
|
io_shape, tim::vx::TensorAttribute::OUTPUT);
|
||||||
|
|
||||||
|
auto input_tensor = graph->CreateTensor(input_spec);
|
||||||
|
auto output_tensor = graph->CreateTensor(output_spec);
|
||||||
|
|
||||||
|
std::vector<float> in_data = { 0.1, 0.5, 0.9, 1.2, 1.5,
|
||||||
|
1.8, 2.3, 2.5, 2.7, -1.1,
|
||||||
|
-1.5, -1.9, -2.2, -2.5, -2.8 };
|
||||||
|
std::vector<float> golden = {0., 0., 1., 1., 2.,
|
||||||
|
2., 2., 2., 3., -1.,
|
||||||
|
-2., -2., -2., -2., -3. };
|
||||||
|
|
||||||
|
EXPECT_TRUE(input_tensor->CopyDataToTensor(in_data.data(), in_data.size()*4));
|
||||||
|
|
||||||
|
auto add = graph->CreateOperation<tim::vx::ops::Round>();
|
||||||
|
(*add).BindInputs({input_tensor}).BindOutputs({output_tensor});
|
||||||
|
|
||||||
|
EXPECT_TRUE(graph->Compile());
|
||||||
|
EXPECT_TRUE(graph->Run());
|
||||||
|
std::vector<float> output(15, 0);
|
||||||
|
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||||
|
EXPECT_EQ(golden, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Ceil, shape_5_1_fp32) {
|
||||||
|
auto ctx = tim::vx::Context::Create();
|
||||||
|
auto graph = ctx->CreateGraph();
|
||||||
|
|
||||||
|
tim::vx::ShapeType io_shape({5, 1});
|
||||||
|
tim::vx::TensorSpec input_spec(tim::vx::DataType::FLOAT32,
|
||||||
|
io_shape, tim::vx::TensorAttribute::INPUT);
|
||||||
|
tim::vx::TensorSpec output_spec(tim::vx::DataType::FLOAT32,
|
||||||
|
io_shape, tim::vx::TensorAttribute::OUTPUT);
|
||||||
|
|
||||||
|
auto input_tensor = graph->CreateTensor(input_spec);
|
||||||
|
auto output_tensor = graph->CreateTensor(output_spec);
|
||||||
|
|
||||||
|
std::vector<float> in_data = { -2.5, -0.1, 0, 0.55, std::numeric_limits<float>::infinity() };
|
||||||
|
std::vector<float> golden = {-2, 0, 0, 1, std::numeric_limits<float>::infinity() };
|
||||||
|
|
||||||
|
EXPECT_TRUE(input_tensor->CopyDataToTensor(in_data.data(), in_data.size()*4));
|
||||||
|
|
||||||
|
auto add = graph->CreateOperation<tim::vx::ops::Ceil>();
|
||||||
|
(*add).BindInputs({input_tensor}).BindOutputs({output_tensor});
|
||||||
|
|
||||||
|
EXPECT_TRUE(graph->Compile());
|
||||||
|
EXPECT_TRUE(graph->Run());
|
||||||
|
std::vector<float> output(5, 0);
|
||||||
|
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||||
|
EXPECT_EQ(golden, output);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Cast, shape_5_1_fp32_to_int32) {
|
TEST(Cast, shape_5_1_fp32_to_int32) {
|
||||||
auto ctx = tim::vx::Context::Create();
|
auto ctx = tim::vx::Context::Create();
|
||||||
auto graph = ctx->CreateGraph();
|
auto graph = ctx->CreateGraph();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue