Skip to content

Commit

Permalink
feat: add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
paquiteau committed Jan 5, 2024
1 parent 463eba5 commit fff5907
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mrinufft/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import partial
import warnings
import numpy as np
from mrinufft._utils import _power_method
from mrinufft._utils import power_method

from mrinufft.density import get_density

Expand Down Expand Up @@ -204,7 +204,7 @@ def get_lipschitz_cst(self, max_iter=10, **kwargs):
tmp_op = self.__class__(
self.samples, self.shape, density=self.density, n_coils=1, **kwargs
)
return _power_method(max_iter, tmp_op)
return power_method(max_iter, tmp_op)

@property
def uses_sense(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,22 @@ def test_interfaces_autoadjoint(operator):
reldiff[i] = abs(rightadjoint - leftadjoint) / abs(leftadjoint)
print(reldiff)
assert np.mean(reldiff) < 5e-5


def test_interface_lipschitz(operator):
"""Test the Lipschitz constant of the operator."""
spec_rad = operator.get_lipschitz_cst(20)

def AHA(x):
return operator.adj_op(operator.op(x))

L = np.zeros(10)
for i in range(10):
img_data = image_from_op(operator)
img2_data = image_from_op(operator)

L[i] = np.linalg.norm(AHA(img2_data) - AHA(img_data)) / np.linalg.norm(
img2_data - img_data
)

assert np.mean(L) < 1.1 * spec_rad

0 comments on commit fff5907

Please sign in to comment.