35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATDMATKRONEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_DMATDMATKRONEXPR_H_ 87 template<
typename MT1
91 :
public MatMatKronExpr< DenseMatrix< DMatDMatKronExpr<MT1,MT2,SO>, SO > >
113 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
199 inline size_t rows() const noexcept {
210 return lhs_.columns() *
rhs_.columns();
240 template<
typename T >
241 inline bool canAlias(
const T* alias )
const noexcept {
242 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
252 template<
typename T >
253 inline bool isAliased(
const T* alias )
const noexcept {
254 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
264 return rhs_.isAligned();
297 template<
typename MT >
312 const size_t M( B.rows() );
313 const size_t N( B.columns() );
317 for(
size_t i=0UL; i<A.rows(); ++i ) {
318 for(
size_t j=0UL; j<A.columns(); ++j ) {
320 for(
size_t l=0UL; l<N; ++l )
321 for(
size_t k=0UL; k<M; ++k )
322 (~lhs)(i*M+k,j*N+l) = A(i,j) * B(k,l);
325 for(
size_t l=0UL; l<N; ++l )
326 for(
size_t k=0UL; k<M; ++k )
327 reset( (~lhs)(i*M+k,j*N+l) );
334 for(
size_t i=0UL; i<A.rows(); ++i ) {
335 for(
size_t k=0UL; k<M; ++k ) {
336 for(
size_t j=0UL; j<A.columns(); ++j ) {
338 for(
size_t l=0UL; l<N; ++l )
339 (~lhs)(i*M+k,j*N+l) = A(i,j) * B(k,l);
342 for(
size_t l=0UL; l<N; ++l )
343 reset( (~lhs)(i*M+k,j*N+l) );
366 template<
typename MT >
381 const size_t M( B.rows() );
382 const size_t N( B.columns() );
386 for(
size_t j=0UL; j<A.columns(); ++j ) {
387 for(
size_t l=0UL; l<N; ++l ) {
388 for(
size_t i=0UL; i<A.rows(); ++i ) {
390 for(
size_t k=0UL; k<M; ++k )
391 (~lhs)(i*M+k,j*N+l) = A(i,j) * B(k,l);
394 for(
size_t k=0UL; k<M; ++k )
395 reset( (~lhs)(i*M+k,j*N+l) );
403 for(
size_t j=0UL; j<A.columns(); ++j ) {
404 for(
size_t i=0UL; i<A.rows(); ++i ) {
406 for(
size_t k=0UL; k<M; ++k )
407 for(
size_t l=0UL; l<N; ++l )
408 (~lhs)(i*M+k,j*N+l) = A(i,j) * B(k,l);
411 for(
size_t k=0UL; k<M; ++k )
412 for(
size_t l=0UL; l<N; ++l )
413 reset( (~lhs)(i*M+k,j*N+l) );
434 template<
typename MT
436 friend inline void assign( SparseMatrix<MT,SO2>& lhs,
const DMatDMatKronExpr& rhs )
440 using TmpType = If_t< SO == SO2, ResultType, OppositeType >;
452 const TmpType tmp(
serial( rhs ) );
471 template<
typename MT >
472 friend inline void addAssign( DenseMatrix<MT,false>& lhs,
const DMatDMatKronExpr& rhs )
479 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
486 const size_t M( B.rows() );
487 const size_t N( B.columns() );
491 for(
size_t i=0UL; i<A.rows(); ++i )
492 for(
size_t j=0UL; j<A.columns(); ++j )
494 for(
size_t l=0UL; l<N; ++l )
496 const size_t kbegin( ( IsLower_v<MT2> )
497 ?( ( IsStrictlyLower_v<MT2> ? l+1UL : l ) )
499 const size_t kend( ( IsUpper_v<MT2> )
500 ?( IsStrictlyUpper_v<MT2> ? l : l+1UL )
504 for(
size_t k=kbegin; k<kend; ++k )
505 (~lhs)(i*M+k,j*N+l) += A(i,j) * B(k,l);
510 for(
size_t i=0UL; i<A.rows(); ++i )
511 for(
size_t k=0UL; k<M; ++k )
513 const size_t lbegin( ( IsUpper_v<MT2> )
514 ?( ( IsStrictlyUpper_v<MT2> ? k+1UL : k ) )
516 const size_t lend( ( IsLower_v<MT2> )
517 ?( IsStrictlyLower_v<MT2> ? k : k+1UL )
521 for(
size_t j=0UL; j<A.columns(); ++j )
523 for(
size_t l=lbegin; l<lend; ++l )
524 (~lhs)(i*M+k,j*N+l) += A(i,j) * B(k,l);
544 template<
typename MT >
545 friend inline void addAssign( DenseMatrix<MT,true>& lhs,
const DMatDMatKronExpr& rhs )
552 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
559 const size_t M( B.rows() );
560 const size_t N( B.columns() );
564 for(
size_t j=0UL; j<A.columns(); ++j )
565 for(
size_t l=0UL; l<N; ++l )
567 const size_t kbegin( ( IsLower_v<MT2> )
568 ?( ( IsStrictlyLower_v<MT2> ? l+1UL : l ) )
570 const size_t kend( ( IsUpper_v<MT2> )
571 ?( IsStrictlyUpper_v<MT2> ? l : l+1UL )
575 for(
size_t i=0UL; i<A.rows(); ++i )
577 for(
size_t k=kbegin; k<kend; ++k )
578 (~lhs)(i*M+k,j*N+l) += A(i,j) * B(k,l);
583 for(
size_t j=0UL; j<A.columns(); ++j )
584 for(
size_t i=0UL; i<A.rows(); ++i )
586 for(
size_t k=0UL; k<M; ++k )
588 const size_t lbegin( ( IsUpper_v<MT2> )
589 ?( ( IsStrictlyUpper_v<MT2> ? k+1UL : k ) )
591 const size_t lend( ( IsLower_v<MT2> )
592 ?( IsStrictlyLower_v<MT2> ? k : k+1UL )
596 for(
size_t l=lbegin; l<lend; ++l )
597 (~lhs)(i*M+k,j*N+l) += A(i,j) * B(k,l);
621 template<
typename MT >
622 friend inline void subAssign( DenseMatrix<MT,false>& lhs,
const DMatDMatKronExpr& rhs )
629 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
636 const size_t M( B.rows() );
637 const size_t N( B.columns() );
641 for(
size_t i=0UL; i<A.rows(); ++i )
642 for(
size_t j=0UL; j<A.columns(); ++j )
644 for(
size_t l=0UL; l<N; ++l )
646 const size_t kbegin( ( IsLower_v<MT2> )
647 ?( ( IsStrictlyLower_v<MT2> ? l+1UL : l ) )
649 const size_t kend( ( IsUpper_v<MT2> )
650 ?( IsStrictlyUpper_v<MT2> ? l : l+1UL )
654 for(
size_t k=kbegin; k<kend; ++k )
655 (~lhs)(i*M+k,j*N+l) -= A(i,j) * B(k,l);
660 for(
size_t i=0UL; i<A.rows(); ++i )
661 for(
size_t k=0UL; k<M; ++k )
663 const size_t lbegin( ( IsUpper_v<MT2> )
664 ?( ( IsStrictlyUpper_v<MT2> ? k+1UL : k ) )
666 const size_t lend( ( IsLower_v<MT2> )
667 ?( IsStrictlyLower_v<MT2> ? k : k+1UL )
671 for(
size_t j=0UL; j<A.columns(); ++j )
673 for(
size_t l=lbegin; l<lend; ++l )
674 (~lhs)(i*M+k,j*N+l) -= A(i,j) * B(k,l);
694 template<
typename MT >
695 friend inline void subAssign( DenseMatrix<MT,true>& lhs,
const DMatDMatKronExpr& rhs )
702 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
709 const size_t M( B.rows() );
710 const size_t N( B.columns() );
714 for(
size_t j=0UL; j<A.columns(); ++j )
715 for(
size_t l=0UL; l<N; ++l )
717 const size_t kbegin( ( IsLower_v<MT2> )
718 ?( ( IsStrictlyLower_v<MT2> ? l+1UL : l ) )
720 const size_t kend( ( IsUpper_v<MT2> )
721 ?( IsStrictlyUpper_v<MT2> ? l : l+1UL )
725 for(
size_t i=0UL; i<A.rows(); ++i )
727 for(
size_t k=kbegin; k<kend; ++k )
728 (~lhs)(i*M+k,j*N+l) -= A(i,j) * B(k,l);
733 for(
size_t j=0UL; j<A.columns(); ++j )
734 for(
size_t i=0UL; i<A.rows(); ++i )
736 for(
size_t k=0UL; k<M; ++k )
738 const size_t lbegin( ( IsUpper_v<MT2> )
739 ?( ( IsStrictlyUpper_v<MT2> ? k+1UL : k ) )
741 const size_t lend( ( IsLower_v<MT2> )
742 ?( IsStrictlyLower_v<MT2> ? k : k+1UL )
746 for(
size_t l=lbegin; l<lend; ++l )
747 (~lhs)(i*M+k,j*N+l) -= A(i,j) * B(k,l);
771 template<
typename MT >
772 friend inline void schurAssign( DenseMatrix<MT,false>& lhs,
const DMatDMatKronExpr& rhs )
779 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
786 const size_t M( B.rows() );
787 const size_t N( B.columns() );
791 for(
size_t i=0UL; i<A.rows(); ++i ) {
792 for(
size_t j=0UL; j<A.columns(); ++j ) {
794 for(
size_t l=0UL; l<N; ++l )
795 for(
size_t k=0UL; k<M; ++k )
796 (~lhs)(i*M+k,j*N+l) *= A(i,j) * B(k,l);
799 for(
size_t l=0UL; l<N; ++l )
800 for(
size_t k=0UL; k<M; ++k )
801 reset( (~lhs)(i*M+k,j*N+l) );
808 for(
size_t i=0UL; i<A.rows(); ++i ) {
809 for(
size_t k=0UL; k<M; ++k ) {
810 for(
size_t j=0UL; j<A.columns(); ++j ) {
812 for(
size_t l=0UL; l<N; ++l )
813 (~lhs)(i*M+k,j*N+l) *= A(i,j) * B(k,l);
816 for(
size_t l=0UL; l<N; ++l )
817 reset( (~lhs)(i*M+k,j*N+l) );
840 template<
typename MT >
841 friend inline void schurAssign( DenseMatrix<MT,true>& lhs,
const DMatDMatKronExpr& rhs )
848 if( rhs.rows() == 0UL || rhs.columns() == 0UL ) {
855 const size_t M( B.rows() );
856 const size_t N( B.columns() );
860 for(
size_t j=0UL; j<A.columns(); ++j ) {
861 for(
size_t l=0UL; l<N; ++l ) {
862 for(
size_t i=0UL; i<A.rows(); ++i ) {
864 for(
size_t k=0UL; k<M; ++k )
865 (~lhs)(i*M+k,j*N+l) *= A(i,j) * B(k,l);
868 for(
size_t k=0UL; k<M; ++k )
869 reset( (~lhs)(i*M+k,j*N+l) );
877 for(
size_t j=0UL; j<A.columns(); ++j ) {
878 for(
size_t i=0UL; i<A.rows(); ++i ) {
880 for(
size_t k=0UL; k<M; ++k )
881 for(
size_t l=0UL; l<N; ++l )
882 (~lhs)(i*M+k,j*N+l) *= A(i,j) * B(k,l);
885 for(
size_t k=0UL; k<M; ++k )
886 for(
size_t l=0UL; l<N; ++l )
887 reset( (~lhs)(i*M+k,j*N+l) );
949 template<
typename MT1
953 inline decltype(
auto)
959 return ReturnType( ~lhs, ~rhs );
Expression object for dense matrix-dense matrix Kronecker products.The DMatDMatKronExpr class represe...
Definition: DMatDMatKronExpr.h:90
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:97
Header file for auxiliary alias declarations.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatDMatKronExpr.h:253
Header file for the alignment flag values.
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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatDMatKronExpr.h:126
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatDMatKronExpr.h:219
ElementType_t< MT1 > ET1
Element type of the left-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:102
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.
#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
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: DMatDMatKronExpr.h:129
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatDMatKronExpr.h:143
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Header file for the MAYBE_UNUSED function template.
Header file for the Computation base class.
Header file for the reset shim.
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:99
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
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatDMatKronExpr.h:273
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
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Base class for all matrix/matrix Kronecker expression templates.The MatMatKronExpr class serves as a ...
Definition: MatMatKronExpr.h:67
Constraint on the data type.
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:101
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: DMatDMatKronExpr.h:116
Header file for the IsTemporary type trait class.
Header file for the IsStrictlyUpper type trait.
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: DMatDMatKronExpr.h:209
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatDMatKronExpr.h:146
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
Header file for the DenseMatrix base class.
Header file for the IsLower type trait.
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: DMatDMatKronExpr.h:229
Header file for the Kron product trait.
Constraints on the storage order of matrix types.
ElementType_t< MT2 > ET2
Element type of the right-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:103
Header file for the exception macros of the math module.
Constraint on the data type.
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatDMatKronExpr.h:199
Constraint on the data type.
Header file for the IsStrictlyLower type trait.
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:138
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:135
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatDMatKronExpr.h:132
ReturnType_t< MT1 > RN1
Return type of the left-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:98
RightOperand rhs_
Right-hand side dense matrix of the Kronecker product expression.
Definition: DMatDMatKronExpr.h:281
DMatDMatKronExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the DMatDMatKronExpr class.
Definition: DMatDMatKronExpr.h:155
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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatDMatKronExpr.h:183
#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 all forward declarations for expression class templates.
Header file for the isDefault shim.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatDMatKronExpr.h:125
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_SAME_STORAGE_ORDER(T1, T2)
Constraint on the data type.In case either of the two given data types T1 or T2 is not a matrix type ...
Definition: StorageOrder.h:84
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DMatDMatKronExpr.h:123
LeftOperand lhs_
Left-hand side dense matrix of the Kronecker product expression.
Definition: DMatDMatKronExpr.h:280
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatDMatKronExpr.h:168
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatDMatKronExpr.h:263
#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
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:96
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatDMatKronExpr.h:241
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.
CompositeType_t< MT1 > CT1
Composite type of the left-hand side dense matrix expression.
Definition: DMatDMatKronExpr.h:100
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: DMatDMatKronExpr.h:113
#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
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatDMatKronExpr.h:124