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

Sync some changes from KvikIO's Array #1080

Open
wants to merge 3 commits into
base: branch-0.41
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion ucp/_libs/arr.pxd
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.

# cython: language_level=3
Expand All @@ -24,3 +24,6 @@ cdef class Array:
cpdef bint _f_contiguous(self)
cpdef bint _contiguous(self)
cpdef Py_ssize_t _nbytes(self)


cpdef Array asarray(obj)
17 changes: 14 additions & 3 deletions ucp/_libs/arr.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from typing import Tuple
# Copyright (c) 2020-2024, NVIDIA CORPORATION. All rights reserved.
# See file LICENSE for terms.

class Array:
def __init__(self, obj: object): ...
from typing import Generic, Tuple, TypeVar

T = TypeVar("T")

class Array(Generic[T]):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This a slightly weird use of a generic type. Usually one would read a type Array[T] as "an array containing objects of type T", that is for x : Array[T], then x[i] : T forall i \in [0, len(x)). However, here you're using it to mean the wrapped type.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is taken from verbatim from KvikIO. Appears this was added in PR ( rapidsai/kvikio#214 ), which it looks like you approved 😉

That said, no objection to changing it to something else. Could you please submit a PR to KvikIO with the syntax you prefer? Can then incorporate it here 🙂

def __init__(self, obj: T): ...
@property
def c_contiguous(self) -> bool: ...
@property
Expand All @@ -14,3 +19,9 @@ class Array:
def shape(self) -> Tuple[int]: ...
@property
def strides(self) -> Tuple[int]: ...
@property
def cuda(self) -> bool: ...
@property
def obj(self) -> T: ...

def asarray(obj) -> Array: ...
9 changes: 8 additions & 1 deletion ucp/_libs/arr.pyx
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.

# cython: language_level=3
Expand Down Expand Up @@ -297,3 +297,10 @@ cdef inline Py_ssize_t _nbytes(Py_ssize_t itemsize,
for i in range(ndim):
nbytes *= shape_mv[i]
return nbytes


cpdef Array asarray(obj):
jakirkham marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(obj, Array):
return <Array>obj
else:
return Array(obj)