| 374 | |
| 375 | template <class Shape> |
| 376 | void TensorShapeBase<Shape>::AddDim(int64 size) { |
| 377 | if (!kIsPartial) CHECK_GE(size, 0); |
| 378 | if (unknown_rank()) return; |
| 379 | CHECK_LT(ndims_byte(), MaxDimensions()) << "Too many dimensions in tensor"; |
| 380 | int64 new_num_elements; |
| 381 | if (kIsPartial && (num_elements() < 0 || size < 0)) { |
| 382 | new_num_elements = -1; |
| 383 | } else { |
| 384 | new_num_elements = MultiplyWithoutOverflow(num_elements(), size); |
| 385 | CHECK_LE(0, new_num_elements); |
| 386 | } |
| 387 | UnsafeAddDim(size, new_num_elements); |
| 388 | } |
| 389 | |
| 390 | template <class Shape> |
| 391 | Status TensorShapeBase<Shape>::AddDimWithStatus(int64 size) { |