35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATSMATKRONEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_DMATSMATKRONEXPR_H_ 92 template<
typename MT1
96 :
public MatMatKronExpr< SparseMatrix< DMatSMatKronExpr<MT1,MT2,SO>, SO > >
116 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
199 inline size_t rows() const noexcept {
210 return lhs_.columns() *
rhs_.columns();
264 template<
typename T >
265 inline bool canAlias(
const T* alias )
const noexcept {
266 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
276 template<
typename T >
277 inline bool isAliased(
const T* alias )
const noexcept {
278 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
300 template<
typename MT
321 const size_t M( B.rows() );
322 const size_t N( B.columns() );
326 for(
size_t j=0UL; j<A.columns(); ++j )
328 const size_t ibegin( ( IsLower_v<MT1> )
329 ?( ( IsStrictlyLower_v<MT1> ? j+1UL : j ) )
331 const size_t iend( ( IsUpper_v<MT1> )
332 ?( IsStrictlyUpper_v<MT1> ? j : j+1UL )
336 for(
size_t l=0UL; l<N; ++l ) {
337 for(
size_t i=ibegin; i<iend; ++i ) {
339 const auto bbegin( B.begin(l) );
340 const auto bend ( B.end(l) );
341 for(
auto belem=bbegin; belem!=bend; ++belem ) {
342 (~lhs)(i*M+belem->index(),j*N+l) = A(i,j) * belem->value();
351 for(
size_t i=0UL; i<A.rows(); ++i )
353 const size_t jbegin( ( IsUpper_v<MT1> )
354 ?( ( IsStrictlyUpper_v<MT1> ? i+1UL : i ) )
356 const size_t jend( ( IsLower_v<MT1> )
357 ?( IsStrictlyLower_v<MT1> ? i : i+1UL )
361 for(
size_t k=0UL; k<M; ++k ) {
362 for(
size_t j=jbegin; j<jend; ++j ) {
364 const auto bbegin( B.begin(k) );
365 const auto bend ( B.end(k) );
366 for(
auto belem=bbegin; belem!=bend; ++belem ) {
367 (~lhs)(i*M+k,j*N+belem->index()) = A(i,j) * belem->value();
391 template<
typename MT >
411 const size_t M( B.rows() );
412 const size_t N( B.columns() );
417 std::vector<size_t> nonzeros( M, 0UL );
418 for(
size_t j=0UL; j<N; ++j ) {
419 const auto end( B.end(j) );
420 for(
auto elem=B.begin(j); elem!=
end; ++elem ) {
421 ++nonzeros[elem->index()];
426 for(
size_t i=0UL; i<A.rows(); ++i ) {
427 for(
size_t j=0UL; j<M; ++j ) {
428 (~lhs).reserve( i*M+j, A.columns()*nonzeros[j] );
433 for(
size_t j=0UL; j<A.columns(); ++j )
435 const size_t ibegin( ( IsLower_v<MT1> )
436 ?( ( IsStrictlyLower_v<MT1> ? j+1UL : j ) )
438 const size_t iend( ( IsUpper_v<MT1> )
439 ?( IsStrictlyUpper_v<MT1> ? j : j+1UL )
443 for(
size_t l=0UL; l<N; ++l ) {
444 for(
size_t i=ibegin; i<iend; ++i ) {
446 const auto end( B.end(l) );
447 for(
auto belem=B.begin(l); belem!=
end; ++belem ) {
448 (~lhs).append( i*M+belem->index(), j*N+l, A(i,j) * belem->value(), true );
457 for(
size_t i=0UL; i<A.rows(); ++i )
459 const size_t jbegin( ( IsUpper_v<MT1> )
460 ?( ( IsStrictlyUpper_v<MT1> ? i+1UL : i ) )
462 const size_t jend( ( IsLower_v<MT1> )
463 ?( IsStrictlyLower_v<MT1> ? i : i+1UL )
467 for(
size_t k=0UL; k<M; ++k ) {
468 for(
size_t j=jbegin; j<jend; ++j ) {
470 const auto bend( B.end(k) );
471 for(
auto belem=B.begin(k); belem!=bend; ++belem )
472 (~lhs).append( i*M+k, j*N+belem->index(), A(i,j) * belem->value(), true );
475 (~lhs).finalize( i*M+k );
496 template<
typename MT >
497 friend inline void assign( SparseMatrix<MT,true>& lhs,
const DMatSMatKronExpr& rhs )
504 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
516 const size_t M( B.rows() );
517 const size_t N( B.columns() );
521 for(
size_t j=0UL; j<A.columns(); ++j )
523 const size_t ibegin( ( IsLower_v<MT1> )
524 ?( ( IsStrictlyLower_v<MT1> ? j+1UL : j ) )
526 const size_t iend( ( IsUpper_v<MT1> )
527 ?( IsStrictlyUpper_v<MT1> ? j : j+1UL )
531 for(
size_t l=0UL; l<N; ++l ) {
532 for(
size_t i=ibegin; i<iend; ++i ) {
534 const auto end( B.end(l) );
535 for(
auto belem=B.begin(l); belem!=
end; ++belem )
536 (~lhs).append( i*M+belem->index(), j*N+l, A(i,j) * belem->value(), true );
539 (~lhs).finalize( j*N+l );
546 std::vector<size_t> nonzeros( N, 0UL );
547 for(
size_t i=0UL; i<M; ++i ) {
548 const auto end( B.end(i) );
549 for(
auto elem=B.begin(i); elem!=
end; ++elem ) {
550 ++nonzeros[elem->index()];
555 for(
size_t i=0UL; i<A.columns(); ++i ) {
556 for(
size_t j=0UL; j<N; ++j ) {
557 (~lhs).reserve( i*N+j, A.rows()*nonzeros[j] );
562 for(
size_t i=0UL; i<A.rows(); ++i )
564 const size_t jbegin( ( IsUpper_v<MT1> )
565 ?( ( IsStrictlyUpper_v<MT1> ? i+1UL : i ) )
567 const size_t jend( ( IsLower_v<MT1> )
568 ?( IsStrictlyLower_v<MT1> ? i : i+1UL )
572 for(
size_t k=0UL; k<M; ++k ) {
573 for(
size_t j=jbegin; j<jend; ++j ) {
575 const auto end( B.end(k) );
576 for(
auto belem=B.begin(k); belem!=
end; ++belem ) {
577 (~lhs).append( i*M+k, j*N+belem->index(), A(i,j) * belem->value(), true );
600 template<
typename MT
602 friend inline void addAssign( DenseMatrix<MT,SO2>& lhs,
const DMatSMatKronExpr& rhs )
609 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
621 const size_t M( B.rows() );
622 const size_t N( B.columns() );
626 for(
size_t j=0UL; j<A.columns(); ++j )
628 const size_t ibegin( ( IsLower_v<MT1> )
629 ?( ( IsStrictlyLower_v<MT1> ? j+1UL : j ) )
631 const size_t iend( ( IsUpper_v<MT1> )
632 ?( IsStrictlyUpper_v<MT1> ? j : j+1UL )
636 for(
size_t l=0UL; l<N; ++l ) {
637 for(
size_t i=ibegin; i<iend; ++i ) {
639 const auto bbegin( B.begin(l) );
640 const auto bend ( B.end(l) );
641 for(
auto belem=bbegin; belem!=bend; ++belem )
642 (~lhs)(i*M+belem->index(),j*N+l) += A(i,j) * belem->value();
650 for(
size_t i=0UL; i<A.rows(); ++i )
652 const size_t jbegin( ( IsUpper_v<MT1> )
653 ?( ( IsStrictlyUpper_v<MT1> ? i+1UL : i ) )
655 const size_t jend( ( IsLower_v<MT1> )
656 ?( IsStrictlyLower_v<MT1> ? i : i+1UL )
660 for(
size_t k=0UL; k<M; ++k ) {
661 for(
size_t j=jbegin; j<jend; ++j ) {
663 const auto bbegin( B.begin(k) );
664 const auto bend ( B.end(k) );
665 for(
auto belem=bbegin; belem!=bend; ++belem )
666 (~lhs)(i*M+k,j*N+belem->index()) += A(i,j) * belem->value();
693 template<
typename MT
695 friend inline void subAssign( DenseMatrix<MT,SO2>& lhs,
const DMatSMatKronExpr& rhs )
702 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
714 const size_t M( B.rows() );
715 const size_t N( B.columns() );
719 for(
size_t j=0UL; j<A.columns(); ++j )
721 const size_t ibegin( ( IsLower_v<MT1> )
722 ?( ( IsStrictlyLower_v<MT1> ? j+1UL : j ) )
724 const size_t iend( ( IsUpper_v<MT1> )
725 ?( IsStrictlyUpper_v<MT1> ? j : j+1UL )
729 for(
size_t l=0UL; l<N; ++l ) {
730 for(
size_t i=ibegin; i<iend; ++i ) {
732 const auto bbegin( B.begin(l) );
733 const auto bend ( B.end(l) );
734 for(
auto belem=bbegin; belem!=bend; ++belem )
735 (~lhs)(i*M+belem->index(),j*N+l) -= A(i,j) * belem->value();
743 for(
size_t i=0UL; i<A.rows(); ++i )
745 const size_t jbegin( ( IsUpper_v<MT1> )
746 ?( ( IsStrictlyUpper_v<MT1> ? i+1UL : i ) )
748 const size_t jend( ( IsLower_v<MT1> )
749 ?( IsStrictlyLower_v<MT1> ? i : i+1UL )
753 for(
size_t k=0UL; k<M; ++k ) {
754 for(
size_t j=jbegin; j<jend; ++j ) {
756 const auto bbegin( B.begin(k) );
757 const auto bend ( B.end(k) );
758 for(
auto belem=bbegin; belem!=bend; ++belem )
759 (~lhs)(i*M+k,j*N+belem->index()) -= A(i,j) * belem->value();
786 template<
typename MT
788 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs,
const DMatSMatKronExpr& rhs )
795 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
807 const size_t M( B.rows() );
808 const size_t N( B.columns() );
812 for(
size_t j=0UL; j<A.columns(); ++j ) {
813 for(
size_t l=0UL; l<N; ++l )
815 const auto bbegin( B.begin(l) );
816 const auto bend ( B.end(l) );
818 for(
size_t i=0UL; i<A.rows(); ++i )
823 for(
auto belem=bbegin; belem!=bend; ++belem, ++k ) {
824 for( ; k<belem->index(); ++k )
825 reset( (~lhs)(i*M+k,j*N+l) );
826 (~lhs)(i*M+k,j*N+l) *= A(i,j) * belem->value();
831 reset( (~lhs)(i*M+k,j*N+l) );
839 for(
size_t i=0UL; i<A.rows(); ++i ) {
840 for(
size_t k=0UL; k<M; ++k )
842 const auto bbegin( B.begin(k) );
843 const auto bend ( B.end(k) );
845 for(
size_t j=0UL; j<A.columns(); ++j )
850 for(
auto belem=bbegin; belem!=bend; ++belem, ++l ) {
851 for( ; l<belem->index(); ++l )
852 reset( (~lhs)(i*M+k,j*N+l) );
853 (~lhs)(i*M+k,j*N+l) *= A(i,j) * belem->value();
858 reset( (~lhs)(i*M+k,j*N+l) );
914 template<
typename MT1
918 , DisableIf_t< IsZero_v<MT2> >* =
nullptr >
919 inline const DMatSMatKronExpr<MT1,MT2,SO2>
920 dmatsmatkron(
const DenseMatrix<MT1,SO1>& lhs,
const SparseMatrix<MT2,SO2>& rhs )
924 return DMatSMatKronExpr<MT1,MT2,SO2>( ~lhs, ~rhs );
943 template<
typename MT1
947 , EnableIf_t< IsZero_v<MT2> >* =
nullptr >
948 inline decltype(
auto)
949 dmatsmatkron( const DenseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
953 using ReturnType =
const KronTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
986 template<
typename MT1
990 inline decltype(
auto)
995 return dmatsmatkron( ~lhs, ~rhs );
Header file for auxiliary alias declarations.
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DMatSMatKronExpr.h:126
Header file for basic type definitions.
Expression object for dense matrix-sparse matrix Kronecker product.The DMatSMatKronExpr class represe...
Definition: DMatSMatKronExpr.h:95
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
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.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: DMatSMatKronExpr.h:219
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:63
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type,...
Definition: DenseMatrix.h:61
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatSMatKronExpr.h:209
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: DMatSMatKronExpr.h:106
Header file for the IsColumnMajorMatrix type trait.
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: DMatSMatKronExpr.h:102
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 MAYBE_UNUSED function template.
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: DMatSMatKronExpr.h:104
Header file for the Computation base class.
Header file for the reset shim.
ReturnType_t< MT1 > RN1
Return type of the left-hand side dense matrix expression.
Definition: DMatSMatKronExpr.h:103
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatSMatKronExpr.h:183
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatSMatKronExpr.h:265
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
Header file for the SparseMatrix base class.
Constraint on the data type.
Base class for all matrix/matrix Kronecker expression templates.The MatMatKronExpr class serves as a ...
Definition: MatMatKronExpr.h:67
Constraint on the data type.
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: DMatSMatKronExpr.h:119
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the IsStrictlyUpper type trait.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: DMatSMatKronExpr.h:230
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: DMatSMatKronExpr.h:132
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#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
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatSMatKronExpr.h:127
#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
Header file for the DenseMatrix base class.
Header file for the IsLower type trait.
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatSMatKronExpr.h:101
LeftOperand lhs_
Left-hand side dense matrix of the Kronecker product expression.
Definition: DMatSMatKronExpr.h:284
Header file for the Kron product trait.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: DMatSMatKronExpr.h:116
Constraints on the storage order of matrix types.
Header file for the exception macros of the math module.
Constraint on the data type.
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: DMatSMatKronExpr.h:141
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.
Header file for the IsStrictlyLower type trait.
DMatSMatKronExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the DMatSMatKronExpr class.
Definition: DMatSMatKronExpr.h:155
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatSMatKronExpr.h:168
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
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatSMatKronExpr.h:128
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
Header file for the isDefault shim.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatSMatKronExpr.h:146
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
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatSMatKronExpr.h:243
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatSMatKronExpr.h:129
Header file for the IsRowMajorMatrix type trait.
RightOperand rhs_
Right-hand side sparse matrix of the Kronecker product expression.
Definition: DMatSMatKronExpr.h:285
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatSMatKronExpr.h:277
#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
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
CompositeType_t< MT1 > CT1
Composite type of the left-hand side dense matrix expression.
Definition: DMatSMatKronExpr.h:105
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatSMatKronExpr.h:138
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatSMatKronExpr.h:135
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
Header file for the IsUpper type trait.
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatSMatKronExpr.h:199
#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
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: DMatSMatKronExpr.h:253
#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.