Skip to content

Commit

Permalink
Merge pull request #67 from SimoneMartino98/num_precision
Browse files Browse the repository at this point in the history
replaced all the array_equal with all_close to avoid numerical precision issues. Thank you @SimoneMartino98
  • Loading branch information
andrewtarzia authored Feb 18, 2025
2 parents 52ee36a + 67ee436 commit 06d0766
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/analysis/rdf/test_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def test_compute_rdf(case_data: RDFCaseData) -> None:

exp_bins = np.load(expected_bins)
exp_rdf = np.load(expected_rdf)
assert np.array_equal(exp_rdf, test_rdf)
assert np.array_equal(exp_bins, test_bins)
assert np.allclose(exp_rdf, test_rdf)
assert np.allclose(exp_bins, test_bins)
2 changes: 1 addition & 1 deletion tests/analysis/test_spatialaverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def test_spatialaverage() -> None:

# Load expected results and compare
expected_arr = np.load(expected_results)
assert np.array_equal(test_arr, expected_arr)
assert np.allclose(test_arr, expected_arr)
2 changes: 1 addition & 1 deletion tests/lens/test_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_lens_signals() -> None:
check_lens_nn = check_file[f"LENS_{i}"]

# Check if control and test array are equal
assert np.array_equal(check_lens_nn, test_lens_nn), (
assert np.allclose(check_lens_nn, test_lens_nn), (
f"LENS analyses provided different values "
f"compared to the control system "
f"for r_cut: {lens_cutoffs[i]} (results: {output_file})."
Expand Down
5 changes: 2 additions & 3 deletions tests/lens/test_special_lens.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MDAnalysis
import numpy as np
from numpy.testing import assert_array_equal

import dynsight

Expand Down Expand Up @@ -33,8 +32,8 @@ def test_special_lens(lensfixtures: MDAnalysis.Universe) -> None:
mydentot,
) = dynsight.lens.neighbour_change_in_time(nnlistperframe)

assert_array_equal(mynconttot[:, 0], [0] * mynconttot.shape[0])
assert_array_equal(mynconttot[:, 1], expected)
np.allclose(mynconttot[:, 0], [0] * mynconttot.shape[0])
np.allclose(mynconttot[:, 1], expected)

for frame in [0, 1]:
for atom in universe.atoms:
Expand Down
3 changes: 1 addition & 2 deletions tests/lens/to_remove_test_count_neigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import MDAnalysis
import numpy as np
from numpy.testing import assert_array_equal

import dynsight

Expand Down Expand Up @@ -61,4 +60,4 @@ def test_count_neigh_for_lens(
for atomgroupnn, myatomsid in zip(nnlistorig, mynnlist):
atomsid = np.sort([at.ix for at in atomgroupnn])
assert is_sorted(myatomsid)
assert_array_equal(atomsid, myatomsid)
np.allclose(atomsid, myatomsid)

0 comments on commit 06d0766

Please sign in to comment.