Internal helper for recursively copying layouts.
| 357 | |
| 358 | // Internal helper for recursively copying layouts. |
| 359 | Status CopyLayoutInternal(const Shape& src, Shape* dst) { |
| 360 | if (src.IsTuple() != dst->IsTuple()) { |
| 361 | return InvalidArgument( |
| 362 | "cannot copy layout from shape: shape structure differs"); |
| 363 | } |
| 364 | if (src.IsTuple()) { |
| 365 | if (ShapeUtil::TupleElementCount(src) != |
| 366 | ShapeUtil::TupleElementCount(*dst)) { |
| 367 | return InvalidArgument( |
| 368 | "cannot copy layout from shape: tuple element count differs"); |
| 369 | } |
| 370 | for (int64 i = 0; i < ShapeUtil::TupleElementCount(src); ++i) { |
| 371 | TF_RETURN_IF_ERROR(CopyLayoutInternal(src.tuple_shapes(i), |
| 372 | dst->mutable_tuple_shapes(i))); |
| 373 | } |
| 374 | } else { |
| 375 | if (src.has_layout()) { |
| 376 | if (src.rank() != dst->rank()) { |
| 377 | return InvalidArgument("cannot copy layout from shape: ranks differs"); |
| 378 | } |
| 379 | TF_RETURN_IF_ERROR( |
| 380 | LayoutUtil::ValidateLayoutForShape(src.layout(), *dst)); |
| 381 | *dst->mutable_layout() = src.layout(); |
| 382 | } else { |
| 383 | dst->clear_layout(); |
| 384 | } |
| 385 | } |
| 386 | return Status::OK(); |
| 387 | } |
| 388 | |
| 389 | } // namespace |
| 390 |
no test coverage detected