| 694 | |
| 695 | template <typename T, class Shape> |
| 696 | Status 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) { \ |
nothing calls this directly
no test coverage detected