12 #ifndef KRONECKER_TENSOR_PRODUCT_H
13 #define KRONECKER_TENSOR_PRODUCT_H
26 template<
typename Derived>
30 typedef typename internal::traits<Derived>
Traits;
31 typedef typename Traits::Scalar
Scalar;
67 typename Lhs::Nested
m_A;
68 typename Rhs::Nested
m_B;
83 template<
typename Lhs,
typename Rhs>
98 template<
typename Dest>
void evalTo(Dest& dst)
const;
116 template<
typename Lhs,
typename Rhs>
131 template<
typename Dest>
void evalTo(Dest& dst)
const;
134 template<
typename Lhs,
typename Rhs>
135 template<
typename Dest>
138 const int BlockRows = Rhs::RowsAtCompileTime,
139 BlockCols = Rhs::ColsAtCompileTime;
140 const Index Br = m_B.rows(),
142 for (
Index i=0;
i < m_A.rows(); ++
i)
143 for (
Index j=0;
j < m_A.cols(); ++
j)
147 template<
typename Lhs,
typename Rhs>
148 template<
typename Dest>
151 Index Br = m_B.rows(), Bc = m_B.cols();
152 dst.resize(this->
rows(), this->
cols());
153 dst.resizeNonZeros(0);
156 typedef typename internal::nested_eval<Lhs,Dynamic>::type Lhs1;
158 const Lhs1 lhs1(m_A);
159 typedef typename internal::nested_eval<Rhs,Dynamic>::type Rhs1;
161 const Rhs1 rhs1(m_B);
164 typedef Eigen::InnerIterator<Lhs1Cleaned> LhsInnerIterator;
165 typedef Eigen::InnerIterator<Rhs1Cleaned> RhsInnerIterator;
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())++;
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())++;
184 for (
Index kA=0; kA < m_A.outerSize(); ++kA)
186 for (
Index kB=0; kB < m_B.outerSize(); ++kB)
188 for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
190 for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
192 Index i = itA.row() * Br + itB.row(),
193 j = itA.col() * Bc + itB.col();
194 dst.insert(
i,
j) = itA.value() * itB.value();
203 template<
typename Lhs_,
typename Rhs_>
209 typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex;
218 typedef Matrix<Scalar,Rows,Cols> ReturnType;
221 template<
typename Lhs_,
typename Rhs_>
222 struct traits<KroneckerProductSparse<Lhs_,Rhs_> >
224 typedef MatrixXpr XprKind;
227 typedef typename ScalarBinaryOpTraits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar;
228 typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
typename traits<Rhs>::StorageKind, scalar_product_op<typename Lhs::Scalar, typename Rhs::Scalar> >::ret StorageKind;
229 typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex;
232 LhsFlags = Lhs::Flags,
233 RhsFlags = Rhs::Flags,
240 EvalToRowMajor = (int(LhsFlags) & int(RhsFlags) &
RowMajorBit),
243 Flags = ((int(LhsFlags) | int(RhsFlags)) &
HereditaryBits & RemovedBits)
248 typedef SparseMatrix<Scalar, 0, StorageIndex> ReturnType;
272 template<
typename A,
typename B>
299 template<
typename A,
typename B>
SparseMatrix< double > A(n, n)
RowXpr row(Index i) const
ColXpr col(Index i) const
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
static const ConstantReturnType Zero()
TransposeReturnType transpose()
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
The base class of dense and sparse Kronecker product.
Scalar coeff(Index row, Index col) const
KroneckerProductBase(const Lhs &A, const Rhs &B)
Constructor.
Scalar coeff(Index i) const
internal::traits< Derived > Traits
Kronecker tensor product helper class for sparse matrices.
KroneckerProductBase< KroneckerProductSparse > Base
void evalTo(Dest &dst) const
Evaluate the Kronecker tensor product.
KroneckerProductSparse(const Lhs &A, const Rhs &B)
Constructor.
Kronecker tensor product helper class for dense matrices.
KroneckerProduct(const Lhs &A, const Rhs &B)
Constructor.
void evalTo(Dest &dst) const
Evaluate the Kronecker tensor product.
KroneckerProductBase< KroneckerProduct > Base
static ConstMapType Map(const Scalar *data)
internal::dense_xpr_base< ReturnByValue >::type Base
KroneckerProduct< A, B > kroneckerProduct(const MatrixBase< A > &a, const MatrixBase< B > &b)
const unsigned int EvalBeforeNestingBit
const unsigned int RowMajorBit
constexpr int size_at_compile_time(int rows, int cols)
typename remove_all< T >::type remove_all_t
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
const unsigned int HereditaryBits
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index