static */
| 492 | } |
| 493 | |
| 494 | /* static */ string ShapeUtil::HumanStringWithLayout(const Shape& shape) { |
| 495 | if (shape.IsTuple()) { |
| 496 | string text = "("; |
| 497 | const char* prefix = ""; |
| 498 | for (const Shape& elem_shape : shape.tuple_shapes()) { |
| 499 | StrAppend(&text, prefix, HumanStringWithLayout(elem_shape)); |
| 500 | prefix = ", "; |
| 501 | } |
| 502 | text += ")"; |
| 503 | return text; |
| 504 | } |
| 505 | string result = StrCat( |
| 506 | primitive_util::LowercasePrimitiveTypeName(shape.element_type()), "["); |
| 507 | for (int i = 0; i < shape.dimensions().size(); i++) { |
| 508 | StrAppend(&result, (i > 0) ? "," : "", |
| 509 | shape.is_dynamic_dimension(i) ? "<=" : "", shape.dimensions(i)); |
| 510 | } |
| 511 | result += "]"; |
| 512 | if (IsScalar(shape)) { |
| 513 | string layout_str = LayoutUtil::HumanString(shape.layout()); |
| 514 | // Don't print "{}" as layout for scalars. |
| 515 | if (layout_str != "{}") { |
| 516 | StrAppend(&result, layout_str); |
| 517 | } |
| 518 | } else if (shape.IsArray() && LayoutUtil::HasLayout(shape)) { |
| 519 | StrAppend(&result, LayoutUtil::HumanString(shape.layout())); |
| 520 | } |
| 521 | return result; |
| 522 | } |
| 523 | |
| 524 | /* static */ string ShapeUtil::HumanString(const ProgramShape& program_shape) { |
| 525 | std::vector<string> parameters; |
nothing calls this directly
no test coverage detected