| 442 | |
| 443 | template <typename Device, typename T> |
| 444 | Status TensorArray::LockedWriteOrAggregate(OpKernelContext* ctx, |
| 445 | const int32 index, |
| 446 | PersistentTensor* value) { |
| 447 | TF_RETURN_IF_ERROR(LockedReturnIfClosed()); |
| 448 | size_t index_size = static_cast<size_t>(index); |
| 449 | if (index < 0 || (!dynamic_size_ && index_size >= tensors_.size())) { |
| 450 | return errors::InvalidArgument( |
| 451 | "TensorArray ", handle_.vec<tstring>()(1), ": Tried to write to index ", |
| 452 | index, " but array is not resizeable and size is: ", tensors_.size()); |
| 453 | } |
| 454 | if (dynamic_size_) { |
| 455 | // We must grow the internal TensorArray |
| 456 | if (index_size >= tensors_.capacity()) { |
| 457 | tensors_.reserve(2 * (index_size + 1)); |
| 458 | } |
| 459 | if (index_size >= tensors_.size()) { |
| 460 | tensors_.resize(index_size + 1); |
| 461 | } |
| 462 | } |
| 463 | TensorAndState& t = tensors_[index]; |
| 464 | |
| 465 | Tensor* value_t = value->AccessTensor(ctx); |
| 466 | if (value_t->dtype() != dtype_) { |
| 467 | return errors::InvalidArgument( |
| 468 | "TensorArray ", handle_.vec<tstring>()(1), |
| 469 | ": Could not write to TensorArray index ", index, |
| 470 | " because the value dtype is ", DataTypeString(value_t->dtype()), |
| 471 | " but TensorArray dtype is ", DataTypeString(dtype_), "."); |
| 472 | } |
| 473 | if (!element_shape_.IsCompatibleWith(value_t->shape())) { |
| 474 | return errors::InvalidArgument( |
| 475 | "TensorArray ", handle_.vec<tstring>()(1), |
| 476 | ": Could not write to TensorArray index ", index, |
| 477 | " because the value shape is ", value_t->shape().DebugString(), |
| 478 | " which is incompatible with the TensorArray's inferred element " |
| 479 | "shape: ", |
| 480 | element_shape_.DebugString(), " (consider setting infer_shape=False)."); |
| 481 | } else if (identical_element_shapes_ && !element_shape_.IsFullyDefined()) { |
| 482 | element_shape_ = PartialTensorShape(value_t->shape().dim_sizes()); |
| 483 | } |
| 484 | |
| 485 | if (t.read) { |
| 486 | return errors::InvalidArgument("TensorArray ", handle_.vec<tstring>()(1), |
| 487 | ": Could not write to TensorArray index ", |
| 488 | index, " because it has already been read."); |
| 489 | } |
| 490 | |
| 491 | if (!multiple_writes_aggregate_ && t.written) { |
| 492 | return errors::InvalidArgument("TensorArray ", handle_.vec<tstring>()(1), |
| 493 | ": Could not write to TensorArray index ", |
| 494 | index, |
| 495 | " because it has already been written to."); |
| 496 | } |
| 497 | |
| 498 | if (t.written) { |
| 499 | DCHECK(multiple_writes_aggregate_); |
| 500 | |
| 501 | // Check that value_t shape matches t.shape |
nothing calls this directly
no test coverage detected