| 274 | using pointer_type = value_type*; |
| 275 | |
| 276 | static Result<CppDLTensor> TakeOwnership(pointer_type ptr) { |
| 277 | if (ARROW_PREDICT_FALSE(ptr == nullptr)) { |
| 278 | return Status::Invalid("Received null pointer."); |
| 279 | } |
| 280 | // Create the wrapper before checking the version as the spec mandates that the |
| 281 | // deleter MUST be called on version major mismatch. |
| 282 | auto out = CppDLTensor(ptr); |
| 283 | if (ARROW_PREDICT_FALSE(out.ptr_->version.major != kVersion.major)) { |
| 284 | return Status::Invalid("Unsupported DLPack major version ", out.ptr_->version.major, |
| 285 | ", expected ", kVersion.major); |
| 286 | } |
| 287 | if (ARROW_PREDICT_FALSE(out.tensor().ndim < 0)) { |
| 288 | return Status::Invalid("Invalid DLPack tensor: ndim must be >= 0"); |
| 289 | } |
| 290 | if (ARROW_PREDICT_FALSE(out.tensor().ndim != 0 && out.tensor().shape == nullptr)) { |
| 291 | return Status::Invalid( |
| 292 | "Invalid DLPack tensor: shape must be non-null when ndim != 0"); |
| 293 | } |
| 294 | // Null strides are handled as row major |
| 295 | return out; |
| 296 | } |
| 297 | |
| 298 | const DLTensor& tensor() const { return ptr_->dl_tensor; } |
| 299 |
nothing calls this directly
no test coverage detected