12#ifndef KRONECKER_TENSOR_PRODUCT_H
13#define KRONECKER_TENSOR_PRODUCT_H
24template<
typename Derived>
29 typedef typename Traits::Scalar Scalar;
32 typedef typename Traits::Lhs
Lhs;
33 typedef typename Traits::Rhs
Rhs;
65 typename Lhs::Nested
m_A;
66 typename Rhs::Nested
m_B;
81template<
typename Lhs,
typename Rhs>
96 template<
typename Dest>
void evalTo(Dest& dst)
const;
114template<
typename Lhs,
typename Rhs>
129 template<
typename Dest>
void evalTo(Dest& dst)
const;
132template<
typename Lhs,
typename Rhs>
133template<
typename Dest>
136 const int BlockRows = Rhs::RowsAtCompileTime,
137 BlockCols = Rhs::ColsAtCompileTime;
138 const Index Br = m_B.rows(),
140 for (
Index i=0;
i < m_A.rows(); ++
i)
141 for (
Index j=0;
j < m_A.cols(); ++
j)
145template<
typename Lhs,
typename Rhs>
146template<
typename Dest>
149 Index Br = m_B.rows(), Bc = m_B.cols();
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();
201template<
typename _Lhs,
typename _Rhs>
219template<
typename _Lhs,
typename _Rhs>
230 LhsFlags = Lhs::Flags,
231 RhsFlags = Rhs::Flags,
270template<
typename A,
typename B>
297template<
typename A,
typename B>
ArrayXXi a
Definition Array_initializer_list_23_cxx11.cpp:1
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition StaticAssert.h:142
int rows
Definition Tutorial_commainit_02.cpp:1
int cols
Definition Tutorial_commainit_02.cpp:1
Scalar * b
Definition benchVecAdd.cpp:17
Expression of a fixed-size or dynamic-size block.
Definition Block.h:105
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:34
The base class of dense and sparse Kronecker product.
Definition KroneckerTensorProduct.h:26
Scalar coeff(Index row, Index col) const
Definition KroneckerTensorProduct.h:48
KroneckerProductBase(const Lhs &A, const Rhs &B)
Constructor.
Definition KroneckerTensorProduct.h:37
Traits::Rhs Rhs
Definition KroneckerTensorProduct.h:33
Rhs::Nested m_B
Definition KroneckerTensorProduct.h:66
Lhs::Nested m_A
Definition KroneckerTensorProduct.h:65
Scalar coeff(Index i) const
Definition KroneckerTensorProduct.h:58
Traits::Lhs Lhs
Definition KroneckerTensorProduct.h:32
Index cols() const
Definition KroneckerTensorProduct.h:42
Index rows() const
Definition KroneckerTensorProduct.h:41
Kronecker tensor product helper class for sparse matrices.
Definition KroneckerTensorProduct.h:116
void evalTo(Dest &dst) const
Evaluate the Kronecker tensor product.
Definition KroneckerTensorProduct.h:147
KroneckerProductSparse(const Lhs &A, const Rhs &B)
Constructor.
Definition KroneckerTensorProduct.h:124
Kronecker tensor product helper class for dense matrices.
Definition KroneckerTensorProduct.h:83
KroneckerProduct(const Lhs &A, const Rhs &B)
Constructor.
Definition KroneckerTensorProduct.h:91
void evalTo(Dest &dst) const
Evaluate the Kronecker tensor product.
Definition KroneckerTensorProduct.h:134
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition PlainObjectBase.h:247
Definition ReturnByValue.h:52
Definition TensorRef.h:81
const unsigned int EvalBeforeNestingBit
Definition Constants.h:70
const unsigned int RowMajorBit
Definition Constants.h:66
DenseIndex ret
Definition level1_cplx_impl.h:44
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
const unsigned int HereditaryBits
Definition Constants.h:195
const int HugeCost
Definition Constants.h:44
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
KroneckerProduct< A, B > kroneckerProduct(const MatrixBase< A > &a, const MatrixBase< B > &b)
Definition KroneckerTensorProduct.h:271
Definition BandTriangularSolver.h:13
Definition EigenBase.h:30
Definition Constants.h:522
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:806
remove_all< _Rhs >::type Rhs
Definition KroneckerTensorProduct.h:224
remove_all< _Lhs >::type Lhs
Definition KroneckerTensorProduct.h:223
promote_index_type< typenameLhs::StorageIndex, typenameRhs::StorageIndex >::type StorageIndex
Definition KroneckerTensorProduct.h:227
MatrixXpr XprKind
Definition KroneckerTensorProduct.h:222
ScalarBinaryOpTraits< typenameLhs::Scalar, typenameRhs::Scalar >::ReturnType Scalar
Definition KroneckerTensorProduct.h:225
SparseMatrix< Scalar, 0, StorageIndex > ReturnType
Definition KroneckerTensorProduct.h:246
cwise_promote_storage_type< typenametraits< Lhs >::StorageKind, typenametraits< Rhs >::StorageKind, scalar_product_op< typenameLhs::Scalar, typenameRhs::Scalar > >::ret StorageKind
Definition KroneckerTensorProduct.h:226
promote_index_type< typenameLhs::StorageIndex, typenameRhs::StorageIndex >::type StorageIndex
Definition KroneckerTensorProduct.h:207
Matrix< Scalar, Rows, Cols > ReturnType
Definition KroneckerTensorProduct.h:216
remove_all< _Rhs >::type Rhs
Definition KroneckerTensorProduct.h:205
remove_all< _Lhs >::type Lhs
Definition KroneckerTensorProduct.h:204
ScalarBinaryOpTraits< typenameLhs::Scalar, typenameRhs::Scalar >::ReturnType Scalar
Definition KroneckerTensorProduct.h:206
Definition ForwardDeclarations.h:17
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2