35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTSMATADDEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SMATTSMATADDEXPR_H_ 94 template<
typename MT1
96 class SMatTSMatAddExpr
97 :
public MatMatAddExpr< SparseMatrix< SMatTSMatAddExpr<MT1,MT2>, IsZero_v<MT1> > >
117 static constexpr
bool returnExpr = !IsTemporary_v<RN1> && !IsTemporary_v<RN2>;
130 template<
typename T1,
typename T2 >
131 static constexpr
bool UseSymmetricKernel_v =
132 ( IsVoid_v< EnableIf_t< StorageOrder_v<T1> != StorageOrder_v<T2> > > && IsSymmetric_v<T2> );
143 template<
typename MT >
217 if( i >=
lhs_.rows() ) {
220 if( j >=
lhs_.columns() ) {
232 inline size_t rows() const noexcept {
243 return lhs_.columns();
253 return lhs_.nonZeros() +
rhs_.nonZeros();
264 return lhs_.nonZeros(i) +
rhs_.nonZeros(i);
294 template<
typename T >
295 inline bool canAlias(
const T* alias )
const noexcept {
296 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
306 template<
typename T >
307 inline bool isAliased(
const T* alias )
const noexcept {
308 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
330 template<
typename MT
339 assign( ~lhs, rhs.lhs_ );
342 addAssign( ~lhs, rhs.rhs_ );
353 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
354 const auto end( B.end(j) );
355 for(
auto element=B.begin(j); element!=
end; ++element ) {
356 if(
isDefault( (~lhs)(element->index(),j) ) )
357 (~lhs)(element->index(),j) = element->value();
359 (~lhs)(element->index(),j) += element->value();
380 template<
typename MT >
403 (~lhs).reserve( A.nonZeros() + B.nonZeros() );
406 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
408 const auto lend( A.end(i) );
409 const auto rend( B.end(i) );
411 auto l( A.begin(i) );
412 auto r( B.begin(i) );
414 while( l != lend && r != rend )
416 if( l->index() < r->index() ) {
417 (~lhs).append( i, l->index(), l->value() );
420 else if( l->index() > r->index() ) {
421 (~lhs).append( i, r->index(), r->value() );
425 (~lhs).append( i, l->index(), l->value() + r->value() );
432 (~lhs).append( i, l->index(), l->value() );
437 (~lhs).append( i, r->index(), r->value() );
441 (~lhs).finalize( i );
460 template<
typename MT >
461 friend inline auto assign( SparseMatrix<MT,false>& lhs,
const SMatTSMatAddExpr& rhs )
462 -> EnableIf_t< UseSymmetricKernel_v<MT,MT2> >
469 assign( ~lhs, rhs.lhs_ +
trans( rhs.rhs_ ) );
487 template<
typename MT >
488 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const SMatTSMatAddExpr& rhs )
489 -> DisableIf_t< UseSymmetricKernel_v<MT,MT1> >
499 const OppositeType_t<RT1> A(
serial( rhs.lhs_ ) );
512 (~lhs).reserve( A.nonZeros() + B.nonZeros() );
515 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
517 const auto lend( A.end(j) );
518 const auto rend( B.end(j) );
520 auto l( A.begin(j) );
521 auto r( B.begin(j) );
523 while( l != lend && r != rend )
525 if( l->index() < r->index() ) {
526 (~lhs).append( l->index(), j, l->value() );
529 else if( l->index() > r->index() ) {
530 (~lhs).append( r->index(), j, r->value() );
534 (~lhs).append( l->index(), j, l->value() + r->value() );
541 (~lhs).append( l->index(), j, l->value() );
546 (~lhs).append( r->index(), j, r->value() );
550 (~lhs).finalize( j );
569 template<
typename MT >
570 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const SMatTSMatAddExpr& rhs )
571 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1> >
580 assign( ~lhs,
trans( rhs.lhs_ ) + rhs.rhs_ );
598 template<
typename MT
600 friend inline void addAssign( DenseMatrix<MT,SO>& lhs,
const SMatTSMatAddExpr& rhs )
607 addAssign( ~lhs, rhs.lhs_ );
608 addAssign( ~lhs, rhs.rhs_ );
630 template<
typename MT
632 friend inline void subAssign( DenseMatrix<MT,SO>& lhs,
const SMatTSMatAddExpr& rhs )
639 subAssign( ~lhs, rhs.lhs_ );
640 subAssign( ~lhs, rhs.rhs_ );
662 template<
typename MT
664 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs,
const SMatTSMatAddExpr& rhs )
675 schurAssign( ~lhs, tmp );
715 template<
typename MT
718 -> EnableIf_t< UseSMPAssign_v<MT> >
750 template<
typename MT
753 -> EnableIf_t< UseSMPAssign_v<MT> >
785 template<
typename MT
788 -> EnableIf_t< UseSMPAssign_v<MT> >
850 template<
typename MT1
852 , DisableIf_t< ( ( IsZero_v<MT1> || IsZero_v<MT2> ) &&
853 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
854 ( IsZero_v<MT1> && IsZero_v<MT2> ) >* =
nullptr >
855 inline const SMatTSMatAddExpr<MT1,MT2>
856 smattsmatadd(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
863 return SMatTSMatAddExpr<MT1,MT2>( ~lhs, ~rhs );
883 template<
typename MT1
885 , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
886 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
888 smattsmatadd(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
917 template<
typename MT1
919 , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
920 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
922 smattsmatadd(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
950 template<
typename MT1
952 , EnableIf_t< IsZero_v<MT1> && IsZero_v<MT2> >* =
nullptr >
953 inline decltype(
auto)
954 smattsmatadd( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
963 using ReturnType =
const AddTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1003 template<
typename MT1
1005 inline decltype(
auto)
1014 return smattsmatadd( ~lhs, ~rhs );
1048 template<
typename MT1
1050 inline decltype(
auto)
1059 return smattsmatadd( ~rhs, ~lhs );
#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
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: SMatTSMatAddExpr.h:307
Header file for the UNUSED_PARAMETER function template.
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
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:106
Header file for the serial shim.
Header file for the IsSame and IsStrictlySame type traits.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTSMatAddExpr.h:242
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Constraint on the data type.
Header file for the Computation base class.
Constraints on the storage order of matrix types.
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
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
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:137
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 IsVoid type trait.
LeftOperand lhs_
Left-hand side sparse matrix of the addition expression.
Definition: SMatTSMatAddExpr.h:314
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTSMatAddExpr.h:158
Header file for the SparseMatrix base class.
Constraint on the data type.
ReturnType_t< MT2 > RN2
Evaluation type of the right-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:105
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
decltype(std::declval< RN1 >()+std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatTSMatAddExpr.h:120
Header file for the IsSymmetric type trait.
constexpr bool IsResizable_v
Auxiliary variable template for the IsResizable type trait.The IsResizable_v variable template provid...
Definition: IsResizable.h:134
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#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_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
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTSMatAddExpr.h:232
#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
If_t< IsExpression_v< MT2 >, const MT2, const MT2 &> RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:171
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatTSMatAddExpr.h:295
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatTSMatAddExpr.h:162
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatTSMatAddExpr.h:252
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
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatTSMatAddExpr.h:263
Header file for the exception macros of the math module.
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
#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
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatTSMatAddExpr.h:176
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatTSMatAddExpr.h:165
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTSMatAddExpr.h:157
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
#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
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
If_t< IsExpression_v< MT1 >, const MT1, const MT1 &> LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:168
Header file for the addition trait.
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
Constraint on the data type.
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
AddTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatTSMatAddExpr.h:156
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:103
Header file for the isDefault shim.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTSMatAddExpr.h:201
RightOperand rhs_
Right-hand side sparse matrix of the addition expression.
Definition: SMatTSMatAddExpr.h:315
Constraint on the data type.
Constraints on the storage order of matrix types.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatTSMatAddExpr.h:117
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTSMatAddExpr.h:216
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: SMatTSMatAddExpr.h:283
#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.
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
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:102
Expression object for sparse matrix-transpose sparse matrix additions.The SMatTSMatAddExpr class repr...
Definition: Forward.h:133
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
SMatTSMatAddExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatTSMatAddExpr class.
Definition: SMatTSMatAddExpr.h:185
Header file for the IsComputation type trait class.
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
Header file for the StorageOrder type trait.
Header file for the IntegralConstant class template.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:631
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:107
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
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatTSMatAddExpr.h:273
ReturnType_t< MT1 > RN1
Evaluation type of the left-hand side sparse matrix expression.
Definition: SMatTSMatAddExpr.h:104
Header file for the IsResizable type trait.
constexpr bool IsSame_v
Auxiliary variable template for the IsSame type trait.The IsSame_v variable template provides a conve...
Definition: IsSame.h:161
#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
#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.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatTSMatAddExpr.h:159