Compute Library
 22.11
Utils.cpp File Reference

Go to the source code of this file.

Functions

 DATA_TEST_CASE (RoundHalfUp, framework::DatasetMode::ALL, zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -3.f, -4.f, -4.f, -4.f })), value, result)
 
 DATA_TEST_CASE (RoundHalfEven, framework::DatasetMode::ALL, zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 2.f, 3.f, -3.f, -4.f, -4.f, -4.f, -4.f })), value, result)
 
 DATA_TEST_CASE (Index2Coord, framework::DatasetMode::ALL, zip(zip(framework::dataset::make("Shape", { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), framework::dataset::make("Index", { 0, 1, 2 })), framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })), shape, index, ref_coordinate)
 
 DATA_TEST_CASE (RoundFloatToZero, framework::DatasetMode::ALL, zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 1.f, 2.f, 2.f, -3.f, -3.f, -3.f, -4.f, -4.f })), value, result)
 
 DATA_TEST_CASE (RoundFloatToNearestUp, framework::DatasetMode::ALL, zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -4.f, -4.f, -4.f, -5.f })), value, result)
 
 DATA_TEST_CASE (Coord2Index, framework::DatasetMode::ALL, zip(zip(framework::dataset::make("Shape", { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })), framework::dataset::make("Index", { 0, 1, 2 })), shape, coordinate, ref_index)
 

Function Documentation

◆ DATA_TEST_CASE() [1/6]

DATA_TEST_CASE ( RoundHalfUp  ,
framework::DatasetMode::ALL  ,
zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -3.f, -4.f, -4.f, -4.f }))  ,
value  ,
result   
)

Definition at line 40 of file Utils.cpp.

References arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::framework::ERRORS, arm_compute::test::framework::dataset::make(), and arm_compute::test::round_half_up().

40  { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }),
41  framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -3.f, -4.f, -4.f, -4.f })),
42  value, result)
43 {
44  ARM_COMPUTE_EXPECT(round_half_up(value) == result, framework::LogLevel::ERRORS);
45 }
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131
T round_half_up(T value)
Round floating-point value with half value rounding to positive infinity.
Definition: Utils.h:69

◆ DATA_TEST_CASE() [2/6]

DATA_TEST_CASE ( RoundHalfEven  ,
framework::DatasetMode::ALL  ,
zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 2.f, 3.f, -3.f, -4.f, -4.f, -4.f, -4.f }))  ,
value  ,
result   
)

Definition at line 47 of file Utils.cpp.

References arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::framework::ERRORS, arm_compute::test::framework::dataset::make(), and arm_compute::test::round_half_even().

47  { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }),
48  framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 2.f, 3.f, -3.f, -4.f, -4.f, -4.f, -4.f })),
49  value, result)
50 {
51  ARM_COMPUTE_EXPECT(round_half_even(value) == result, framework::LogLevel::ERRORS);
52 }
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
T round_half_even(T value, T epsilon=std::numeric_limits< T >::epsilon())
Round floating-point value with half value rounding to nearest even.
Definition: Utils.h:82
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131

◆ DATA_TEST_CASE() [3/6]

DATA_TEST_CASE ( Index2Coord  ,
framework::DatasetMode::ALL  ,
zip(zip(framework::dataset::make("Shape", { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), framework::dataset::make("Index", { 0, 1, 2 })), framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } }))  ,
shape  ,
index  ,
ref_coordinate   
)

Definition at line 54 of file Utils.cpp.

References arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::validation::compare_dimensions(), arm_compute::test::framework::ERRORS, arm_compute::test::index2coord(), arm_compute::test::framework::dataset::make(), arm_compute::test::validation::shape, and arm_compute::utils::cast::U.

54  { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), framework::dataset::make("Index", { 0, 1, 2 })),
55  framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })),
56  shape, index, ref_coordinate)
57 {
58  Coordinates coordinate = index2coord(shape, index);
59 
60  ARM_COMPUTE_EXPECT(compare_dimensions(coordinate, ref_coordinate), framework::LogLevel::ERRORS);
61 }
Shape of a tensor.
Definition: TensorShape.h:39
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
bool compare_dimensions(const Dimensions< T > &dimensions1, const Dimensions< T > &dimensions2, const DataLayout &data_layout=DataLayout::NCHW)
Definition: Validation.h:150
Coordinates of an item.
Definition: Coordinates.h:37
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131

◆ DATA_TEST_CASE() [4/6]

DATA_TEST_CASE ( RoundFloatToZero  ,
framework::DatasetMode::ALL  ,
zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 1.f, 2.f, 2.f, -3.f, -3.f, -3.f, -4.f, -4.f }))  ,
value  ,
result   
)

Definition at line 63 of file Utils.cpp.

References arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::framework::ERRORS, arm_compute::test::framework::dataset::make(), arm_compute::round(), and arm_compute::TO_ZERO.

63  { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }),
64  framework::dataset::make("FloatOut", { 1.f, 1.f, 1.f, 2.f, 2.f, -3.f, -3.f, -3.f, -4.f, -4.f })),
65  value, result)
66 {
67  ARM_COMPUTE_EXPECT(round(value, RoundingPolicy::TO_ZERO) == result, framework::LogLevel::ERRORS);
68 }
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131

◆ DATA_TEST_CASE() [5/6]

DATA_TEST_CASE ( RoundFloatToNearestUp  ,
framework::DatasetMode::ALL  ,
zip(framework::dataset::make("FloatIn", { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }), framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -4.f, -4.f, -4.f, -5.f }))  ,
value  ,
result   
)

Definition at line 70 of file Utils.cpp.

References arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::framework::ERRORS, arm_compute::test::framework::dataset::make(), arm_compute::round(), and arm_compute::TO_NEAREST_UP.

70  { 1.f, 1.2f, 1.5f, 2.5f, 2.9f, -3.f, -3.5f, -3.8f, -4.3f, -4.5f }),
71  framework::dataset::make("FloatOut", { 1.f, 1.f, 2.f, 3.f, 3.f, -3.f, -4.f, -4.f, -4.f, -5.f })),
72  value, result)
73 {
74  ARM_COMPUTE_EXPECT(round(value, RoundingPolicy::TO_NEAREST_UP) == result, framework::LogLevel::ERRORS);
75 }
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131

◆ DATA_TEST_CASE() [6/6]

DATA_TEST_CASE ( Coord2Index  ,
framework::DatasetMode::ALL  ,
zip(zip(framework::dataset::make("Shape", { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }), framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })), framework::dataset::make("Index", { 0, 1, 2 }))  ,
shape  ,
coordinate  ,
ref_index   
)

Definition at line 77 of file Utils.cpp.

References arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::coord2index(), arm_compute::test::framework::ERRORS, arm_compute::test::framework::dataset::make(), arm_compute::test::validation::shape, arm_compute::test::validation::TEST_SUITE_END(), and arm_compute::utils::cast::U.

77  { TensorShape{ 1U }, TensorShape{ 2U }, TensorShape{ 2U, 3U } }),
78  framework::dataset::make("Coordinates", { Coordinates{ 0 }, Coordinates{ 1 }, Coordinates{ 0, 1 } })),
79  framework::dataset::make("Index", { 0, 1, 2 })),
80  shape, coordinate, ref_index)
81 {
82  int index = coord2index(shape, coordinate);
83 
84  ARM_COMPUTE_EXPECT(index == ref_index, framework::LogLevel::ERRORS);
85 }
Shape of a tensor.
Definition: TensorShape.h:39
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
Definition: Utils.h:388
Coordinates of an item.
Definition: Coordinates.h:37
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131