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

Method Reshape

tensorflow/compiler/xla/literal.cc:642–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

640}
641
642StatusOr<Literal> LiteralBase::Reshape(
643 absl::Span<const int64> dimensions) const {
644 if (!shape().IsArray()) {
645 return InvalidArgument("Reshape does not support tuples.");
646 }
647 Literal output;
648 if (!LayoutUtil::IsMonotonicWithDim0Major(shape().layout())) {
649 output = Relayout(LayoutUtil::GetDefaultLayoutForRank(shape().rank()));
650 } else {
651 output = Clone();
652 }
653 // Because the layout is monotonic, we can simply reuse the same sequence of
654 // values without changing their order.
655 *output.mutable_shape_do_not_use() =
656 ShapeUtil::MakeShape(shape().element_type(), dimensions);
657
658 int64 elements_before = ShapeUtil::ElementsIn(shape());
659 int64 elements_after = ShapeUtil::ElementsIn(output.shape());
660 if (elements_before != elements_after) {
661 return InvalidArgument(
662 "Shapes before and after Literal::Reshape have different numbers "
663 "of elements: %s vs %s.",
664 ShapeUtil::HumanString(shape()),
665 ShapeUtil::HumanString(output.shape()));
666 }
667 return std::move(output);
668}
669
670Literal LiteralBase::Transpose(absl::Span<const int64> permutation) const {
671 CHECK(shape().IsArray()) << "Tuple is not supported for transpose";

Callers 7

model_fnMethod · 0.45
create_modelFunction · 0.45
create_modelFunction · 0.45
model_fnMethod · 0.45
TEST_FFunction · 0.45
create_modelFunction · 0.45
trainFunction · 0.45

Calls 9

InvalidArgumentFunction · 0.85
MakeShapeFunction · 0.85
shapeFunction · 0.50
IsArrayMethod · 0.45
layoutMethod · 0.45
rankMethod · 0.45
element_typeMethod · 0.45
shapeMethod · 0.45

Tested by 3

model_fnMethod · 0.36
model_fnMethod · 0.36
TEST_FFunction · 0.36