Compute Library
 22.11
WindowIterator.cpp File Reference

Go to the source code of this file.

Functions

template<typename Dim , typename... Dims>
Window create_window (Dim &&dim0, Dims &&... dims)
 
template<typename T >
std::vector< T > create_vector (std::initializer_list< T > list_objs)
 
 DATA_TEST_CASE (WholeWindow, framework::DatasetMode::ALL, zip(framework::dataset::make("Window", { create_window(Window::Dimension(0, 1)), create_window(Window::Dimension(1, 5, 2), Window::Dimension(3, 5)), create_window(Window::Dimension(4, 16, 4), Window::Dimension(3, 13, 5), Window::Dimension(1, 3, 2)) }), framework::dataset::make("Expected", { create_vector({ Coordinates(0, 0) }), create_vector({ Coordinates(1, 3), Coordinates(3, 3), Coordinates(1, 4), Coordinates(3, 4) }), create_vector({ Coordinates(4, 3, 1), Coordinates(8, 3, 1), Coordinates(12, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1) }) })), window, expected)
 
 DATA_TEST_CASE (PartialWindow2D, framework::DatasetMode::ALL, zip(zip(zip(combine(framework::dataset::make("Window", create_window(Window::Dimension(4, 20, 4), Window::Dimension(3, 32, 5), Window::Dimension(1, 2, 1))), framework::dataset::make("Start", { 0, 1, 3, 2, 4 })), framework::dataset::make("End", { 0, 2, 5, 8, 7 })), framework::dataset::make("RowSize", { create_vector({ 4 }), create_vector({ 8, 8 }), create_vector({ 4, 8, 8 }), create_vector({ 8, 8, 16, 16, 16, 16, 4 }), create_vector({ 16, 16, 16, 16 }), })), framework::dataset::make("Expected", { create_vector({ Coordinates(4, 3, 1) }), create_vector({ Coordinates(8, 3, 1), Coordinates(12, 3, 1) }), create_vector({ Coordinates(16, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1) }), create_vector({ Coordinates(12, 3, 1), Coordinates(16, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1), Coordinates(16, 8, 1), Coordinates(4, 13, 1) }), create_vector({ Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1), Coordinates(16, 8, 1) }) })), window, start, end, expected_row_size, expected)
 

Function Documentation

◆ create_vector()

std::vector<T> create_vector ( std::initializer_list< T >  list_objs)

Definition at line 54 of file WindowIterator.cpp.

Referenced by DATA_TEST_CASE().

55 {
56  std::vector<T> vec_objs;
57  for(auto it : list_objs)
58  {
59  vec_objs.push_back(it);
60  }
61  return vec_objs;
62 }

◆ create_window()

Window create_window ( Dim &&  dim0,
Dims &&...  dims 
)

Definition at line 42 of file WindowIterator.cpp.

References Window::set().

Referenced by DATA_TEST_CASE().

43 {
44  Window win;
45  const std::array < Dim, 1 + sizeof...(Dims) > dimensions{ { dim0, std::forward<Dims>(dims)... } };
46  for(size_t i = 0; i < dimensions.size(); i++)
47  {
48  win.set(i, dimensions[i]);
49  }
50  return win;
51 }
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
Describe a multidimensional execution window.
Definition: Window.h:39

◆ DATA_TEST_CASE() [1/2]

DATA_TEST_CASE ( WholeWindow  ,
framework::DatasetMode::ALL  ,
zip(framework::dataset::make("Window", { create_window(Window::Dimension(0, 1)), create_window(Window::Dimension(1, 5, 2), Window::Dimension(3, 5)), create_window(Window::Dimension(4, 16, 4), Window::Dimension(3, 13, 5), Window::Dimension(1, 3, 2)) }), framework::dataset::make("Expected", { create_vector({ Coordinates(0, 0) }), create_vector({ Coordinates(1, 3), Coordinates(3, 3), Coordinates(1, 4), Coordinates(3, 4) }), create_vector({ Coordinates(4, 3, 1), Coordinates(8, 3, 1), Coordinates(12, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1) }) }))  ,
window  ,
expected   
)

