Skip to content

Commit

Permalink
Touch ups to Array
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Sep 28, 2024
1 parent 638d53d commit 5c10774
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions python/kvikio/kvikio/_lib/arr.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
2 changes: 1 addition & 1 deletion python/kvikio/kvikio/_lib/arr.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2020-2024, NVIDIA CORPORATION. All rights reserved.
# See file LICENSE for terms.

from typing import Generic, Tuple, TypeVar
Expand Down
18 changes: 14 additions & 4 deletions python/kvikio/kvikio/_lib/arr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@

from cpython.array cimport array, newarrayobject
from cpython.buffer cimport PyBuffer_IsContiguous
from cpython.memoryview cimport PyMemoryView_FromObject, PyMemoryView_GET_BUFFER
from cpython.memoryview cimport (
PyMemoryView_FromObject,
PyMemoryView_GET_BUFFER,
)
from cpython.object cimport PyObject
from cpython.ref cimport Py_INCREF
from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
from cython cimport auto_pickle, boundscheck, initializedcheck, nonecheck, wraparound
from cython cimport (
auto_pickle,
boundscheck,
initializedcheck,
nonecheck,
wraparound,
)
from libc.stdint cimport uintptr_t
from libc.string cimport memcpy

Expand Down Expand Up @@ -289,9 +298,10 @@ cdef inline Py_ssize_t _nbytes(Py_ssize_t itemsize,
nbytes *= shape_mv[i]
return nbytes

cpdef asarray(obj):

cpdef Array asarray(obj):
if isinstance(obj, Array):
return obj
return <Array>obj
else:
return Array(obj)

Expand Down

0 comments on commit 5c10774

Please sign in to comment.