apache / arrow-nanoarrow

Helpers for Arrow C Data & Arrow C Stream interfaces
https://arrow.apache.org/nanoarrow
Apache License 2.0
151 stars 34 forks source link

feat(python): Clarify interaction between the CDeviceArray, the CArrayView, and the CArray #409

Closed paleolimbot closed 3 months ago

paleolimbot commented 3 months ago

When device support was first added, the CArrayView was device-aware but the CArray was not. This worked well until it was clear that __arrow_c_array__ needed to error if it did not represent a CPU array (and the CArray had no way to check). Now, the CArray has a device_type and device_id. A nice side-effect of this is that we get back the view() method (whose removal @jorisvandenbossche had lamented!).

This also implements the device array protocol to help test https://github.com/apache/arrow/pull/40717 . This protocol isn't finalized yet and I could remove that part until it is (although it doesn't seem likely to change).

The non-cpu case is still hard to test without real-world CUDA support...this PR is just trying to get the right information in the right place as early as possible.

import nanoarrow as na

array = na.c_array([1, 2, 3], na.int32())
array.device_type, array.device_id
#> (1, 0)
paleolimbot commented 3 months ago

Apologies for the two additional changes, but: