35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSMATKRONEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_TSMATSMATKRONEXPR_H_ 86 template<
typename MT1
88 class TSMatSMatKronExpr
89 :
public MatMatKronExpr< SparseMatrix< TSMatSMatKronExpr<MT1,MT2>, false > >
109 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
192 inline size_t rows() const noexcept {
203 return lhs_.columns() *
rhs_.columns();
213 return lhs_.nonZeros() *
rhs_.nonZeros();
255 template<
typename T >
256 inline bool canAlias(
const T* alias )
const noexcept {
257 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
267 template<
typename T >
268 inline bool isAliased(
const T* alias )
const noexcept {
269 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
292 template<
typename MT
301 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
313 const size_t M( B.rows() );
314 const size_t N( B.columns() );
316 for(
size_t j=0UL; j<A.columns(); ++j )
317 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
318 for(
size_t k=0UL; k<M; ++k )
319 for(
auto belem=B.begin(k); belem!=B.end(k); ++belem )
320 (~lhs)(aelem->index()*M+k,j*N+belem->index()) = aelem->value() * belem->value();
338 template<
typename MT >
346 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
358 const size_t M( B.rows() );
359 const size_t N( B.columns() );
362 std::vector<size_t> nonzeros( A.rows(), 0UL );
363 for(
size_t j=0UL; j<A.columns(); ++j ) {
364 const auto end( A.end(j) );
365 for(
auto aelem=A.begin(j); aelem!=
end; ++aelem ) {
366 ++nonzeros[aelem->index()];
371 for(
size_t i=0UL; i<A.rows(); ++i ) {
372 for(
size_t j=0UL; j<M; ++j ) {
373 (~lhs).reserve( i*M+j, nonzeros[i]*B.nonZeros(j) );
378 for(
size_t j=0UL; j<A.columns(); ++j )
379 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
380 for(
size_t k=0UL; k<M; ++k )
381 for(
auto belem=B.begin(k); belem!=B.end(k); ++belem )
382 (~lhs).append( aelem->index()*M+k, j*N+belem->index(), aelem->value() * belem->value(), true );
400 template<
typename MT >
401 friend inline void assign( SparseMatrix<MT,true>& lhs,
const TSMatSMatKronExpr& rhs )
408 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
420 const size_t M( B.rows() );
421 const size_t N( B.columns() );
424 std::vector<size_t> nonzeros( B.columns(), 0UL );
425 for(
size_t i=0UL; i<B.rows(); ++i ) {
426 const auto end( B.end(i) );
427 for(
auto belem=B.begin(i); belem!=
end; ++belem ) {
428 ++nonzeros[belem->index()];
433 for(
size_t i=0UL; i<A.columns(); ++i ) {
434 for(
size_t j=0UL; j<N; ++j ) {
435 (~lhs).reserve( i*N+j, A.nonZeros(i)*nonzeros[j] );
440 for(
size_t j=0UL; j<A.columns(); ++j )
441 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
442 for(
size_t k=0UL; k<M; ++k )
443 for(
auto belem=B.begin(k); belem!=B.end(k); ++belem )
444 (~lhs).append( aelem->index()*M+k, j*N+belem->index(), aelem->value() * belem->value(), true );
462 template<
typename MT
464 friend inline void addAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatSMatKronExpr& rhs )
471 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
483 const size_t M( B.rows() );
484 const size_t N( B.columns() );
486 for(
size_t j=0UL; j<A.columns(); ++j )
487 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
488 for(
size_t k=0UL; k<M; ++k )
489 for(
auto belem=B.begin(k); belem!=B.end(k); ++belem )
490 (~lhs)(aelem->index()*M+k,j*N+belem->index()) += aelem->value() * belem->value();
512 template<
typename MT
514 friend inline void subAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatSMatKronExpr& rhs )
521 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
533 const size_t M( B.rows() );
534 const size_t N( B.columns() );
536 for(
size_t j=0UL; j<A.columns(); ++j )
537 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
538 for(
size_t k=0UL; k<M; ++k )
539 for(
auto belem=B.begin(k); belem!=B.end(k); ++belem )
540 (~lhs)(aelem->index()*M+k,j*N+belem->index()) -= aelem->value() * belem->value();
562 template<
typename MT
564 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatSMatKronExpr& rhs )
571 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
583 const size_t M( B.rows() );
584 const size_t N( B.columns() );
586 for(
size_t j=0UL; j<A.columns(); ++j )
590 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem, ++i )
592 for( ; i<aelem->index(); ++i ) {
593 for(
size_t k=0UL; k<M; ++k )
594 for(
size_t l=0UL; l<N; ++l )
595 reset( (~lhs)(i*M+k,j*N+l) );
598 for(
size_t k=0UL; k<M; ++k )
602 for(
auto belem=B.begin(k); belem!=B.end(k); ++belem, ++l ) {
603 for( ; l<belem->index(); ++l )
604 reset( (~lhs)(i*M+k,j*N+l) );
605 (~lhs)(i*M+k,j*N+l) *= aelem->value() * belem->value();
609 reset( (~lhs)(i*M+k,j*N+l) );
614 for( ; i<A.rows(); ++i ) {
615 for(
size_t k=0UL; k<M; ++k )
616 for(
size_t l=0UL; l<N; ++l )
617 reset( (~lhs)(i*M+k,j*N+l) );
672 template<
typename MT1
674 ,
DisableIf_t< ( IsIdentity_v<MT1> && IsIdentity_v<MT2> ) ||
675 ( IsZero_v<MT1> || IsZero_v<MT2> ) >* =
nullptr >
676 inline const TSMatSMatKronExpr<MT1,MT2>
677 tsmatsmatkron(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
681 return TSMatSMatKronExpr<MT1,MT2>( ~lhs, ~rhs );
700 template<
typename MT1
702 , EnableIf_t< IsIdentity_v<MT1> && IsIdentity_v<MT2> >* =
nullptr >
703 inline decltype(
auto)
704 tsmatsmatkron( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,false>& rhs )
708 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
713 return ReturnType( (~lhs).
rows()*(~rhs).
rows() );
732 template<
typename MT1
734 , EnableIf_t< IsZero_v<MT1> || IsZero_v<MT2> >* =
nullptr >
735 inline decltype(
auto)
736 tsmatsmatkron( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,false>& rhs )
740 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
777 template<
typename MT1
779 inline decltype(
auto)
784 return tsmatsmatkron( ~lhs, ~rhs );
Constraint on the data type.
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatSMatKronExpr.h:192
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatSMatKronExpr.h:122
Header file for auxiliary alias declarations.
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not an identity matrix type,...
Definition: Identity.h:60
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatSMatKronExpr.h:161
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:98
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
LeftOperand lhs_
Left-hand side sparse matrix of the Kronecker product expression.
Definition: TSMatSMatKronExpr.h:275
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the serial shim.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatSMatKronExpr.h:109
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatSMatKronExpr.h:112
Expression object for sparse matrix-sparse matrix Kronecker product.The TSMatSMatKronExpr class repre...
Definition: Forward.h:183
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Constraint on the data type.
Header file for the IsIdentity type trait.
Header file for the Computation base class.
Header file for the reset shim.
Constraints on the storage order of matrix types.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
decltype(auto) kron(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the Kronecker product of two dense matrices ( ).
Definition: DMatDMatKronExpr.h:954
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Header file for the MatMatKronExpr base class.
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatSMatKronExpr.h:176
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:96
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatSMatKronExpr.h:223
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is not a zero vector or matrix type,...
Definition: Zero.h:61
typename KronTrait< T1, T2 >::Type KronTrait_t
Auxiliary alias declaration for the KronTrait class template.The KronTrait_t alias declaration provid...
Definition: KronTrait.h:163
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
TSMatSMatKronExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatSMatKronExpr class.
Definition: TSMatSMatKronExpr.h:148
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatSMatKronExpr.h:125
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for the Kron product trait.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatSMatKronExpr.h:256
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatSMatKronExpr.h:139
Constraints on the storage order of matrix types.
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:131
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:95
Header file for the exception macros of the math module.
Constraint on the data type.
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:438
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSMatSMatKronExpr.h:121
Header file for the EnableIf class template.
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:61
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatSMatKronExpr.h:128
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: TSMatSMatKronExpr.h:234
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: TSMatSMatKronExpr.h:244
Header file for the IsZero type trait.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatSMatKronExpr.h:268
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:94
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
RightOperand rhs_
Right-hand side sparse matrix of the Kronecker product expression.
Definition: TSMatSMatKronExpr.h:276
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:99
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatSMatKronExpr.h:212
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatSMatKronExpr.h:119
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATKRONEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: MatMatKronExpr.h:102
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatSMatKronExpr.h:202
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:134
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: TSMatSMatKronExpr.h:97
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is a zero vector or matrix type,...
Definition: Zero.h:81
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatSMatKronExpr.h:120
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type,...
Definition: SparseMatrix.h:61
Header file for the IsExpression type trait class.
Header file for the function trace functionality.