35#ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSMATSUBEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_TSMATSMATSUBEXPR_H_
94 :
public MatMatSubExpr< SparseMatrix< TSMatSMatSubExpr<MT1,MT2>, IsZero_v<MT2> > >
114 static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
127 template<
typename T1,
typename T2 >
128 static constexpr bool UseSymmetricKernel_v =
129 ( ( StorageOrder_v<T1> != StorageOrder_v<T2> ) && IsSymmetric_v<T2> );
140 template<
typename MT >
141 static constexpr bool UseSMPAssign_v = MT::smpAssignable;
214 if( i >=
lhs_.rows() ) {
217 if( j >=
lhs_.columns() ) {
229 inline size_t rows() const noexcept {
240 return lhs_.columns();
250 return lhs_.nonZeros() +
rhs_.nonZeros();
261 return lhs_.nonZeros(i) +
rhs_.nonZeros(i);
291 template<
typename T >
292 inline bool canAlias(
const T* alias )
const noexcept {
293 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
303 template<
typename T >
304 inline bool isAliased(
const T* alias )
const noexcept {
305 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
327 template<
typename MT
336 assign( *lhs, rhs.
lhs_ );
339 subAssign( *lhs, rhs.
rhs_ );
350 for(
size_t i=0UL; i<(*lhs).rows(); ++i ) {
351 const auto end( B.end(i) );
352 for(
auto element=B.begin(i); element!=
end; ++element ) {
353 if(
isDefault( (*lhs)(i,element->index()) ) )
354 (*lhs)(i,element->index()) = -element->value();
356 (*lhs)(i,element->index()) -= element->value();
377 template<
typename MT >
400 (*lhs).reserve( A.nonZeros() + B.nonZeros() );
403 for(
size_t i=0UL; i<(*lhs).rows(); ++i )
405 const auto lend( A.end(i) );
406 const auto rend( B.end(i) );
408 auto l( A.begin(i) );
409 auto r( B.begin(i) );
411 while( l != lend && r != rend )
413 if( l->index() < r->index() ) {
414 (*lhs).append( i, l->index(), l->value() );
417 else if( l->index() > r->index() ) {
418 (*lhs).append( i, r->index(), -r->value() );
422 (*lhs).append( i, l->index(), l->value() - r->value() );
429 (*lhs).append( i, l->index(), l->value() );
434 (*lhs).append( i, r->index(), -r->value() );
438 (*lhs).finalize( i );
457 template<
typename MT >
458 friend inline auto assign( SparseMatrix<MT,false>& lhs,
const TSMatSMatSubExpr& rhs )
459 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1> >
466 assign( *lhs,
trans( rhs.lhs_ ) - rhs.rhs_ );
484 template<
typename MT >
485 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const TSMatSMatSubExpr& rhs )
486 -> DisableIf_t< UseSymmetricKernel_v<MT,MT2> >
499 const OppositeType_t<RT2> B(
serial( rhs.rhs_ ) );
509 (*lhs).reserve( A.nonZeros() + B.nonZeros() );
512 for(
size_t j=0UL; j<(*lhs).columns(); ++j )
514 const auto lend( A.end(j) );
515 const auto rend( B.end(j) );
517 auto l( A.begin(j) );
518 auto r( B.begin(j) );
520 while( l != lend && r != rend )
522 if( l->index() < r->index() ) {
523 (*lhs).append( l->index(), j, l->value() );
526 else if( l->index() > r->index() ) {
527 (*lhs).append( r->index(), j, -r->value() );
531 (*lhs).append( l->index(), j, l->value() - r->value() );
538 (*lhs).append( l->index(), j, l->value() );
543 (*lhs).append( r->index(), j, -r->value() );
547 (*lhs).finalize( j );
566 template<
typename MT >
567 friend inline auto assign( SparseMatrix<MT,true>& lhs,
const TSMatSMatSubExpr& rhs )
568 -> EnableIf_t< UseSymmetricKernel_v<MT,MT2> >
577 assign( *lhs, rhs.lhs_ -
trans( rhs.rhs_ ) );
595 template<
typename MT
597 friend inline void addAssign( DenseMatrix<MT,SO>& lhs,
const TSMatSMatSubExpr& rhs )
604 addAssign( *lhs, rhs.lhs_ );
605 subAssign( *lhs, rhs.rhs_ );
627 template<
typename MT
629 friend inline void subAssign( DenseMatrix<MT,SO>& lhs,
const TSMatSMatSubExpr& rhs )
636 subAssign( *lhs, rhs.lhs_ );
637 addAssign( *lhs, rhs.rhs_ );
659 template<
typename MT
661 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs,
const TSMatSMatSubExpr& rhs )
672 schurAssign( *lhs, tmp );
712 template<
typename MT
715 -> EnableIf_t< UseSMPAssign_v<MT> >
747 template<
typename MT
750 -> EnableIf_t< UseSMPAssign_v<MT> >
782 template<
typename MT
785 -> EnableIf_t< UseSMPAssign_v<MT> >
847template<
typename MT1
849 ,
DisableIf_t< ( ( IsZero_v<MT1> || IsZero_v<MT2> ) &&
850 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
851 ( IsZero_v<MT1> && IsZero_v<MT2> ) >* =
nullptr >
852inline const TSMatSMatSubExpr<MT1,MT2>
853 tsmatsmatsub(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
860 return TSMatSMatSubExpr<MT1,MT2>( *lhs, *rhs );
880template<
typename MT1
882 , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
883 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
885 tsmatsmatsub(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
914template<
typename MT1
916 , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
917 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
919 tsmatsmatsub(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
947template<
typename MT1
949 , EnableIf_t< IsZero_v<MT1> && IsZero_v<MT2> >* =
nullptr >
951 tsmatsmatsub(
const SparseMatrix<MT1,true>& lhs,
const SparseMatrix<MT2,false>& rhs )
960 using ReturnType =
const SubTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
965 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1000template<
typename MT1
1002inline decltype(
auto)
1007 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1011 return tsmatsmatsub( *lhs, *rhs );
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.
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 isDefault shim.
Header file for the IsExpression type trait class.
Header file for the IsResizable type trait.
Header file for the IsSame and IsStrictlySame type traits.
Header file for the IsSymmetric type trait.
Header file for the IsTemporary type trait class.
Header file for the MAYBE_UNUSED function template.
Constraints on the storage order of matrix types.
Header file for the subtraction trait.
Constraint on the data type.
Constraint on the data type.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Expression object for transpose sparse matrix-sparse matrix subtractions.
Definition: TSMatSMatSubExpr.h:96
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:168
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatSMatSubExpr.h:114
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: TSMatSMatSubExpr.h:280
LeftOperand leftOperand() const noexcept
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatSMatSubExpr.h:270
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatSMatSubExpr.h:159
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatSMatSubExpr.h:173
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:102
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatSMatSubExpr.h:229
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:103
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:99
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatSMatSubExpr.h:260
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatSMatSubExpr.h:198
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatSMatSubExpr.h:239
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatSMatSubExpr.h:156
LeftOperand lhs_
Left-hand side sparse matrix of the subtraction expression.
Definition: TSMatSMatSubExpr.h:311
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatSMatSubExpr.h:153
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatSMatSubExpr.h:213
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatSMatSubExpr.h:162
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatSMatSubExpr.h:304
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatSMatSubExpr.h:117
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSMatSMatSubExpr.h:155
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatSMatSubExpr.h:292
RightOperand rhs_
Right-hand side sparse matrix of the subtraction expression.
Definition: TSMatSMatSubExpr.h:312
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:165
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:104
TSMatSMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatSMatSubExpr class.
Definition: TSMatSMatSubExpr.h:182
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:101
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatSMatSubExpr.h:154
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatSMatSubExpr.h:100
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatSMatSubExpr.h:249
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 MatMatSubExpr base class.
Header file for the SparseMatrix 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
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#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_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.
Definition: SubTrait.h:163
constexpr bool IsResizable_v
Auxiliary variable template for the IsResizable type trait.
Definition: IsResizable.h:136
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:584
#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 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
constexpr bool IsSame_v
Auxiliary variable template for the IsSame type trait.
Definition: IsSame.h:159
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#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.
Header file for all forward declarations for expression class templates.
Header file for the StorageOrder type trait.
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 IsZero type trait.
Header file for basic type definitions.