Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/bispectrum/so3_on_s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ def _load_sparse_cache(
cached_meta = data['entry_meta']
if len(cached_meta) != len(entries_for_cg):
return None
expected_meta = [
[l1, l2, l_val, int(is_power)] for _, l1, l2, l_val, is_power in entries_for_cg
]
if cached_meta != expected_meta:
return None
return data['cg_vals'], data['m1_idx'], data['m_idx'], data['offsets'], cached_meta
except (OSError, RuntimeError, KeyError):
return None
Expand Down Expand Up @@ -910,7 +915,7 @@ def _ensure_precomputed_on_device(self, device: torch.device, dtype: torch.dtype
fl_i = self._sparse_fl_abs
eid = self._sparse_entry_ids

perm = torch.randperm(bi.numel(), generator=torch.Generator().manual_seed(42))
perm = torch.randperm(bi.numel())
bi_perm = bi[perm]
self._sc_bi_fl1 = fl1_i[bi_perm].to(device=device)
self._sc_bi_fl2 = fl2_i[bi_perm].to(device=device)
Expand Down
11 changes: 3 additions & 8 deletions tests/test_so3_on_s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,7 @@ def test_sparse_fast_vs_dict_cpu(self, lmax):

@pytest.mark.parametrize('lmax', [3, 5, 10])
def test_sparse_matches_full_bispectrum(self, lmax):
"""Selective sparse entries match the corresponding full bispectrum entries.

The sparse path (scatter-add) and the python-loop path (einsum+matmul) accumulate products
in different orders, so we allow tolerance proportional to lmax to account for floating-
point non-associativity.
"""
"""Selective sparse entries match the corresponding full bispectrum entries."""
sel = SO3onS2(lmax=lmax, nlat=32, nlon=64, selective=True)
full = SO3onS2(lmax=lmax, nlat=32, nlon=64, selective=False)

Expand All @@ -1023,8 +1018,8 @@ def test_sparse_matches_full_bispectrum(self, lmax):
torch.testing.assert_close(
out_sel[:, i],
out_full[:, j],
atol=2e-2,
rtol=1e-2,
atol=5e-7,
rtol=1e-5,
)

def test_sparse_rotation_invariance(self):
Expand Down
Loading