From 50efeb960e9b133b7a735d834e796fa23472da9a Mon Sep 17 00:00:00 2001 From: hmacdope Date: Thu, 24 Oct 2024 14:42:14 +1100 Subject: [PATCH] hmmm --- package/MDAnalysis/lib/_distopia.py | 5 +++-- testsuite/MDAnalysisTests/lib/test_distances.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/package/MDAnalysis/lib/_distopia.py b/package/MDAnalysis/lib/_distopia.py index a467efee2a..f442ed9d19 100644 --- a/package/MDAnalysis/lib/_distopia.py +++ b/package/MDAnalysis/lib/_distopia.py @@ -66,7 +66,7 @@ def calc_bond_distance_ortho( distopia.calc_bonds_ortho( coords1, coords2, box[:3], results=results ) - # upcast is currently required, change for 3.0, see #3927 + def calc_bond_distance( @@ -75,7 +75,6 @@ def calc_bond_distance( distopia.calc_bonds_no_box( coords1, coords2, results=results ) - # upcast is currently required, change for 3.0, see #3927 def calc_bond_distance_triclinic( @@ -89,6 +88,7 @@ def calc_angle( ) -> None: distopia.calc_angles_no_box(coords1, coords2, coords3, results=results) + def calc_angle_ortho( coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, box: np.ndarray, results: np.ndarray ) -> None: @@ -122,6 +122,7 @@ def calc_distance_array( ) -> None: distopia.calc_distance_array_no_box(coords1, coords2, results=results) + def calc_distance_array_ortho( coords1: np.ndarray, coords2: np.ndarray, box: np.ndarray, results: np.ndarray ) -> None: diff --git a/testsuite/MDAnalysisTests/lib/test_distances.py b/testsuite/MDAnalysisTests/lib/test_distances.py index a2955cbaf4..8c35e1c725 100644 --- a/testsuite/MDAnalysisTests/lib/test_distances.py +++ b/testsuite/MDAnalysisTests/lib/test_distances.py @@ -473,6 +473,8 @@ def test_outarray(self, DCD_Universe, backend): natoms = len(U.atoms) d = np.zeros((natoms, natoms), np.float64) distances.distance_array(x0, x1, result=d, backend=backend) + print("AFTER") + print(d) assert_equal(d.shape, (natoms, natoms), "wrong shape, should be" " (Natoms,Natoms) entries") assert_almost_equal(d.min(), 0.11981228170520701, self.prec, @@ -937,6 +939,19 @@ def test_bonds(self, box, backend, dtype, pos, request): assert_almost_equal(dists_pbc[3], 3.46410072, self.prec, err_msg="PBC check #w with box") + @pytest.mark.parametrize("dtype", (np.float32, np.float64)) + @pytest.mark.parametrize("backend", distopia_conditional_backend()) + def test_results_inplace_all_backends(self, backend, dtype,): + N = 10 + c0 = np.ones(3 * N, dtype=dtype).reshape(N, 3) * 2 + c1 = np.ones(3 * N, dtype=dtype).reshape(N, 3) * 3 + + result = np.zeros(N, dtype=np.float64) + distances.calc_bonds(c0, c1, result=result, backend=backend) + expected = np.ones(N, dtype=dtype) * 3**(1/2) + # test the result array is updated in place + assert_almost_equal(result, expected, self.prec, err_msg="calc_bonds inplace failed") + @pytest.mark.parametrize("backend", distopia_conditional_backend()) def test_bonds_badbox(self, positions, backend): a, b, c, d = positions