From 493e0e0a9c1adab73a2f127df79e6704a8aaf24c Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Sun, 27 Nov 2022 19:52:55 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A9=B9=F0=9F=9A=A7=20Fix=20matrix=20p?= =?UTF-8?q?rovider?= 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. From e60842fd93f29ec0527d2b13db72a8d02179d021 Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Mon, 28 Nov 2022 01:57:13 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A9=B9Fix=20matrix=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- glotaran/optimization/matrix_provider.py | 32 ++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/glotaran/optimization/matrix_provider.py b/glotaran/optimization/matrix_provider.py index 9d80d2a83..664772717 100644 --- a/glotaran/optimization/matrix_provider.py +++ b/glotaran/optimization/matrix_provider.py @@ -644,18 +644,25 @@ 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() - # } full_clp_labels = self.align_full_clp_labels() for i, global_index_value in enumerate(self._data_provider.aligned_global_axis): + matrix_containers = [] group_label = self._data_provider.get_aligned_group_label(i) - matrix_containers = [ - self._matrix_containers[label] - for label in self._data_provider.group_definitions[group_label] - ] + for label, index in zip( + self._data_provider.group_definitions[group_label], + self._data_provider.get_aligned_dataset_indices(i), + ): + matrix_container_temp = self._matrix_containers[label] + if matrix_container_temp.is_index_dependent: + matrix_containers.append( + MatrixContainer( + clp_labels=matrix_container_temp.clp_labels, + matrix=matrix_container_temp.matrix[index], + ) + ) + else: + matrix_containers.append(matrix_container_temp) + matrix_scales = [ self.group.dataset_models[label].scale if self.group.dataset_models[label].scale is not None @@ -668,10 +675,9 @@ def calculate_aligned_matrices(self): ) 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] + group_matrix_single = self.reduce_matrix( + group_matrix, np.array([self._data_provider.aligned_global_axis[i]]) + )[0] weight = self._data_provider.get_aligned_weight(i) if weight is not None: From 5927e23fc59c3c4b1db202e6accadf163ed6b13b Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Mon, 28 Nov 2022 02:17:33 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9A=20Added=20change=20to=20change?= =?UTF-8?q?log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since this fixed a bug introduced within the 0.7.0 development cycle (so after 0.6.0 but before 0.7.0) the change is included in a 'hidden' manner (not rendered unless you look at the source code of the MD file) --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 3f38dc922..ca5d479cc 100644 --- a/changelog.md +++ b/changelog.md @@ -24,6 +24,9 @@ - 🩹 Fix result data overwritten when using multiple dataset_groups (#1147) - 🩹 Fix for normalization issue described in #1157 (multi-gaussian irfs and multiple time ranges (streak)) - 🩹 Fix for crash described in #1183 when doing an optimization using more than 30 datasets (#1184) + ### 📚 Documentation