11 #ifndef EIGEN_COEFFBASED_PRODUCT_H 12 #define EIGEN_COEFFBASED_PRODUCT_H 31 template<
int Traversal,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename RetScalar>
34 template<
int StorageOrder,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
37 template<
typename LhsNested,
typename RhsNested,
int NestingFlags>
50 LhsCoeffReadCost = _LhsNested::CoeffReadCost,
51 RhsCoeffReadCost = _RhsNested::CoeffReadCost,
52 LhsFlags = _LhsNested::Flags,
53 RhsFlags = _RhsNested::Flags,
55 RowsAtCompileTime = _LhsNested::RowsAtCompileTime,
56 ColsAtCompileTime = _RhsNested::ColsAtCompileTime,
57 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime),
59 MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
60 MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
68 && (ColsAtCompileTime ==
Dynamic 75 && (RowsAtCompileTime ==
Dynamic 76 || ( (RowsAtCompileTime % packet_traits<Scalar>::size) == 0
81 EvalToRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
82 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
83 : (RhsRowMajor && !CanVectorizeLhs),
85 Flags = ((
unsigned int)(LhsFlags | RhsFlags) & HereditaryBits & ~RowMajorBit)
86 | (EvalToRowMajor ? RowMajorBit : 0)
90 | (SameType && (CanVectorizeLhs || CanVectorizeRhs) ?
PacketAccessBit : 0),
102 CanVectorizeInner = SameType
105 && (LhsFlags & RhsFlags & ActualPacketAccessBit)
106 && (LhsFlags & RhsFlags & AlignedBit)
107 && (InnerSize % packet_traits<Scalar>::size == 0)
113 template<
typename LhsNested,
typename RhsNested,
int NestingFlags>
116 public MatrixBase<CoeffBasedProduct<LhsNested, RhsNested, NestingFlags> >
122 typedef typename Base::PlainObject PlainObject;
132 Unroll = CoeffReadCost !=
Dynamic && CoeffReadCost <= EIGEN_UNROLLING_LIMIT,
145 : Base(), m_lhs(other.m_lhs), m_rhs(other.m_rhs)
148 template<
typename Lhs,
typename Rhs>
150 : m_lhs(lhs), m_rhs(rhs)
155 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
156 eigen_assert(lhs.cols() == rhs.rows()
157 &&
"invalid matrix product" 158 &&
"if you wanted a coeff-wise or a dot product use the respective explicit functions");
161 EIGEN_STRONG_INLINE
Index rows()
const {
return m_lhs.rows(); }
162 EIGEN_STRONG_INLINE
Index cols()
const {
return m_rhs.cols(); }
164 EIGEN_STRONG_INLINE
const Scalar coeff(
Index row,
Index col)
const 167 ScalarCoeffImpl::run(row, col, m_lhs, m_rhs, res);
174 EIGEN_STRONG_INLINE
const Scalar coeff(
Index index)
const 177 const Index row = RowsAtCompileTime == 1 ? 0 : index;
178 const Index col = RowsAtCompileTime == 1 ? index : 0;
179 ScalarCoeffImpl::run(row, col, m_lhs, m_rhs, res);
183 template<
int LoadMode>
190 ::run(row, col, m_lhs, m_rhs, res);
195 EIGEN_STRONG_INLINE
operator const PlainObject& ()
const 197 m_result.lazyAssign(*
this);
201 const _LhsNested& lhs()
const {
return m_lhs; }
202 const _RhsNested& rhs()
const {
return m_rhs; }
205 {
return reinterpret_cast<const LazyCoeffBasedProductType&
>(*this); }
207 template<
int DiagonalIndex>
209 {
return reinterpret_cast<const LazyCoeffBasedProductType&
>(*this); }
212 {
return reinterpret_cast<const LazyCoeffBasedProductType&
>(*this).diagonal(index); }
218 mutable PlainObject m_result;
225 template<
typename Lhs,
typename Rhs,
int N,
typename PlainObject>
228 typedef PlainObject
const& type;
239 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename RetScalar>
242 typedef typename Lhs::Index Index;
243 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, RetScalar &res)
246 res += lhs.coeff(row, UnrollingIndex-1) * rhs.coeff(UnrollingIndex-1, col);
250 template<
typename Lhs,
typename Rhs,
typename RetScalar>
253 typedef typename Lhs::Index Index;
254 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, RetScalar &res)
256 res = lhs.coeff(row, 0) * rhs.coeff(0, col);
260 template<
typename Lhs,
typename Rhs,
typename RetScalar>
263 typedef typename Lhs::Index Index;
264 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& ,
const Rhs& , RetScalar &res)
270 template<
typename Lhs,
typename Rhs,
typename RetScalar>
273 typedef typename Lhs::Index Index;
274 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, RetScalar& res)
276 res = (lhs.row(row).transpose().cwiseProduct( rhs.col(col) )).sum();
284 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet>
287 typedef typename Lhs::Index Index;
289 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::PacketScalar &pres)
292 pres = padd(pres, pmul( lhs.template packet<Aligned>(row, UnrollingIndex) , rhs.template packet<Aligned>(UnrollingIndex, col) ));
296 template<
typename Lhs,
typename Rhs,
typename Packet>
299 typedef typename Lhs::Index Index;
300 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::PacketScalar &pres)
302 pres = pmul(lhs.template packet<Aligned>(row, 0) , rhs.template packet<Aligned>(0, col));
306 template<
typename Lhs,
typename Rhs,
typename RetScalar>
309 typedef typename Lhs::Index Index;
310 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& ,
const Rhs& , RetScalar &res)
316 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename RetScalar>
319 typedef typename Lhs::PacketScalar Packet;
320 typedef typename Lhs::Index Index;
322 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, RetScalar &res)
330 template<
typename Lhs,
typename Rhs,
int LhsRows = Lhs::RowsAtCompileTime,
int RhsCols = Rhs::ColsAtCompileTime>
333 typedef typename Lhs::Index Index;
334 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::Scalar &res)
336 res = lhs.row(row).transpose().cwiseProduct(rhs.col(col)).sum();
342 template<
typename Lhs,
typename Rhs,
int RhsCols>
345 typedef typename Lhs::Index Index;
346 static EIGEN_STRONG_INLINE
void run(Index , Index col,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::Scalar &res)
348 res = lhs.transpose().cwiseProduct(rhs.col(col)).sum();
352 template<
typename Lhs,
typename Rhs,
int LhsRows>
355 typedef typename Lhs::Index Index;
356 static EIGEN_STRONG_INLINE
void run(Index row, Index ,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::Scalar &res)
358 res = lhs.row(row).transpose().cwiseProduct(rhs).sum();
362 template<
typename Lhs,
typename Rhs>
365 typedef typename Lhs::Index Index;
366 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::Scalar &res)
368 res = lhs.transpose().cwiseProduct(rhs).sum();
372 template<
typename Lhs,
typename Rhs,
typename RetScalar>
375 typedef typename Lhs::Index Index;
376 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs,
typename Lhs::Scalar &res)
386 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
389 typedef typename Lhs::Index Index;
390 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Packet &res)
393 res = pmadd(pset1<Packet>(lhs.coeff(row, UnrollingIndex-1)), rhs.template packet<LoadMode>(UnrollingIndex-1, col), res);
397 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
400 typedef typename Lhs::Index Index;
401 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Packet &res)
404 res = pmadd(lhs.template packet<LoadMode>(row, UnrollingIndex-1), pset1<Packet>(rhs.coeff(UnrollingIndex-1, col)), res);
408 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
411 typedef typename Lhs::Index Index;
412 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Packet &res)
414 res = pmul(pset1<Packet>(lhs.coeff(row, 0)),rhs.template packet<LoadMode>(0, col));
418 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
421 typedef typename Lhs::Index Index;
422 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Packet &res)
424 res = pmul(lhs.template packet<LoadMode>(row, 0), pset1<Packet>(rhs.coeff(0, col)));
428 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
431 typedef typename Lhs::Index Index;
432 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& ,
const Rhs& , Packet &res)
434 res = pset1<Packet>(0);
438 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
441 typedef typename Lhs::Index Index;
442 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& ,
const Rhs& , Packet &res)
444 res = pset1<Packet>(0);
448 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
451 typedef typename Lhs::Index Index;
452 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Packet& res)
454 res = pset1<Packet>(0);
455 for(Index i = 0; i < lhs.cols(); ++i)
456 res = pmadd(pset1<Packet>(lhs.coeff(row, i)), rhs.template packet<LoadMode>(i, col), res);
460 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
463 typedef typename Lhs::Index Index;
464 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Packet& res)
466 res = pset1<Packet>(0);
467 for(Index i = 0; i < lhs.cols(); ++i)
468 res = pmadd(lhs.template packet<LoadMode>(row, i), pset1<Packet>(rhs.coeff(i, col)), res);
476 #endif // EIGEN_COEFFBASED_PRODUCT_H Definition: CoeffBasedProduct.h:285
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Definition: XprHelper.h:32
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition: Constants.h:81
The type used to identify a matrix expression.
Definition: Constants.h:431
Definition: GenericPacketMath.h:71
const unsigned int AlignedBit
means the first coefficient packet is guaranteed to be aligned
Definition: Constants.h:147
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:264
Definition: CoeffBasedProduct.h:32
Definition: XprHelper.h:371
const unsigned int EvalBeforeAssigningBit
means the expression should be evaluated before any assignment
Definition: Constants.h:63
Definition: CoeffBasedProduct.h:114
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:266
Definition: CoeffBasedProduct.h:35
Definition: XprHelper.h:316
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:64
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
const unsigned int EvalBeforeNestingBit
means the expression should be evaluated by the calling expression
Definition: Constants.h:58
Definition: CoeffBasedProduct.h:331
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48