Use more .noalias()

This commit is contained in:
Markus Vieth 2025-03-17 19:32:43 +01:00
parent 14f845a1a8
commit 0259a52b0e
No known key found for this signature in database
GPG Key ID: 187D6EDEAF2978D1
6 changed files with 15 additions and 14 deletions

View File

@ -449,23 +449,23 @@ inline void RealQZ<MatrixType>::step(Index f, Index l, Index iter) {
Index lr = (std::min)(k + 4, dim); // last row to update Index lr = (std::min)(k + 4, dim); // last row to update
Map<Matrix<Scalar, Dynamic, 1> > tmp(m_workspace.data(), lr); Map<Matrix<Scalar, Dynamic, 1> > tmp(m_workspace.data(), lr);
// S // S
tmp = m_S.template middleCols<2>(k).topRows(lr) * essential2; tmp.noalias() = m_S.template middleCols<2>(k).topRows(lr) * essential2;
tmp += m_S.col(k + 2).head(lr); tmp += m_S.col(k + 2).head(lr);
m_S.col(k + 2).head(lr) -= tau * tmp; m_S.col(k + 2).head(lr) -= tau * tmp;
m_S.template middleCols<2>(k).topRows(lr) -= (tau * tmp) * essential2.adjoint(); m_S.template middleCols<2>(k).topRows(lr).noalias() -= (tau * tmp) * essential2.adjoint();
// T // T
tmp = m_T.template middleCols<2>(k).topRows(lr) * essential2; tmp = m_T.template middleCols<2>(k).topRows(lr) * essential2;
tmp += m_T.col(k + 2).head(lr); tmp += m_T.col(k + 2).head(lr);
m_T.col(k + 2).head(lr) -= tau * tmp; m_T.col(k + 2).head(lr) -= tau * tmp;
m_T.template middleCols<2>(k).topRows(lr) -= (tau * tmp) * essential2.adjoint(); m_T.template middleCols<2>(k).topRows(lr).noalias() -= (tau * tmp) * essential2.adjoint();
} }
if (m_computeQZ) { if (m_computeQZ) {
// Z // Z
Map<Matrix<Scalar, 1, Dynamic> > tmp(m_workspace.data(), dim); Map<Matrix<Scalar, 1, Dynamic> > tmp(m_workspace.data(), dim);
tmp = essential2.adjoint() * (m_Z.template middleRows<2>(k)); tmp.noalias() = essential2.adjoint() * (m_Z.template middleRows<2>(k));
tmp += m_Z.row(k + 2); tmp += m_Z.row(k + 2);
m_Z.row(k + 2) -= tau * tmp; m_Z.row(k + 2) -= tau * tmp;
m_Z.template middleRows<2>(k) -= essential2 * (tau * tmp); m_Z.template middleRows<2>(k).noalias() -= essential2 * (tau * tmp);
} }
m_T.coeffRef(k + 2, k) = m_T.coeffRef(k + 2, k + 1) = Scalar(0.0); m_T.coeffRef(k + 2, k) = m_T.coeffRef(k + 2, k + 1) = Scalar(0.0);

View File

