| 19 | using std::vector; |
| 20 | |
| 21 | TEST(MatrixManipulation, SNIPPET_matrix_manipulation_tile) { |
| 22 | //! [ex_matrix_manipulation_tile] |
| 23 | float h[] = {1, 2, 3, 4}; |
| 24 | array small_arr = array(2, 2, h); // 2x2 matrix |
| 25 | af_print(small_arr); |
| 26 | array large_arr = |
| 27 | tile(small_arr, 2, 3); // produces 4x6 matrix: (2*2)x(2*3) |
| 28 | af_print(large_arr); |
| 29 | //! [ex_matrix_manipulation_tile] |
| 30 | |
| 31 | ASSERT_EQ(4, large_arr.dims(0)); |
| 32 | ASSERT_EQ(6, large_arr.dims(1)); |
| 33 | |
| 34 | vector<float> h_large_arr(large_arr.elements()); |
| 35 | large_arr.host(&h_large_arr.front()); |
| 36 | |
| 37 | unsigned fdim = large_arr.dims(0); |
| 38 | unsigned sdim = large_arr.dims(1); |
| 39 | for (unsigned i = 0; i < sdim; i++) { |
| 40 | for (unsigned j = 0; j < fdim; j++) { |
| 41 | ASSERT_FLOAT_EQ(h[(i % 2) * 2 + (j % 2)], |
| 42 | h_large_arr[i * fdim + j]); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | TEST(MatrixManipulation, SNIPPET_matrix_manipulation_join) { |
| 48 | //! [ex_matrix_manipulation_join] |