Skip to content

Commit

Permalink
Fix unit tests for eig
Browse files Browse the repository at this point in the history
  • Loading branch information
HippocampusGirl committed Oct 4, 2024
1 parent 9f8ed8d commit 28b862f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/gwas/tests/test_eig.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from gwas.vcf.base import VCFFile

from .conftest import chromosomes
from .utils import check_bias


def load_genotypes(
Expand Down Expand Up @@ -152,8 +153,13 @@ def test_eig(
request.addfinalizer(eig_array.free)

scipy_eigenvalues = np.square(scipy_singular_values) / variant_count
np.testing.assert_allclose(scipy_eigenvalues, eig_array.eigenvalues)
assert np.abs(scipy_eigenvalues - eig_array.eigenvalues).mean() < 1e-14
np.testing.assert_allclose(
scipy_eigenvalues,
eig_array.eigenvalues,
rtol=1e-5,
atol=1e-8,
)
assert check_bias(scipy_eigenvalues, eig_array.eigenvalues)

# Check reconstructing covariance
eig_c = (
Expand Down Expand Up @@ -285,7 +291,7 @@ def test_eig_rmw(
assert np.logical_or(permutation == 0, np.abs(permutation) == 1).all()
assert (1 == np.count_nonzero(permutation, axis=0)).all()
assert (1 == np.count_nonzero(permutation, axis=1)).all()
np.testing.assert_allclose(numpy_eigenvalues[::-1], eig_array.eigenvalues, atol=1e-6)
assert check_bias(numpy_eigenvalues[::-1], eig_array.eigenvalues)

new_allocation_names = {eig_array.name}
assert set(sw.allocations.keys()) <= (allocation_names | new_allocation_names)
Expand Down

0 comments on commit 28b862f

Please sign in to comment.