| 1052 | |
| 1053 | template <typename NativeT> |
| 1054 | Literal LiteralBase::Replicate(int64 times) const { |
| 1055 | DimensionVector bounds = {times}; |
| 1056 | bounds.reserve(shape().dimensions_size() + 1); |
| 1057 | for (int64 bound : shape().dimensions()) { |
| 1058 | bounds.push_back(bound); |
| 1059 | } |
| 1060 | Literal literal(ShapeUtil::MakeShape(shape().element_type(), bounds)); |
| 1061 | int64 elements = ShapeUtil::ElementsIn(literal.shape()); |
| 1062 | if (elements == 0) { |
| 1063 | return literal; |
| 1064 | } |
| 1065 | |
| 1066 | DimensionVector output_indices(bounds.size(), 0); |
| 1067 | absl::Span<const int64> input_indices = output_indices; |
| 1068 | input_indices.remove_prefix(1); |
| 1069 | |
| 1070 | bool done = false; |
| 1071 | while (!done) { |
| 1072 | const auto element = Get<NativeT>(input_indices); |
| 1073 | literal.Set<NativeT>(output_indices, element); |
| 1074 | |
| 1075 | done = true; |
| 1076 | for (int n = 0; n < output_indices.size(); ++n) { |
| 1077 | ++output_indices[n]; |
| 1078 | if (output_indices[n] < bounds[n]) { |
| 1079 | done = false; |
| 1080 | break; |
| 1081 | } |
| 1082 | output_indices[n] = 0; |
| 1083 | } |
| 1084 | } |
| 1085 | return literal; |
| 1086 | } |
| 1087 | |
| 1088 | } // namespace xla |
| 1089 |
nothing calls this directly
no test coverage detected