| 149 | } |
| 150 | |
| 151 | TF_Tensor* TF_TensorMaybeMove(TF_Tensor* tensor) { |
| 152 | // It is safe to move the Tensor if and only if we own the unique reference to |
| 153 | // it. In that case, we might as well not delete and reallocate, but a future |
| 154 | // implementation might need to do so. |
| 155 | TensorBuffer* buf = tensorflow::TensorCApi::Buffer(tensor->tensor); |
| 156 | if (buf->RefCountIsOne() && buf->root_buffer()->RefCountIsOne() && |
| 157 | buf->OwnsMemory()) { |
| 158 | return tensor; |
| 159 | } |
| 160 | return nullptr; |
| 161 | } |
| 162 | |
| 163 | void TF_DeleteTensor(TF_Tensor* t) { delete t; } |
| 164 | |