-
Notifications
You must be signed in to change notification settings - Fork 105
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
ENH: add cupy tensor space #1231
base: master
Are you sure you want to change the base?
Changes from 35 commits
d028dd5
dd2b7c4
e1ce7fb
f282947
b84ee8d
4a0c67c
1d431c6
2fdebff
3bdc3f0
6fbcc81
f6a8022
ee386ab
2b7103c
2ed9ae1
8414458
7d5bf9d
9cf8917
e47f78a
0fc7de3
9f24b7b
1422fc0
cbd7b87
cbdfe04
2703c3e
fbfba6c
71ccc46
392762d
cd12e84
6a9f733
dfeee85
66728f2
23149ee
6efe98c
daac62e
58b921d
eb10834
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,16 +331,18 @@ def copy(self): | |
"""Create an identical (deep) copy of this element.""" | ||
return self.space.element(self.tensor.copy()) | ||
|
||
def asarray(self, out=None): | ||
"""Extract the data of this array as a numpy array. | ||
def asarray(self, out=None, impl='numpy'): | ||
"""Extract the data of this element as an array. | ||
|
||
Parameters | ||
---------- | ||
out : `numpy.ndarray`, optional | ||
Array in which the result should be written in-place. | ||
Has to be contiguous and of the correct dtype. | ||
out : ndarray, optional | ||
Array into which the result should be written. Must be contiguous | ||
and of the correct dtype. | ||
impl : str, optional | ||
Array backend for the output, used when ``out`` is not given. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably mention where the valid choices come from. |
||
""" | ||
return self.tensor.asarray(out=out) | ||
return self.tensor.asarray(out=out, impl=impl) | ||
|
||
def astype(self, dtype): | ||
"""Return a copy of this element with new ``dtype``. | ||
|
@@ -409,7 +411,7 @@ def __setitem__(self, indices, values): | |
indices = indices.tensor | ||
if isinstance(values, type(self)): | ||
values = values.tensor | ||
self.tensor.__setitem__(indices, values) | ||
self.tensor[indices] = values | ||
|
||
def sampling(self, ufunc, **kwargs): | ||
"""Sample a continuous function and assign to this element. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,10 +374,10 @@ def __pow__(self, shape): | |
>>> r2 ** 4 | ||
ProductSpace(rn(2), 4) | ||
|
||
Multiple powers work as expected: | ||
Multiple powers work as expected (first entry is outermost power): | ||
|
||
>>> r2 ** (4, 2) | ||
ProductSpace(ProductSpace(rn(2), 4), 2) | ||
>>> r2 ** (3, 4) | ||
ProductSpace(ProductSpace(rn(2), 4), 3) | ||
""" | ||
from odl.space import ProductSpace | ||
|
||
|
@@ -387,7 +387,7 @@ def __pow__(self, shape): | |
shape = tuple(shape) | ||
|
||
pspace = self | ||
for n in shape: | ||
for n in reversed(shape): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this? Wouldn't our users expect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. When doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I concur with your statement. It certainly makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was an actual bug. |
||
pspace = ProductSpace(pspace, n) | ||
|
||
return pspace | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This of course assumes that
impl
has the same interface as numpy.Perhaps it's better to implement wrappers for the most common functions, like
asarray
(already done),empty
, and whatever else is needed. That would be more extensible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be how e.g. Keras does it, but I say we leave this for now. Changing should be rather easy (just search replace basically).