diff --git a/include/tim/vx/ops/simple_operations.h b/include/tim/vx/ops/simple_operations.h index 084e377..a1f78d0 100644 --- a/include/tim/vx/ops/simple_operations.h +++ b/include/tim/vx/ops/simple_operations.h @@ -82,6 +82,10 @@ namespace ops { * * 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 * * 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(LogicalNot) DECLARE_SIMPLE_OP(Floor) +DECLARE_SIMPLE_OP(Ceil) +DECLARE_SIMPLE_OP(Round) DECLARE_SIMPLE_OP(Cast) #undef DECLARE_SIMPLE_OP diff --git a/src/tim/vx/ops/simple_operations.cc b/src/tim/vx/ops/simple_operations.cc index 016d86d..43e5974 100644 --- a/src/tim/vx/ops/simple_operations.cc +++ b/src/tim/vx/ops/simple_operations.cc @@ -49,6 +49,8 @@ DEFINE_SIMPLE_OP(Rsqrt, VSI_NN_OP_RSQRT) DEFINE_SIMPLE_OP(Square, VSI_NN_OP_SQUARE) DEFINE_SIMPLE_OP(LogicalNot, VSI_NN_OP_LOGICAL_NOT) 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) #undef DEFINE_SIMPLE_OP diff --git a/src/tim/vx/ops/simple_operations_test.cc b/src/tim/vx/ops/simple_operations_test.cc index af58062..6c4828c 100644 --- a/src/tim/vx/ops/simple_operations_test.cc +++ b/src/tim/vx/ops/simple_operations_test.cc @@ -56,6 +56,66 @@ TEST(Floor, shape_5_1_fp32) { 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 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 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(); + (*add).BindInputs({input_tensor}).BindOutputs({output_tensor}); + + EXPECT_TRUE(graph->Compile()); + EXPECT_TRUE(graph->Run()); + std::vector 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 in_data = { -2.5, -0.1, 0, 0.55, std::numeric_limits::infinity() }; + std::vector golden = {-2, 0, 0, 1, std::numeric_limits::infinity() }; + + EXPECT_TRUE(input_tensor->CopyDataToTensor(in_data.data(), in_data.size()*4)); + + auto add = graph->CreateOperation(); + (*add).BindInputs({input_tensor}).BindOutputs({output_tensor}); + + EXPECT_TRUE(graph->Compile()); + EXPECT_TRUE(graph->Run()); + std::vector output(5, 0); + EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data())); + EXPECT_EQ(golden, output); +} + TEST(Cast, shape_5_1_fp32_to_int32) { auto ctx = tim::vx::Context::Create(); auto graph = ctx->CreateGraph();