| 117 | } |
| 118 | |
| 119 | bool Shape::Equal::operator()(const Shape& lhs, const Shape& rhs) { |
| 120 | if (lhs.IsTuple()) { |
| 121 | return rhs.IsTuple() && |
| 122 | absl::c_equal( |
| 123 | lhs.tuple_shapes(), rhs.tuple_shapes(), |
| 124 | [=](const Shape& l, const Shape& r) { return (*this)(l, r); }); |
| 125 | } else if (!lhs.IsArray()) { |
| 126 | // Non-tuple, non-array tupes such as opaque and token types are trivially |
| 127 | // the same. |
| 128 | return lhs.element_type() == rhs.element_type(); |
| 129 | } |
| 130 | |
| 131 | if (!rhs.IsArray()) { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | if (!ignore_element_type_) { |
| 136 | if ((ignore_fp_precision_ && |
| 137 | !ShapeUtil::SameElementTypeIgnoringFpPrecision(lhs, rhs)) || |
| 138 | (!ignore_fp_precision_ && !ShapeUtil::SameElementType(lhs, rhs))) { |
| 139 | VLOG(3) << "CompareShapes: lhs element type != rhs element type"; |
| 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (!ShapeUtil::SameDimensions(lhs, rhs)) { |
| 145 | VLOG(3) << "CompareShapes: lhs dimensions != rhs dimensions"; |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | if (!ignore_layout_) { |
| 150 | if (lhs.layout().format() != rhs.layout().format()) { |
| 151 | VLOG(3) << "CompareShapes: lhs layout format != rhs layout format"; |
| 152 | return false; |
| 153 | } |
| 154 | if (LayoutUtil::IsDenseArray(lhs)) { |
| 155 | Layout::Equal equal; |
| 156 | if (ignore_tiles_in_layout_) { |
| 157 | equal.IgnoreTiles(); |
| 158 | } |
| 159 | if (ignore_element_size_in_layout_) { |
| 160 | equal.IgnoreElementSize(); |
| 161 | } |
| 162 | if (ignore_memory_space_in_layout_) { |
| 163 | equal.IgnoreMemorySpace(); |
| 164 | } |
| 165 | if (!equal(lhs.layout(), rhs.layout())) { |
| 166 | VLOG(3) << "CompareShapes: lhs layout != rhs layout"; |
| 167 | return false; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (!ignore_dynamic_dimension_) { |
| 173 | for (int i = 0; i < lhs.rank(); ++i) { |
| 174 | if (lhs.is_dynamic_dimension(i) != rhs.is_dynamic_dimension(i)) { |
| 175 | VLOG(3) |
| 176 | << "CompareShapes: lhs and rhs have different dynamic dimensions."; |
no test coverage detected