| 522 | |
| 523 | template <class Shape> |
| 524 | Status TensorShapeBase<Shape>::SetDimWithStatus(int d, int64 size) { |
| 525 | if (TF_PREDICT_FALSE(d < 0)) { |
| 526 | return errors::InvalidArgument("Index must be non-negative, got ", d); |
| 527 | } |
| 528 | if (TF_PREDICT_FALSE(d >= dims())) { |
| 529 | return errors::InvalidArgument("Index must be less than ", dims(), ", got ", |
| 530 | d); |
| 531 | } |
| 532 | if (TF_PREDICT_FALSE(size < 0)) { |
| 533 | return errors::InvalidArgument("Expected a non-negative size, got ", size); |
| 534 | } |
| 535 | |
| 536 | if (tag() == REP16 && size < kMaxRep16) { |
| 537 | as16()->dims_[d] = |
| 538 | kIsPartial && size < 0 ? kUnknownRep16 : static_cast<uint16>(size); |
| 539 | } else if (tag() == REP32 && size < kMaxRep32) { |
| 540 | as32()->dims_[d] = |
| 541 | kIsPartial && size < 0 ? kUnknownRep32 : static_cast<uint32>(size); |
| 542 | } else if (tag() == REP_OUT_OF_LINE) { |
| 543 | (*as64()->dims_)[d] = size; |
| 544 | } else { |
| 545 | // Must upgrade |
| 546 | gtl::InlinedVector<int64, 8> vals; |
| 547 | AppendTo(*this, &vals); |
| 548 | vals[d] = size; |
| 549 | ClearAllButDataType(); |
| 550 | |
| 551 | Status s = Status::OK(); |
| 552 | for (auto dval : vals) { |
| 553 | s.Update(AddDimWithStatus(dval)); |
| 554 | if (!s.ok()) { |
| 555 | return s; |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | return RecomputeNumElements(); |
| 561 | } |
| 562 | |
| 563 | template <class Shape> |
| 564 | void TensorShapeBase<Shape>::RemoveDimRange(int begin, int end) { |