@ -1059,11 +1059,11 @@ EIGEN_DEVICE_FUNC void Transform<Scalar, Dim, Mode, Options>::computeRotationSca
: Scalar(1); // so x has absolute value 1 : Scalar(1); // so x has absolute value 1
VectorType sv(svd.singularValues()); VectorType sv(svd.singularValues());
sv.coeffRef(Dim - 1) *= x; sv.coeffRef(Dim - 1) *= x;
if (scaling) *scaling = svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint(); if (scaling) (*scaling).noalias() = svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint();
if (rotation) { if (rotation) {
LinearMatrixType m(svd.matrixU()); LinearMatrixType m(svd.matrixU());
m.col(Dim - 1) *= x; m.col(Dim - 1) *= x;
*rotation = m * svd.matrixV().adjoint(); (*rotation).noalias() = m * svd.matrixV().adjoint();
} }
} }
@ -1182,7 +1182,8 @@ EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options> Transform<Scalar, Dim, M
eigen_assert(false && "Invalid transform traits in Transform::Inverse"); eigen_assert(false && "Invalid transform traits in Transform::Inverse");
} }
// translation and remaining parts // translation and remaining parts
res.matrix().template topRightCorner<Dim, 1>() = -res.matrix().template topLeftCorner<Dim, Dim>() * translation(); res.matrix().template topRightCorner<Dim, 1>().noalias() =
-res.matrix().template topLeftCorner<Dim, Dim>() * translation();
res.makeAffine(); // we do need this, because in the beginning res is uninitialized res.makeAffine(); // we do need this, because in the beginning res is uninitialized
} }
return res; return res;
@ -1432,7 +1433,7 @@ struct transform_transform_product_impl<Transform<Scalar, Dim, LhsMode, LhsOptio
typedef Transform<Scalar, Dim, ResultMode, LhsOptions> ResultType; typedef Transform<Scalar, Dim, ResultMode, LhsOptions> ResultType;
static EIGEN_DEVICE_FUNC ResultType run(const Lhs& lhs, const Rhs& rhs) { static EIGEN_DEVICE_FUNC ResultType run(const Lhs& lhs, const Rhs& rhs) {
ResultType res; ResultType res;
res.linear() = lhs.linear() * rhs.linear(); res.linear().noalias() = lhs.linear() * rhs.linear();
res.translation() = lhs.linear() * rhs.translation() + lhs.translation(); res.translation() = lhs.linear() * rhs.translation() + lhs.translation();
res.makeAffine(); res.makeAffine();
return res; return res;

View File

@ -717,7 +717,7 @@ void FullPivLU<MatrixType_, PermutationIndex_>::_solve_impl(const RhsType& rhs,
// Step 2 // Step 2
m_lu.topLeftCorner(smalldim, smalldim).template triangularView<UnitLower>().solveInPlace(c.topRows(smalldim)); m_lu.topLeftCorner(smalldim, smalldim).template triangularView<UnitLower>().solveInPlace(c.topRows(smalldim));
if (rows > cols) c.bottomRows(rows - cols) -= m_lu.bottomRows(rows - cols) * c.topRows(cols); if (rows > cols) c.bottomRows(rows - cols).noalias() -= m_lu.bottomRows(rows - cols) * c.topRows(cols);
// Step 3 // Step 3
m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots) m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)

View File

@ -379,7 +379,7 @@ void SVDBase<Derived>::_solve_impl(const RhsType& rhs, DstType& dst) const {
Index l_rank = rank(); Index l_rank = rank();
tmp.noalias() = m_matrixU.leftCols(l_rank).adjoint() * rhs; tmp.noalias() = m_matrixU.leftCols(l_rank).adjoint() * rhs;
tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp; tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp;
dst = m_matrixV.leftCols(l_rank) * tmp; dst.noalias() = m_matrixV.leftCols(l_rank) * tmp;
} }
template <typename Derived> template <typename Derived>

View File

@ -172,7 +172,7 @@ void upperbidiagonalization_blocked_helper(
// 1 - update the k-th column of A // 1 - update the k-th column of A
SubColumnType v_k = A.col(k).tail(remainingRows); SubColumnType v_k = A.col(k).tail(remainingRows);
v_k -= V_k1 * Y.row(k).head(k).adjoint(); v_k -= V_k1 * Y.row(k).head(k).adjoint();
if (k) v_k -= X_k1 * A.col(k).head(k); if (k) v_k.noalias() -= X_k1 * A.col(k).head(k);
// 2 - construct left Householder transform in-place // 2 - construct left Householder transform in-place
v_k.makeHouseholderInPlace(tau_v, diagonal[k]); v_k.makeHouseholderInPlace(tau_v, diagonal[k]);
@ -203,7 +203,7 @@ void upperbidiagonalization_blocked_helper(
SubRowType u_k(A.row(k).tail(remainingCols)); SubRowType u_k(A.row(k).tail(remainingCols));
u_k = u_k.conjugate(); u_k = u_k.conjugate();
{ {
u_k -= Y_k * A.row(k).head(k + 1).adjoint(); u_k.noalias() -= Y_k * A.row(k).head(k + 1).adjoint();
if (k) u_k -= U_k1.adjoint() * X.row(k).head(k).adjoint(); if (k) u_k -= U_k1.adjoint() * X.row(k).head(k).adjoint();
} }

View File

@ -268,7 +268,7 @@ LevenbergMarquardtSpace::Status LevenbergMarquardt<FunctorType, Scalar>::minimiz
/* compute the scaled predicted reduction and */ /* compute the scaled predicted reduction and */
/* the scaled directional derivative. */ /* the scaled directional derivative. */
wa3 = fjac.template triangularView<Upper>() * (qrfac.colsPermutation().inverse() * wa1); wa3.noalias() = fjac.template triangularView<Upper>() * (qrfac.colsPermutation().inverse() * wa1);
temp1 = numext::abs2(wa3.stableNorm() / fnorm); temp1 = numext::abs2(wa3.stableNorm() / fnorm);
temp2 = numext::abs2(sqrt(par) * pnorm / fnorm); temp2 = numext::abs2(sqrt(par) * pnorm / fnorm);
prered = temp1 + temp2 / Scalar(.5); prered = temp1 + temp2 / Scalar(.5);