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

Function ImportTensorVersioned

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

Source from the content-addressed store, hash-verified

496}
497
498Result<std::shared_ptr<Tensor>> ImportTensorVersioned(
499 DLManagedTensorVersioned* unmanaged) {
500 ARROW_ASSIGN_OR_RAISE(auto dl, CppDLTensor::TakeOwnership(unmanaged));
501
502 if (dl.tensor().device.device_type != kDLCPU) {
503 return Status::NotImplemented(
504 "DLPack support is implemented only for buffers on CPU device.");
505 }
506
507 ARROW_ASSIGN_OR_RAISE(auto type, DataTypeFromDLPack(dl.tensor().dtype));
508 auto shape = std::vector<int64_t>(dl.shape().begin(), dl.shape().end());
509 const auto strides = dl.strides();
510
511 ARROW_ASSIGN_OR_RAISE(auto buffer, ImportBuffer(std::move(dl)));
512 const auto byte_width = type->byte_width();
513
514 // In older DLPack null strides means row major, same as in Arrow.
515 if (strides.empty()) {
516 return Tensor::Make(std::move(type), std::move(buffer), std::move(shape));
517 }
518
519 ARROW_ASSIGN_OR_RAISE(
520 auto strides_bytes,
521 StridesInBytes(std::vector<int64_t>(strides.begin(), strides.end()), byte_width));
522 return Tensor::Make(std::move(type), std::move(buffer), std::move(shape),
523 std::move(strides_bytes));
524}
525
526} // namespace arrow::dlpack

Callers 1

ImportMethod · 0.85

Calls 8

NotImplementedFunction · 0.50
MakeFunction · 0.50
beginMethod · 0.45
shapeMethod · 0.45
endMethod · 0.45
stridesMethod · 0.45
byte_widthMethod · 0.45
emptyMethod · 0.45

Tested by 1

ImportMethod · 0.68