From 493e0e0a9c1adab73a2f127df79e6704a8aaf24c Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Sun, 27 Nov 2022 19:52:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=F0=9F=9A=A7=20Fix=20matrix=20provi?= =?UTF-8?q?der?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More in line with main prior to 1175 Excessive extra (wasted) computation --- glotaran/optimization/matrix_provider.py | 45 +++++++++++++----------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/glotaran/optimization/matrix_provider.py b/glotaran/optimization/matrix_provider.py index 141762e8e..9d80d2a83 100644 --- a/glotaran/optimization/matrix_provider.py +++ b/glotaran/optimization/matrix_provider.py @@ -644,35 +644,40 @@ def calculate(self): def calculate_aligned_matrices(self): """Calculate the aligned matrices of the dataset group.""" - reduced_matrices = { - label: self.reduce_matrix(matrix_container, self._data_provider.get_global_axis(label)) - for label, matrix_container in self._matrix_containers.items() - } + # reduced_matrices = { + # label: self.reduce_matrix(matrix_container, + # self._data_provider.get_global_axis(label)) + # for label, matrix_container in self._matrix_containers.items() + # } full_clp_labels = self.align_full_clp_labels() for i, global_index_value in enumerate(self._data_provider.aligned_global_axis): group_label = self._data_provider.get_aligned_group_label(i) - self._aligned_full_clp_labels[i] = full_clp_labels[group_label] + matrix_containers = [ + self._matrix_containers[label] + for label in self._data_provider.group_definitions[group_label] + ] + matrix_scales = [ + self.group.dataset_models[label].scale + if self.group.dataset_models[label].scale is not None + else 1 + for label in self._data_provider.group_definitions[group_label] + ] + group_matrix = self.align_matrices( - [ - reduced_matrices[label][index] - for label, index in zip( - self._data_provider.group_definitions[group_label], - self._data_provider.get_aligned_dataset_indices(i), - ) - ], - [ - self.group.dataset_models[label].scale # type:ignore[misc] - if self.group.dataset_models[label].scale is not None - else 1 - for label in self._data_provider.group_definitions[group_label] - ], + matrix_containers, matrix_scales # type:ignore[arg-type] + ) + + self._aligned_full_clp_labels[i] = full_clp_labels[group_label] + group_matrix_for_all = self.reduce_matrix( + group_matrix, self._data_provider.aligned_global_axis ) + group_matrix_single = group_matrix_for_all[i] weight = self._data_provider.get_aligned_weight(i) if weight is not None: - group_matrix = group_matrix.create_weighted_matrix(weight) + group_matrix_single = group_matrix_single.create_weighted_matrix(weight) - self._aligned_matrices[i] = group_matrix + self._aligned_matrices[i] = group_matrix_single def align_full_clp_labels(self) -> dict[str, list[str]]: """Align the unreduced clp labels.