35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATDMATADDEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_DMATDMATADDEXPR_H_ 91 template<
typename MT1
95 :
public MatMatAddExpr< DenseMatrix< DMatDMatAddExpr<MT1,MT2,SO>, SO > >
117 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
132 ( RequiresEvaluation_v<MT1> || RequiresEvaluation_v<MT2> || !
returnExpr );
135 template<
typename MT >
137 static constexpr
bool UseAssign_v =
useAssign;
149 template<
typename MT >
150 static constexpr
bool UseSMPAssign_v =
151 ( ( !MT1::smpAssignable || !MT2::smpAssignable ) &&
useAssign );
292 return (*
left_) + (*right_);
301 inline auto load() const noexcept {
430 ( MT1::simdEnabled && MT2::simdEnabled && HasSIMDAdd_v<ET1,ET2> );
433 static constexpr
bool smpAssignable = ( MT1::smpAssignable && MT2::smpAssignable );
479 if( i >=
lhs_.rows() ) {
482 if( j >=
lhs_.columns() ) {
501 return lhs_.load(i,j) +
rhs_.load(i,j);
532 inline size_t rows() const noexcept {
543 return lhs_.columns();
573 template<
typename T >
574 inline bool canAlias(
const T* alias )
const noexcept {
575 return ( IsExpression_v<MT1> && ( RequiresEvaluation_v<MT1> ?
lhs_.isAliased( alias ) :
lhs_.canAlias( alias ) ) ) ||
576 ( IsExpression_v<MT2> && ( RequiresEvaluation_v<MT2> ?
rhs_.isAliased( alias ) :
rhs_.canAlias( alias ) ) );
586 template<
typename T >
587 inline bool isAliased(
const T* alias )
const noexcept {
588 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
598 return lhs_.isAligned() &&
rhs_.isAligned();
608 return lhs_.canSMPAssign() ||
rhs_.canSMPAssign() ||
609 (
rows() *
columns() >= SMP_DMATDMATADD_THRESHOLD );
633 template<
typename MT
643 if( !IsOperation_v<MT1> &&
isSame( ~lhs, rhs.lhs_ ) ) {
644 addAssign( ~lhs, rhs.rhs_ );
646 else if( !IsOperation_v<MT2> &&
isSame( ~lhs, rhs.rhs_ ) ) {
647 addAssign( ~lhs, rhs.lhs_ );
649 else if( !RequiresEvaluation_v<MT2> ) {
650 assign ( ~lhs, rhs.rhs_ );
651 addAssign( ~lhs, rhs.lhs_ );
654 assign ( ~lhs, rhs.lhs_ );
655 addAssign( ~lhs, rhs.rhs_ );
675 template<
typename MT
694 const TmpType tmp(
serial( rhs ) );
714 template<
typename MT
716 friend inline auto addAssign( DenseMatrix<MT,SO2>& lhs,
const DMatDMatAddExpr& rhs )
717 -> EnableIf_t< UseAssign_v<MT> >
724 if( !RequiresEvaluation_v<MT2> ) {
725 addAssign( ~lhs, rhs.rhs_ );
726 addAssign( ~lhs, rhs.lhs_ );
729 addAssign( ~lhs, rhs.lhs_ );
730 addAssign( ~lhs, rhs.rhs_ );
754 template<
typename MT
756 friend inline auto subAssign( DenseMatrix<MT,SO2>& lhs,
const DMatDMatAddExpr& rhs )
757 -> EnableIf_t< UseAssign_v<MT> >
764 if( !RequiresEvaluation_v<MT2> ) {
765 subAssign( ~lhs, rhs.rhs_ );
766 subAssign( ~lhs, rhs.lhs_ );
769 subAssign( ~lhs, rhs.lhs_ );
770 subAssign( ~lhs, rhs.rhs_ );
794 template<
typename MT
796 friend inline auto schurAssign( DenseMatrix<MT,SO2>& lhs,
const DMatDMatAddExpr& rhs )
797 -> EnableIf_t< UseAssign_v<MT> >
809 schurAssign( ~lhs, tmp );
840 template<
typename MT
843 -> EnableIf_t< UseSMPAssign_v<MT> >
850 if( !IsOperation_v<MT1> &&
isSame( ~lhs, rhs.lhs_ ) ) {
853 else if( !IsOperation_v<MT2> &&
isSame( ~lhs, rhs.rhs_ ) ) {
856 else if( !RequiresEvaluation_v<MT2> ) {
882 template<
typename MT
885 -> EnableIf_t< UseSMPAssign_v<MT> >
889 using TmpType = If_t< SO == SO2, ResultType, OppositeType >;
901 const TmpType tmp( rhs );
921 template<
typename MT
924 -> EnableIf_t< UseSMPAssign_v<MT> >
931 if( !RequiresEvaluation_v<MT2> ) {
961 template<
typename MT
964 -> EnableIf_t< UseSMPAssign_v<MT> >
971 if( !RequiresEvaluation_v<MT2> ) {
1001 template<
typename MT
1004 -> EnableIf_t< UseSMPAssign_v<MT> >
1080 template<
typename MT1
1083 inline decltype(
auto)
1093 return ReturnType( ~lhs, ~rhs );
1108 template<
typename MT1,
typename MT2,
bool SO >
1109 struct IsAligned< DMatDMatAddExpr<MT1,MT2,SO> >
1110 :
public BoolConstant< IsAligned_v<MT1> && IsAligned_v<MT2> >
1126 template<
typename MT1,
typename MT2,
bool SO >
1127 struct IsPadded< DMatDMatAddExpr<MT1,MT2,SO> >
1128 :
public BoolConstant< IsPadded_v<MT1> && IsPadded_v<MT2> >
#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
Pointer difference type of the Blaze library.
BLAZE_DEVICE_CALLABLE const ConstIterator operator--(int)
Post-decrement operator.
Definition: DMatDMatAddExpr.h:281
ValueType value_type
Type of the underlying elements.
Definition: DMatDMatAddExpr.h:192
Header file for auxiliary alias declarations.
DMatDMatAddExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the DMatDMatAddExpr class.
Definition: DMatDMatAddExpr.h:447
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.
friend BLAZE_DEVICE_CALLABLE const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: DMatDMatAddExpr.h:390
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatDMatAddExpr.h:160
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
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:101
ElementType_t< MT2 > ET2
Element type of the right-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:107
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
BLAZE_DEVICE_CALLABLE bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DMatDMatAddExpr.h:345
#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
friend BLAZE_DEVICE_CALLABLE const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: DMatDMatAddExpr.h:402
BLAZE_DEVICE_CALLABLE DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: DMatDMatAddExpr.h:378
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatDMatAddExpr.h:161
BLAZE_DEVICE_CALLABLE ReturnType operator *() const
Direct access to the element at the current iterator position.
Definition: DMatDMatAddExpr.h:291
Header file for the Computation base class.
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatDMatAddExpr.h:429
friend BLAZE_DEVICE_CALLABLE const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: DMatDMatAddExpr.h:414
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatDMatAddExpr.h:587
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatDMatAddExpr.h:542
ConstIterator_t< MT2 > RightIteratorType
ConstIterator type of the right-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:201
Header file for the RequiresEvaluation type trait.
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatDMatAddExpr.h:552
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:81
BLAZE_DEVICE_CALLABLE bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DMatDMatAddExpr.h:334
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
Iterator over the elements of the dense matrix.
Definition: DMatDMatAddExpr.h:180
decltype(std::declval< RN1 >()+std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: DMatDMatAddExpr.h:120
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
RightIteratorType right_
Iterator to the current right-hand side element.
Definition: DMatDMatAddExpr.h:422
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: DMatDMatAddExpr.h:511
ElementType & ReferenceType
Reference return type.
Definition: DMatDMatAddExpr.h:187
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatDMatAddExpr.h:532
Expression object for dense matrix-dense matrix additions.The DMatDMatAddExpr class represents the co...
Definition: DMatDMatAddExpr.h:94
Header file for the IsTemporary type trait class.
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DMatDMatAddExpr.h:188
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Header file for the If class template.
BLAZE_DEVICE_CALLABLE ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DMatDMatAddExpr.h:222
BLAZE_DEVICE_CALLABLE bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DMatDMatAddExpr.h:367
#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 HasSIMDAdd type trait.
Header file for the DenseMatrix base class.
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:171
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatDMatAddExpr.h:463
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: DMatDMatAddExpr.h:522
PointerType pointer
Pointer return type.
Definition: DMatDMatAddExpr.h:193
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: DMatDMatAddExpr.h:562
Header file for all SIMD functionality.
Base class for all matrix/matrix addition expression templates.The MatMatAddExpr class serves as a ta...
Definition: MatMatAddExpr.h:66
Header file for the IsOperation type trait class.
typename AddTrait< T1, T2 >::Type AddTrait_t
Auxiliary alias declaration for the AddTrait class template.The AddTrait_t alias declaration provides...
Definition: AddTrait.h:238
BLAZE_ALWAYS_INLINE auto load(size_t i, size_t j) const noexcept
Access to the SIMD elements of the matrix.
Definition: DMatDMatAddExpr.h:496
Header file for the IsAligned type trait.
AddTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DMatDMatAddExpr.h:159
BLAZE_DEVICE_CALLABLE bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DMatDMatAddExpr.h:323
Constraints on the storage order of matrix types.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatDMatAddExpr.h:574
ElementType ValueType
Type of the underlying elements.
Definition: DMatDMatAddExpr.h:185
Header file for the exception macros of the math module.
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the addition expression.
Definition: DMatDMatAddExpr.h:131
CompositeType_t< MT1 > CT1
Composite type of the left-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:104
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATADDEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: MatMatAddExpr.h:103
BLAZE_DEVICE_CALLABLE ConstIterator(LeftIteratorType left, RightIteratorType right)
Constructor for the ConstIterator class.
Definition: DMatDMatAddExpr.h:210
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatDMatAddExpr.h:478
Constraint on the data type.
BLAZE_DEVICE_CALLABLE ConstIterator & operator++()
Pre-increment operator.
Definition: DMatDMatAddExpr.h:247
RightOperand rhs_
Right-hand side dense matrix of the addition expression.
Definition: DMatDMatAddExpr.h:616
Header file for the EnableIf class template.
auto load() const noexcept
Access to the SIMD elements of the matrix.
Definition: DMatDMatAddExpr.h:301
Header file for the IsPadded type trait.
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatDMatAddExpr.h:597
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatDMatAddExpr.h:433
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
BLAZE_DEVICE_CALLABLE bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DMatDMatAddExpr.h:312
ElementType_t< MT1 > ET1
Element type of the left-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:106
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
BLAZE_DEVICE_CALLABLE bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DMatDMatAddExpr.h:356
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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatDMatAddExpr.h:162
Header file for the addition trait.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: DMatDMatAddExpr.h:117
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
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:100
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:105
ReferenceType reference
Reference return type.
Definition: DMatDMatAddExpr.h:194
Constraint on the data type.
SIMD characteristics of data types.The SIMDTrait class template provides the SIMD characteristics of ...
Definition: SIMDTrait.h:295
#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.
ReturnType_t< MT1 > RN1
Return type of the left-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:102
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
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
Header file for the MatMatAddExpr base class.
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant alias template represents ...
Definition: IntegralConstant.h:110
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
ConstIterator_t< MT1 > LeftIteratorType
ConstIterator type of the left-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:198
#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
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatDMatAddExpr.h:607
Macro for CUDA compatibility.
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DMatDMatAddExpr.h:184
LeftIteratorType left_
Iterator to the current left-hand side element.
Definition: DMatDMatAddExpr.h:421
IteratorCategory iterator_category
The iterator category.
Definition: DMatDMatAddExpr.h:191
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
BLAZE_DEVICE_CALLABLE const ConstIterator operator++(int)
Post-increment operator.
Definition: DMatDMatAddExpr.h:259
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
ElementType * PointerType
Pointer return type.
Definition: DMatDMatAddExpr.h:186
LeftOperand lhs_
Left-hand side dense matrix of the addition expression.
Definition: DMatDMatAddExpr.h:615
BLAZE_DEVICE_CALLABLE ConstIterator & operator--()
Pre-decrement operator.
Definition: DMatDMatAddExpr.h:269
Header file for the IntegralConstant class template.
If_t< useAssign, const ResultType, const DMatDMatAddExpr & > CompositeType
Data type for composite expression templates.
Definition: DMatDMatAddExpr.h:168
#define BLAZE_DEVICE_CALLABLE
Conditional macro that sets host and device attributes when compiled with CUDA.
Definition: HostDevice.h:94
BLAZE_DEVICE_CALLABLE ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DMatDMatAddExpr.h:235
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:174
System settings for the inline keywords.
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,...
Definition: Assert.h:101
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: DMatDMatAddExpr.h:165
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: DMatDMatAddExpr.h:103
static constexpr size_t SIMDSIZE
The number of elements packed within a single SIMD element.
Definition: DMatDMatAddExpr.h:438