Blaze 3.9
SMatTSMatSubExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATTSMATSUBEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATTSMATSUBEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <utility>
44#include <blaze/math/Aliases.h>
66#include <blaze/util/Assert.h>
67#include <blaze/util/EnableIf.h>
71#include <blaze/util/mpl/If.h>
72#include <blaze/util/Types.h>
74
75
76namespace blaze {
77
78//=================================================================================================
79//
80// CLASS SMATTSMATSUBEXPR
81//
82//=================================================================================================
83
84//*************************************************************************************************
91template< typename MT1 // Type of the left-hand side sparse matrix
92 , typename MT2 > // Type of the right-hand side sparse matrix
94 : public MatMatSubExpr< SparseMatrix< SMatTSMatSubExpr<MT1,MT2>, IsZero_v<MT1> > >
95 , private Computation
96{
97 private:
98 //**Type definitions****************************************************************************
105 //**********************************************************************************************
106
107 //**Return type evaluation**********************************************************************
109
114 static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
115
117 using ExprReturnType = decltype( std::declval<RN1>() - std::declval<RN2>() );
118 //**********************************************************************************************
119
120 //**Serial evaluation strategy******************************************************************
122
127 template< typename T1, typename T2 >
128 static constexpr bool UseSymmetricKernel_v =
129 ( ( StorageOrder_v<T1> != StorageOrder_v<T2> ) && IsSymmetric_v<T2> );
131 //**********************************************************************************************
132
133 //**Parallel evaluation strategy****************************************************************
135
140 template< typename MT >
141 static constexpr bool UseSMPAssign_v = MT::smpAssignable;
143 //**********************************************************************************************
144
145 public:
146 //**Type definitions****************************************************************************
149
152
157
160
163
165 using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
166
168 using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
169 //**********************************************************************************************
170
171 //**Compilation flags***************************************************************************
173 static constexpr bool smpAssignable = false;
174 //**********************************************************************************************
175
176 //**Constructor*********************************************************************************
182 inline SMatTSMatSubExpr( const MT1& lhs, const MT2& rhs ) noexcept
183 : lhs_( lhs ) // Left-hand side sparse matrix of the subtraction expression
184 , rhs_( rhs ) // Right-hand side sparse matrix of the subtraction expression
185 {
186 BLAZE_INTERNAL_ASSERT( lhs.rows() == rhs.rows() , "Invalid number of rows" );
187 BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.columns(), "Invalid number of columns" );
188 }
189 //**********************************************************************************************
190
191 //**Access operator*****************************************************************************
198 inline ReturnType operator()( size_t i, size_t j ) const {
199 BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
200 BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
201 return lhs_(i,j) - rhs_(i,j);
202 }
203 //**********************************************************************************************
204
205 //**At function*********************************************************************************
213 inline ReturnType at( size_t i, size_t j ) const {
214 if( i >= lhs_.rows() ) {
215 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
216 }
217 if( j >= lhs_.columns() ) {
218 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
219 }
220 return (*this)(i,j);
221 }
222 //**********************************************************************************************
223
224 //**Rows function*******************************************************************************
229 inline size_t rows() const noexcept {
230 return lhs_.rows();
231 }
232 //**********************************************************************************************
233
234 //**Columns function****************************************************************************
239 inline size_t columns() const noexcept {
240 return lhs_.columns();
241 }
242 //**********************************************************************************************
243
244 //**NonZeros function***************************************************************************
249 inline size_t nonZeros() const {
250 return lhs_.nonZeros() + rhs_.nonZeros();
251 }
252 //**********************************************************************************************
253
254 //**NonZeros function***************************************************************************
260 inline size_t nonZeros( size_t i ) const {
261 return lhs_.nonZeros(i) + rhs_.nonZeros(i);
262 }
263 //**********************************************************************************************
264
265 //**Left operand access*************************************************************************
270 inline LeftOperand leftOperand() const noexcept {
271 return lhs_;
272 }
273 //**********************************************************************************************
274
275 //**Right operand access************************************************************************
280 inline RightOperand rightOperand() const noexcept {
281 return rhs_;
282 }
283 //**********************************************************************************************
284
285 //**********************************************************************************************
291 template< typename T >
292 inline bool canAlias( const T* alias ) const noexcept {
293 return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
294 }
295 //**********************************************************************************************
296
297 //**********************************************************************************************
303 template< typename T >
304 inline bool isAliased( const T* alias ) const noexcept {
305 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
306 }
307 //**********************************************************************************************
308
309 private:
310 //**Member variables****************************************************************************
313 //**********************************************************************************************
314
315 //**Assignment to dense matrices****************************************************************
327 template< typename MT // Type of the target dense matrix
328 , bool SO > // Storage order of the target dense matrix
329 friend inline void assign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
330 {
332
333 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
334 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
335
336 assign( *lhs, rhs.lhs_ );
337
339 subAssign( *lhs, rhs.rhs_ );
340 }
341 else
342 {
343 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
344
345 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
346 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
347 BLAZE_INTERNAL_ASSERT( B.rows() == (*lhs).rows() , "Invalid number of rows" );
348 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
349
350 for( size_t j=0UL; j<(*lhs).columns(); ++j ) {
351 const auto end( B.end(j) );
352 for( auto element=B.begin(j); element!=end; ++element ) {
353 if( isDefault( (*lhs)(element->index(),j) ) )
354 (*lhs)(element->index(),j) = -element->value();
355 else
356 (*lhs)(element->index(),j) -= element->value();
357 }
358 }
359 }
360 }
362 //**********************************************************************************************
363
364 //**Assignment to row-major sparse matrices*****************************************************
377 template< typename MT > // Type of the target sparse matrix
378 friend inline auto assign( SparseMatrix<MT,false>& lhs, const SMatTSMatSubExpr& rhs )
380 {
382
383 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
384 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
385
386 // Evaluation of the left-hand side sparse matrix operand
387 CT1 A( serial( rhs.lhs_ ) );
388
389 // Evaluation of the right-hand side sparse matrix operand
390 const OppositeType_t<RT2> B( serial( rhs.rhs_ ) );
391
392 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
393 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
394 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
395 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
396 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
397 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
398
399 // Final memory allocation (based on the evaluated operands)
400 (*lhs).reserve( A.nonZeros() + B.nonZeros() );
401
402 // Performing the matrix subtraction
403 for( size_t i=0UL; i<(*lhs).rows(); ++i )
404 {
405 const auto lend( A.end(i) );
406 const auto rend( B.end(i) );
407
408 auto l( A.begin(i) );
409 auto r( B.begin(i) );
410
411 while( l != lend && r != rend )
412 {
413 if( l->index() < r->index() ) {
414 (*lhs).append( i, l->index(), l->value() );
415 ++l;
416 }
417 else if( l->index() > r->index() ) {
418 (*lhs).append( i, r->index(), -r->value() );
419 ++r;
420 }
421 else {
422 (*lhs).append( i, l->index(), l->value() - r->value() );
423 ++l;
424 ++r;
425 }
426 }
427
428 while( l != lend ) {
429 (*lhs).append( i, l->index(), l->value() );
430 ++l;
431 }
432
433 while( r != rend ) {
434 (*lhs).append( i, r->index(), -r->value() );
435 ++r;
436 }
437
438 (*lhs).finalize( i );
439 }
440 }
442 //**********************************************************************************************
443
444 //**Assignment to row-major sparse matrices*****************************************************
457 template< typename MT > // Type of the target sparse matrix
458 friend inline auto assign( SparseMatrix<MT,false>& lhs, const SMatTSMatSubExpr& rhs )
459 -> EnableIf_t< UseSymmetricKernel_v<MT,MT2> >
460 {
462
463 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
464 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
465
466 assign( *lhs, rhs.lhs_ - trans( rhs.rhs_ ) );
467 }
469 //**********************************************************************************************
470
471 //**Assignment to column-major sparse matrices**************************************************
484 template< typename MT > // Type of the target sparse matrix
485 friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatTSMatSubExpr& rhs )
486 -> DisableIf_t< UseSymmetricKernel_v<MT,MT1> >
487 {
489
491
492 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
493 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
494
495 // Evaluation of the left-hand side sparse matrix operand
496 const OppositeType_t<RT1> A( serial( rhs.lhs_ ) );
497
498 // Evaluation of the right-hand side sparse matrix operand
499 CT2 B( serial( rhs.rhs_ ) );
500
501 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
502 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
503 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
504 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
505 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
506 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
507
508 // Final memory allocation (based on the evaluated operands)
509 (*lhs).reserve( A.nonZeros() + B.nonZeros() );
510
511 // Performing the matrix subtraction
512 for( size_t j=0UL; j<(*lhs).columns(); ++j )
513 {
514 const auto lend( A.end(j) );
515 const auto rend( B.end(j) );
516
517 auto l( A.begin(j) );
518 auto r( B.begin(j) );
519
520 while( l != lend && r != rend )
521 {
522 if( l->index() < r->index() ) {
523 (*lhs).append( l->index(), j, l->value() );
524 ++l;
525 }
526 else if( l->index() > r->index() ) {
527 (*lhs).append( r->index(), j, -r->value() );
528 ++r;
529 }
530 else {
531 (*lhs).append( l->index(), j, l->value() - r->value() );
532 ++l;
533 ++r;
534 }
535 }
536
537 while( l != lend ) {
538 (*lhs).append( l->index(), j, l->value() );
539 ++l;
540 }
541
542 while( r != rend ) {
543 (*lhs).append( r->index(), j, -r->value() );
544 ++r;
545 }
546
547 (*lhs).finalize( j );
548 }
549 }
551 //**********************************************************************************************
552
553 //**Assignment to column-major sparse matrices**************************************************
566 template< typename MT > // Type of the target sparse matrix
567 friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatTSMatSubExpr& rhs )
568 -> EnableIf_t< UseSymmetricKernel_v<MT,MT1> >
569 {
571
573
574 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
575 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
576
577 assign( *lhs, trans( rhs.lhs_ ) - rhs.rhs_ );
578 }
580 //**********************************************************************************************
581
582 //**Addition assignment to dense matrices*******************************************************
595 template< typename MT // Type of the target dense matrix
596 , bool SO > // Storage order of the target dense matrix
597 friend inline void addAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
598 {
600
601 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
602 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
603
604 addAssign( *lhs, rhs.lhs_ );
605 subAssign( *lhs, rhs.rhs_ );
606 }
608 //**********************************************************************************************
609
610 //**Addition assignment to sparse matrices******************************************************
611 // No special implementation for the addition assignment to sparse matrices.
612 //**********************************************************************************************
613
614 //**Subtraction assignment to dense matrices****************************************************
627 template< typename MT // Type of the target dense matrix
628 , bool SO > // Storage order of the target dense matrix
629 friend inline void subAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
630 {
632
633 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
634 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
635
636 subAssign( *lhs, rhs.lhs_ );
637 addAssign( *lhs, rhs.rhs_ );
638 }
640 //**********************************************************************************************
641
642 //**Subtraction assignment to sparse matrices***************************************************
643 // No special implementation for the subtraction assignment to sparse matrices.
644 //**********************************************************************************************
645
646 //**Schur product assignment to dense matrices**************************************************
659 template< typename MT // Type of the target dense matrix
660 , bool SO > // Storage order of the target dense matrix
661 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
662 {
664
667
668 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
669 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
670
671 const ResultType tmp( serial( rhs ) );
672 schurAssign( *lhs, tmp );
673 }
675 //**********************************************************************************************
676
677 //**Schur product assignment to sparse matrices*************************************************
678 // No special implementation for the Schur product assignment to sparse matrices.
679 //**********************************************************************************************
680
681 //**Multiplication assignment to dense matrices*************************************************
682 // No special implementation for the multiplication assignment to dense matrices.
683 //**********************************************************************************************
684
685 //**Multiplication assignment to sparse matrices************************************************
686 // No special implementation for the multiplication assignment to sparse matrices.
687 //**********************************************************************************************
688
689 //**SMP assignment to dense matrices************************************************************
690 // No special implementation for the SMP assignment to dense matrices.
691 //**********************************************************************************************
692
693 //**Assignment to sparse matrices***************************************************************
694 // No special implementation for the SMP assignment to sparse matrices.
695 //**********************************************************************************************
696
697 //**SMP addition assignment to dense matrices***************************************************
712 template< typename MT // Type of the target dense matrix
713 , bool SO > // Storage order of the target dense matrix
714 friend inline auto smpAddAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
715 -> EnableIf_t< UseSMPAssign_v<MT> >
716 {
718
719 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
720 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
721
722 smpAddAssign( *lhs, rhs.lhs_ );
723 smpSubAssign( *lhs, rhs.rhs_ );
724 }
726 //**********************************************************************************************
727
728 //**SMP addition assignment to sparse matrices**************************************************
729 // No special implementation for the SMP addition assignment to sparse matrices.
730 //**********************************************************************************************
731
732 //**SMP subtraction assignment to dense matrices************************************************
747 template< typename MT // Type of the target dense matrix
748 , bool SO > // Storage order of the target dense matrix
749 friend inline auto smpSubAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
750 -> EnableIf_t< UseSMPAssign_v<MT> >
751 {
753
754 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
755 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
756
757 smpSubAssign( *lhs, rhs.lhs_ );
758 smpAddAssign( *lhs, rhs.rhs_ );
759 }
761 //**********************************************************************************************
762
763 //**SMP subtraction assignment to sparse matrices***********************************************
764 // No special implementation for the SMP subtraction assignment to sparse matrices.
765 //**********************************************************************************************
766
767 //**SMP Schur product assignment to dense matrices**********************************************
782 template< typename MT // Type of the target dense matrix
783 , bool SO > // Storage order of the target dense matrix
784 friend inline auto smpSchurAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatSubExpr& rhs )
785 -> EnableIf_t< UseSMPAssign_v<MT> >
786 {
788
791
792 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
793 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
794
795 const ResultType tmp( rhs );
796 smpSchurAssign( *lhs, tmp );
797 }
799 //**********************************************************************************************
800
801 //**SMP Schur product assignment to sparse matrices*********************************************
802 // No special implementation for the SMP Schur product assignment to sparse matrices.
803 //**********************************************************************************************
804
805 //**SMP multiplication assignment to dense matrices*********************************************
806 // No special implementation for the SMP multiplication assignment to dense matrices.
807 //**********************************************************************************************
808
809 //**SMP multiplication assignment to sparse matrices********************************************
810 // No special implementation for the SMP multiplication assignment to sparse matrices.
811 //**********************************************************************************************
812
813 //**Compile time checks*************************************************************************
821 //**********************************************************************************************
822};
823//*************************************************************************************************
824
825
826
827
828//=================================================================================================
829//
830// GLOBAL BINARY ARITHMETIC OPERATORS
831//
832//=================================================================================================
833
834//*************************************************************************************************
847template< typename MT1 // Type of the left-hand side sparse matrix
848 , typename MT2 // Type of the right-hand side sparse matrix
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 SMatTSMatSubExpr<MT1,MT2>
853 smattsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
854{
856
857 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
858 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
859
860 return SMatTSMatSubExpr<MT1,MT2>( *lhs, *rhs );
861}
863//*************************************************************************************************
864
865
866//*************************************************************************************************
880template< typename MT1 // Type of the left-hand side sparse matrix
881 , typename MT2 // Type of the right-hand side sparse matrix
882 , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
883 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
884inline const MT1&
885 smattsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
886{
888
889 MAYBE_UNUSED( rhs );
890
891 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
892 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
893
894 return (*lhs);
895}
897//*************************************************************************************************
898
899
900//*************************************************************************************************
914template< typename MT1 // Type of the left-hand side sparse matrix
915 , typename MT2 // Type of the right-hand side sparse matrix
916 , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
917 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
918inline decltype(auto)
919 smattsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
920{
922
923 MAYBE_UNUSED( lhs );
924
925 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
926 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
927
928 return -(*rhs);
929}
931//*************************************************************************************************
932
933
934//*************************************************************************************************
947template< typename MT1 // Type of the left-hand side sparse matrix
948 , typename MT2 // Type of the right-hand side sparse matrix
949 , EnableIf_t< IsZero_v<MT1> && IsZero_v<MT2> >* = nullptr >
950inline decltype(auto)
951 smattsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
952{
954
955 MAYBE_UNUSED( rhs );
956
957 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
958 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
959
960 using ReturnType = const SubTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
961
964
965 return ReturnType( (*lhs).rows(), (*lhs).columns() );
966}
968//*************************************************************************************************
969
970
971//*************************************************************************************************
1000template< typename MT1 // Type of the left-hand side sparse matrix
1001 , typename MT2 > // Type of the right-hand side sparse matrix
1002inline decltype(auto)
1003 operator-( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1004{
1006
1007 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1008 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1009 }
1010
1011 return smattsmatsub( *lhs, *rhs );
1012}
1013//*************************************************************************************************
1014
1015} // namespace blaze
1016
1017#endif
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
Expression object for sparse matrix-transpose sparse matrix subtractions.
Definition: SMatTSMatSubExpr.h:96
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:101
RightOperand rhs_
Right-hand side sparse matrix of the subtraction expression.
Definition: SMatTSMatSubExpr.h:312
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatTSMatSubExpr.h:270
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTSMatSubExpr.h:213
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTSMatSubExpr.h:154
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatTSMatSubExpr.h:153
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatTSMatSubExpr.h:117
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatTSMatSubExpr.h:156
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTSMatSubExpr.h:155
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatTSMatSubExpr.h:162
SMatTSMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatTSMatSubExpr class.
Definition: SMatTSMatSubExpr.h:182
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:103
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTSMatSubExpr.h:198
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:104
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatTSMatSubExpr.h:260
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:165
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTSMatSubExpr.h:229
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatTSMatSubExpr.h:249
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatTSMatSubExpr.h:304
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatTSMatSubExpr.h:292
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatTSMatSubExpr.h:173
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatTSMatSubExpr.h:114
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTSMatSubExpr.h:239
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatTSMatSubExpr.h:159
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:100
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:168
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:99
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: SMatTSMatSubExpr.h:102
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: SMatTSMatSubExpr.h:280
LeftOperand lhs_
Left-hand side sparse matrix of the subtraction expression.
Definition: SMatTSMatSubExpr.h:311
Base class for sparse matrices.
Definition: SparseMatrix.h:77
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.