Eigen::KroneckerProductSparse< Lhs, Rhs > Class Template Reference

Kronecker tensor product helper class for sparse matrices. More...

+ Inheritance diagram for Eigen::KroneckerProductSparse< Lhs, Rhs >:

Public Member Functions

template<typename Dest >
void evalTo (Dest &dst) const
 Evaluate the Kronecker tensor product. More...
 
 KroneckerProductSparse (const Lhs &A, const Rhs &B)
 Constructor. More...
 
- Public Member Functions inherited from Eigen::KroneckerProductBase< KroneckerProductSparse< Lhs, Rhs > >
Scalar coeff (Index i) const
 
Scalar coeff (Index row, Index col) const
 
Index cols () const
 
 KroneckerProductBase (const Lhs &A, const Rhs &B)
 Constructor. More...
 
Index rows () const
 
- Public Member Functions inherited from Eigen::ReturnByValue< class >
EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT
 
void evalTo (Dest &dst) const
 
EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT
 

Private Types

typedef KroneckerProductBase< KroneckerProductSparseBase
 

Additional Inherited Members

- Public Types inherited from Eigen::ReturnByValue< class >
typedef internal::dense_xpr_base< ReturnByValue >::type Base
 
typedef internal::traits< Derived >::ReturnType ReturnType
 
- Protected Types inherited from Eigen::KroneckerProductBase< KroneckerProductSparse< Lhs, Rhs > >
typedef Traits::Lhs Lhs
 
typedef Traits::Rhs Rhs
 
- Protected Attributes inherited from Eigen::KroneckerProductBase< KroneckerProductSparse< Lhs, Rhs > >
Lhs::Nested m_A
 
Rhs::Nested m_B
 

Detailed Description

template<typename Lhs, typename Rhs>
class Eigen::KroneckerProductSparse< Lhs, Rhs >

Kronecker tensor product helper class for sparse matrices.

If at least one of the operands is a sparse matrix expression, then this class is returned and evaluates into a sparse matrix.

This class is the return value of kroneckerProduct(EigenBase, EigenBase). Use the function rather than construct this class directly to avoid specifying template prarameters.

Template Parameters
LhsType of the left-hand side, a matrix expression.
RhsType of the rignt-hand side, a matrix expression.

Definition at line 117 of file KroneckerTensorProduct.h.

Member Typedef Documentation

◆ Base

template<typename Lhs , typename Rhs >
typedef KroneckerProductBase<KroneckerProductSparse> Eigen::KroneckerProductSparse< Lhs, Rhs >::Base
private

Definition at line 120 of file KroneckerTensorProduct.h.

Constructor & Destructor Documentation

◆ KroneckerProductSparse()

template<typename Lhs , typename Rhs >
Eigen::KroneckerProductSparse< Lhs, Rhs >::KroneckerProductSparse ( const Lhs A,
const Rhs B 
)
inline

Constructor.

Definition at line 126 of file KroneckerTensorProduct.h.

127  : Base(A, B)
128  {}
KroneckerProductBase< KroneckerProductSparse > Base

Member Function Documentation

◆ evalTo()

template<typename Lhs , typename Rhs >
template<typename Dest >
void Eigen::KroneckerProductSparse< Lhs, Rhs >::evalTo ( Dest &  dst) const

Evaluate the Kronecker tensor product.

Definition at line 149 of file KroneckerTensorProduct.h.

150 {
151  Index Br = m_B.rows(), Bc = m_B.cols();
152  dst.resize(this->rows(), this->cols());
153  dst.resizeNonZeros(0);
154 
155  // 1 - evaluate the operands if needed:
156  typedef typename internal::nested_eval<Lhs,Dynamic>::type Lhs1;
157  typedef internal::remove_all_t<Lhs1> Lhs1Cleaned;
158  const Lhs1 lhs1(m_A);
159  typedef typename internal::nested_eval<Rhs,Dynamic>::type Rhs1;
160  typedef internal::remove_all_t<Rhs1> Rhs1Cleaned;
161  const Rhs1 rhs1(m_B);
162 
163  // 2 - construct respective iterators
164  typedef Eigen::InnerIterator<Lhs1Cleaned> LhsInnerIterator;
165  typedef Eigen::InnerIterator<Rhs1Cleaned> RhsInnerIterator;
166 
167  // compute number of non-zeros per innervectors of dst
168  {
169  // TODO VectorXi is not necessarily big enough!
170  VectorXi nnzA = VectorXi::Zero(Dest::IsRowMajor ? m_A.rows() : m_A.cols());
171  for (Index kA=0; kA < m_A.outerSize(); ++kA)
172  for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
173  nnzA(Dest::IsRowMajor ? itA.row() : itA.col())++;
174 
175  VectorXi nnzB = VectorXi::Zero(Dest::IsRowMajor ? m_B.rows() : m_B.cols());
176  for (Index kB=0; kB < m_B.outerSize(); ++kB)
177  for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
178  nnzB(Dest::IsRowMajor ? itB.row() : itB.col())++;
179 
180  Matrix<int,Dynamic,Dynamic,ColMajor> nnzAB = nnzB * nnzA.transpose();
181  dst.reserve(VectorXi::Map(nnzAB.data(), nnzAB.size()));
182  }
183 
184  for (Index kA=0; kA < m_A.outerSize(); ++kA)
185  {
186  for (Index kB=0; kB < m_B.outerSize(); ++kB)
187  {
188  for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
189  {
190  for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
191  {
192  Index i = itA.row() * Br + itB.row(),
193  j = itA.col() * Bc + itB.col();
194  dst.insert(i,j) = itA.value() * itB.value();
195  }
196  }
197  }
198  }
199 }
int i
static const ConstantReturnType Zero()
Matrix< int, Dynamic, 1 > VectorXi
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
std::ptrdiff_t j

The documentation for this class was generated from the following file: