35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATTDMATSUBEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_DMATTDMATSUBEXPR_H_ 90 template<
typename MT1
93 :
public MatMatSubExpr< DenseMatrix< DMatTDMatSubExpr<MT1,MT2>, false > >
113 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
128 ( RequiresEvaluation_v<MT1> || RequiresEvaluation_v<MT2> || !
returnExpr );
131 template<
typename MT >
133 static constexpr
bool UseAssign_v =
useAssign;
145 template<
typename MT >
146 static constexpr
bool UseSMPAssign_v =
219 if( i >=
lhs_.rows() ) {
222 if( j >=
lhs_.columns() ) {
234 inline size_t rows() const noexcept {
245 return lhs_.columns();
275 template<
typename T >
276 inline bool canAlias(
const T* alias )
const noexcept {
277 return ( IsExpression_v<MT1> && ( RequiresEvaluation_v<MT1> ?
lhs_.isAliased( alias ) :
lhs_.canAlias( alias ) ) ) ||
278 ( IsExpression_v<MT2> && ( RequiresEvaluation_v<MT2> ?
rhs_.isAliased( alias ) :
rhs_.canAlias( alias ) ) );
288 template<
typename T >
289 inline bool isAliased(
const T* alias )
const noexcept {
290 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
300 return lhs_.isAligned() &&
rhs_.isAligned();
310 return lhs_.canSMPAssign() ||
rhs_.canSMPAssign() ||
311 (
rows() *
columns() >= SMP_DMATTDMATSUB_THRESHOLD );
335 template<
typename MT
345 constexpr
size_t block( BLOCK_SIZE );
347 const size_t m( rhs.rows() );
348 const size_t n( rhs.columns() );
350 for(
size_t ii=0UL; ii<m; ii+=block ) {
351 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
352 for(
size_t jj=0UL; jj<n; jj+=block ) {
353 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
354 for(
size_t i=ii; i<iend; ++i ) {
355 for(
size_t j=jj; j<jend; ++j ) {
356 (~lhs)(i,j) = rhs.lhs_(i,j) - rhs.rhs_(i,j);
379 template<
typename MT
389 if( !IsOperation_v<MT1> &&
isSame( ~lhs, rhs.lhs_ ) ) {
390 subAssign( ~lhs, rhs.rhs_ );
392 else if( ( !IsOperation_v<MT2> &&
isSame( ~lhs, rhs.rhs_ ) ) ||
393 ( !RequiresEvaluation_v<MT2> && rhs.rhs_.isAliased( &(~lhs) ) ) ) {
394 assign ( ~lhs, -rhs.rhs_ );
395 addAssign( ~lhs, rhs.lhs_ );
398 assign ( ~lhs, rhs.lhs_ );
399 subAssign( ~lhs, rhs.rhs_ );
417 template<
typename MT
419 friend inline void assign( SparseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
423 using TmpType = If_t< SO, OppositeType, ResultType >;
435 const TmpType tmp(
serial( rhs ) );
456 template<
typename MT
458 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
459 -> DisableIf_t< UseAssign_v<MT> >
466 constexpr
size_t block( BLOCK_SIZE );
468 const size_t m( rhs.rows() );
469 const size_t n( rhs.columns() );
471 for(
size_t ii=0UL; ii<m; ii+=block ) {
472 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
473 for(
size_t jj=0UL; jj<n; jj+=block ) {
474 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
475 for(
size_t i=ii; i<iend; ++i ) {
476 for(
size_t j=jj; j<jend; ++j ) {
477 (~lhs)(i,j) += rhs.lhs_(i,j) - rhs.rhs_(i,j);
501 template<
typename MT
503 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
504 -> EnableIf_t< UseAssign_v<MT> >
511 if( !RequiresEvaluation_v<MT2> ) {
512 subAssign( ~lhs, rhs.rhs_ );
513 addAssign( ~lhs, rhs.lhs_ );
516 addAssign( ~lhs, rhs.lhs_ );
517 subAssign( ~lhs, rhs.rhs_ );
542 template<
typename MT
544 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
545 -> DisableIf_t< UseAssign_v<MT> >
552 constexpr
size_t block( BLOCK_SIZE );
554 const size_t m( rhs.rows() );
555 const size_t n( rhs.columns() );
557 for(
size_t ii=0UL; ii<m; ii+=block ) {
558 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
559 for(
size_t jj=0UL; jj<n; jj+=block ) {
560 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
561 for(
size_t i=ii; i<iend; ++i ) {
562 for(
size_t j=jj; j<jend; ++j ) {
563 (~lhs)(i,j) -= rhs.lhs_(i,j) - rhs.rhs_(i,j);
587 template<
typename MT
589 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
590 -> EnableIf_t< UseAssign_v<MT> >
597 if( !RequiresEvaluation_v<MT2> ) {
598 addAssign( ~lhs, rhs.rhs_ );
599 subAssign( ~lhs, rhs.lhs_ );
602 subAssign( ~lhs, rhs.lhs_ );
603 addAssign( ~lhs, rhs.rhs_ );
628 template<
typename MT
630 friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
631 -> EnableIf_t< UseAssign_v<MT> >
643 schurAssign( ~lhs, tmp );
674 template<
typename MT
677 -> EnableIf_t< UseSMPAssign_v<MT> >
684 if( !IsOperation_v<MT1> &&
isSame( ~lhs, rhs.lhs_ ) ) {
687 else if( ( !IsOperation_v<MT2> &&
isSame( ~lhs, rhs.rhs_ ) ) ||
688 ( !RequiresEvaluation_v<MT2> && rhs.rhs_.isAliased( &(~lhs) ) ) ) {
714 template<
typename MT
717 -> EnableIf_t< UseSMPAssign_v<MT> >
721 using TmpType = If_t< SO, OppositeType, ResultType >;
733 const TmpType tmp( rhs );
754 template<
typename MT
757 -> EnableIf_t< UseSMPAssign_v<MT> >
764 if( !RequiresEvaluation_v<MT2> ) {
795 template<
typename MT
798 -> EnableIf_t< UseSMPAssign_v<MT> >
805 if( !RequiresEvaluation_v<MT2> ) {
836 template<
typename MT
839 -> EnableIf_t< UseSMPAssign_v<MT> >
901 template<
typename MT1
903 , EnableIf_t< !IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* =
nullptr >
904 inline const DMatTDMatSubExpr<MT1,MT2>
905 dmattdmatsub(
const DenseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
912 return DMatTDMatSubExpr<MT1,MT2>( ~lhs, ~rhs );
931 template<
typename MT1
933 , EnableIf_t< IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* =
nullptr >
934 inline decltype(
auto)
935 dmattdmatsub( const DenseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs )
942 return trans( ~lhs ) - ~rhs;
961 template<
typename MT1
963 , EnableIf_t< IsSymmetric_v<MT2> >* =
nullptr >
964 inline decltype(
auto)
965 dmattdmatsub( const DenseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs )
972 return (~lhs) -
trans( ~rhs );
1007 template<
typename MT1
1009 inline decltype(
auto)
1018 return dmattdmatsub( ~lhs, ~rhs );
1036 template<
typename MT1
1038 , EnableIf_t< !IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* =
nullptr >
1039 inline const DMatTDMatSubExpr<MT1,MT2>
1040 tdmatdmatsub(
const DenseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
1047 return DMatTDMatSubExpr<MT1,MT2>( ~lhs, ~rhs );
1066 template<
typename MT1
1068 , EnableIf_t< !IsSymmetric_v<MT1> && IsSymmetric_v<MT2> >* =
nullptr >
1069 inline decltype(
auto)
1070 tdmatdmatsub( const DenseMatrix<MT1,true>& lhs, const DenseMatrix<MT2,false>& rhs )
1077 return (~lhs) -
trans( ~rhs );
1096 template<
typename MT1
1098 , EnableIf_t< IsSymmetric_v<MT1> >* =
nullptr >
1099 inline decltype(
auto)
1100 tdmatdmatsub( const DenseMatrix<MT1,true>& lhs, const DenseMatrix<MT2,false>& rhs )
1107 return trans( ~lhs ) - (~rhs);
1142 template<
typename MT1
1144 inline decltype(
auto)
1153 return tdmatdmatsub( ~lhs, ~rhs );
1168 template<
typename MT1,
typename MT2 >
1169 struct IsAligned< DMatTDMatSubExpr<MT1,MT2> >
1170 :
public BoolConstant< IsAligned_v<MT1> && IsAligned_v<MT2> >
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatTDMatSubExpr.h:276
Constraint on the data type.
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose dense matrix operand.
Definition: DMatTDMatSubExpr.h:264
Header file for auxiliary alias declarations.
Header file for kernel specific block sizes.
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatTDMatSubExpr.h:218
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatTDMatSubExpr.h:164
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.The SubTrait_t alias declaration provides...
Definition: SubTrait.h:238
Header file for the subtraction trait.
bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:992
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
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.
#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
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatTDMatSubExpr.h:158
LeftOperand lhs_
Left-hand side dense matrix of the subtraction expression.
Definition: DMatTDMatSubExpr.h:317
Header file for the Computation base class.
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ReturnType_t< MT1 > RN1
Return type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:100
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DMatTDMatSubExpr.h:155
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatTDMatSubExpr.h:254
Expression object for dense matrix-transpose dense matrix subtractions.The DMatTDMatSubExpr class rep...
Definition: DMatTDMatSubExpr.h:92
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: DMatTDMatSubExpr.h:116
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:99
Header file for the IsSymmetric type trait.
Base class for all matrix/matrix subtraction expression templates.The MatMatSubExpr class serves as a...
Definition: MatMatSubExpr.h:67
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatTDMatSubExpr.h:289
#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_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 MatMatSubExpr base class.
Header file for the IsOperation type trait class.
Header file for the IsAligned type trait.
RightOperand rhs_
Right-hand side dense matrix of the subtraction expression.
Definition: DMatTDMatSubExpr.h:318
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatTDMatSubExpr.h:178
Constraints on the storage order of matrix types.
Header file for the exception macros of the math module.
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_DIFFERENT_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:106
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
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatTDMatSubExpr.h:244
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.
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatTDMatSubExpr.h:175
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the subtraction expression.
Definition: DMatTDMatSubExpr.h:127
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
DMatTDMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the DMatTDMatSubExpr class.
Definition: DMatTDMatSubExpr.h:187
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:98
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatTDMatSubExpr.h:157
#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
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: DMatTDMatSubExpr.h:113
CompositeType_t< MT1 > CT1
Composite type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:102
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
#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
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatTDMatSubExpr.h:299
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant class template represents ...
Definition: IntegralConstant.h:101
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatTDMatSubExpr.h:234
If_t< IsExpression_v< MT1 >, const MT1, const MT1 &> LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:167
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
#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
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatTDMatSubExpr.h:156
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:101
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
Header file for the IntegralConstant class template.
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:103
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatTDMatSubExpr.h:309
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: DMatTDMatSubExpr.h:161
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATSUBEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: MatMatSubExpr.h:103
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatTDMatSubExpr.h:203
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
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
If_t< IsExpression_v< MT2 >, const MT2, const MT2 &> RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:170