MCPcopy Create free account
hub / github.com/apache/arrow / TakeOwnership

Method TakeOwnership

cpp/src/arrow/c/dlpack.cc:276–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

CppDLTensorClass · 0.85
InvalidFunction · 0.50

Tested by

no test coverage detected