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

Function ImportArrayVersioned

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

Source from the content-addressed store, hash-verified

474} // namespace
475
476Result<std::shared_ptr<Array>> ImportArrayVersioned(DLManagedTensorVersioned* unmanaged) {
477 ARROW_ASSIGN_OR_RAISE(auto dl, CppDLTensor::TakeOwnership(unmanaged));
478
479 if (dl.tensor().device.device_type != kDLCPU) {
480 return Status::NotImplemented(
481 "DLPack support is implemented only for buffers on CPU device.");
482 }
483
484 const auto strides = dl.strides();
485 if (dl.ndim() != 1 || (!strides.empty() && strides.front() != 1)) {
486 return Status::Invalid(
487 "Only contiguous one dimensional tensor can be imported as arrays."
488 " Try importing to Tensor first.");
489 }
490
491 ARROW_ASSIGN_OR_RAISE(auto type, DataTypeFromDLPack(dl.tensor().dtype));
492 const auto nelements = dl.shape().front();
493 ARROW_ASSIGN_OR_RAISE(auto buffer, ImportBuffer(std::move(dl)));
494 auto data = ArrayData::Make(type, nelements, {nullptr, std::move(buffer)});
495 return MakeArray(std::move(data));
496}
497
498Result<std::shared_ptr<Tensor>> ImportTensorVersioned(
499 DLManagedTensorVersioned* unmanaged) {

Callers 1

ImportMethod · 0.85

Calls 8

ndimMethod · 0.80
NotImplementedFunction · 0.50
InvalidFunction · 0.50
MakeFunction · 0.50
MakeArrayFunction · 0.50
stridesMethod · 0.45
emptyMethod · 0.45
shapeMethod · 0.45

Tested by 1

ImportMethod · 0.68