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

Method ValidateShapeSize

tensorflow/compiler/xla/shape_util.cc:713–746  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

711}
712
713/* static */ Status ShapeUtil::ValidateShapeSize(const Shape& shape) {
714 VLOG(3) << "Validating shape size: " << ShapeUtil::HumanString(shape);
715
716 if (!shape.IsArray()) {
717 return Status::OK();
718 }
719
720 int64 shape_size = [&]() {
721 int64 dense_shape_size = 1;
722 if (shape.dimensions().empty()) {
723 return dense_shape_size;
724 }
725
726 absl::Span<const int64> shape_max_dimensions =
727 AsInt64Slice(shape.dimensions());
728 for (int64 dim : shape_max_dimensions) {
729 dense_shape_size = MultiplyWithoutOverflow(dense_shape_size, dim);
730 if (dense_shape_size < 0) {
731 return dense_shape_size;
732 }
733 }
734 dense_shape_size = MultiplyWithoutOverflow(
735 dense_shape_size, ByteSizeOfPrimitiveType(shape.element_type()));
736 return dense_shape_size;
737 }();
738
739 if (shape_size < 0) {
740 return InvalidArgument("Shape %s size may overflow int64.",
741 ShapeUtil::HumanString(shape));
742 }
743
744 VLOG(3) << "Shape size is valid: " << shape_size;
745 return Status::OK();
746}
747
748/* static */ Status ShapeUtil::ValidateShapeWithOptionalLayout(
749 const Shape& shape) {

Callers

nothing calls this directly

Calls 8

ByteSizeOfPrimitiveTypeFunction · 0.85
InvalidArgumentFunction · 0.85
AsInt64SliceFunction · 0.70
MultiplyWithoutOverflowFunction · 0.70
IsArrayMethod · 0.45
emptyMethod · 0.45
dimensionsMethod · 0.45
element_typeMethod · 0.45

Tested by

no test coverage detected