From 13c962f8e83b0a4a4b170ee2b7bb468834179983 Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Wed, 8 May 2024 12:15:28 -0400 Subject: [PATCH] givens decomposition: apply zrot without copying matrix (#165) --- python/ffsim/linalg/givens.py | 10 ++++------ python/ffsim/qiskit/gates/slater_determinant.py | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/python/ffsim/linalg/givens.py b/python/ffsim/linalg/givens.py index 65b5b8717..cd1858a99 100644 --- a/python/ffsim/linalg/givens.py +++ b/python/ffsim/linalg/givens.py @@ -168,17 +168,15 @@ def givens_decomposition( right_rotations.append( GivensRotation(c, s, target_index + 1, target_index) ) - current_matrix = current_matrix.T.copy() ( - current_matrix[target_index + 1], - current_matrix[target_index], + current_matrix[:, target_index + 1], + current_matrix[:, target_index], ) = zrot( - current_matrix[target_index + 1], - current_matrix[target_index], + current_matrix[:, target_index + 1], + current_matrix[:, target_index], c, s, ) - current_matrix = current_matrix.T else: # rotate rows by left multiplication for j in range(i + 1): diff --git a/python/ffsim/qiskit/gates/slater_determinant.py b/python/ffsim/qiskit/gates/slater_determinant.py index 03be69d78..b98f4024d 100644 --- a/python/ffsim/qiskit/gates/slater_determinant.py +++ b/python/ffsim/qiskit/gates/slater_determinant.py @@ -244,16 +244,14 @@ def _givens_decomposition_slater(orbital_coeffs: np.ndarray) -> list[GivensRotat # zero out element j of row i c, s = zrotg(current_matrix[i, j - 1], current_matrix[i, j]) rotations.append(GivensRotation(c, s, j, j - 1)) - current_matrix = current_matrix.T.copy() ( - current_matrix[j - 1], - current_matrix[j], + current_matrix[:, j - 1], + current_matrix[:, j], ) = zrot( - current_matrix[j - 1], - current_matrix[j], + current_matrix[:, j - 1], + current_matrix[:, j], c, s, ) - current_matrix = current_matrix.T return rotations[::-1]