| 774 | } |
| 775 | |
| 776 | Status PartialTensorShape::MergeWith(const PartialTensorShape& shape, |
| 777 | PartialTensorShape* result) const { |
| 778 | if (unknown_rank()) { |
| 779 | *result = shape; |
| 780 | return Status::OK(); |
| 781 | } |
| 782 | if (shape.unknown_rank()) { |
| 783 | *result = *this; |
| 784 | return Status::OK(); |
| 785 | } |
| 786 | const int dims_ = dims(); |
| 787 | if (dims_ != shape.dims()) { |
| 788 | return errors::InvalidArgument( |
| 789 | "PartialTensorShape: Incompatible ranks during merge: ", dims_, " vs. ", |
| 790 | shape.dims()); |
| 791 | } |
| 792 | CHECK(result != this); |
| 793 | result->Clear(); |
| 794 | for (int i = 0; i < dims_; ++i) { |
| 795 | const int64 dim0 = dim_size(i); |
| 796 | const int64 dim1 = shape.dim_size(i); |
| 797 | if (dim0 >= 0 && dim1 >= 0 && dim0 != dim1) { |
| 798 | return errors::InvalidArgument( |
| 799 | "PartialTensorShape: Incompatible shapes during merge: ", |
| 800 | DebugString(), " vs. ", shape.DebugString()); |
| 801 | } |
| 802 | result->AddDim(dim0 >= 0 ? dim0 : dim1); |
| 803 | } |
| 804 | return Status::OK(); |
| 805 | } |
| 806 | |
| 807 | bool PartialTensorShape::AsTensorShape(TensorShape* shape) const { |
| 808 | if (IsFullyDefined()) { |