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

Function MakeShapeHelper

tensorflow/core/framework/tensor_shape.cc:696–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

694
695template <typename T, class Shape>
696Status MakeShapeHelper(const T* dims, int64 n, Shape* out) {
697 out->Clear();
698 if (n > TensorShape::MaxDimensions()) {
699 return errors::InvalidArgument("Too many dimensions");
700 }
701 if (n < 0) {
702 return errors::InvalidArgument("Negative number of dimensions ", n);
703 }
704 for (int64 i = 0; i < n; ++i) {
705 T dim = internal::SubtleMustCopy(dims[i]);
706 int64 new_num_elements;
707 if (dim < 0) {
708 if (!out->kIsPartial) {
709 return errors::InvalidArgument("Dimension ", dim, " must be >= 0");
710 }
711 if (dim < -1) {
712 return errors::InvalidArgument("Dimension ", dim, " must be >= -1");
713 }
714 dim = -1;
715 new_num_elements = -1;
716 } else if (out->num_elements() < 0) {
717 new_num_elements = -1;
718 } else {
719 new_num_elements = MultiplyWithoutOverflow(out->num_elements(), dim);
720 if (TF_PREDICT_FALSE(new_num_elements < 0)) {
721 TensorShapeProto proto;
722 for (int64 j = 0; j < n; ++j) {
723 proto.add_dim()->set_size(dim);
724 }
725 return errors::InvalidArgument(
726 "Shape ", TensorShape::DebugString(proto),
727 " would have more than 2**63 - 1 elements");
728 }
729 }
730 out->UnsafeAddDim(dim, new_num_elements);
731 }
732 return Status::OK();
733}
734
735#define MAKE_SHAPE(T, Shape) \
736 Status TensorShapeUtils::MakeShape(const T* dims, int64 n, Shape* out) { \

Callers

nothing calls this directly

Calls 8

InvalidArgumentFunction · 0.85
SubtleMustCopyFunction · 0.85
UnsafeAddDimMethod · 0.80
DebugStringFunction · 0.70
MultiplyWithoutOverflowFunction · 0.50
ClearMethod · 0.45
num_elementsMethod · 0.45
set_sizeMethod · 0.45

Tested by

no test coverage detected