35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSMATSUBEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_TSMATSMATSUBEXPR_H_ 93 template<
typename MT1
95 class TSMatSMatSubExpr
96 :
public MatMatSubExpr< SparseMatrix< TSMatSMatSubExpr<MT1,MT2>, IsZero_v<MT2> > >
116 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
129 template<
typename T1,
typename T2 >
130 static constexpr
bool UseSymmetricKernel_v =
131 ( ( StorageOrder_v<T1> != StorageOrder_v<T2> ) && IsSymmetric_v<T2> );
142 template<
typename MT >
143 static constexpr
bool UseSMPAssign_v = MT::smpAssignable;
216 if( i >=
lhs_.rows() ) {
219 if( j >=
lhs_.columns() ) {
231 inline size_t rows() const noexcept {
242 return lhs_.columns();
252 return lhs_.nonZeros() +
rhs_.nonZeros();
263 return lhs_.nonZeros(i) +
rhs_.nonZeros(i);
293 template<
typename T >
294 inline bool canAlias(
const T* alias )
const noexcept {
295 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
305 template<
typename T >
306 inline bool isAliased(
const T* alias )
const noexcept {
307 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
329 template<
typename MT
338 assign( ~lhs, rhs.lhs_ );
341 subAssign( ~lhs, rhs.rhs_ );
352 for(
size_t i=0UL; i<(~lhs).
rows(); ++i ) {
353 const auto end( B.end(i) );
354 for(
auto element=B.begin(i); element!=
end; ++element ) {
355 if(
isDefault( (~lhs)(i,element->index()) ) )
356 (~lhs)(i,element->index()) = -element->value();
358 (~lhs)(i,element->index()) -= element->value();
379 template<
typename MT >
402 (~lhs).reserve( A.nonZeros() + B.nonZeros() );
405 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
407 const auto lend( A.end(i) );
408 const auto rend( B.end(i) );
410 auto l( A.begin(i) );
411 auto r( B.begin(i) );
413 while( l != lend && r != rend )
415 if( l->index() < r->index() ) {
416 (~lhs).append( i, l->index(), l->value() );
419 else if( l->index() > r->index() ) {
420 (~lhs).append( i, r->index(), -r->value() );
424 (~lhs).append( i, l->index(), l->value() - r->value() );
431 (~lhs).append( i, l->index(), l->value() );
436 (~lhs).append( i, r->index(), -r->value() );
440 (~lhs).finalize( i );
459 template<
typename MT >
460 friend inline auto assign( SparseMatrix<MT,false>& lhs,
const TSMatSMatSubExpr& rhs )
461 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1> >
468 assign( ~lhs,
trans( rhs.lhs_ ) - rhs.rhs_ );
486 template<
typename MT >
487 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const TSMatSMatSubExpr& rhs )
488 -> DisableIf_t< UseSymmetricKernel_v<MT,MT2> >
501 const OppositeType_t<RT2> B(
serial( rhs.rhs_ ) );
511 (~lhs).reserve( A.nonZeros() + B.nonZeros() );
514 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
516 const auto lend( A.end(j) );
517 const auto rend( B.end(j) );
519 auto l( A.begin(j) );
520 auto r( B.begin(j) );
522 while( l != lend && r != rend )
524 if( l->index() < r->index() ) {
525 (~lhs).append( l->index(), j, l->value() );
528 else if( l->index() > r->index() ) {
529 (~lhs).append( r->index(), j, -r->value() );
533 (~lhs).append( l->index(), j, l->value() - r->value() );
540 (~lhs).append( l->index(), j, l->value() );
545 (~lhs).append( r->index(), j, -r->value() );
549 (~lhs).finalize( j );
568 template<
typename MT >
569 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const TSMatSMatSubExpr& rhs )
570 -> EnableIf_t< UseSymmetricKernel_v<MT,MT2> >
579 assign( ~lhs, rhs.lhs_ -
trans( rhs.rhs_ ) );
597 template<
typename MT
599 friend inline void addAssign( DenseMatrix<MT,SO>& lhs,
const TSMatSMatSubExpr& rhs )
606 addAssign( ~lhs, rhs.lhs_ );
607 subAssign( ~lhs, rhs.rhs_ );
629 template<
typename MT
631 friend inline void subAssign( DenseMatrix<MT,SO>& lhs,
const TSMatSMatSubExpr& rhs )
638 subAssign( ~lhs, rhs.lhs_ );
639 addAssign( ~lhs, rhs.rhs_ );
661 template<
typename MT
663 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs,
const TSMatSMatSubExpr& rhs )
674 schurAssign( ~lhs, tmp );
714 template<
typename MT
717 -> EnableIf_t< UseSMPAssign_v<MT> >
749 template<
typename MT
752 -> EnableIf_t< UseSMPAssign_v<MT> >
784 template<
typename MT
787 -> EnableIf_t< UseSMPAssign_v<MT> >
849 template<
typename MT1
851 ,
DisableIf_t< ( ( IsZero_v<MT1> || IsZero_v<MT2> ) &&
852 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
853 ( IsZero_v<MT1> && IsZero_v<MT2> ) >* =
nullptr >
854 inline const TSMatSMatSubExpr<MT1,MT2>
855 tsmatsmatsub(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
862 return TSMatSMatSubExpr<MT1,MT2>( ~lhs, ~rhs );
882 template<
typename MT1
884 , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
885 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
887 tsmatsmatsub(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
916 template<
typename MT1
918 , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
919 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
920 inline decltype(
auto)
921 tsmatsmatsub( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,false>& rhs )
949 template<
typename MT1
951 , EnableIf_t< IsZero_v<MT1> && IsZero_v<MT2> >* =
nullptr >
952 inline decltype(
auto)
953 tsmatsmatsub( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,false>& rhs )
962 using ReturnType =
const SubTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
967 return ReturnType( (~lhs).
rows(), (~lhs).
columns() );
1002 template<
typename MT1
1004 inline decltype(
auto)
1013 return tsmatsmatsub( ~lhs, ~rhs );
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
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatSMatSubExpr.h:231
Header file for auxiliary alias declarations.
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.
Header file for basic type definitions.
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
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: TSMatSMatSubExpr.h:282
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatSMatSubExpr.h:241
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatSMatSubExpr.h:306
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.
Header file for the IsSame and IsStrictlySame type traits.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatSMatSubExpr.h:156
Constraint on the data type.
LeftOperand leftOperand() const noexcept
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatSMatSubExpr.h:272
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:170
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatSMatSubExpr.h:155
Header file for the MAYBE_UNUSED function template.
Header file for the Computation base class.
Constraints on the storage order of matrix types.
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
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
Header file for the SparseMatrix base class.
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSMatSMatSubExpr.h:157
Constraint on the data type.
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:103
constexpr bool IsResizable_v
Auxiliary variable template for the IsResizable type trait.The IsResizable_v variable template provid...
Definition: IsResizable.h:133
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the IsSymmetric type trait.
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
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:104
#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
TSMatSMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatSMatSubExpr class.
Definition: TSMatSMatSubExpr.h:184
#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 MatMatSubExpr base class.
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatSMatSubExpr.h:164
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatSMatSubExpr.h:294
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:105
Header file for the exception macros of the math module.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatSMatSubExpr.h:200
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
Constraint on the data type.
Header file for the EnableIf class template.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatSMatSubExpr.h:262
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_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type,...
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
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:102
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
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatSMatSubExpr.h:116
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatSMatSubExpr.h:161
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
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
Header file for all forward declarations for expression class templates.
Header file for the isDefault shim.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatSMatSubExpr.h:158
Constraint on the data type.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatSMatSubExpr.h:175
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
LeftOperand lhs_
Left-hand side sparse matrix of the subtraction expression.
Definition: TSMatSMatSubExpr.h:313
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
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:106
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatSMatSubExpr.h:215
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:167
Header file for the StorageOrder type trait.
Header file for the IntegralConstant class template.
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatSMatSubExpr.h:119
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatSMatSubExpr.h:251
#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
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
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
Expression object for transpose sparse matrix-sparse matrix subtractions.The TSMatSMatSubExpr class r...
Definition: Forward.h:186
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:159
#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
RightOperand rhs_
Right-hand side sparse matrix of the subtraction expression.
Definition: TSMatSMatSubExpr.h:314
#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.
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:101