| 27 | |
| 28 | template <typename T> |
| 29 | void RunTestPermutation(const std::vector<int>& shape, |
| 30 | const std::vector<int>& perms, |
| 31 | std::vector<T>* input_transposed) { |
| 32 | // Count elements and allocate output. |
| 33 | int count = 1; |
| 34 | for (auto factor : shape) count *= factor; |
| 35 | input_transposed->resize(count); |
| 36 | |
| 37 | // Create the dummy data |
| 38 | std::vector<T> input(count); |
| 39 | for (int i = 0; i < input.size(); i++) { |
| 40 | input[i] = i; |
| 41 | } |
| 42 | |
| 43 | // Make input and output shapes. |
| 44 | const RuntimeShape input_shape = GetTensorShape(shape); |
| 45 | RuntimeShape output_shape(perms.size()); |
| 46 | for (int i = 0; i < perms.size(); i++) { |
| 47 | output_shape.SetDim(i, input_shape.Dims(perms[i])); |
| 48 | } |
| 49 | |
| 50 | TransposeParams params; |
| 51 | params.perm_count = perms.size(); |
| 52 | for (int i = 0; i < perms.size(); ++i) { |
| 53 | params.perm[i] = perms[i]; |
| 54 | } |
| 55 | |
| 56 | reference_ops::Transpose<T>(params, input_shape, input.data(), output_shape, |
| 57 | input_transposed->data()); |
| 58 | } |
| 59 | |
| 60 | TEST(TransposeTest, TestRefOps1D) { |
| 61 | // Basic 1D identity. |