diff --git a/python/kvikio/kvikio/_lib/arr.pxd b/python/kvikio/kvikio/_lib/arr.pxd index a9d2b7e7f1..47bad21a3b 100644 --- a/python/kvikio/kvikio/_lib/arr.pxd +++ b/python/kvikio/kvikio/_lib/arr.pxd @@ -28,6 +28,9 @@ cdef class Array: cpdef Py_ssize_t _nbytes(self) +cpdef Array asarray(obj) + + cdef pair[uintptr_t, size_t] parse_buffer_argument( buf, size, bint accept_host_buffer ) except * diff --git a/python/kvikio/kvikio/_lib/arr.pyx b/python/kvikio/kvikio/_lib/arr.pyx index 793a414b17..45c7430313 100644 --- a/python/kvikio/kvikio/_lib/arr.pyx +++ b/python/kvikio/kvikio/_lib/arr.pyx @@ -289,9 +289,18 @@ cdef inline Py_ssize_t _nbytes(Py_ssize_t itemsize, nbytes *= shape_mv[i] return nbytes -cpdef asarray(obj): + +cpdef Array asarray(obj): + """Coerce other objects to ``Array``. No-op for existing ``Array``s. + + Args: + obj: Object exposing the Python buffer protocol or ``__cuda_array_interface__`` + + Returns: + Array: An instance of the ``Array`` class + """ if isinstance(obj, Array): - return obj + return obj else: return Array(obj)