| 99 | // with dimensions n1 x n2. |
| 100 | template <typename NativeT = float> |
| 101 | std::unique_ptr<Array2D<NativeT>> MakeLinspaceArray2D(double from, double to, |
| 102 | int64 n1, int64 n2) { |
| 103 | auto array = absl::make_unique<Array2D<NativeT>>(n1, n2); |
| 104 | int64 count = n1 * n2; |
| 105 | NativeT step = |
| 106 | static_cast<NativeT>((count > 1) ? (to - from) / (count - 1) : 0); |
| 107 | auto set = [&array, n2](int64 index, NativeT value) { |
| 108 | (*array)(index / n2, index % n2) = value; |
| 109 | }; |
| 110 | for (int64 i = 0; i < count - 1; ++i) { |
| 111 | set(i, (static_cast<NativeT>(from) + |
| 112 | static_cast<NativeT>(i) * static_cast<NativeT>(step))); |
| 113 | } |
| 114 | set(count - 1, static_cast<NativeT>(to)); |
| 115 | return array; |
| 116 | } |
| 117 | } // namespace xla |
| 118 | |
| 119 | #endif // TENSORFLOW_COMPILER_XLA_ARRAY2D_H_ |
no outgoing calls