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

Method TransposeIsBitcast

tensorflow/compiler/xla/shape_util.cc:1097–1125  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

1095}
1096
1097/* static */ bool ShapeUtil::TransposeIsBitcast(
1098 const Shape& input_shape, const Shape& output_shape,
1099 absl::Span<const int64> dimension_mapping) {
1100 CHECK(LayoutUtil::HasLayout(input_shape) &&
1101 LayoutUtil::HasLayout(output_shape));
1102
1103 if (!SameElementType(input_shape, output_shape)) {
1104 return false;
1105 }
1106
1107 // Check the reshape permutes the positions of each dimension in the
1108 // minor-to-major order. positions[i]=k means dimension `i` is k-th minor.
1109 // input_positions = apply(dimension_mapping, output_positions)
1110 //
1111 // Because the positions of each dimension are the inverse permutation of the
1112 // minor-to-major order, the above check is equivalent to
1113 // inverse(input_dimensions) =
1114 // apply(dimension_mapping, inverse(output_dimensions))
1115 // # `I` indicates identity permutation.
1116 // apply(input_dimensions, I) =
1117 // apply(dimension_mapping, apply(output_dimensions, I))
1118 // apply(input_dimensions, I) =
1119 // apply((dimension_mapping * output_dimensions), I)
1120 // input_dimensions = dimension_mapping * output_dimensions
1121 return absl::c_equal(
1122 ComposePermutations(dimension_mapping,
1123 AsInt64Slice(output_shape.layout().minor_to_major())),
1124 input_shape.layout().minor_to_major());
1125}
1126
1127/* static */ bool ShapeUtil::ReshapeIsBitcast(const Shape& input_shape,
1128 const Shape& output_shape) {

Callers

nothing calls this directly

Calls 4

ComposePermutationsFunction · 0.85
minor_to_majorMethod · 0.80
AsInt64SliceFunction · 0.70
layoutMethod · 0.45

Tested by

no test coverage detected