Skip to content

Commit 35d9d2e

Browse files
lexi-xLexi Xu
andauthored
Implementing Numpy Performance Improvements for Array Copying (#4987)
* faster array copying --------- Co-authored-by: Lexi Xu <[email protected]>
1 parent dcaa087 commit 35d9d2e

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

package/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ Chronological list of authors
249249
2025
250250
- Joshua Raphael Uy
251251
- Namir Oues
252+
- Lexi Xu
252253

253254
External code
254255
-------------

testsuite/MDAnalysisTests/lib/test_distances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ def test_input_unchanged_transform_RtoS_and_StoR(
19731973
res = distances.transform_RtoS(crd, box, backend=backend)
19741974
assert_equal(crd, ref)
19751975
crd = res
1976-
ref = crd.copy()
1976+
np.copyto(ref, crd)
19771977
res = distances.transform_StoR(crd, box, backend=backend)
19781978
assert_equal(crd, ref)
19791979

testsuite/MDAnalysisTests/transformations/test_positionaveraging.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_posavging_fwd(posaveraging_universes):
4545
)
4646
avgd = np.empty(size)
4747
for ts in posaveraging_universes.trajectory:
48-
avgd[..., ts.frame] = ts.positions.copy()
48+
np.copyto(avgd[..., ts.frame], ts.positions)
4949

5050
assert_array_almost_equal(ref_matrix_fwd, avgd[1, :, -1], decimal=5)
5151

@@ -63,7 +63,7 @@ def test_posavging_bwd(posaveraging_universes):
6363
)
6464
back_avgd = np.empty(size)
6565
for ts in posaveraging_universes.trajectory[::-1]:
66-
back_avgd[..., 9 - ts.frame] = ts.positions.copy()
66+
np.copyto(back_avgd[..., 9 - ts.frame], ts.positions)
6767
assert_array_almost_equal(ref_matrix_bwd, back_avgd[1, :, -1], decimal=5)
6868

6969

@@ -78,7 +78,7 @@ def test_posavging_reset(posaveraging_universes):
7878
)
7979
avgd = np.empty(size)
8080
for ts in posaveraging_universes.trajectory:
81-
avgd[..., ts.frame] = ts.positions.copy()
81+
np.copyto(avgd[..., ts.frame], ts.positions)
8282
after_reset = ts.positions.copy()
8383
assert_array_almost_equal(avgd[..., 0], after_reset, decimal=5)
8484

@@ -99,7 +99,7 @@ def test_posavging_specific(posaveraging_universes):
9999
specr_avgd = np.empty(size)
100100
idx = 0
101101
for ts in posaveraging_universes.trajectory[fr_list]:
102-
specr_avgd[..., idx] = ts.positions.copy()
102+
np.copyto(specr_avgd[..., idx], ts.positions)
103103
idx += 1
104104
assert_array_almost_equal(
105105
ref_matrix_specr, specr_avgd[1, :, -1], decimal=5
@@ -122,7 +122,7 @@ def test_posavging_specific_noreset(posaveraging_universes_noreset):
122122
specr_avgd = np.empty(size)
123123
idx = 0
124124
for ts in posaveraging_universes_noreset.trajectory[fr_list]:
125-
specr_avgd[..., idx] = ts.positions.copy()
125+
np.copyto(specr_avgd[..., idx], ts.positions)
126126
idx += 1
127127
assert_array_almost_equal(
128128
ref_matrix_specr, specr_avgd[1, :, -1], decimal=5

0 commit comments

Comments
 (0)