35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATTSMATKRONEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_TSMATTSMATKRONEXPR_H_ 85 template<
typename MT1
87 class TSMatTSMatKronExpr
88 :
public MatMatKronExpr< SparseMatrix< TSMatTSMatKronExpr<MT1,MT2>, true > >
108 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
191 inline size_t rows() const noexcept {
202 return lhs_.columns() *
rhs_.columns();
212 return lhs_.nonZeros() *
rhs_.nonZeros();
223 return lhs_.nonZeros( i/
rhs_.columns() ) *
rhs_.nonZeros( i%
rhs_.columns() );
253 template<
typename T >
254 inline bool canAlias(
const T* alias )
const noexcept {
255 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
265 template<
typename T >
266 inline bool isAliased(
const T* alias )
const noexcept {
267 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
290 template<
typename MT
299 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
311 const size_t M( B.rows() );
312 const size_t N( B.columns() );
314 for(
size_t j=0UL; j<A.columns(); ++j )
315 for(
size_t l=0UL; l<N; ++l )
316 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
317 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
318 (~lhs)(aelem->index()*M+belem->index(),j*N+l) = aelem->value() * belem->value();
336 template<
typename MT >
344 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
356 const size_t M( B.rows() );
357 const size_t N( B.columns() );
360 std::vector<size_t> lnonzeros( A.rows(), 0UL );
361 for(
size_t j=0UL; j<A.columns(); ++j ) {
362 const auto end( A.end(j) );
363 for(
auto aelem=A.begin(j); aelem!=
end; ++aelem ) {
364 ++lnonzeros[aelem->index()];
369 std::vector<size_t> rnonzeros( M, 0UL );
370 for(
size_t j=0UL; j<N; ++j ) {
371 const auto end( B.end(j) );
372 for(
auto belem=B.begin(j); belem!=
end; ++belem ) {
373 ++rnonzeros[belem->index()];
378 for(
size_t i=0UL; i<A.rows(); ++i ) {
379 for(
size_t j=0UL; j<M; ++j ) {
380 (~lhs).reserve( i*M+j, lnonzeros[i]*rnonzeros[j] );
385 for(
size_t j=0UL; j<A.columns(); ++j )
386 for(
size_t l=0UL; l<N; ++l )
387 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
388 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
389 (~lhs).append( aelem->index()*M+belem->index(), j*N+l, aelem->value() * belem->value(), true );
407 template<
typename MT >
408 friend inline void assign( SparseMatrix<MT,true>& lhs,
const TSMatTSMatKronExpr& rhs )
415 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
427 const size_t M( B.rows() );
428 const size_t N( B.columns() );
430 for(
size_t j=0UL; j<A.columns(); ++j ) {
431 for(
size_t l=0UL; l<N; ++l ) {
432 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
433 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
434 (~lhs).append( aelem->index()*M+belem->index(), j*N+l, aelem->value() * belem->value(), true );
435 (~lhs).finalize( j*N+l );
455 template<
typename MT
457 friend inline void addAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatTSMatKronExpr& rhs )
464 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
476 const size_t M( B.rows() );
477 const size_t N( B.columns() );
479 for(
size_t j=0UL; j<A.columns(); ++j )
480 for(
size_t l=0UL; l<N; ++l )
481 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
482 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
483 (~lhs)(aelem->index()*M+belem->index(),j*N+l) += aelem->value() * belem->value();
505 template<
typename MT
507 friend inline void subAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatTSMatKronExpr& rhs )
514 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
526 const size_t M( B.rows() );
527 const size_t N( B.columns() );
529 for(
size_t j=0UL; j<A.columns(); ++j )
530 for(
size_t l=0UL; l<N; ++l )
531 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem )
532 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem )
533 (~lhs)(aelem->index()*M+belem->index(),j*N+l) -= aelem->value() * belem->value();
555 template<
typename MT
557 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs,
const TSMatTSMatKronExpr& rhs )
564 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
576 const size_t M( B.rows() );
577 const size_t N( B.columns() );
579 for(
size_t j=0UL; j<A.columns(); ++j ) {
580 for(
size_t l=0UL; l<N; ++l )
584 for(
auto aelem=A.begin(j); aelem!=A.end(j); ++aelem ) {
585 for(
auto belem=B.begin(l); belem!=B.end(l); ++belem, ++i ) {
586 const size_t index( aelem->index()*M+belem->index() );
587 for( ; i<index; ++i )
588 reset( (~lhs)(i,j*N+l) );
589 (~lhs)(i,j*N+l) *= aelem->value() * belem->value();
593 for( ; i<(~lhs).
rows(); ++i )
594 reset( (~lhs)(i,j*N+l) );
649 template<
typename MT1
651 ,
DisableIf_t< ( IsIdentity_v<MT1> && IsIdentity_v<MT2> ) ||
652 ( IsZero_v<MT1> || IsZero_v<MT2> ) >* =
nullptr >
653 inline const TSMatTSMatKronExpr<MT1,MT2>
654 tsmattsmatkron(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,true>& rhs )
658 return TSMatTSMatKronExpr<MT1,MT2>( ~lhs, ~rhs );
677 template<
typename MT1
679 , EnableIf_t< IsIdentity_v<MT1> && IsIdentity_v<MT2> >* =
nullptr >
680 inline decltype(
auto)
681 tsmattsmatkron( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
685 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
690 return ReturnType( (~lhs).
rows()*(~rhs).
rows() );
709 template<
typename MT1
711 , EnableIf_t< IsZero_v<MT1> || IsZero_v<MT2> >* =
nullptr >
712 inline decltype(
auto)
713 tsmattsmatkron( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
717 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
751 template<
typename MT1
753 inline decltype(
auto)
758 return tsmattsmatkron( ~lhs, ~rhs );
Constraint on the data type.
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:96
Header file for auxiliary alias declarations.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: TSMatTSMatKronExpr.h:232
#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
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:130
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
Expression object for transpose sparse matrix-transpose sparse matrix Kronecker product....
Definition: Forward.h:190
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.
RightOperand rhs_
Right-hand side sparse matrix of the Kronecker product expression.
Definition: TSMatTSMatKronExpr.h:274
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Constraint on the data type.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatTSMatKronExpr.h:119
Header file for the IsIdentity type trait.
Header file for the Computation base class.
Header file for the reset shim.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: TSMatTSMatKronExpr.h:242
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
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:95
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Header file for the SparseMatrix base class.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatTSMatKronExpr.h:222
Constraint on the data type.
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSMatTSMatKronExpr.h:120
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatTSMatKronExpr.h:191
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatTSMatKronExpr.h:254
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatTSMatKronExpr.h:201
#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
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatTSMatKronExpr.h:160
#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
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:93
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatTSMatKronExpr.h:138
#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
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:133
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatTSMatKronExpr.h:127
Header file for the Kron product trait.
Constraints on the storage order of matrix types.
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
Header file for the EnableIf class template.
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:94
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatTSMatKronExpr.h:266
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatTSMatKronExpr.h:211
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:97
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
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
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatTSMatKronExpr.h:118
TSMatTSMatKronExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatTSMatKronExpr class.
Definition: TSMatTSMatKronExpr.h:147
Header file for the IsZero type trait.
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatTSMatKronExpr.h:111
#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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatTSMatKronExpr.h:121
LeftOperand lhs_
Left-hand side sparse matrix of the Kronecker product expression.
Definition: TSMatTSMatKronExpr.h:273
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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatTSMatKronExpr.h:175
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatTSMatKronExpr.h:108
#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
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatTSMatKronExpr.h:124
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatKronExpr.h:98
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
#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
#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.