MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CopyLayoutInternal

Function CopyLayoutInternal

tensorflow/compiler/xla/layout_util.cc:359–387  ·  view source on GitHub ↗

Internal helper for recursively copying layouts.

Source from the content-addressed store, hash-verified

357
358// Internal helper for recursively copying layouts.
359Status 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

Callers 1

Calls 9

InvalidArgumentFunction · 0.85
mutable_tuple_shapesMethod · 0.80
has_layoutMethod · 0.80
mutable_layoutMethod · 0.80
clear_layoutMethod · 0.80
IsTupleMethod · 0.45
tuple_shapesMethod · 0.45
rankMethod · 0.45
layoutMethod · 0.45

Tested by

no test coverage detected