Skip to content

Commit baa4ebf

Browse files
authored
molecular hamiltonia linop only add constant when nonzero (#370)
1 parent 3baf827 commit baa4ebf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

python/ffsim/hamiltonians/molecular_hamiltonian.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,15 @@ def _linear_operator_(self, norb: int, nelec: tuple[int, int]) -> LinearOperator
104104
)
105105

106106
def matvec(vec: np.ndarray):
107-
result = self.constant * vec.astype(complex, copy=False)
108-
result += contract_2e(two_body, vec, norb, nelec, link_index=link_index)
107+
result = contract_2e(
108+
two_body,
109+
vec.astype(complex, copy=False),
110+
norb,
111+
nelec,
112+
link_index=link_index,
113+
)
114+
if self.constant:
115+
result += self.constant * vec
109116
return result
110117

111118
dim_ = dim(norb, nelec)

0 commit comments

Comments
 (0)