| 56 | } |
| 57 | |
| 58 | ShapeProto Shape::ToProto() const { |
| 59 | ShapeProto proto; |
| 60 | proto.set_element_type(element_type_); |
| 61 | proto.mutable_dimensions()->Reserve(dimensions_size()); |
| 62 | for (const int64 dimension : dimensions()) { |
| 63 | proto.add_dimensions(dimension); |
| 64 | } |
| 65 | for (const bool dynamic : dynamic_dimensions_) { |
| 66 | proto.add_is_dynamic_dimension(dynamic); |
| 67 | } |
| 68 | proto.mutable_tuple_shapes()->Reserve(tuple_shapes_size()); |
| 69 | for (const Shape& shape : tuple_shapes()) { |
| 70 | *proto.add_tuple_shapes() = shape.ToProto(); |
| 71 | } |
| 72 | if (has_layout()) { |
| 73 | *proto.mutable_layout() = layout().ToProto(); |
| 74 | } |
| 75 | return proto; |
| 76 | } |
| 77 | |
| 78 | string Shape::ToString(bool print_layout) const { |
| 79 | if (print_layout) { |