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

Method DimensionsUnmodifiedByReshape

tensorflow/compiler/xla/shape_util.cc:1048–1069  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

1046}
1047
1048/* static */ std::vector<std::pair<int64, int64>>
1049ShapeUtil::DimensionsUnmodifiedByReshape(const Shape& input_shape,
1050 const Shape& output_shape) {
1051 CHECK(input_shape.IsArray());
1052 CHECK(output_shape.IsArray());
1053
1054 // Unmodified dimensions are merely common factors of rank 1.
1055 auto common_factors = CommonFactors(AsInt64Slice(input_shape.dimensions()),
1056 AsInt64Slice(output_shape.dimensions()));
1057 for (size_t i = 0; i < common_factors.size() - 1;) {
1058 if (1 != common_factors[i + 1].first - common_factors[i].first ||
1059 1 != common_factors[i + 1].second - common_factors[i].second) {
1060 common_factors.erase(common_factors.begin() + i);
1061 } else {
1062 ++i;
1063 }
1064 }
1065 // `CommonFactors(a, b).back() == (a.rank, b.rank)` so we must pop it.
1066 common_factors.pop_back();
1067 return std::vector<std::pair<int64, int64>>(common_factors.begin(),
1068 common_factors.end());
1069}
1070
1071/* static */ absl::optional<std::vector<int64>>
1072ShapeUtil::ReshapeLeavesDimensionsUnmodified(

Callers

nothing calls this directly

Calls 9

CommonFactorsFunction · 0.85
pop_backMethod · 0.80
AsInt64SliceFunction · 0.70
IsArrayMethod · 0.45
dimensionsMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected