35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATADDEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATADDEXPR_H_
103 template<
typename MT1
105 class SMatSMatAddExpr :
public SparseMatrix< SMatSMatAddExpr<MT1,MT2>, false >
106 ,
private MatMatAddExpr
107 ,
private Computation
139 template<
typename T1,
typename T2,
typename T3 >
140 struct UseSymmetricKernel {
154 template<
typename MT >
155 struct UseSMPAssign {
156 enum :
bool { value = MT::smpAssignable };
184 enum :
bool { smpAssignable =
false };
224 inline ReturnType
at(
size_t i,
size_t j )
const {
225 if( i >=
lhs_.rows() ) {
228 if( j >=
lhs_.columns() ) {
240 inline size_t rows() const noexcept {
251 return lhs_.columns();
261 return lhs_.nonZeros() +
rhs_.nonZeros();
272 return lhs_.nonZeros(i) +
rhs_.nonZeros(i);
302 template<
typename T >
303 inline bool canAlias(
const T* alias )
const noexcept {
304 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
314 template<
typename T >
315 inline bool isAliased(
const T* alias )
const noexcept {
316 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
338 template<
typename MT
349 assign( ~lhs, rhs.lhs_ );
352 addAssign( ~lhs, rhs.rhs_ );
356 CT2 B(
serial( rhs.rhs_ ) );
363 for(
size_t i=0UL; i<(~lhs).
rows(); ++i ) {
364 const RightIterator
end( B.end(i) );
365 for( RightIterator element=B.begin(i); element!=
end; ++element ) {
366 if(
isDefault( (~lhs)(i,element->index()) ) )
367 (~lhs)(i,element->index()) = element->value();
369 (~lhs)(i,element->index()) += element->value();
389 template<
typename MT >
400 CT1 A(
serial( rhs.lhs_ ) );
401 CT2 B(
serial( rhs.rhs_ ) );
411 (~lhs).reserve( A.nonZeros() + B.nonZeros() );
414 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
416 const LeftIterator lend( A.end(i) );
417 const RightIterator rend( B.end(i) );
419 LeftIterator l( A.begin(i) );
420 RightIterator r( B.begin(i) );
422 while( l != lend && r != rend )
424 if( l->index() < r->index() ) {
425 (~lhs).append( i, l->index(), l->value() );
428 else if( l->index() > r->index() ) {
429 (~lhs).append( i, r->index(), r->value() );
433 (~lhs).append( i, l->index(), l->value()+r->value() );
440 (~lhs).append( i, l->index(), l->value() );
445 (~lhs).append( i, r->index(), r->value() );
449 (~lhs).finalize( i );
467 template<
typename MT >
468 friend inline DisableIf_< UseSymmetricKernel<MT,MT1,MT2> >
478 typedef ConstIterator_< RemoveReference_<CT1> > LeftIterator;
479 typedef ConstIterator_< RemoveReference_<CT2> > RightIterator;
481 CT1 A(
serial( rhs.lhs_ ) );
482 CT2 B(
serial( rhs.rhs_ ) );
491 const size_t m( A.rows() );
492 const size_t n( A.columns() );
495 std::vector<size_t> nonzeros( n, 0UL );
496 for(
size_t i=0UL; i<m; ++i )
498 const LeftIterator lend( A.end(i) );
499 const RightIterator rend( B.end(i) );
501 LeftIterator l( A.begin(i) );
502 RightIterator r( B.begin(i) );
504 while( l != lend && r != rend )
506 if( l->index() < r->index() ) {
507 ++nonzeros[l->index()];
510 else if( l->index() > r->index() ) {
511 ++nonzeros[r->index()];
515 ++nonzeros[l->index()];
522 ++nonzeros[l->index()];
527 ++nonzeros[r->index()];
533 for(
size_t j=0UL; j<n; ++j ) {
534 (~lhs).reserve( j, nonzeros[j] );
538 for(
size_t i=0UL; i<m; ++i )
540 const LeftIterator lend( A.end(i) );
541 const RightIterator rend( B.end(i) );
543 LeftIterator l( A.begin(i) );
544 RightIterator r( B.begin(i) );
546 while( l != lend && r != rend )
548 if( l->index() < r->index() ) {
549 (~lhs).append( i, l->index(), l->value() );
552 else if( l->index() > r->index() ) {
553 (~lhs).append( i, r->index(), r->value() );
557 (~lhs).append( i, l->index(), l->value()+r->value() );
564 (~lhs).append( i, l->index(), l->value() );
569 (~lhs).append( i, r->index(), r->value() );
589 template<
typename MT >
590 friend inline EnableIf_< UseSymmetricKernel<MT,MT1,MT2> >
600 assign( ~lhs,
trans( rhs.lhs_ ) +
trans( rhs.rhs_ ) );
617 template<
typename MT
619 friend inline void addAssign( DenseMatrix<MT,SO>& lhs,
const SMatSMatAddExpr& rhs )
626 addAssign( ~lhs, rhs.lhs_ );
627 addAssign( ~lhs, rhs.rhs_ );
648 template<
typename MT
650 friend inline void subAssign( DenseMatrix<MT,SO>& lhs,
const SMatSMatAddExpr& rhs )
657 subAssign( ~lhs, rhs.lhs_ );
658 subAssign( ~lhs, rhs.rhs_ );
697 template<
typename MT
699 friend inline EnableIf_< UseSMPAssign<MT> >
731 template<
typename MT
733 friend inline EnableIf_< UseSMPAssign<MT> >
806 template<
typename T1
808 inline const SMatSMatAddExpr<T1,T2>
832 template<
typename MT1,
typename MT2 >
833 struct Rows< SMatSMatAddExpr<MT1,MT2> >
834 :
public Max< Rows<MT1>, Rows<MT2> >
850 template<
typename MT1,
typename MT2 >
851 struct Columns< SMatSMatAddExpr<MT1,MT2> >
852 :
public Max< Columns<MT1>, Columns<MT2> >
868 template<
typename MT1,
typename MT2 >
869 struct IsSymmetric< SMatSMatAddExpr<MT1,MT2> >
870 :
public BoolConstant< IsSymmetric<MT1>::value && IsSymmetric<MT2>::value >
886 template<
typename MT1,
typename MT2 >
887 struct IsHermitian< SMatSMatAddExpr<MT1,MT2> >
888 :
public BoolConstant< IsHermitian<MT1>::value && IsHermitian<MT2>::value >
904 template<
typename MT1,
typename MT2 >
905 struct IsLower< SMatSMatAddExpr<MT1,MT2> >
906 :
public BoolConstant< And< IsLower<MT1>, IsLower<MT2> >::value >
922 template<
typename MT1,
typename MT2 >
923 struct IsUniLower< SMatSMatAddExpr<MT1,MT2> >
924 :
public BoolConstant< Or< And< IsUniLower<MT1>, IsStrictlyLower<MT2> >
925 , And< IsUniLower<MT2>, IsStrictlyLower<MT1> > >::value >
941 template<
typename MT1,
typename MT2 >
942 struct IsStrictlyLower< SMatSMatAddExpr<MT1,MT2> >
943 :
public BoolConstant< And< IsStrictlyLower<MT1>, IsStrictlyLower<MT2> >::value >
959 template<
typename MT1,
typename MT2 >
960 struct IsUpper< SMatSMatAddExpr<MT1,MT2> >
961 :
public BoolConstant< And< IsUpper<MT1>, IsUpper<MT2> >::value >
977 template<
typename MT1,
typename MT2 >
978 struct IsUniUpper< SMatSMatAddExpr<MT1,MT2> >
979 :
public BoolConstant< Or< And< IsUniUpper<MT1>, IsStrictlyUpper<MT2> >
980 , And< IsUniUpper<MT2>, IsStrictlyUpper<MT1> > >::value >
996 template<
typename MT1,
typename MT2 >
997 struct IsStrictlyUpper< SMatSMatAddExpr<MT1,MT2> >
998 :
public BoolConstant< And< IsStrictlyUpper<MT1>, IsStrictlyUpper<MT2> >::value >
1014 template<
typename MT1,
typename MT2,
bool AF >
1015 struct SubmatrixExprTrait< SMatSMatAddExpr<MT1,MT2>, AF >
1019 using Type = AddExprTrait_< SubmatrixExprTrait_<const MT1,AF>
1020 , SubmatrixExprTrait_<const MT2,AF> >;
1029 template<
typename MT1,
typename MT2 >
1030 struct RowExprTrait< SMatSMatAddExpr<MT1,MT2> >
1034 using Type = AddExprTrait_< RowExprTrait_<const MT1>
1035 , RowExprTrait_<const MT2> >;
1044 template<
typename MT1,
typename MT2 >
1045 struct ColumnExprTrait< SMatSMatAddExpr<MT1,MT2> >
1049 using Type = AddExprTrait_< ColumnExprTrait_<const MT1>
1050 , ColumnExprTrait_<const 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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatAddExpr.h:260
Header file for auxiliary alias declarations.
Header file for the Max class template.
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:70
Header file for the Rows type trait.
Header file for the IsUniUpper type trait.
Header file for basic type definitions.
EnableIf_< IsDenseMatrix< MT1 > > smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
Header file for the serial shim.
Header file for the ColumnExprTrait class template.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatAddExpr.h:303
const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:699
Header file for the And class template.
Header file for the AddExprTrait class template.
SMatSMatAddExpr< MT1, MT2 > This
Type of this SMatSMatAddExpr instance.
Definition: SMatSMatAddExpr.h:163
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:723
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatAddExpr.h:209
Header file for the Computation base class.
Constraints on the storage order of matrix types.
Header file for the IsUniLower type trait.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
EnableIf_< IsDenseMatrix< MT1 > > smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:129
SMatSMatAddExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatSMatAddExpr class.
Definition: SMatSMatAddExpr.h:193
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:109
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SMatSMatAddExpr.h:167
typename IfTrue< Condition, T1, T2 >::Type IfTrue_
Auxiliary alias declaration for the IfTrue class template.The IfTrue_ alias declaration provides a co...
Definition: If.h:109
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
Header file for the SparseMatrix base class.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatAddExpr.h:271
Constraint on the data type.
If_< IsExpression< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:176
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
typename AddExprTrait< T1, T2 >::Type AddExprTrait_
Auxiliary alias declaration for the AddExprTrait class template.The AddExprTrait_ alias declaration p...
Definition: AddExprTrait.h:219
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatAddExpr.h:224
Header file for the Or class template.
#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 Columns type trait.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
CompositeType_< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:114
Header file for the IsLower type trait.
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:330
RightOperand rhs_
Right-hand side sparse matrix of the addition expression.
Definition: SMatSMatAddExpr.h:323
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
Header file for the exception macros of the math module.
OppositeType_< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatAddExpr.h:165
BLAZE_ALWAYS_INLINE 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:254
#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:109
Header file for the RowExprTrait class template.
CompositeType_< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:113
Header file for all forward declarations for expression class templates.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatAddExpr.h:315
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatAddExpr.h:291
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
ResultType_< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:111
AddTrait_< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatSMatAddExpr.h:164
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
#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
Header file for the SubmatrixExprTrait class template.
ResultType_< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:112
#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: SMatSMatAddExpr.h:250
Header file for run time assertion macros.
Header file for the addition trait.
LeftOperand lhs_
Left-hand side sparse matrix of the addition expression.
Definition: SMatSMatAddExpr.h:322
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:160
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatAddExpr.h:166
Constraint on the data type.
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatSMatAddExpr.h:240
Header file for the isDefault shim.
Constraint on the data type.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatAddExpr.h:281
Constraints on the storage order of matrix types.
If_< IsExpression< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:179
Header file for the MatMatAddExpr base class.
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant class template represents ...
Definition: IntegralConstant.h:100
AddExprTrait_< RN1, RN2 > ExprReturnType
Expression return type for the subscript operator.
Definition: SMatSMatAddExpr.h:129
Header file for the RemoveReference type trait.
typename T::OppositeType OppositeType_
Alias declaration for nested OppositeType type definitions.The OppositeType_ alias declaration provid...
Definition: Aliases.h:243
ReturnType_< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:115
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:314
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
ReturnType_< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:116
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatAddExpr.h:173
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:950
Header file for the IsComputation type trait class.
Expression object for sparse matrix-sparse matrix additions.The SMatSMatAddExpr class represents the ...
Definition: Forward.h:98
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
Header file for the IntegralConstant class template.
const IfTrue_< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatSMatAddExpr.h:170
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
Header file for the IsUpper type trait.
Header file for the IsHermitian type trait.
Header file for the IsResizable type trait.
typename AddTrait< T1, T2 >::Type AddTrait_
Auxiliary alias declaration for the AddTrait class template.The AddTrait_ alias declaration provides ...
Definition: AddTrait.h:245
#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 FunctionTrace class.