Skip to content

Commit

Permalink
🩹🚧 Fix matrix provider
Browse files Browse the repository at this point in the history
More in line with main prior to 1175
Excessive extra (wasted) computation
  • Loading branch information
jsnel committed Nov 27, 2022
1 parent a1bdb83 commit 493e0e0
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions glotaran/optimization/matrix_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 493e0e0

Please sign in to comment.