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

Method Visit

python/pyarrow/src/arrow/python/numpy_to_arrow.cc:420–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418 }
419 template <int TYPE>
420 Status Visit(PyArrayObject* arr) {
421 using traits = internal::npy_traits<TYPE>;
422 using T = typename traits::value_type;
423
424 ARROW_ASSIGN_OR_RAISE(buffer_, AllocateBuffer(sizeof(T) * length_, pool_));
425
426 const int64_t stride = PyArray_STRIDES(arr)[0];
427 // ARROW-16013: convert sizeof(T) to signed int64 first, otherwise dividing by it
428 // would do an unsigned division. This cannot be caught by tests without ubsan, since
429 // common signed overflow behavior and the fact that the sizeof(T) is currently always
430 // a power of two here cause CopyStridedNatural to still produce correct results
431 const int64_t element_size = sizeof(T);
432 if (stride % element_size == 0) {
433 const int64_t stride_elements = stride / element_size;
434 CopyStridedNatural(reinterpret_cast<T*>(PyArray_DATA(arr)), length_,
435 stride_elements, reinterpret_cast<T*>(buffer_->mutable_data()));
436 } else {
437 CopyStridedBytewise(reinterpret_cast<int8_t*>(PyArray_DATA(arr)), length_, stride,
438 reinterpret_cast<T*>(buffer_->mutable_data()));
439 }
440 return Status::OK();
441 }
442
443 protected:
444 NumPyStridedConverter(PyArrayObject* arr, int64_t length, MemoryPool* pool)

Callers

nothing calls this directly

Calls 6

CopyStridedNaturalFunction · 0.85
CopyStridedBytewiseFunction · 0.85
ARROW_ASSIGN_OR_RAISEFunction · 0.50
AllocateBufferFunction · 0.50
OKFunction · 0.50
mutable_dataMethod · 0.45

Tested by

no test coverage detected