35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATTSMATKRONEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATTSMATKRONEXPR_H_
89 :
public MatMatKronExpr< SparseMatrix< SMatTSMatKronExpr<MT1,MT2>, true > >
109 static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
196 inline size_t rows() const noexcept {
207 return lhs_.columns() *
rhs_.columns();
217 return lhs_.nonZeros() *
rhs_.nonZeros();
259 template<
typename T >
260 inline bool canAlias(
const T* alias )
const noexcept {
261 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
271 template<
typename T >
272 inline bool isAliased(
const T* alias )
const noexcept {
273 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
296 template<
typename MT
317 const size_t M( B.rows() );
318 const size_t N( B.columns() );
320 for(
size_t i=0UL; i<A.rows(); ++i )
321 for(
auto aelem=A.begin(i); aelem!=A.end(i); ++aelem )
322 for(
size_t l=0UL; l<N; ++l )
323 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
324 (*lhs)(i*M+belem->index(),aelem->index()*N+l) = aelem->value() * belem->value();
342 template<
typename MT >
362 const size_t M( B.rows() );
363 const size_t N( B.columns() );
366 std::vector<size_t> nonzeros( B.rows(), 0UL );
367 for(
size_t j=0UL; j<B.columns(); ++j ) {
368 const auto end( B.end(j) );
369 for(
auto belem=B.begin(j); belem!=
end; ++belem ) {
370 ++nonzeros[belem->index()];
375 for(
size_t i=0UL; i<A.rows(); ++i ) {
376 for(
size_t j=0UL; j<M; ++j ) {
377 (*lhs).reserve( i*M+j, A.nonZeros(i)*nonzeros[j] );
382 for(
size_t i=0UL; i<A.rows(); ++i )
383 for(
auto aelem=A.begin(i); aelem!=A.end(i); ++aelem )
384 for(
size_t l=0UL; l<N; ++l )
385 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
386 (*lhs).append( i*M+belem->index(), aelem->index()*N+l, aelem->value() * belem->value(),
true );
404 template<
typename MT >
405 friend inline void assign( SparseMatrix<MT,true>& lhs,
const SMatTSMatKronExpr& rhs )
412 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
424 const size_t M( B.rows() );
425 const size_t N( B.columns() );
428 std::vector<size_t> nonzeros( A.columns(), 0UL );
429 for(
size_t i=0UL; i<A.rows(); ++i ) {
430 const auto end( A.end(i) );
431 for(
auto aelem=A.begin(i); aelem!=
end; ++aelem ) {
432 ++nonzeros[aelem->index()];
437 for(
size_t i=0UL; i<A.columns(); ++i ) {
438 for(
size_t j=0UL; j<N; ++j ) {
439 (*lhs).reserve( i*N+j, nonzeros[i]*B.nonZeros(j) );
444 for(
size_t i=0UL; i<A.rows(); ++i )
445 for(
auto aelem=A.begin(i); aelem!=A.end(i); ++aelem )
446 for(
size_t l=0UL; l<N; ++l )
447 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
448 (*lhs).append( i*M+belem->index(), aelem->index()*N+l, aelem->value() * belem->value(),
true );
466 template<
typename MT
468 friend inline void addAssign( DenseMatrix<MT,SO2>& lhs,
const SMatTSMatKronExpr& rhs )
475 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
487 const size_t M( B.rows() );
488 const size_t N( B.columns() );
490 for(
size_t i=0UL; i<A.rows(); ++i )
491 for(
auto aelem=A.begin(i); aelem!=A.end(i); ++aelem )
492 for(
size_t l=0UL; l<N; ++l )
493 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
494 (*lhs)(i*M+belem->index(),aelem->index()*N+l) += aelem->value() * belem->value();
516 template<
typename MT
518 friend inline void subAssign( DenseMatrix<MT,SO2>& lhs,
const SMatTSMatKronExpr& rhs )
525 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
537 const size_t M( B.rows() );
538 const size_t N( B.columns() );
540 for(
size_t i=0UL; i<A.rows(); ++i )
541 for(
auto aelem=A.begin(i); aelem!=A.end(i); ++aelem )
542 for(
size_t l=0UL; l<N; ++l )
543 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
544 (*lhs)(i*M+belem->index(),aelem->index()*N+l) -= aelem->value() * belem->value();
566 template<
typename MT
568 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs,
const SMatTSMatKronExpr& rhs )
575 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
587 const size_t M( B.rows() );
588 const size_t N( B.columns() );
590 for(
size_t i=0UL; i<A.rows(); ++i )
594 for(
auto aelem=A.begin(i); aelem!=A.end(i); ++aelem, ++j )
596 for( ; j<aelem->index(); ++j ) {
597 for(
size_t k=0UL; k<M; ++k )
598 for(
size_t l=0UL; l<N; ++l )
599 reset( (*lhs)(i*M+k,j*N+l) );
602 for(
size_t l=0UL; l<N; ++l )
606 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem, ++k ) {
607 for( ; k<belem->index(); ++k )
608 reset( (*lhs)(i*M+k,j*N+l) );
609 (*lhs)(i*M+k,j*N+l) *= aelem->value() * belem->value();
613 reset( (*lhs)(i*M+k,j*N+l) );
617 for( ; j<A.columns(); ++j ) {
618 for(
size_t k=0UL; k<M; ++k )
619 for(
size_t l=0UL; l<N; ++l )
620 reset( (*lhs)(i*M+k,j*N+l) );
675template<
typename MT1
677 ,
DisableIf_t< ( IsIdentity_v<MT1> && IsIdentity_v<MT2> ) ||
678 ( IsZero_v<MT1> || IsZero_v<MT2> ) >* =
nullptr >
679inline const SMatTSMatKronExpr<MT1,MT2>
680 smattsmatkron(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
684 return SMatTSMatKronExpr<MT1,MT2>( *lhs, *rhs );
703template<
typename MT1
705 , EnableIf_t< IsIdentity_v<MT1> && IsIdentity_v<MT2> >* =
nullptr >
707 smattsmatkron(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
711 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
716 return ReturnType( (*lhs).rows()*(*rhs).rows() );
735template<
typename MT1
737 , EnableIf_t< IsZero_v<MT1> || IsZero_v<MT2> >* =
nullptr >
739 smattsmatkron(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
743 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
747 return ReturnType( (*lhs).rows()*(*rhs).rows(), (*lhs).columns()*(*rhs).columns() );
780template<
typename MT1
787 return smattsmatkron( *lhs, *rhs );
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Constraints on the storage order of matrix types.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Constraint on the data type.
Header file for the If class template.
Header file for the IsExpression type trait class.
Header file for the IsIdentity type trait.
Header file for the IsTemporary type trait class.
Header file for the Kron product trait.
Header file for the MAYBE_UNUSED function template.
Constraints on the storage order of matrix types.
Constraint on the data type.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Expression object for sparse matrix-transpose sparse matrix Kronecker product.
Definition: SMatTSMatKronExpr.h:91
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatTSMatKronExpr.h:227
SMatTSMatKronExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatTSMatKronExpr class.
Definition: SMatTSMatKronExpr.h:152
LeftOperand lhs_
Left-hand side sparse matrix of the Kronecker product expression.
Definition: SMatTSMatKronExpr.h:279
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTSMatKronExpr.h:196
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatTSMatKronExpr.h:129
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatTSMatKronExpr.h:109
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatTSMatKronExpr.h:132
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatTSMatKronExpr.h:238
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatTSMatKronExpr.h:143
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:135
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTSMatKronExpr.h:165
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatTSMatKronExpr.h:112
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatTSMatKronExpr.h:272
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:96
RightOperand rhs_
Right-hand side sparse matrix of the Kronecker product expression.
Definition: SMatTSMatKronExpr.h:280
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatTSMatKronExpr.h:248
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:99
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatTSMatKronExpr.h:123
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTSMatKronExpr.h:125
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:94
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTSMatKronExpr.h:180
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatTSMatKronExpr.h:260
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTSMatKronExpr.h:206
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTSMatKronExpr.h:124
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatTSMatKronExpr.h:126
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:97
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:98
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatTSMatKronExpr.h:216
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:138
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatTSMatKronExpr.h:95
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the MatMatKronExpr base class.
Header file for the SparseMatrix base class.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
decltype(auto) kron(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the Kronecker product of two dense matrices ( ).
Definition: DMatDMatKronExpr.h:957
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATKRONEXPR(T1, T2)
Constraint on the data type.
Definition: MatMatKronExpr.h:102
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Identity.h:60
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
typename KronTrait< T1, T2 >::Type KronTrait_t
Auxiliary alias declaration for the KronTrait class template.
Definition: KronTrait.h:137
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:584
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for the reset shim.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix/matrix Kronecker expression templates.
Definition: MatMatKronExpr.h:69
Header file for the IsZero type trait.
Header file for basic type definitions.