10 #ifndef EIGEN_TRIANGULARMATRIXVECTOR_H 11 #define EIGEN_TRIANGULARMATRIXVECTOR_H 17 template<
typename Index,
int Mode,
typename LhsScalar,
bool ConjLhs,
typename RhsScalar,
bool ConjRhs,
int StorageOrder,
int Version=Specialized>
20 template<
typename Index,
int Mode,
typename LhsScalar,
bool ConjLhs,
typename RhsScalar,
bool ConjRhs,
int Version>
27 HasZeroDiag = (Mode &
ZeroDiag)==ZeroDiag
29 static EIGEN_DONT_INLINE
void run(Index _rows, Index _cols,
const LhsScalar* _lhs, Index lhsStride,
30 const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr,
const ResScalar& alpha);
33 template<
typename Index,
int Mode,
typename LhsScalar,
bool ConjLhs,
typename RhsScalar,
bool ConjRhs,
int Version>
35 ::run(Index _rows, Index _cols,
const LhsScalar* _lhs, Index lhsStride,
36 const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr,
const ResScalar& alpha)
38 static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH;
39 Index
size = (std::min)(_rows,_cols);
40 Index rows = IsLower ? _rows : (std::min)(_rows,_cols);
41 Index cols = IsLower ? (std::min)(_rows,_cols) : _cols;
52 ResMap res(_res,rows);
54 for (Index pi=0; pi<
size; pi+=PanelWidth)
56 Index actualPanelWidth = (std::min)(PanelWidth, size-pi);
57 for (Index k=0; k<actualPanelWidth; ++k)
60 Index s = IsLower ? ((HasUnitDiag||HasZeroDiag) ? i+1 : i ) : pi;
61 Index r = IsLower ? actualPanelWidth-k : k+1;
62 if ((!(HasUnitDiag||HasZeroDiag)) || (--r)>0)
63 res.segment(s,r) += (alpha * cjRhs.coeff(i)) * cjLhs.
col(i).segment(s,r);
65 res.coeffRef(i) += alpha * cjRhs.coeff(i);
67 Index r = IsLower ? rows - pi - actualPanelWidth : pi;
70 Index s = IsLower ? pi+actualPanelWidth : 0;
73 &lhs.coeffRef(s,pi), lhsStride,
74 &rhs.coeffRef(pi), rhsIncr,
75 &res.coeffRef(s), resIncr, alpha);
78 if((!IsLower) && cols>
size)
82 &lhs.coeffRef(0,size), lhsStride,
83 &rhs.coeffRef(size), rhsIncr,
84 _res, resIncr, alpha);
88 template<
typename Index,
int Mode,
typename LhsScalar,
bool ConjLhs,
typename RhsScalar,
bool ConjRhs,
int Version>
95 HasZeroDiag = (Mode &
ZeroDiag)==ZeroDiag
97 static EIGEN_DONT_INLINE
void run(Index _rows, Index _cols,
const LhsScalar* _lhs, Index lhsStride,
98 const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr,
const ResScalar& alpha);
101 template<
typename Index,
int Mode,
typename LhsScalar,
bool ConjLhs,
typename RhsScalar,
bool ConjRhs,
int Version>
103 ::run(Index _rows, Index _cols,
const LhsScalar* _lhs, Index lhsStride,
104 const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr,
const ResScalar& alpha)
106 static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH;
107 Index diagSize = (std::min)(_rows,_cols);
108 Index rows = IsLower ? _rows : diagSize;
109 Index cols = IsLower ? diagSize : _cols;
116 const RhsMap rhs(_rhs,cols);
122 for (Index pi=0; pi<diagSize; pi+=PanelWidth)
124 Index actualPanelWidth = (std::min)(PanelWidth, diagSize-pi);
125 for (Index k=0; k<actualPanelWidth; ++k)
128 Index s = IsLower ? pi : ((HasUnitDiag||HasZeroDiag) ? i+1 : i);
129 Index r = IsLower ? k+1 : actualPanelWidth-k;
130 if ((!(HasUnitDiag||HasZeroDiag)) || (--r)>0)
131 res.coeffRef(i) += alpha * (cjLhs.
row(i).segment(s,r).cwiseProduct(cjRhs.segment(s,r).transpose())).sum();
133 res.coeffRef(i) += alpha * cjRhs.coeff(i);
135 Index r = IsLower ? pi : cols - pi - actualPanelWidth;
138 Index s = IsLower ? 0 : pi + actualPanelWidth;
141 &lhs.coeffRef(pi,s), lhsStride,
142 &rhs.coeffRef(s), rhsIncr,
143 &res.coeffRef(pi), resIncr, alpha);
146 if(IsLower && rows>diagSize)
150 &lhs.coeffRef(diagSize,0), lhsStride,
151 &rhs.coeffRef(0), rhsIncr,
152 &res.coeffRef(diagSize), resIncr, alpha);
160 template<
int Mode,
bool LhsIsTriangular,
typename Lhs,
typename Rhs>
162 :
traits<ProductBase<TriangularProduct<Mode,LhsIsTriangular,Lhs,false,Rhs,true>, Lhs, Rhs> >
165 template<
int Mode,
bool LhsIsTriangular,
typename Lhs,
typename Rhs>
167 :
traits<ProductBase<TriangularProduct<Mode,LhsIsTriangular,Lhs,true,Rhs,false>, Lhs, Rhs> >
171 template<
int StorageOrder>
176 template<
int Mode,
typename Lhs,
typename Rhs>
178 :
public ProductBase<TriangularProduct<Mode,true,Lhs,false,Rhs,true>, Lhs, Rhs >
184 template<
typename Dest>
void scaleAndAddTo(Dest& dst,
const Scalar& alpha)
const 186 eigen_assert(dst.rows()==m_lhs.rows() && dst.cols()==m_rhs.cols());
192 template<
int Mode,
typename Lhs,
typename Rhs>
194 :
public ProductBase<TriangularProduct<Mode,false,Lhs,true,Rhs,false>, Lhs, Rhs >
200 template<
typename Dest>
void scaleAndAddTo(Dest& dst,
const Scalar& alpha)
const 202 eigen_assert(dst.rows()==m_lhs.rows() && dst.cols()==m_rhs.cols());
207 TriangularProductTranspose(m_rhs.transpose(),m_lhs.transpose()), dstT, alpha);
217 template<
int Mode,
typename Lhs,
typename Rhs,
typename Dest>
218 static void run(
const TriangularProduct<Mode,true,Lhs,false,Rhs,true>& prod, Dest& dest,
const typename TriangularProduct<Mode,true,Lhs,false,Rhs,true>::Scalar& alpha)
221 typedef typename ProductType::Index Index;
222 typedef typename ProductType::LhsScalar LhsScalar;
223 typedef typename ProductType::RhsScalar RhsScalar;
225 typedef typename ProductType::RealScalar RealScalar;
226 typedef typename ProductType::ActualLhsType ActualLhsType;
227 typedef typename ProductType::ActualRhsType ActualRhsType;
228 typedef typename ProductType::LhsBlasTraits LhsBlasTraits;
229 typedef typename ProductType::RhsBlasTraits RhsBlasTraits;
235 ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs())
236 * RhsBlasTraits::extractScalarFactor(prod.rhs());
241 EvalToDestAtCompileTime = Dest::InnerStrideAtCompileTime==1,
243 MightCannotUseDest = (Dest::InnerStrideAtCompileTime!=1) || ComplexByReal
248 bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0));
249 bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible;
253 ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(),
254 evalToDest ? dest.data() : static_dest.data());
258 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN 259 Index
size = dest.size();
260 EIGEN_DENSE_STORAGE_CTOR_PLUGIN
262 if(!alphaIsCompatible)
264 MappedDest(actualDestPtr, dest.size()).setZero();
265 compatibleAlpha = RhsScalar(1);
268 MappedDest(actualDestPtr, dest.size()) = dest;
273 LhsScalar, LhsBlasTraits::NeedToConjugate,
274 RhsScalar, RhsBlasTraits::NeedToConjugate,
276 ::run(actualLhs.rows(),actualLhs.cols(),
277 actualLhs.data(),actualLhs.outerStride(),
278 actualRhs.data(),actualRhs.innerStride(),
279 actualDestPtr,1,compatibleAlpha);
283 if(!alphaIsCompatible)
284 dest += actualAlpha * MappedDest(actualDestPtr, dest.size());
286 dest = MappedDest(actualDestPtr, dest.size());
293 template<
int Mode,
typename Lhs,
typename Rhs,
typename Dest>
294 static void run(
const TriangularProduct<Mode,true,Lhs,false,Rhs,true>& prod, Dest& dest,
const typename TriangularProduct<Mode,true,Lhs,false,Rhs,true>::Scalar& alpha)
297 typedef typename ProductType::LhsScalar LhsScalar;
298 typedef typename ProductType::RhsScalar RhsScalar;
300 typedef typename ProductType::Index Index;
301 typedef typename ProductType::ActualLhsType ActualLhsType;
302 typedef typename ProductType::ActualRhsType ActualRhsType;
303 typedef typename ProductType::_ActualRhsType _ActualRhsType;
304 typedef typename ProductType::LhsBlasTraits LhsBlasTraits;
305 typedef typename ProductType::RhsBlasTraits RhsBlasTraits;
310 ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs())
311 * RhsBlasTraits::extractScalarFactor(prod.rhs());
314 DirectlyUseRhs = _ActualRhsType::InnerStrideAtCompileTime==1
319 ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,actualRhs.size(),
320 DirectlyUseRhs ?
const_cast<RhsScalar*
>(actualRhs.data()) : static_rhs.data());
324 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN 325 int size = actualRhs.size();
326 EIGEN_DENSE_STORAGE_CTOR_PLUGIN
333 LhsScalar, LhsBlasTraits::NeedToConjugate,
334 RhsScalar, RhsBlasTraits::NeedToConjugate,
336 ::run(actualLhs.rows(),actualLhs.cols(),
337 actualLhs.data(),actualLhs.outerStride(),
339 dest.data(),dest.innerStride(),
348 #endif // EIGEN_TRIANGULARMATRIXVECTOR_H A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
Definition: ProductBase.h:63
Expression of the transpose of a matrix.
Definition: Transpose.h:57
Definition: TriangularMatrixVector.h:172
Definition: BlasUtil.h:111
Definition: TriangularMatrixVector.h:18
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Matrix has ones on the diagonal; to be used in combination with Lower or Upper.
Definition: Constants.h:171
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Matrix has zeros on the diagonal; to be used in combination with Lower or Upper.
Definition: Constants.h:173
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Object is aligned for vectorization.
Definition: Constants.h:194
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:264
Definition: XprHelper.h:371
Convenience specialization of Stride to specify only an inner stride See class Map for some examples...
Definition: Stride.h:85
const Index & col() const
Definition: SparseUtil.h:161
Definition: GeneralProduct.h:370
Definition: TriangularMatrix.h:156
Definition: BlasUtil.h:38
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:266
View matrix as a lower triangular matrix.
Definition: Constants.h:167
Definition: TriangularMatrixVector.h:177
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
const Index & row() const
Definition: SparseUtil.h:158