From e93a0717746c859d85890cc201f5f57ec0bb2449 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Wed, 15 Dec 2021 22:00:40 +0000 Subject: [PATCH] Fix a bug introduced in !751. --- blas/PackedTriangularMatrixVector.h | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/blas/PackedTriangularMatrixVector.h b/blas/PackedTriangularMatrixVector.h index 63b76aabc..cc2a9b8cf 100644 --- a/blas/PackedTriangularMatrixVector.h +++ b/blas/PackedTriangularMatrixVector.h @@ -31,15 +31,16 @@ struct packed_triangular_matrix_vector_product::type ConjLhsType; typedef Map > ResMap; - for (Index i=0; i0)) - ResMap(res+(IsLower ? s+i : 0),r) += alpha * cj(rhs[i]) * ConjLhsType(LhsMap(lhs+s,r)); - if (HasUnitDiag) - res[i] += alpha * cj(rhs[i]); - lhs += IsLower ? size-i: i+1; + for (Index i = 0; i < size; ++i) { + Index s = IsLower && (HasUnitDiag || HasZeroDiag) ? 1 : 0; + Index r = IsLower ? size - i : i + 1; + if (!(HasUnitDiag || HasZeroDiag) || (--r > 0)) { + ResMap(res + (IsLower ? s + i : 0), r) += alpha * cj(rhs[i]) * ConjLhsType(LhsMap(lhs + s, r)); + } + if (HasUnitDiag) { + res[i] += alpha * cj(rhs[i]); + } + lhs += IsLower ? size - i : i + 1; } }; }; @@ -61,15 +62,16 @@ struct packed_triangular_matrix_vector_product > RhsMap; typedef typename conj_expr_if::type ConjRhsType; - for (Index i=0; i0)) - res[i] += alpha * (ConjLhsType(LhsMap(lhs+s,r)).cwiseProduct(ConjRhsType(RhsMap(rhs+(IsLower ? 0 : s+i),r)))).sum(); - if (HasUnitDiag) - res[i] += alpha * cj(rhs[i]); - lhs += IsLower ? i+1 : size-i; + for (Index i = 0; i < size; ++i) { + Index s = !IsLower && (HasUnitDiag || HasZeroDiag) ? 1 : 0; + Index r = IsLower ? i + 1 : size - i; + if (!(HasUnitDiag || HasZeroDiag) || (--r > 0)) { + res[i] += alpha * (ConjLhsType(LhsMap(lhs + s, r)).cwiseProduct(ConjRhsType(RhsMap(rhs + (IsLower ? 0 : s + i), r)))).sum(); + } + if (HasUnitDiag) { + res[i] += alpha * cj(rhs[i]); + } + lhs += IsLower ? i + 1 : size - i; } }; };