A ShapeLayout object encapsulates the layout of a particular shape (including tuples). This differs from the Layout proto which describes the layout of a single array. ShapeLayout contains a Layout proto for each array in the shape (a tuple can have more than one array). For array shapes, this object trivially holds a single Layout. Logically, ShapeLayout holds a nonmutable shape with mutable layo
| 32 | // trivially holds a single Layout. Logically, ShapeLayout holds a nonmutable |
| 33 | // shape with mutable layouts. |
| 34 | class ShapeLayout { |
| 35 | public: |
| 36 | // Constructs a ShapeLayout of the given shape. Layouts are copied from the |
| 37 | // shape parameter. |
| 38 | explicit ShapeLayout(const Shape& shape) : shape_(shape) {} |
| 39 | |
| 40 | // Assigns the layouts in this ShapeLayout to the Layout fields of the given |
| 41 | // shape. 'to_shape' and the shape of the ShapeLayout object must be |
| 42 | // compatible. |
| 43 | Status AssignLayoutToShape(Shape* to_shape) const; |
| 44 | |
| 45 | // Returns true if the Layouts in this ShapeLayout match the layouts in the |
| 46 | // given shape. Returns false otherwise. If the given shape is not compatible |
| 47 | // with the ShapeLayout's shape, then false is returned. |
| 48 | bool MatchesLayoutInShape(const Shape& shape, |
| 49 | bool minor_to_major_only = false) const; |
| 50 | |
| 51 | // Copies the layout from the given shape into this ShapeLayout. 'other_shape' |
| 52 | // must be compatible with the ShapeLayout's shape. |
| 53 | Status CopyLayoutFromShape(const Shape& other_shape); |
| 54 | |
| 55 | // Clears (Layout::Clear) all the Layouts stored in this object. |
| 56 | void Clear(); |
| 57 | |
| 58 | // Sets all Layouts stored in this object to the default layout. |
| 59 | void SetToDefaultLayout(); |
| 60 | |
| 61 | // Returns the shape (with layouts). |
| 62 | const Shape& shape() const { return shape_; } |
| 63 | |
| 64 | // Checks that a layout is set for the shape, and returns a reference to the |
| 65 | // layout directly on the shape. Shape must not be a tuple. |
| 66 | const Layout& layout() const; |
| 67 | |
| 68 | // Returns true if all layouts have been set for this ShapeLayout object. That |
| 69 | // is, every array has a layout. |
| 70 | bool LayoutIsSet() const; |
| 71 | |
| 72 | // Resets the layout on the shape to the provided layout. Shape must not be a |
| 73 | // tuple. |
| 74 | void ResetLayout(const Layout& layout); |
| 75 | |
| 76 | // Resets the layout on the shape at the provided ShapeIndex to the provided |
| 77 | // layout. Shape must be a tuple. |
| 78 | void ResetLayout(const Layout& layout, ShapeIndexView shape_index); |
| 79 | |
| 80 | // Returns a string representation of this object. |
| 81 | string ToString() const { return ShapeUtil::HumanStringWithLayout(shape_); } |
| 82 | |
| 83 | // Tests for equality of both shape and layout (ShapeUtil::Equal). |
| 84 | bool operator==(const ShapeLayout& other) const; |
| 85 | bool operator!=(const ShapeLayout& other) const; |
| 86 | |
| 87 | private: |
| 88 | Shape shape_; |
| 89 | }; |
| 90 | |
| 91 | } // namespace xla |
no outgoing calls