Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch ups to Array #475

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 *
13 changes: 11 additions & 2 deletions python/kvikio/kvikio/_lib/arr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
madsbk marked this conversation as resolved.
Show resolved Hide resolved
"""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
"""
Comment on lines +293 to +301
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this look?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @jakirkham !

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

Expand Down