11#ifndef EIGEN_DIAGONALPRODUCT_H
12#define EIGEN_DIAGONALPRODUCT_H
17template<
typename MatrixType,
typename DiagonalType,
int ProductOrder>
18struct traits<DiagonalProduct<MatrixType, DiagonalType, ProductOrder> >
21 typedef typename scalar_product_traits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar;
23 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
24 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
25 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
26 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
29 _ScalarAccessOnDiag = !((int(_StorageOrder) ==
ColMajor && int(ProductOrder) ==
OnTheLeft)
31 _SameTypes = is_same<typename MatrixType::Scalar, typename DiagonalType::Scalar>::value,
34 _Vectorizable =
bool(
int(MatrixType::Flags)&
PacketAccessBit) && _SameTypes && (_ScalarAccessOnDiag || (bool(
int(DiagonalType::DiagonalVectorType::Flags)&
PacketAccessBit))),
35 _LinearAccessMask = (RowsAtCompileTime==1 || ColsAtCompileTime==1) ?
LinearAccessBit : 0,
37 Flags = ((HereditaryBits|_LinearAccessMask|
AlignedBit) & (
unsigned int)(MatrixType::Flags)) | (_Vectorizable ?
PacketAccessBit : 0),
38 Cost0 = EIGEN_ADD_COST(NumTraits<Scalar>::MulCost, MatrixType::CoeffReadCost),
39 CoeffReadCost = EIGEN_ADD_COST(Cost0,DiagonalType::DiagonalVectorType::CoeffReadCost)
44template<
typename MatrixType,
typename DiagonalType,
int ProductOrder>
45class DiagonalProduct : internal::no_assignment_operator,
46 public MatrixBase<DiagonalProduct<MatrixType, DiagonalType, ProductOrder> >
50 typedef MatrixBase<DiagonalProduct> Base;
51 EIGEN_DENSE_PUBLIC_INTERFACE(DiagonalProduct)
53 inline DiagonalProduct(
const MatrixType& matrix,
const DiagonalType&
diagonal)
54 : m_matrix(matrix), m_diagonal(
diagonal)
56 eigen_assert(
diagonal.diagonal().size() == (ProductOrder ==
OnTheLeft ? matrix.rows() : matrix.cols()));
59 EIGEN_STRONG_INLINE
Index rows()
const {
return m_matrix.rows(); }
60 EIGEN_STRONG_INLINE
Index cols()
const {
return m_matrix.cols(); }
67 EIGEN_STRONG_INLINE
const Scalar coeff(
Index idx)
const
72 return coeff(
int(StorageOrder)==
ColMajor?idx:0,
int(StorageOrder)==
ColMajor?0:idx);
75 template<
int LoadMode>
82 return packet_impl<LoadMode>(
row,
col,indexInDiagonalVector,
typename internal::conditional<
84 ||(
int(StorageOrder) ==
ColMajor &&
int(ProductOrder) ==
OnTheRight)), internal::true_type, internal::false_type>::type());
87 template<
int LoadMode>
88 EIGEN_STRONG_INLINE PacketScalar packet(
Index idx)
const
93 return packet<LoadMode>(
int(StorageOrder)==
ColMajor?idx:0,
int(StorageOrder)==
ColMajor?0:idx);
97 template<
int LoadMode>
98 EIGEN_STRONG_INLINE PacketScalar packet_impl(
Index row,
Index col,
Index id, internal::true_type)
const
100 return internal::pmul(m_matrix.template packet<LoadMode>(
row,
col),
101 internal::pset1<PacketScalar>(m_diagonal.diagonal().coeff(
id)));
104 template<
int LoadMode>
105 EIGEN_STRONG_INLINE PacketScalar packet_impl(
Index row,
Index col,
Index id, internal::false_type)
const
111 return internal::pmul(m_matrix.template packet<LoadMode>(
row,
col),
112 m_diagonal.diagonal().template packet<DiagonalVectorPacketLoadMode>(
id));
115 typename MatrixType::Nested m_matrix;
116 typename DiagonalType::Nested m_diagonal;
121template<
typename Derived>
122template<
typename DiagonalDerived>
123inline const DiagonalProduct<Derived, DiagonalDerived, OnTheRight>
126 return DiagonalProduct<Derived, DiagonalDerived, OnTheRight>(derived(), a_diagonal.derived());
internal::traits< DiagonalProduct< MatrixType, DiagonalType, ProductOrder > >::Index Index
Definition DenseBase.h:60
ColXpr col(Index i)
Definition DenseBase.h:733
RowXpr row(Index i)
Definition DenseBase.h:750
@ RowsAtCompileTime
Definition DenseBase.h:102
@ Flags
Definition DenseBase.h:162
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
Definition MatrixBase.h:50
MatrixBase< DiagonalProduct< MatrixType, DiagonalType, ProductOrder > >::template DiagonalIndexReturnType< Index >::Type diagonal()
Definition Diagonal.h:221
@ OnTheLeft
Definition Constants.h:277
@ OnTheRight
Definition Constants.h:279
@ RowMajor
Definition Constants.h:266
@ ColMajor
Definition Constants.h:264
@ Aligned
Definition Constants.h:194
@ Unaligned
Definition Constants.h:192
const unsigned int RowMajorBit
Definition Constants.h:53
const unsigned int AlignedBit
Definition Constants.h:147
const unsigned int PacketAccessBit
Definition Constants.h:81
const unsigned int LinearAccessBit
Definition Constants.h:117