Definition at line 64 of file WindowIterator.cpp.

References ARM_COMPUTE_ASSERT, arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::validation::ARM_COMPUTE_EXPECT_EQUAL(), create_vector(), create_window(), arm_compute::create_window_iterator(), arm_compute::mlgo::parser::end(), arm_compute::test::framework::ERRORS, arm_compute::test::validation::expected, arm_compute::index2coords(), arm_compute::test::framework::dataset::make(), and Dimensions< int >::num_max_dimensions.

67  }),
68  framework::dataset::make("Expected", { create_vector({ Coordinates(0, 0) }),
69  create_vector({ Coordinates(1, 3), Coordinates(3, 3), Coordinates(1, 4), Coordinates(3, 4) }),
70  create_vector({ Coordinates(4, 3, 1), Coordinates(8, 3, 1), Coordinates(12, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1) })
71  })),
72  window, expected)
73 {
74  unsigned int i = 0;
75  int row_size = 0;
76  TensorShape window_shape = window.shape();
77  Coordinates start_offset = index2coords(window_shape, 0);
78  Coordinates end_offset = index2coords(window_shape, window.num_iterations_total() - 1);
79  auto window_iterator = create_window_iterator(window, start_offset, end_offset, [&](const Coordinates & id)
80  {
81  ARM_COMPUTE_EXPECT_EQUAL(row_size, (window[0].end() - window[0].start()), framework::LogLevel::ERRORS);
82  ARM_COMPUTE_ASSERT(i < expected.size());
83  Coordinates expected_coords = expected[i++];
84  //Set number of dimensions to the maximum (To match the number of dimensions used by the id passed to the lambda function)
85  expected_coords.set_num_dimensions(Coordinates::num_max_dimensions);
86  ARM_COMPUTE_EXPECT_EQUAL(id, expected_coords, framework::LogLevel::ERRORS);
87  });
88  window_iterator.iterate_3D([&](int start, int end)
89  {
90  ARM_COMPUTE_EXPECT_EQUAL(window[0].start(), start, framework::LogLevel::ERRORS);
91  ARM_COMPUTE_EXPECT_EQUAL(window[0].end(), end, framework::LogLevel::ERRORS);
92  ARM_COMPUTE_EXPECT(end > start, framework::LogLevel::ERRORS);
93  row_size = end - start;
94  });
95  ARM_COMPUTE_EXPECT_EQUAL(i, expected.size(), framework::LogLevel::ERRORS);
96 }
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
Shape of a tensor.
Definition: TensorShape.h:39
Coordinates index2coords(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Helpers.inl:156
WindowIterator< L > create_window_iterator(const Window &w, const Coordinates &start, const Coordinates &end, L &&lambda_function)
Create a WindowIterator object.
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:79
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_EQUAL(X, Y, LEVEL)
Definition: Asserts.h:111
Coordinates of an item.
Definition: Coordinates.h:37
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
std::vector< T > create_vector(std::initializer_list< T > list_objs)
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131
Window create_window(Dim &&dim0, Dims &&... dims)

◆ DATA_TEST_CASE() [2/2]

DATA_TEST_CASE ( PartialWindow2D  ,
framework::DatasetMode::ALL  ,
zip(zip(zip(combine(framework::dataset::make("Window", create_window(Window::Dimension(4, 20, 4), Window::Dimension(3, 32, 5), Window::Dimension(1, 2, 1))), framework::dataset::make("Start", { 0, 1, 3, 2, 4 })), framework::dataset::make("End", { 0, 2, 5, 8, 7 })), framework::dataset::make("RowSize",{ create_vector({ 4 }), create_vector({ 8, 8 }), create_vector({ 4, 8, 8 }), create_vector({ 8, 8, 16, 16, 16, 16, 4 }), create_vector({ 16, 16, 16, 16 }),})), framework::dataset::make("Expected", { create_vector({ Coordinates(4, 3, 1) }), create_vector({ Coordinates(8, 3, 1), Coordinates(12, 3, 1) }), create_vector({ Coordinates(16, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1) }), create_vector({ Coordinates(12, 3, 1), Coordinates(16, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1), Coordinates(16, 8, 1), Coordinates(4, 13, 1) }), create_vector({ Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1), Coordinates(16, 8, 1) }) }))  ,
window  ,
start  ,
end  ,
expected_row_size  ,
expected   
)

