[go: up one dir, main page]

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

Add Cupy space #1401

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2898db6
ENH: add cupy tensor space
Oct 6, 2017
f8fed7a
MAINT: improve import of cupy
Nov 23, 2017
1c64fcb
WIP: fix cupy->numpy transfers
Nov 23, 2017
8564f2f
WIP: fix custom cupy kernels
Nov 23, 2017
f2085f8
MAINT: minor fixes
Nov 23, 2017
0654031
WIP: implement cupy space unit tests
Nov 23, 2017
dab3926
WIP: fix cublas stuff
Nov 24, 2017
ffde709
WIP: fix cublas, weight propagation, implement (add,multiply).(reduce…
Nov 25, 2017
3298d74
TST: ignore cupy_tensors in doctests if cupy is not available
Nov 25, 2017
dd7f635
MAINT: fix various numpy and cupy tensor things
Nov 25, 2017
5ab4756
ENH: allow indexing of CupyTensor with CupyTensor
Nov 25, 2017
fefb722
MAINT: minor stuff
Nov 25, 2017
6648425
MAINT: change weighted inf-norm to ignore weight
Nov 25, 2017
a1cd482
ENH: make comparison of cupy arrays in tests faster
Nov 25, 2017
cad427c
WIP: fix tensor tests for cupy
Nov 25, 2017
658051f
MAINT: adapt all_almost_equal to cupy
Nov 26, 2017
8a7dc33
WIP: fix cupy tensor tests
Nov 26, 2017
d456e6e
WIP: fix cupy tests
Nov 27, 2017
f0136b5
ENH: make ufuncs and ufunc_ops work with 2 outputs
Nov 27, 2017
1e89425
MAINT: make weighting methods numpy-independent
Nov 27, 2017
41fe853
WIP: fix cupy tests
Nov 27, 2017
039f76f
WIP: fix cupy stuff
Nov 28, 2017
07822cc
WIP: fix cupy tensor tests
Nov 28, 2017
47f74c9
WIP: fix pspace noise_array and out aliasing issue
Nov 29, 2017
cc95a04
ENH: implement Numpy-style broadcasting in pspace ufuncs
Nov 29, 2017
3084f1d
WIP: simplify tests and add utils for array modules
Nov 29, 2017
e3e364b
ENH: add impl to writable_array
Nov 29, 2017
d0c9705
ENH: add impl to asarray, tests, and fix real and imag for cupy
Nov 29, 2017
f4f376c
WIP: add asarray helper, fix diff_ops for cupy
Nov 30, 2017
d0fc8e2
MAINT: fix utils
Nov 30, 2017
c632802
MAINT: exclude unsupported ufunc operators
Nov 30, 2017
7879a50
MAINT: fix bad parens in test
Nov 30, 2017
4d1183e
BUG: fix indexing with cupy tensor
Nov 30, 2017
4ac503d
MAINT: minor fix in diff_ops
Nov 30, 2017
5c638d6
TST: mark cupy-only test as skip if cupy is not available
Dec 1, 2017
3cdde9f
MAINT: fix Py2-incompatible doctest in utility
Dec 1, 2017
87f8401
MAINT: Minor improvements related to cupy
adler-j Feb 14, 2018
958dacc
WIP: Fixes to tests due to cupy rebase
adler-j Jun 28, 2018
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
Prev Previous commit
Next Next commit
TST: ignore cupy_tensors in doctests if cupy is not available
  • Loading branch information
Holger Kohr authored and adler-j committed Jun 28, 2018
commit 3298d74c8f9cea85aac1b46d125dadd30ee4c408
42 changes: 26 additions & 16 deletions odl/space/cupy_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,25 @@ def _lincomb_impl(a, x1, b, x2, out):
lico(a, x1.data, b, x2.data, out.data)


def _python_scalar(arr):
"""Convert a CuPy array to a Python scalar.

The shape of the array must be ``()`` or ``(1,)``, otherwise an
error is raised.
"""
if arr.dtype.kind == 'f':
return float(cupy.asnumpy(arr))
elif arr.dtype.kind == 'c':
return complex(cupy.asnumpy(arr))
elif arr.dtype.kind in ('u', 'i'):
return int(cupy.asnumpy(arr))
elif arr.dtype.kind == 'b':
return bool(cupy.asnumpy(arr))
else:
raise RuntimeError("no conversion for dtype {}"
"".format(arr.dtype))


# --- Space and element classes --- #


Expand Down Expand Up @@ -1337,15 +1356,7 @@ def __getitem__(self, indices):
"""
arr = self.data[indices]
if arr.shape == ():
if arr.dtype.kind == 'f':
return float(cupy.asnumpy(arr))
elif arr.dtype.kind == 'c':
return complex(cupy.asnumpy(arr))
elif arr.dtype.kind in ('u', 'i'):
return int(cupy.asnumpy(arr))
else:
raise RuntimeError("no conversion for dtype {}"
"".format(arr.dtype))
return _python_scalar(arr)
else:
if is_numeric_dtype(self.dtype):
weighting = self.space.weighting
Expand Down Expand Up @@ -1898,18 +1909,18 @@ def eval_at_via_npy(*inputs, **kwargs):
elif (ufunc in (np.add, np.multiply) and
method in ('reduce', 'accumulate')):
# These cases are implemented but not available as methods
# of cupy.ufunc. We do the manual assignment
# of cupy.ufunc. We map the implementation by hand.
if ufunc == np.add:
function = cupy.sum if method == 'reduce' else cupy.cumsum
else:
function = cupy.prod if method == 'reduce' else cupy.cumprod

res = function(*inputs, **kwargs)

# Shortcut for scalar or no return value
if np.isscalar(res):
# Shortcut for scalar return value
if getattr(res, 'shape', ()) == ():
# Happens for `reduce` with all axes
return res
return _python_scalar(res)

# Wrap result if necessary (lazily)
if out is None:
Expand Down Expand Up @@ -2647,6 +2658,5 @@ def __init__(self, dist):


if __name__ == '__main__':
if CUPY_AVAILABLE:
from odl.util.testutils import run_doctests
run_doctests()
from odl.util.testutils import run_doctests
run_doctests()
5 changes: 5 additions & 0 deletions odl/util/pytest_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os

import odl
from odl.space.cupy_tensors import CUPY_AVAILABLE
from odl.space.entry_points import tensor_space_impl_names
from odl.trafos.backends import PYFFTW_AVAILABLE, PYWT_AVAILABLE
from odl.util.testutils import simple_fixture
Expand Down Expand Up @@ -80,6 +81,10 @@ def find_example_dirs():
collect_ignore.append(
os.path.join(odl_root, 'odl', 'trafos', 'wavelet.py'))

if not CUPY_AVAILABLE:
collect_ignore.append(
os.path.join(odl_root, 'odl', 'space', 'cupy_tensors.py'))


# Remove duplicates
collect_ignore = list(set(collect_ignore))
Expand Down