35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATTDMATSUBEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATTDMATSUBEXPR_H_
92 :
public MatMatSubExpr< DenseMatrix< DMatTDMatSubExpr<MT1,MT2>, false > >
112 static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
127 ( RequiresEvaluation_v<MT1> || RequiresEvaluation_v<MT2> || !
returnExpr );
131 template<
typename MT >
132 static constexpr bool UseAssign_v =
useAssign;
144 template<
typename MT >
145 static constexpr bool UseSMPAssign_v =
146 ( ( !MT1::smpAssignable || !MT2::smpAssignable ) &&
useAssign );
181 static constexpr bool smpAssignable = ( MT1::smpAssignable && MT2::smpAssignable );
222 if( i >=
lhs_.rows() ) {
225 if( j >=
lhs_.columns() ) {
237 inline size_t rows() const noexcept {
248 return lhs_.columns();
278 template<
typename T >
279 inline bool canAlias(
const T* alias )
const noexcept {
280 return ( IsExpression_v<MT1> && ( RequiresEvaluation_v<MT1> ?
lhs_.isAliased( alias ) :
lhs_.canAlias( alias ) ) ) ||
281 ( IsExpression_v<MT2> && ( RequiresEvaluation_v<MT2> ?
rhs_.isAliased( alias ) :
rhs_.canAlias( alias ) ) );
291 template<
typename T >
292 inline bool isAliased(
const T* alias )
const noexcept {
293 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
303 return lhs_.isAligned() &&
rhs_.isAligned();
313 return lhs_.canSMPAssign() ||
rhs_.canSMPAssign() ||
314 (
rows() *
columns() >= SMP_DMATTDMATSUB_THRESHOLD );
338 template<
typename MT
348 constexpr size_t block( BLOCK_SIZE );
350 const size_t m( rhs.rows() );
351 const size_t n( rhs.columns() );
353 for(
size_t ii=0UL; ii<m; ii+=block ) {
354 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
355 for(
size_t jj=0UL; jj<n; jj+=block ) {
356 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
357 for(
size_t i=ii; i<iend; ++i ) {
358 for(
size_t j=jj; j<jend; ++j ) {
359 (*lhs)(i,j) = rhs.lhs_(i,j) - rhs.rhs_(i,j);
382 template<
typename MT
392 if( !IsOperation_v<MT1> &&
isSame( *lhs, rhs.lhs_ ) ) {
393 subAssign( *lhs, rhs.rhs_ );
395 else if( ( !IsOperation_v<MT2> &&
isSame( *lhs, rhs.rhs_ ) ) ||
396 ( !RequiresEvaluation_v<MT2> && rhs.rhs_.isAliased( &(*lhs) ) ) ) {
397 assign ( *lhs, -rhs.rhs_ );
398 addAssign( *lhs, rhs.lhs_ );
401 assign ( *lhs, rhs.lhs_ );
402 subAssign( *lhs, rhs.rhs_ );
420 template<
typename MT
422 friend inline void assign( SparseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
426 using TmpType = If_t< SO, OppositeType, ResultType >;
438 const TmpType tmp(
serial( rhs ) );
459 template<
typename MT
461 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
462 -> DisableIf_t< UseAssign_v<MT> >
469 constexpr size_t block( BLOCK_SIZE );
471 const size_t m( rhs.rows() );
472 const size_t n( rhs.columns() );
474 for(
size_t ii=0UL; ii<m; ii+=block ) {
475 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
476 for(
size_t jj=0UL; jj<n; jj+=block ) {
477 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
478 for(
size_t i=ii; i<iend; ++i ) {
479 for(
size_t j=jj; j<jend; ++j ) {
480 (*lhs)(i,j) += rhs.lhs_(i,j) - rhs.rhs_(i,j);
504 template<
typename MT
506 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
507 -> EnableIf_t< UseAssign_v<MT> >
514 if( !RequiresEvaluation_v<MT2> ) {
515 subAssign( *lhs, rhs.rhs_ );
516 addAssign( *lhs, rhs.lhs_ );
519 addAssign( *lhs, rhs.lhs_ );
520 subAssign( *lhs, rhs.rhs_ );
545 template<
typename MT
547 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
548 -> DisableIf_t< UseAssign_v<MT> >
555 constexpr size_t block( BLOCK_SIZE );
557 const size_t m( rhs.rows() );
558 const size_t n( rhs.columns() );
560 for(
size_t ii=0UL; ii<m; ii+=block ) {
561 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
562 for(
size_t jj=0UL; jj<n; jj+=block ) {
563 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
564 for(
size_t i=ii; i<iend; ++i ) {
565 for(
size_t j=jj; j<jend; ++j ) {
566 (*lhs)(i,j) -= rhs.lhs_(i,j) - rhs.rhs_(i,j);
590 template<
typename MT
592 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
593 -> EnableIf_t< UseAssign_v<MT> >
600 if( !RequiresEvaluation_v<MT2> ) {
601 addAssign( *lhs, rhs.rhs_ );
602 subAssign( *lhs, rhs.lhs_ );
605 subAssign( *lhs, rhs.lhs_ );
606 addAssign( *lhs, rhs.rhs_ );
631 template<
typename MT
633 friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs,
const DMatTDMatSubExpr& rhs )
634 -> EnableIf_t< UseAssign_v<MT> >
646 schurAssign( *lhs, tmp );
677 template<
typename MT
680 -> EnableIf_t< UseSMPAssign_v<MT> >
687 if( !IsOperation_v<MT1> &&
isSame( *lhs, rhs.lhs_ ) ) {
690 else if( ( !IsOperation_v<MT2> &&
isSame( *lhs, rhs.rhs_ ) ) ||
691 ( !RequiresEvaluation_v<MT2> && rhs.rhs_.isAliased( &(*lhs) ) ) ) {
717 template<
typename MT
720 -> EnableIf_t< UseSMPAssign_v<MT> >
724 using TmpType = If_t< SO, OppositeType, ResultType >;
736 const TmpType tmp( rhs );
757 template<
typename MT
760 -> EnableIf_t< UseSMPAssign_v<MT> >
767 if( !RequiresEvaluation_v<MT2> ) {
798 template<
typename MT
801 -> EnableIf_t< UseSMPAssign_v<MT> >
808 if( !RequiresEvaluation_v<MT2> ) {
839 template<
typename MT
842 -> EnableIf_t< UseSMPAssign_v<MT> >
904template<
typename MT1
906 , EnableIf_t< !IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* =
nullptr >
907inline const DMatTDMatSubExpr<MT1,MT2>
908 dmattdmatsub(
const DenseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
915 return DMatTDMatSubExpr<MT1,MT2>( *lhs, *rhs );
934template<
typename MT1
936 , EnableIf_t< IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* =
nullptr >
938 dmattdmatsub(
const DenseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
945 return trans( *lhs ) - *rhs;
964template<
typename MT1
966 , EnableIf_t< IsSymmetric_v<MT2> >* =
nullptr >
968 dmattdmatsub(
const DenseMatrix<MT1,false>& lhs,
const DenseMatrix<MT2,true>& rhs )
975 return (*lhs) -
trans( *rhs );
1010template<
typename MT1
1012inline decltype(
auto)
1017 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1021 return dmattdmatsub( *lhs, *rhs );
1039template<
typename MT1
1041 , EnableIf_t< !IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* =
nullptr >
1042inline const DMatTDMatSubExpr<MT1,MT2>
1043 tdmatdmatsub(
const DenseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
1050 return DMatTDMatSubExpr<MT1,MT2>( *lhs, *rhs );
1069template<
typename MT1
1071 , EnableIf_t< !IsSymmetric_v<MT1> && IsSymmetric_v<MT2> >* =
nullptr >
1072inline decltype(
auto)
1073 tdmatdmatsub(
const DenseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
1080 return (*lhs) -
trans( *rhs );
1099template<
typename MT1
1101 , EnableIf_t< IsSymmetric_v<MT1> >* =
nullptr >
1102inline decltype(
auto)
1103 tdmatdmatsub(
const DenseMatrix<MT1,true>& lhs,
const DenseMatrix<MT2,false>& rhs )
1110 return trans( *lhs ) - (*rhs);
1145template<
typename MT1
1147inline decltype(
auto)
1152 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1156 return tdmatdmatsub( *lhs, *rhs );
1171template<
typename MT1,
typename MT2 >
1172struct IsAligned< DMatTDMatSubExpr<MT1,MT2> >
1173 :
public BoolConstant< IsAligned_v<MT1> && IsAligned_v<MT2> >
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for kernel specific block sizes.
Constraints on the storage order of matrix types.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsAligned type trait.
Header file for the IsExpression type trait class.
Header file for the IsOperation type trait class.
Header file for the IsSymmetric type trait.
Header file for the IsTemporary type trait class.
Constraints on the storage order of matrix types.
Header file for the subtraction trait.
Expression object for dense matrix-transpose dense matrix subtractions.
Definition: DMatTDMatSubExpr.h:94
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:170
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the subtraction expression.
Definition: DMatTDMatSubExpr.h:126
RightOperand rhs_
Right-hand side dense matrix of the subtraction expression.
Definition: DMatTDMatSubExpr.h:321
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:97
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatTDMatSubExpr.h:312
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatTDMatSubExpr.h:159
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: DMatTDMatSubExpr.h:115
ReturnType_t< MT1 > RN1
Return type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:99
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:100
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: DMatTDMatSubExpr.h:164
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:102
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatTDMatSubExpr.h:247
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DMatTDMatSubExpr.h:158
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatTDMatSubExpr.h:257
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatTDMatSubExpr.h:279
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatTDMatSubExpr.h:237
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:98
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatTDMatSubExpr.h:181
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:173
LeftOperand lhs_
Left-hand side dense matrix of the subtraction expression.
Definition: DMatTDMatSubExpr.h:320
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatTDMatSubExpr.h:292
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose dense matrix operand.
Definition: DMatTDMatSubExpr.h:267
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatTDMatSubExpr.h:178
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: DMatTDMatSubExpr.h:112
CompositeType_t< MT1 > CT1
Composite type of the left-hand side dense matrix expression.
Definition: DMatTDMatSubExpr.h:101
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatTDMatSubExpr.h:302
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatTDMatSubExpr.h:206
DMatTDMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the DMatTDMatSubExpr class.
Definition: DMatTDMatSubExpr.h:190
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatTDMatSubExpr.h:167
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatTDMatSubExpr.h:161
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatTDMatSubExpr.h:221
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatTDMatSubExpr.h:160
Base class for dense matrices.
Definition: DenseMatrix.h:82
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the MatMatSubExpr base class.
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_SAME_STORAGE_ORDER(T1, T2)
Constraint on the data type.
Definition: StorageOrder.h:84
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATSUBEXPR(T1, T2)
Constraint on the data type.
Definition: MatMatSubExpr.h:103
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_DIFFERENT_STORAGE_ORDER(T1, T2)
Constraint on the data type.
Definition: StorageOrder.h:106
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.
Definition: SubTrait.h:163
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:1424
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
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
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
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
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
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.
Definition: IntegralConstant.h:110
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for all forward declarations for expression class templates.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix/matrix subtraction expression templates.
Definition: MatMatSubExpr.h:69
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.