Definition at line 98 of file WindowIterator.cpp.

References ARM_COMPUTE_ASSERT, arm_compute::test::validation::ARM_COMPUTE_EXPECT(), arm_compute::test::validation::ARM_COMPUTE_EXPECT_EQUAL(), create_vector(), arm_compute::create_window_iterator(), arm_compute::mlgo::parser::end(), arm_compute::test::framework::ERRORS, arm_compute::test::validation::expected, arm_compute::index2coords(), arm_compute::test::framework::dataset::make(), Dimensions< int >::num_max_dimensions, Dimensions< T >::set_num_dimensions(), and arm_compute::test::validation::TEST_SUITE_END().

100  { 0, 1, 3, 2, 4 })),
101  framework::dataset::make("End", { 0, 2, 5, 8, 7 })),
102  framework::dataset::make("RowSize",
103 {
104  create_vector({ 4 }),
105  create_vector({ 8, 8 }),
106  create_vector({ 4, 8, 8 }),
107  create_vector({ 8, 8, 16, 16, 16, 16, 4 }),
108  create_vector({ 16, 16, 16, 16 }),
109 })),
110 framework::dataset::make("Expected", { create_vector({ Coordinates(4, 3, 1) }), create_vector({ Coordinates(8, 3, 1), Coordinates(12, 3, 1) }), create_vector({ Coordinates(16, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1) }), create_vector({ Coordinates(12, 3, 1), Coordinates(16, 3, 1), Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1), Coordinates(16, 8, 1), Coordinates(4, 13, 1) }), create_vector({ Coordinates(4, 8, 1), Coordinates(8, 8, 1), Coordinates(12, 8, 1), Coordinates(16, 8, 1) }) })),
111 window, start, end, expected_row_size, expected)
112 {
113  unsigned int i = 0;
114  int row_size = 0;
115  TensorShape window_shape = window.shape();
116  Coordinates start_offset = index2coords(window_shape, start);
117  Coordinates end_offset = index2coords(window_shape, end);
118  auto window_iterator = create_window_iterator(window, start_offset, end_offset, [&](const Coordinates & id)
119  {
120  ARM_COMPUTE_ASSERT(i < expected.size());
121  ARM_COMPUTE_EXPECT_EQUAL(expected_row_size[i], row_size, framework::LogLevel::ERRORS);
122  Coordinates expected_coords = expected[i++];
123  //Set number of dimensions to the maximum (To match the number of dimensions used by the id passed to the lambda function)
124  expected_coords.set_num_dimensions(Coordinates::num_max_dimensions);
125  ARM_COMPUTE_EXPECT_EQUAL(id, expected_coords, framework::LogLevel::ERRORS);
126  });
127  window_iterator.iterate_3D([&](int start, int end)
128  {
129  ARM_COMPUTE_EXPECT(start >= window[0].start(), framework::LogLevel::ERRORS);
130  ARM_COMPUTE_EXPECT(end <= window[0].end(), framework::LogLevel::ERRORS);
131  ARM_COMPUTE_EXPECT(end > start, framework::LogLevel::ERRORS);
132  row_size = end - start;
133  });
134  ARM_COMPUTE_EXPECT_EQUAL(i, expected.size(), framework::LogLevel::ERRORS);
135 }
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
Shape of a tensor.
Definition: TensorShape.h:39
Coordinates index2coords(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Helpers.inl:156
WindowIterator< L > create_window_iterator(const Window &w, const Coordinates &start, const Coordinates &end, L &&lambda_function)
Create a WindowIterator object.
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_EQUAL(X, Y, LEVEL)
Definition: Asserts.h:111
Coordinates of an item.
Definition: Coordinates.h:37
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
std::vector< T > create_vector(std::initializer_list< T > list_objs)
#define ARM_COMPUTE_EXPECT(X, LEVEL)
Definition: Asserts.h:131
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
Definition: Dimensions.h:149