| 723 | } |
| 724 | |
| 725 | Status Tensor::BitcastFrom(const Tensor& other, DataType dtype, |
| 726 | const TensorShape& shape) { |
| 727 | int in_size = DataTypeSize(other.dtype()); |
| 728 | int out_size = DataTypeSize(dtype); |
| 729 | if (in_size == 0) { |
| 730 | return errors::InvalidArgument("other tensor has zero-sized data type"); |
| 731 | } |
| 732 | if (out_size == 0) { |
| 733 | return errors::InvalidArgument("specified output type is zero-sized"); |
| 734 | } |
| 735 | if (shape.num_elements() * out_size != |
| 736 | other.shape().num_elements() * in_size) { |
| 737 | return errors::InvalidArgument( |
| 738 | "input and output shapes/data type sizes are not compatible"); |
| 739 | } |
| 740 | shape_ = shape; |
| 741 | shape_.set_data_type(dtype); |
| 742 | if (buf_ != other.buf_) { |
| 743 | UnrefIfNonNull(buf_); |
| 744 | buf_ = other.buf_; |
| 745 | RefIfNonNull(buf_); |
| 746 | } |
| 747 | return Status::OK(); |
| 748 | } |
| 749 | |
| 750 | // Notice that buf_ either points to a regular TensorBuffer or a SubBuffer. |
| 751 | // For the latter case, we have to make sure that the refcount is |
no test coverage detected