| 49 | // random_func returns the generated random element at given index. |
| 50 | template <typename T> |
| 51 | std::vector<T> GenerateRandomTensor(const std::vector<int>& shape, |
| 52 | const std::function<T(int)>& random_func) { |
| 53 | int64_t num_elements = 1; |
| 54 | for (const int dim : shape) { |
| 55 | num_elements *= dim; |
| 56 | } |
| 57 | |
| 58 | std::vector<T> result(num_elements); |
| 59 | for (int i = 0; i < num_elements; i++) { |
| 60 | result[i] = random_func(i); |
| 61 | } |
| 62 | return result; |
| 63 | } |
| 64 | |
| 65 | } // namespace testing |
| 66 | } // namespace tflite |