static */
| 1046 | } |
| 1047 | |
| 1048 | /* static */ std::vector<std::pair<int64, int64>> |
| 1049 | ShapeUtil::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>> |
| 1072 | ShapeUtil::ReshapeLeavesDimensionsUnmodified( |
nothing calls this directly
no test coverage detected