From 3289516cf1f4e0d71882d7b0a40135a50df96106 Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Thu, 16 Feb 2023 22:17:04 -0500 Subject: [PATCH 1/4] not because they are easy, but because they are hard. --- tests/test_FLEbasis2D.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/test_FLEbasis2D.py b/tests/test_FLEbasis2D.py index d1acc64f95..b93fd6743f 100644 --- a/tests/test_FLEbasis2D.py +++ b/tests/test_FLEbasis2D.py @@ -24,10 +24,6 @@ def gpu_ci_skip(): pytest.skip("1e-7 precision for FLEBasis2D.evaluate()") -def odd_resolution_skip(): - pytest.skip("FB matching for odd resolution.") - - fle_params = [ (32, 1e-4), (32, 1e-7), @@ -121,10 +117,6 @@ def testEvaluateExpand(self, basis): @pytest.mark.parametrize("basis", test_bases_match_fb, ids=show_fle_params) def testMatchFBEvaluate(basis): - # see #738 - if basis.nres % 2 == 1: - odd_resolution_skip() - if backend_available("cufinufft") and basis.epsilon == 1e-7: gpu_ci_skip() From 972da1ca3b80c29c74b796a1a18088cb2da90260 Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Thu, 16 Feb 2023 22:21:17 -0500 Subject: [PATCH 2/4] Odd resolution grid patch. Co-authored-by: Chris Langfield --- src/aspire/basis/fle_2d.py | 4 ++-- tests/test_FLEbasis2D.py | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/aspire/basis/fle_2d.py b/src/aspire/basis/fle_2d.py index 0cb6e70de3..d8ee60c916 100644 --- a/src/aspire/basis/fle_2d.py +++ b/src/aspire/basis/fle_2d.py @@ -138,7 +138,7 @@ def _precomp(self): self.smallest_lambda = np.min(self.bessel_zeros) self.greatest_lambda = np.max(self.bessel_zeros) self.max_ell = np.max(np.abs(self.ells)) - self.h = 1 / (self.nres // 2) + self.h = 1 / (self.nres / 2) # give each ell a positive index increasing first in |ell| # then in sign, e.g. 0->1, -1->2, 1->3, -2->4, 2->5, etc. @@ -268,7 +268,7 @@ def _compute_nufft_points(self): ) * nodes + self.smallest_lambda nodes = nodes.reshape(self.num_radial_nodes, 1) - radius = self.nres // 2 + radius = self.nres / 2 h = 1 / radius phi = ( diff --git a/tests/test_FLEbasis2D.py b/tests/test_FLEbasis2D.py index b93fd6743f..f172c9fb0d 100644 --- a/tests/test_FLEbasis2D.py +++ b/tests/test_FLEbasis2D.py @@ -157,11 +157,6 @@ def testMatchFBDenseEvaluate(basis): @pytest.mark.parametrize("basis", test_bases_match_fb, ids=show_fle_params) def testMatchFBEvaluate_t(basis): # ensure that coefficients are the same when evaluating images - - # see #738 - if basis.nres % 2 == 1: - odd_resolution_skip() - fb_basis = FBBasis2D(basis.nres, dtype=np.float64) # test images to evaluate From cf49174570ded1ea910a4efcad9d2e5af29c20af Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Thu, 16 Feb 2023 22:28:35 -0500 Subject: [PATCH 3/4] And the another odd resolution grid patch --- src/aspire/basis/fle_2d.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aspire/basis/fle_2d.py b/src/aspire/basis/fle_2d.py index d8ee60c916..77f8d8d286 100644 --- a/src/aspire/basis/fle_2d.py +++ b/src/aspire/basis/fle_2d.py @@ -214,9 +214,9 @@ def _compute_cartesian_gridpoints(self): # original implementation R = self.nres // 2 x = np.arange(-R, R + self.nres % 2) - y = np.arange(-R, R + self.nres % 2) - xs, ys = np.meshgrid(x, y) - self.xs, self.ys = xs / R, ys / R + xs, ys = np.meshgrid(x, x) + # Note, the original original grids were xs/R, R=nres//2. + self.xs, self.ys = xs / (self.nres / 2), ys / (self.nres / 2) self.rs = np.sqrt(self.xs**2 + self.ys**2) self.radial_mask = self.rs > 1 + 1e-13 From 1c6fe2bc42f6c036a20936c72f72edb5391909ef Mon Sep 17 00:00:00 2001 From: Chris Langfield Date: Fri, 17 Feb 2023 00:30:40 -0500 Subject: [PATCH 4/4] remove normalization requirement for dense method odd res --- tests/test_FLEbasis2D.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_FLEbasis2D.py b/tests/test_FLEbasis2D.py index f172c9fb0d..d17f2e994c 100644 --- a/tests/test_FLEbasis2D.py +++ b/tests/test_FLEbasis2D.py @@ -145,11 +145,6 @@ def testMatchFBDenseEvaluate(basis): fle_out = basis._create_dense_matrix() @ coeffs fle_images = Image(fle_out.T.reshape(-1, basis.nres, basis.nres)).asnumpy() - # odd resolution has to be normalized - if basis.nres % 2 == 1: - fb_images = fb_images / np.max(np.abs(fb_images)) - fle_images = fle_images / np.max(np.abs(fle_images)) - # Matrix column reording in match_fb mode flips signs of some of the basis functions assert np.allclose(np.abs(fb_images), np.abs(fle_images), atol=1e-3) @@ -184,11 +179,6 @@ def testMatchFBDenseEvaluate_t(basis): fb_coeffs = fb_basis.evaluate_t(images) fle_coeffs = basis._create_dense_matrix().T @ vec.T - # odd resolution has to be normalized - if basis.nres % 2 == 1: - fb_coeffs = fb_coeffs / np.max(np.abs(fb_coeffs)) - fle_coeffs = fle_coeffs / np.max(np.abs(fle_coeffs)) - # Matrix column reording in match_fb mode flips signs of some of the basis coefficients assert np.allclose(np.abs(fb_coeffs), np.abs(fle_coeffs), atol=1e-4)