12 #ifndef KRONECKER_TENSOR_PRODUCT_H 13 #define KRONECKER_TENSOR_PRODUCT_H 24 template<
typename Derived>
50 return m_A.coeff(row /
m_B.rows(), col /
m_B.cols()) *
51 m_B.coeff(row %
m_B.rows(), col %
m_B.cols());
61 return m_A.coeff(i /
m_A.size()) *
m_B.coeff(i %
m_A.size());
65 typename Lhs::Nested
m_A;
66 typename Rhs::Nested
m_B;
81 template<
typename Lhs,
typename Rhs>
96 template<
typename Dest>
void evalTo(Dest& dst)
const;
114 template<
typename Lhs,
typename Rhs>
129 template<
typename Dest>
void evalTo(Dest& dst)
const;
132 template<
typename Lhs,
typename Rhs>
133 template<
typename Dest>
136 const int BlockRows = Rhs::RowsAtCompileTime,
137 BlockCols = Rhs::ColsAtCompileTime;
145 template<
typename Lhs,
typename Rhs>
146 template<
typename Dest>
150 dst.resize(this->
rows(), this->
cols());
151 dst.resizeNonZeros(0);
156 const Lhs1 lhs1(
m_A);
159 const Rhs1 rhs1(
m_B);
168 VectorXi nnzA = VectorXi::Zero(Dest::IsRowMajor ?
m_A.rows() :
m_A.cols());
169 for (
Index kA=0; kA <
m_A.outerSize(); ++kA)
170 for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
171 nnzA(Dest::IsRowMajor ? itA.row() : itA.col())++;
173 VectorXi nnzB = VectorXi::Zero(Dest::IsRowMajor ?
m_B.rows() :
m_B.cols());
174 for (
Index kB=0; kB <
m_B.outerSize(); ++kB)
175 for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
176 nnzB(Dest::IsRowMajor ? itB.row() : itB.col())++;
179 dst.reserve(VectorXi::Map(nnzAB.
data(), nnzAB.size()));
182 for (
Index kA=0; kA <
m_A.outerSize(); ++kA)
184 for (
Index kB=0; kB <
m_B.outerSize(); ++kB)
186 for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
188 for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
190 Index i = itA.row() * Br + itB.row(),
191 j = itA.col() * Bc + itB.col();
192 dst.insert(i,
j) = itA.value() * itB.value();
201 template<
typename _Lhs,
typename _Rhs>
219 template<
typename _Lhs,
typename _Rhs>
230 LhsFlags = Lhs::Flags,
231 RhsFlags = Rhs::Flags,
270 template<
typename A,
typename B>
297 template<
typename A,
typename B>
305 #endif // KRONECKER_TENSOR_PRODUCT_H
promote_index_type< typename Lhs::StorageIndex, typename Rhs::StorageIndex >::type StorageIndex
ScalarBinaryOpTraits< typename Lhs::Scalar, typename Rhs::Scalar >::ReturnType Scalar
KroneckerProductBase< KroneckerProductSparse > Base
A versatible sparse matrix representation.
SparseMatrix< Scalar, 0, StorageIndex > ReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Scalar coeff(Index row, Index col) const
internal::traits< Derived > Traits
remove_all< _Rhs >::type Rhs
Namespace containing all symbols from the Eigen library.
void evalTo(Dest &dst) const
Evaluate the Kronecker tensor product.
const unsigned int RowMajorBit
remove_all< _Lhs >::type Lhs
KroneckerProductBase< KroneckerProduct > Base
remove_all< _Rhs >::type Rhs
ScalarBinaryOpTraits< typename Lhs::Scalar, typename Rhs::Scalar >::ReturnType Scalar
const unsigned int HereditaryBits
KroneckerProductSparse(const Lhs &A, const Rhs &B)
Constructor.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
remove_all< _Lhs >::type Lhs
EIGEN_DEVICE_FUNC void evalTo(Dest &dst) const
promote_index_type< typename Lhs::StorageIndex, typename Rhs::StorageIndex >::type StorageIndex
KroneckerProductBase(const Lhs &A, const Rhs &B)
Constructor.
cwise_promote_storage_type< typename traits< Lhs >::StorageKind, typename traits< Rhs >::StorageKind, scalar_product_op< typename Lhs::Scalar, typename Rhs::Scalar > >::ret StorageKind
Expression of a fixed-size or dynamic-size block.
Matrix< Scalar, Rows, Cols > ReturnType
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
KroneckerProduct(const Lhs &A, const Rhs &B)
Constructor.
KroneckerProduct< A, B > kroneckerProduct(const MatrixBase< A > &a, const MatrixBase< B > &b)
const unsigned int EvalBeforeNestingBit
Generic expression where a coefficient-wise unary operator is applied to an expression.
The matrix class, also used for vectors and row-vectors.
void evalTo(Dest &dst) const
Evaluate the Kronecker tensor product.
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
EIGEN_DEVICE_FUNC Derived & derived()
Base class for all dense matrices, vectors, and expressions.
Kronecker tensor product helper class for dense matrices.
The base class of dense and sparse Kronecker product.
Kronecker tensor product helper class for sparse matrices.
An InnerIterator allows to loop over the element of any matrix expression.
Scalar coeff(Index i) const