MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Replicate

Method Replicate

tensorflow/compiler/xla/literal.h:1054–1086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1052
1053template <typename NativeT>
1054Literal 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

Callers

nothing calls this directly

Calls 9

MakeShapeFunction · 0.85
dimensions_sizeMethod · 0.80
shapeFunction · 0.50
reserveMethod · 0.45
dimensionsMethod · 0.45
push_backMethod · 0.45
element_typeMethod · 0.45
shapeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected