Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/aspire/nufft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def anufft(sig_f, fourier_pts, sz, real=False, epsilon=1e-8):

adjoint = adjoint.real if real else adjoint

if cp and not _keep_on_gpu:
if cp and isinstance(adjoint, cp.ndarray) and not _keep_on_gpu:
adjoint = adjoint.get()

return adjoint
Expand Down Expand Up @@ -259,7 +259,7 @@ def nufft(sig_f, fourier_pts, real=False, epsilon=1e-8):

transform = transform.real if real else transform

if cp and not _keep_on_gpu:
if cp and isinstance(transform, cp.ndarray) and not _keep_on_gpu:
transform = transform.get()

return transform
9 changes: 8 additions & 1 deletion tests/test_FFBbasis2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from scipy.special import jv

from aspire.basis import Coef, FFBBasis2D
from aspire.nufft import all_backends
from aspire.source import Simulation
from aspire.utils.misc import grid_2d
from aspire.volume import Volume
Expand Down Expand Up @@ -126,6 +127,9 @@ def testShift(self, basis):
params = [pytest.param(512, np.float32, marks=pytest.mark.expensive)]


@pytest.mark.skipif(
all_backends()[0] == "cufinufft", reason="Not enough memory to run via GPU"
)
@pytest.mark.parametrize(
"L, dtype",
params,
Expand All @@ -136,6 +140,7 @@ def testHighResFFBBasis2D(L, dtype):
sim = Simulation(
n=1,
L=L,
C=1,
dtype=dtype,
amplitudes=1,
offsets=0,
Expand All @@ -149,4 +154,6 @@ def testHighResFFBBasis2D(L, dtype):

# Mask to compare inside disk of radius 1.
mask = grid_2d(L, normalized=True)["r"] < 1
assert np.allclose(im_ffb.asnumpy()[0][mask], im.asnumpy()[0][mask], atol=1e-4)
np.testing.assert_allclose(
im_ffb.asnumpy()[0][mask], im.asnumpy()[0][mask], rtol=1e-05, atol=1e-4
)