Skip to content

Commit a1cbd1f

Browse files
committed
make overlap respect order or argument
1 parent 9f9ca8b commit a1cbd1f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

forte/helpers/math_structures.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,16 @@ class VectorSpace {
284284
/// @brief Calculate the dot product of two vectors
285285
F dot(const Derived& other) const {
286286
F result{0};
287+
bool self_smaller = size() < other.size();
287288
const auto& smaller = size() < other.size() ? elements() : other.elements();
288289
const auto& larger = size() < other.size() ? other.elements() : elements();
289290
for (const auto& [e, c] : smaller) {
290291
if (const auto it = larger.find(e); it != larger.end()) {
291-
result += conjugate(c) * it->second;
292+
if (self_smaller) {
293+
result += conjugate(c) * it->second;
294+
} else {
295+
result += c * conjugate(it->second);
296+
}
292297
}
293298
}
294299
return result;

0 commit comments

Comments
 (0)