Skip to content

Add cupy.shape - #3229

Merged
mergify[bot] merged 1 commit into
cupy:masterfrom
toslunar:cupy-shape
Jun 17, 2020
Merged

mergify[bot] merged 1 commit into
cupy:masterfrom
toslunar:cupy-shape

Conversation

@toslunar

Copy link
Copy Markdown
Member

No description provided.

@leofang

leofang commented Mar 26, 2020

Copy link
Copy Markdown
Member

Interesting. Didn't know this wasn't implemented. Would this allow __array_function__ to take effect, so that numpy.shape(cupy_array) works?

@kmaehashi kmaehashi self-assigned this Mar 26, 2020
@toslunar

Copy link
Copy Markdown
Member Author

Would this allow __array_function__ to take effect, so that numpy.shape(cupy_array) works?

Yes.

cupy/cupy/core/core.pyx

Lines 1351 to 1367 in 766dfd0

def __array_function__(self, func, types, args, kwargs):
module = cupy
for submodule in func.__module__.split('.')[1:]:
try:
module = getattr(module, submodule)
except AttributeError:
return NotImplemented
if not hasattr(module, func.__name__):
return NotImplemented
cupy_func = getattr(module, func.__name__)
if cupy_func is func:
# avoid NumPy func
return NotImplemented
for t in types:
if t not in _HANDLED_TYPES:
return NotImplemented
return cupy_func(*args, **kwargs)

@leofang

leofang commented Mar 26, 2020

Copy link
Copy Markdown
Member

Thanks, @toslunar! I was a bit confused by the logic of __array_function__ there; looks like if a name is in the cupy module, the dispatch will happen?

@emcastillo emcastillo added this to the v8.0.0b4 milestone May 29, 2020
@kmaehashi kmaehashi assigned takagi and unassigned kmaehashi Jun 12, 2020
@takagi

takagi commented Jun 17, 2020

Copy link
Copy Markdown
Contributor

LGTM! Waiting for auto-merge.

@takagi

takagi commented Jun 17, 2020

Copy link
Copy Markdown
Contributor

pfnCI, test this please.

@pfn-ci-bot

Copy link
Copy Markdown
Collaborator

Successfully created a job for commit a908ce5:

@takagi takagi added cat:feature New features/APIs st:test-and-merge (deprecated) Ready to merge after test pass. labels Jun 17, 2020
@chainer-ci

Copy link
Copy Markdown
Member

Jenkins CI test (for commit a908ce5, target branch master) succeeded!

@mergify
mergify Bot merged commit 89fc31a into cupy:master Jun 17, 2020
@toslunar
toslunar deleted the cupy-shape branch June 19, 2020 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature New features/APIs st:test-and-merge (deprecated) Ready to merge after test pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants