Constructs and returns the new shape with the given minor_to_major order in its Layout.
| 89 | // Constructs and returns the new shape with the given minor_to_major order in |
| 90 | // its Layout. |
| 91 | StatusOr<Shape> MakeShapeWithLayoutInternal( |
| 92 | PrimitiveType element_type, absl::Span<const int64> dimensions, |
| 93 | absl::Span<const int64> minor_to_major, absl::Span<const Tile> tiles, |
| 94 | int64 element_size_in_bits, int64 memory_space) { |
| 95 | if (dimensions.size() != minor_to_major.size()) { |
| 96 | return InvalidArgument("Dimensions size is %ld, but layout size is %ld.", |
| 97 | dimensions.size(), minor_to_major.size()); |
| 98 | } |
| 99 | if (element_type == OPAQUE_TYPE || element_type == TUPLE) { |
| 100 | return InvalidArgument("Unsupported element type: %s", |
| 101 | PrimitiveType_Name(element_type)); |
| 102 | } |
| 103 | TF_ASSIGN_OR_RETURN(Shape shape, |
| 104 | ShapeUtil::MakeValidatedShape(element_type, dimensions)); |
| 105 | if (element_size_in_bits == |
| 106 | ShapeUtil::ByteSizeOfPrimitiveType(element_type) * 8) { |
| 107 | // Only set element_size_in_bits if it's different from the default value. |
| 108 | element_size_in_bits = 0; |
| 109 | } |
| 110 | *shape.mutable_layout() = LayoutUtil::MakeLayout( |
| 111 | minor_to_major, tiles, element_size_in_bits, memory_space); |
| 112 | if (!shape.has_layout()) { |
| 113 | return InvalidArgument("Shape has no layout."); |
| 114 | } |
| 115 | TF_RETURN_IF_ERROR(ShapeUtil::ValidateShape(shape)); |
| 116 | return shape; |
| 117 | } |
| 118 | } // namespace |
| 119 | |
| 120 | /* static */ bool ShapeUtil::Equal(const Shape& lhs, const Shape& rhs) { |
no test coverage detected