Skip to content

Commit 6c1f8ec

Browse files
author
John Halloran
committed
refactor: flatten from a single buffer in apply_interpolation_matrix()
1 parent a7adeed commit 6c1f8ec

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/diffpy/snmf/snmf_class.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,18 @@ def apply_interpolation_matrix(self, components=None, weights=None, stretch=None
421421
offset_indices_1 = floor_indices_1 + bias
422422
offset_indices_2 = floor_indices_2 + bias
423423

424-
# Extract values
425-
# Note: this "-1" corrects an off-by-one error that may have originated in an earlier line
426-
comp_values_1 = components_bounded.flatten(order="F")[(offset_indices_1 - 1).ravel(order="F")].reshape(
424+
# Flatten components once (Fortran order, column-major)
425+
components_bounded_flat = components_bounded.ravel(order="F")
426+
427+
# Pre-compute flattened indices
428+
offset_indices_1_flat = (offset_indices_1 - 1).ravel(order="F")
429+
offset_indices_2_flat = (offset_indices_2 - 1).ravel(order="F")
430+
431+
# Extract values using pre-flattened arrays
432+
comp_values_1 = components_bounded_flat[offset_indices_1_flat].reshape(
427433
self.signal_length, self.n_components * self.n_signals, order="F"
428-
) # order = F uses FORTRAN, column major order
429-
comp_values_2 = components_bounded.flatten(order="F")[(offset_indices_2 - 1).ravel(order="F")].reshape(
434+
)
435+
comp_values_2 = components_bounded_flat[offset_indices_2_flat].reshape(
430436
self.signal_length, self.n_components * self.n_signals, order="F"
431437
)
432438

0 commit comments

Comments
 (0)