Blaze  3.6
SMatSMatSubExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATSUBEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATSUBEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
44 #include <blaze/math/Aliases.h>
51 #include <blaze/math/Exception.h>
66 #include <blaze/util/Assert.h>
67 #include <blaze/util/DisableIf.h>
68 #include <blaze/util/EnableIf.h>
71 #include <blaze/util/MaybeUnused.h>
72 #include <blaze/util/mpl/If.h>
73 #include <blaze/util/Types.h>
75 
76 
77 namespace blaze {
78 
79 //=================================================================================================
80 //
81 // CLASS SMATSMATSUBEXPR
82 //
83 //=================================================================================================
84 
85 //*************************************************************************************************
92 template< typename MT1 // Type of the left-hand side sparse matrix
93  , typename MT2 > // Type of the right-hand side sparse matrix
94 class SMatSMatSubExpr
95  : public MatMatSubExpr< SparseMatrix< SMatSMatSubExpr<MT1,MT2>, false > >
96  , private Computation
97 {
98  private:
99  //**Type definitions****************************************************************************
106  //**********************************************************************************************
107 
108  //**Return type evaluation**********************************************************************
110 
115  static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
116 
118  using ExprReturnType = decltype( std::declval<RN1>() - std::declval<RN2>() );
119  //**********************************************************************************************
120 
121  //**Serial evaluation strategy******************************************************************
123 
128  template< typename T1, typename T2, typename T3 >
129  static constexpr bool UseSymmetricKernel_v =
130  ( IsColumnMajorMatrix_v<T1> && IsSymmetric_v<T2> && IsSymmetric_v<T3> );
132  //**********************************************************************************************
133 
134  //**Parallel evaluation strategy****************************************************************
136 
141  template< typename MT >
142  static constexpr bool UseSMPAssign_v = MT::smpAssignable;
144  //**********************************************************************************************
145 
146  public:
147  //**Type definitions****************************************************************************
154 
157 
159  using CompositeType = const ResultType;
160 
162  using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
163 
165  using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
166  //**********************************************************************************************
167 
168  //**Compilation flags***************************************************************************
170  static constexpr bool smpAssignable = false;
171  //**********************************************************************************************
172 
173  //**Constructor*********************************************************************************
179  explicit inline SMatSMatSubExpr( const MT1& lhs, const MT2& rhs ) noexcept
180  : lhs_( lhs ) // Left-hand side sparse matrix of the subtraction expression
181  , rhs_( rhs ) // Right-hand side sparse matrix of the subtraction expression
182  {
183  BLAZE_INTERNAL_ASSERT( lhs.rows() == rhs.rows() , "Invalid number of rows" );
184  BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.columns(), "Invalid number of columns" );
185  }
186  //**********************************************************************************************
187 
188  //**Access operator*****************************************************************************
195  inline ReturnType operator()( size_t i, size_t j ) const {
196  BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
197  BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
198  return lhs_(i,j) - rhs_(i,j);
199  }
200  //**********************************************************************************************
201 
202  //**At function*********************************************************************************
210  inline ReturnType at( size_t i, size_t j ) const {
211  if( i >= lhs_.rows() ) {
212  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
213  }
214  if( j >= lhs_.columns() ) {
215  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
216  }
217  return (*this)(i,j);
218  }
219  //**********************************************************************************************
220 
221  //**Rows function*******************************************************************************
226  inline size_t rows() const noexcept {
227  return lhs_.rows();
228  }
229  //**********************************************************************************************
230 
231  //**Columns function****************************************************************************
236  inline size_t columns() const noexcept {
237  return lhs_.columns();
238  }
239  //**********************************************************************************************
240 
241  //**NonZeros function***************************************************************************
246  inline size_t nonZeros() const {
247  return lhs_.nonZeros() + rhs_.nonZeros();
248  }
249  //**********************************************************************************************
250 
251  //**NonZeros function***************************************************************************
257  inline size_t nonZeros( size_t i ) const {
258  return lhs_.nonZeros(i) + rhs_.nonZeros(i);
259  }
260  //**********************************************************************************************
261 
262  //**Left operand access*************************************************************************
267  inline LeftOperand leftOperand() const noexcept {
268  return lhs_;
269  }
270  //**********************************************************************************************
271 
272  //**Right operand access************************************************************************
277  inline RightOperand rightOperand() const noexcept {
278  return rhs_;
279  }
280  //**********************************************************************************************
281 
282  //**********************************************************************************************
288  template< typename T >
289  inline bool canAlias( const T* alias ) const noexcept {
290  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
291  }
292  //**********************************************************************************************
293 
294  //**********************************************************************************************
300  template< typename T >
301  inline bool isAliased( const T* alias ) const noexcept {
302  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
303  }
304  //**********************************************************************************************
305 
306  private:
307  //**Member variables****************************************************************************
310  //**********************************************************************************************
311 
312  //**Assignment to dense matrices****************************************************************
324  template< typename MT // Type of the target dense matrix
325  , bool SO > // Storage order of the target dense matrix
326  friend inline void assign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
327  {
329 
330  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
331  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
332 
333  assign( ~lhs, rhs.lhs_ );
334 
335  if( !IsResizable_v< ElementType_t<MT> > ) {
336  subAssign( ~lhs, rhs.rhs_ );
337  }
338  else
339  {
340  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
341 
342  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
343  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
344  BLAZE_INTERNAL_ASSERT( B.rows() == (~lhs).rows() , "Invalid number of rows" );
345  BLAZE_INTERNAL_ASSERT( B.columns() == (~lhs).columns() , "Invalid number of columns" );
346 
347  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
348  const auto end( B.end(i) );
349  for( auto element=B.begin(i); element!=end; ++element ) {
350  if( isDefault( (~lhs)(i,element->index()) ) )
351  (~lhs)(i,element->index()) = -element->value();
352  else
353  (~lhs)(i,element->index()) -= element->value();
354  }
355  }
356  }
357  }
359  //**********************************************************************************************
360 
361  //**Assignment to row-major sparse matrices*****************************************************
373  template< typename MT > // Type of the target sparse matrix
374  friend inline void assign( SparseMatrix<MT,false>& lhs, const SMatSMatSubExpr& rhs )
375  {
377 
378  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
379  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
380 
381  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
382  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
383 
384  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
385  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
386  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
387  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
388  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
389  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
390 
391  // Final memory allocation (based on the evaluated operands)
392  (~lhs).reserve( A.nonZeros() + B.nonZeros() );
393 
394  // Performing the matrix subtraction
395  for( size_t i=0UL; i<(~lhs).rows(); ++i )
396  {
397  const auto lend( A.end(i) );
398  const auto rend( B.end(i) );
399 
400  auto l( A.begin(i) );
401  auto r( B.begin(i) );
402 
403  while( l != lend && r != rend )
404  {
405  if( l->index() < r->index() ) {
406  (~lhs).append( i, l->index(), l->value() );
407  ++l;
408  }
409  else if( l->index() > r->index() ) {
410  (~lhs).append( i, r->index(), -r->value() );
411  ++r;
412  }
413  else {
414  (~lhs).append( i, l->index(), l->value() - r->value() );
415  ++l;
416  ++r;
417  }
418  }
419 
420  while( l != lend ) {
421  (~lhs).append( i, l->index(), l->value() );
422  ++l;
423  }
424 
425  while( r != rend ) {
426  (~lhs).append( i, r->index(), -r->value() );
427  ++r;
428  }
429 
430  (~lhs).finalize( i );
431  }
432  }
434  //**********************************************************************************************
435 
436  //**Assignment to column-major sparse matrices**************************************************
448  template< typename MT > // Type of the target sparse matrix
449  friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatSMatSubExpr& rhs )
450  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
451  {
453 
455 
456  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
457  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
458 
459  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
460  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
461 
462  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
463  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
464  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
465  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
466  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
467  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
468 
469  const size_t m( rhs.rows() );
470  const size_t n( rhs.columns() );
471 
472  // Counting the number of elements per column
473  std::vector<size_t> nonzeros( n, 0UL );
474  for( size_t i=0UL; i<m; ++i )
475  {
476  const auto lend( A.end(i) );
477  const auto rend( B.end(i) );
478 
479  auto l( A.begin(i) );
480  auto r( B.begin(i) );
481 
482  while( l != lend && r != rend )
483  {
484  if( l->index() < r->index() ) {
485  ++nonzeros[l->index()];
486  ++l;
487  }
488  else if( l->index() > r->index() ) {
489  ++nonzeros[r->index()];
490  ++r;
491  }
492  else {
493  ++nonzeros[l->index()];
494  ++l;
495  ++r;
496  }
497  }
498 
499  while( l != lend ) {
500  ++nonzeros[l->index()];
501  ++l;
502  }
503 
504  while( r != rend ) {
505  ++nonzeros[r->index()];
506  ++r;
507  }
508  }
509 
510  // Resizing the left-hand side sparse matrix
511  for( size_t j=0UL; j<n; ++j ) {
512  (~lhs).reserve( j, nonzeros[j] );
513  }
514 
515  // Performing the matrix subtraction
516  for( size_t i=0UL; i<m; ++i )
517  {
518  const auto lend( A.end(i) );
519  const auto rend( B.end(i) );
520 
521  auto l( A.begin(i) );
522  auto r( B.begin(i) );
523 
524  while( l != lend && r != rend )
525  {
526  if( l->index() < r->index() ) {
527  (~lhs).append( i, l->index(), l->value() );
528  ++l;
529  }
530  else if( l->index() > r->index() ) {
531  (~lhs).append( i, r->index(), -r->value() );
532  ++r;
533  }
534  else {
535  (~lhs).append( i, l->index(), l->value() - r->value() );
536  ++l;
537  ++r;
538  }
539  }
540 
541  while( l != lend ) {
542  (~lhs).append( i, l->index(), l->value() );
543  ++l;
544  }
545 
546  while( r != rend ) {
547  (~lhs).append( i, r->index(), -r->value() );
548  ++r;
549  }
550  }
551  }
553  //**********************************************************************************************
554 
555  //**Assignment to column-major sparse matrices**************************************************
567  template< typename MT > // Type of the target sparse matrix
568  friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatSMatSubExpr& rhs )
569  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
570  {
572 
574 
575  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
576  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
577 
578  assign( ~lhs, trans( rhs.lhs_ ) - trans( rhs.rhs_ ) );
579  }
581  //**********************************************************************************************
582 
583  //**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 SMatSMatSubExpr& 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****************************************************
626  template< typename MT // Type of the target dense matrix
627  , bool SO > // Storage order of the target dense matrix
628  friend inline void subAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
629  {
631 
632  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
633  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
634 
635  subAssign( ~lhs, rhs.lhs_ );
636  addAssign( ~lhs, rhs.rhs_ );
637  }
639  //**********************************************************************************************
640 
641  //**Subtraction assignment to sparse matrices***************************************************
642  // No special implementation for the subtraction assignment to sparse matrices.
643  //**********************************************************************************************
644 
645  //**Schur product assignment to dense matrices**************************************************
658  template< typename MT // Type of the target dense matrix
659  , bool SO > // Storage order of the target dense matrix
660  friend inline void schurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
661  {
663 
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  //**SMP assignment to sparse matrices***********************************************************
694  // No special implementation for the SMP assignment to sparse matrices.
695  //**********************************************************************************************
696 
697  //**SMP addition assignment to dense matrices***************************************************
711  template< typename MT // Type of the target dense matrix
712  , bool SO > // Storage order of the target dense matrix
713  friend inline auto smpAddAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
714  -> EnableIf_t< UseSMPAssign_v<MT> >
715  {
717 
718  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
719  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
720 
721  smpAddAssign( ~lhs, rhs.lhs_ );
722  smpSubAssign( ~lhs, rhs.rhs_ );
723  }
725  //**********************************************************************************************
726 
727  //**SMP addition assignment to sparse matrices**************************************************
728  // No special implementation for the SMP addition assignment to sparse matrices.
729  //**********************************************************************************************
730 
731  //**SMP subtraction assignment to dense matrices************************************************
746  template< typename MT // Type of the target dense matrix
747  , bool SO > // Storage order of the target dense matrix
748  friend inline auto smpSubAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
749  -> EnableIf_t< UseSMPAssign_v<MT> >
750  {
752 
753  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
754  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
755 
756  smpSubAssign( ~lhs, rhs.lhs_ );
757  smpAddAssign( ~lhs, rhs.rhs_ );
758  }
760  //**********************************************************************************************
761 
762  //**SMP subtraction assignment to sparse matrices***********************************************
763  // No special implementation for the SMP subtraction assignment to sparse matrices.
764  //**********************************************************************************************
765 
766  //**SMP Schur product assignment to dense matrices**********************************************
781  template< typename MT // Type of the target dense matrix
782  , bool SO > // Storage order of the target dense matrix
783  friend inline auto smpSchurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
784  -> EnableIf_t< UseSMPAssign_v<MT> >
785  {
787 
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 //*************************************************************************************************
846 template< typename MT1 // Type of the left-hand side sparse matrix
847  , typename MT2 // Type of the right-hand side sparse matrix
848  , DisableIf_t< ( ( IsZero_v<MT1> || IsZero_v<MT2> ) &&
849  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
850  ( IsZero_v<MT1> && IsZero_v<MT2> ) >* = nullptr >
851 inline const SMatSMatSubExpr<MT1,MT2>
852  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
853 {
855 
856  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
857  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
858 
859  return SMatSMatSubExpr<MT1,MT2>( ~lhs, ~rhs );
860 }
862 //*************************************************************************************************
863 
864 
865 //*************************************************************************************************
879 template< typename MT1 // Type of the left-hand side sparse matrix
880  , typename MT2 // Type of the right-hand side sparse matrix
881  , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
882  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
883 inline const MT1&
884  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
885 {
887 
888  MAYBE_UNUSED( rhs );
889 
890  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
891  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
892 
893  return (~lhs);
894 }
896 //*************************************************************************************************
897 
898 
899 //*************************************************************************************************
913 template< typename MT1 // Type of the left-hand side sparse matrix
914  , typename MT2 // Type of the right-hand side sparse matrix
915  , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
916  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
917 inline decltype(auto)
918  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
919 {
921 
922  MAYBE_UNUSED( lhs );
923 
924  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
925  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
926 
927  return -(~rhs);
928 }
930 //*************************************************************************************************
931 
932 
933 //*************************************************************************************************
945 template< typename MT1 // Type of the left-hand side sparse matrix
946  , typename MT2 // Type of the right-hand side sparse matrix
947  , EnableIf_t< IsZero_v<MT1> && IsZero_v<MT2> >* = nullptr >
948 inline decltype(auto)
949  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
950 {
952 
953  MAYBE_UNUSED( rhs );
954 
955  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
956  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
957 
958  using ReturnType = const SubTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
959 
962 
963  return ReturnType( (~lhs).rows(), (~lhs).columns() );
964 }
966 //*************************************************************************************************
967 
968 
969 //*************************************************************************************************
995 template< typename MT1 // Type of the left-hand side sparse matrix
996  , typename MT2 > // Type of the right-hand side sparse matrix
997 inline decltype(auto)
998  operator-( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
999 {
1001 
1002  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() ) {
1003  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1004  }
1005 
1006  return smatsmatsub( ~lhs, ~rhs );
1007 }
1008 //*************************************************************************************************
1009 
1010 } // namespace blaze
1011 
1012 #endif
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatSMatSubExpr.h:226
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
Header file for auxiliary alias declarations.
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:105
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatSMatSubExpr.h:170
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
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatSubExpr.h:152
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.
Header file for the IsColumnMajorMatrix type trait.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatSubExpr.h:301
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatSMatSubExpr.h:236
Constraint on the data type.
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatSMatSubExpr.h:118
Header file for the MAYBE_UNUSED function template.
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatSubExpr.h:159
Header file for the Computation base class.
Constraints on the storage order of matrix types.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatSubExpr.h:257
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatSubExpr.h:151
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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatSubExpr.h:210
Header file for the SparseMatrix base class.
Constraint on the data type.
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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatSMatSubExpr.h:153
Header file for the If class template.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatSubExpr.h:289
#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
#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< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:162
Header file for the MatMatSubExpr base class.
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
ReturnType_t< MT1 > RN1
ReturnType type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:102
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:101
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
LeftOperand lhs_
Left-hand side sparse matrix of the subtraction expression.
Definition: SMatSMatSubExpr.h:308
Constraint on the data type.
Header file for the EnableIf class template.
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:165
#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
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.
Expression object for sparse matrix-sparse matrix subtractions.The SMatSMatSubExpr class represents t...
Definition: Forward.h:134
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
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
RightOperand rhs_
Right-hand side sparse matrix of the subtraction expression.
Definition: SMatSMatSubExpr.h:309
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:100
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatSubExpr.h:277
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.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatSubExpr.h:195
Constraint on the data type.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatSMatSubExpr.h:115
#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
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
ReturnType_t< MT2 > RN2
ReturnType type of the right-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:103
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatSubExpr.h:267
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatSMatSubExpr.h:150
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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatSubExpr.h:246
SMatSMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatSMatSubExpr class.
Definition: SMatSMatSubExpr.h:179
Header file for the IntegralConstant class template.
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:104
#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
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
#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.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatSMatSubExpr.h:156
Header file for the function trace functionality.