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/mpl/If.h>
72 #include <blaze/util/Types.h>
75 #include <blaze/util/Unused.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS SMATSMATSUBEXPR
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
93 template< typename MT1 // Type of the left-hand side sparse matrix
94  , typename MT2 > // Type of the right-hand side sparse matrix
95 class SMatSMatSubExpr
96  : public MatMatSubExpr< SparseMatrix< SMatSMatSubExpr<MT1,MT2>, false > >
97  , private Computation
98 {
99  private:
100  //**Type definitions****************************************************************************
107  //**********************************************************************************************
108 
109  //**Return type evaluation**********************************************************************
111 
116  static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
117 
119  using ExprReturnType = decltype( std::declval<RN1>() - std::declval<RN2>() );
120  //**********************************************************************************************
121 
122  //**Serial evaluation strategy******************************************************************
124 
129  template< typename T1, typename T2, typename T3 >
130  static constexpr bool UseSymmetricKernel_v =
131  ( IsVoid_v< EnableIf_t< IsColumnMajorMatrix_v<T1> > > &&
132  IsSymmetric_v<T2> && IsSymmetric_v<T3> );
134  //**********************************************************************************************
135 
136  //**Parallel evaluation strategy****************************************************************
138 
143  template< typename MT >
144  static constexpr bool UseSMPAssign_v = MT::smpAssignable;
146  //**********************************************************************************************
147 
148  public:
149  //**Type definitions****************************************************************************
156 
159 
161  using CompositeType = const ResultType;
162 
164  using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
165 
167  using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
168  //**********************************************************************************************
169 
170  //**Compilation flags***************************************************************************
172  static constexpr bool smpAssignable = false;
173  //**********************************************************************************************
174 
175  //**Constructor*********************************************************************************
181  explicit inline SMatSMatSubExpr( const MT1& lhs, const MT2& rhs ) noexcept
182  : lhs_( lhs ) // Left-hand side sparse matrix of the subtraction expression
183  , rhs_( rhs ) // Right-hand side sparse matrix of the subtraction expression
184  {
185  BLAZE_INTERNAL_ASSERT( lhs.rows() == rhs.rows() , "Invalid number of rows" );
186  BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.columns(), "Invalid number of columns" );
187  }
188  //**********************************************************************************************
189 
190  //**Access operator*****************************************************************************
197  inline ReturnType operator()( size_t i, size_t j ) const {
198  BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
199  BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
200  return lhs_(i,j) - rhs_(i,j);
201  }
202  //**********************************************************************************************
203 
204  //**At function*********************************************************************************
212  inline ReturnType at( size_t i, size_t j ) const {
213  if( i >= lhs_.rows() ) {
214  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
215  }
216  if( j >= lhs_.columns() ) {
217  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
218  }
219  return (*this)(i,j);
220  }
221  //**********************************************************************************************
222 
223  //**Rows function*******************************************************************************
228  inline size_t rows() const noexcept {
229  return lhs_.rows();
230  }
231  //**********************************************************************************************
232 
233  //**Columns function****************************************************************************
238  inline size_t columns() const noexcept {
239  return lhs_.columns();
240  }
241  //**********************************************************************************************
242 
243  //**NonZeros function***************************************************************************
248  inline size_t nonZeros() const {
249  return lhs_.nonZeros() + rhs_.nonZeros();
250  }
251  //**********************************************************************************************
252 
253  //**NonZeros function***************************************************************************
259  inline size_t nonZeros( size_t i ) const {
260  return lhs_.nonZeros(i) + rhs_.nonZeros(i);
261  }
262  //**********************************************************************************************
263 
264  //**Left operand access*************************************************************************
269  inline LeftOperand leftOperand() const noexcept {
270  return lhs_;
271  }
272  //**********************************************************************************************
273 
274  //**Right operand access************************************************************************
279  inline RightOperand rightOperand() const noexcept {
280  return rhs_;
281  }
282  //**********************************************************************************************
283 
284  //**********************************************************************************************
290  template< typename T >
291  inline bool canAlias( const T* alias ) const noexcept {
292  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
293  }
294  //**********************************************************************************************
295 
296  //**********************************************************************************************
302  template< typename T >
303  inline bool isAliased( const T* alias ) const noexcept {
304  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
305  }
306  //**********************************************************************************************
307 
308  private:
309  //**Member variables****************************************************************************
312  //**********************************************************************************************
313 
314  //**Assignment to dense matrices****************************************************************
326  template< typename MT // Type of the target dense matrix
327  , bool SO > // Storage order of the target dense matrix
328  friend inline void assign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
329  {
331 
332  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
333  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
334 
335  assign( ~lhs, rhs.lhs_ );
336 
337  if( !IsResizable_v< ElementType_t<MT> > ) {
338  subAssign( ~lhs, rhs.rhs_ );
339  }
340  else
341  {
342  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
343 
344  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
345  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
346  BLAZE_INTERNAL_ASSERT( B.rows() == (~lhs).rows() , "Invalid number of rows" );
347  BLAZE_INTERNAL_ASSERT( B.columns() == (~lhs).columns() , "Invalid number of columns" );
348 
349  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
350  const auto end( B.end(i) );
351  for( auto element=B.begin(i); element!=end; ++element ) {
352  if( isDefault( (~lhs)(i,element->index()) ) )
353  (~lhs)(i,element->index()) = -element->value();
354  else
355  (~lhs)(i,element->index()) -= element->value();
356  }
357  }
358  }
359  }
361  //**********************************************************************************************
362 
363  //**Assignment to row-major sparse matrices*****************************************************
375  template< typename MT > // Type of the target sparse matrix
376  friend inline void assign( SparseMatrix<MT,false>& lhs, const SMatSMatSubExpr& rhs )
377  {
379 
380  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
381  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
382 
383  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
384  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
385 
386  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
387  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
388  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
389  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
390  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
391  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
392 
393  // Final memory allocation (based on the evaluated operands)
394  (~lhs).reserve( A.nonZeros() + B.nonZeros() );
395 
396  // Performing the matrix subtraction
397  for( size_t i=0UL; i<(~lhs).rows(); ++i )
398  {
399  const auto lend( A.end(i) );
400  const auto rend( B.end(i) );
401 
402  auto l( A.begin(i) );
403  auto r( B.begin(i) );
404 
405  while( l != lend && r != rend )
406  {
407  if( l->index() < r->index() ) {
408  (~lhs).append( i, l->index(), l->value() );
409  ++l;
410  }
411  else if( l->index() > r->index() ) {
412  (~lhs).append( i, r->index(), -r->value() );
413  ++r;
414  }
415  else {
416  (~lhs).append( i, l->index(), l->value() - r->value() );
417  ++l;
418  ++r;
419  }
420  }
421 
422  while( l != lend ) {
423  (~lhs).append( i, l->index(), l->value() );
424  ++l;
425  }
426 
427  while( r != rend ) {
428  (~lhs).append( i, r->index(), -r->value() );
429  ++r;
430  }
431 
432  (~lhs).finalize( i );
433  }
434  }
436  //**********************************************************************************************
437 
438  //**Assignment to column-major sparse matrices**************************************************
450  template< typename MT > // Type of the target sparse matrix
451  friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatSMatSubExpr& rhs )
452  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
453  {
455 
457 
458  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
459  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
460 
461  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
462  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
463 
464  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
465  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
466  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
467  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
468  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
469  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
470 
471  const size_t m( rhs.rows() );
472  const size_t n( rhs.columns() );
473 
474  // Counting the number of elements per column
475  std::vector<size_t> nonzeros( n, 0UL );
476  for( size_t i=0UL; i<m; ++i )
477  {
478  const auto lend( A.end(i) );
479  const auto rend( B.end(i) );
480 
481  auto l( A.begin(i) );
482  auto r( B.begin(i) );
483 
484  while( l != lend && r != rend )
485  {
486  if( l->index() < r->index() ) {
487  ++nonzeros[l->index()];
488  ++l;
489  }
490  else if( l->index() > r->index() ) {
491  ++nonzeros[r->index()];
492  ++r;
493  }
494  else {
495  ++nonzeros[l->index()];
496  ++l;
497  ++r;
498  }
499  }
500 
501  while( l != lend ) {
502  ++nonzeros[l->index()];
503  ++l;
504  }
505 
506  while( r != rend ) {
507  ++nonzeros[r->index()];
508  ++r;
509  }
510  }
511 
512  // Resizing the left-hand side sparse matrix
513  for( size_t j=0UL; j<n; ++j ) {
514  (~lhs).reserve( j, nonzeros[j] );
515  }
516 
517  // Performing the matrix subtraction
518  for( size_t i=0UL; i<m; ++i )
519  {
520  const auto lend( A.end(i) );
521  const auto rend( B.end(i) );
522 
523  auto l( A.begin(i) );
524  auto r( B.begin(i) );
525 
526  while( l != lend && r != rend )
527  {
528  if( l->index() < r->index() ) {
529  (~lhs).append( i, l->index(), l->value() );
530  ++l;
531  }
532  else if( l->index() > r->index() ) {
533  (~lhs).append( i, r->index(), -r->value() );
534  ++r;
535  }
536  else {
537  (~lhs).append( i, l->index(), l->value() - r->value() );
538  ++l;
539  ++r;
540  }
541  }
542 
543  while( l != lend ) {
544  (~lhs).append( i, l->index(), l->value() );
545  ++l;
546  }
547 
548  while( r != rend ) {
549  (~lhs).append( i, r->index(), -r->value() );
550  ++r;
551  }
552  }
553  }
555  //**********************************************************************************************
556 
557  //**Assignment to column-major sparse matrices**************************************************
569  template< typename MT > // Type of the target sparse matrix
570  friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatSMatSubExpr& rhs )
571  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
572  {
574 
576 
577  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
578  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
579 
580  assign( ~lhs, trans( rhs.lhs_ ) - trans( rhs.rhs_ ) );
581  }
583  //**********************************************************************************************
584 
585  //**Addition assignment to dense matrices*******************************************************
597  template< typename MT // Type of the target dense matrix
598  , bool SO > // Storage order of the target dense matrix
599  friend inline void addAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
600  {
602 
603  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
604  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
605 
606  addAssign( ~lhs, rhs.lhs_ );
607  subAssign( ~lhs, rhs.rhs_ );
608  }
610  //**********************************************************************************************
611 
612  //**Addition assignment to sparse matrices******************************************************
613  // No special implementation for the addition assignment to sparse matrices.
614  //**********************************************************************************************
615 
616  //**Subtraction assignment to dense matrices****************************************************
628  template< typename MT // Type of the target dense matrix
629  , bool SO > // Storage order of the target dense matrix
630  friend inline void subAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
631  {
633 
634  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
635  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
636 
637  subAssign( ~lhs, rhs.lhs_ );
638  addAssign( ~lhs, rhs.rhs_ );
639  }
641  //**********************************************************************************************
642 
643  //**Subtraction assignment to sparse matrices***************************************************
644  // No special implementation for the subtraction assignment to sparse matrices.
645  //**********************************************************************************************
646 
647  //**Schur product assignment to dense matrices**************************************************
660  template< typename MT // Type of the target dense matrix
661  , bool SO > // Storage order of the target dense matrix
662  friend inline void schurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
663  {
665 
669 
670  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
671  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
672 
673  const ResultType tmp( serial( rhs ) );
674  schurAssign( ~lhs, tmp );
675  }
677  //**********************************************************************************************
678 
679  //**Schur product assignment to sparse matrices*************************************************
680  // No special implementation for the Schur product assignment to sparse matrices.
681  //**********************************************************************************************
682 
683  //**Multiplication assignment to dense matrices*************************************************
684  // No special implementation for the multiplication assignment to dense matrices.
685  //**********************************************************************************************
686 
687  //**Multiplication assignment to sparse matrices************************************************
688  // No special implementation for the multiplication assignment to sparse matrices.
689  //**********************************************************************************************
690 
691  //**SMP assignment to dense matrices************************************************************
692  // No special implementation for the SMP assignment to dense matrices.
693  //**********************************************************************************************
694 
695  //**SMP assignment to sparse matrices***********************************************************
696  // No special implementation for the SMP assignment to sparse matrices.
697  //**********************************************************************************************
698 
699  //**SMP addition assignment to dense matrices***************************************************
713  template< typename MT // Type of the target dense matrix
714  , bool SO > // Storage order of the target dense matrix
715  friend inline auto smpAddAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
716  -> EnableIf_t< UseSMPAssign_v<MT> >
717  {
719 
720  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
721  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
722 
723  smpAddAssign( ~lhs, rhs.lhs_ );
724  smpSubAssign( ~lhs, rhs.rhs_ );
725  }
727  //**********************************************************************************************
728 
729  //**SMP addition assignment to sparse matrices**************************************************
730  // No special implementation for the SMP addition assignment to sparse matrices.
731  //**********************************************************************************************
732 
733  //**SMP subtraction assignment to dense matrices************************************************
748  template< typename MT // Type of the target dense matrix
749  , bool SO > // Storage order of the target dense matrix
750  friend inline auto smpSubAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
751  -> EnableIf_t< UseSMPAssign_v<MT> >
752  {
754 
755  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
756  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
757 
758  smpSubAssign( ~lhs, rhs.lhs_ );
759  smpAddAssign( ~lhs, rhs.rhs_ );
760  }
762  //**********************************************************************************************
763 
764  //**SMP subtraction assignment to sparse matrices***********************************************
765  // No special implementation for the SMP subtraction assignment to sparse matrices.
766  //**********************************************************************************************
767 
768  //**SMP Schur product assignment to dense matrices**********************************************
783  template< typename MT // Type of the target dense matrix
784  , bool SO > // Storage order of the target dense matrix
785  friend inline auto smpSchurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSubExpr& rhs )
786  -> EnableIf_t< UseSMPAssign_v<MT> >
787  {
789 
793 
794  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
795  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
796 
797  const ResultType tmp( rhs );
798  smpSchurAssign( ~lhs, tmp );
799  }
801  //**********************************************************************************************
802 
803  //**SMP Schur product assignment to sparse matrices*********************************************
804  // No special implementation for the SMP Schur product assignment to sparse matrices.
805  //**********************************************************************************************
806 
807  //**SMP multiplication assignment to dense matrices*********************************************
808  // No special implementation for the SMP multiplication assignment to dense matrices.
809  //**********************************************************************************************
810 
811  //**SMP multiplication assignment to sparse matrices********************************************
812  // No special implementation for the SMP multiplication assignment to sparse matrices.
813  //**********************************************************************************************
814 
815  //**Compile time checks*************************************************************************
823  //**********************************************************************************************
824 };
825 //*************************************************************************************************
826 
827 
828 
829 
830 //=================================================================================================
831 //
832 // GLOBAL BINARY ARITHMETIC OPERATORS
833 //
834 //=================================================================================================
835 
836 //*************************************************************************************************
848 template< typename MT1 // Type of the left-hand side sparse matrix
849  , typename MT2 // Type of the right-hand side sparse matrix
850  , DisableIf_t< ( ( IsZero_v<MT1> || IsZero_v<MT2> ) &&
851  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
852  ( IsZero_v<MT1> && IsZero_v<MT2> ) >* = nullptr >
853 inline const SMatSMatSubExpr<MT1,MT2>
854  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
855 {
857 
858  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
859  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
860 
861  return SMatSMatSubExpr<MT1,MT2>( ~lhs, ~rhs );
862 }
864 //*************************************************************************************************
865 
866 
867 //*************************************************************************************************
881 template< typename MT1 // Type of the left-hand side sparse matrix
882  , typename MT2 // Type of the right-hand side sparse matrix
883  , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
884  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
885 inline const MT1&
886  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
887 {
889 
890  UNUSED_PARAMETER( rhs );
891 
892  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
893  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
894 
895  return (~lhs);
896 }
898 //*************************************************************************************************
899 
900 
901 //*************************************************************************************************
915 template< typename MT1 // Type of the left-hand side sparse matrix
916  , typename MT2 // Type of the right-hand side sparse matrix
917  , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
918  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
919 inline decltype(auto)
920  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
921 {
923 
924  UNUSED_PARAMETER( lhs );
925 
926  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
927  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
928 
929  return -(~rhs);
930 }
932 //*************************************************************************************************
933 
934 
935 //*************************************************************************************************
947 template< 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 >
950 inline decltype(auto)
951  smatsmatsub( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
952 {
954 
955  UNUSED_PARAMETER( 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 //*************************************************************************************************
997 template< typename MT1 // Type of the left-hand side sparse matrix
998  , typename MT2 > // Type of the right-hand side sparse matrix
999 inline decltype(auto)
1000  operator-( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
1001 {
1003 
1004  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() ) {
1005  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1006  }
1007 
1008  return smatsmatsub( ~lhs, ~rhs );
1009 }
1010 //*************************************************************************************************
1011 
1012 } // namespace blaze
1013 
1014 #endif
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatSMatSubExpr.h:228
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:106
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatSMatSubExpr.h:172
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 UNUSED_PARAMETER function template.
Header file for the subtraction trait.
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatSubExpr.h:154
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.
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatSubExpr.h:303
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatSMatSubExpr.h:238
Constraint on the data type.
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatSMatSubExpr.h:119
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatSubExpr.h:161
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:259
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatSubExpr.h:153
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
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:80
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:137
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 IsVoid type trait.
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatSubExpr.h:212
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the IsSymmetric type trait.
constexpr bool IsResizable_v
Auxiliary variable template for the IsResizable type trait.The IsResizable_v variable template provid...
Definition: IsResizable.h:134
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatSMatSubExpr.h:155
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:291
#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:164
Header file for the MatMatSubExpr base class.
ReturnType_t< MT1 > RN1
ReturnType type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:103
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:102
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:310
Constraint on the data type.
Header file for all forward declarations for expression class templates.
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:167
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
#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:127
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:311
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:101
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatSubExpr.h:279
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 the isDefault shim.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatSubExpr.h:197
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:116
#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:104
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatSubExpr.h:269
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
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:152
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:248
SMatSMatSubExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatSMatSubExpr class.
Definition: SMatSMatSubExpr.h:181
Header file for the IntegralConstant class template.
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSubExpr.h:105
#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:631
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:161
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:61
Header file for the IsExpression type trait class.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatSMatSubExpr.h:158
Header file for the function trace functionality.