TSMatTSMatAddExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATTSMATADDEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATTSMATADDEXPR_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 TSMATTSMATADDEXPR
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 TSMatTSMatAddExpr
96  : public MatMatAddExpr< SparseMatrix< TSMatTSMatAddExpr<MT1,MT2>, true > >
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< IsRowMajorMatrix_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 TSMatTSMatAddExpr( const MT1& lhs, const MT2& rhs ) noexcept
182  : lhs_( lhs ) // Left-hand side sparse matrix of the addition expression
183  , rhs_( rhs ) // Right-hand side sparse matrix of the addition 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****************************************************************
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 TSMatTSMatAddExpr& 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 
338  if( !IsResizable_v< ElementType_t<MT> > ) {
339  addAssign( ~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 TSMatTSMatAddExpr& rhs )
380  {
382 
384 
385  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
386  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
387 
388  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
389  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
390 
391  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
392  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
393  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
394  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
395  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
396  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
397 
398  const size_t m( rhs.rows() );
399  const size_t n( rhs.columns() );
400 
401  // Counting the number of elements per column
402  std::vector<size_t> nonzeros( m, 0UL );
403  for( size_t j=0UL; j<n; ++j )
404  {
405  const auto lend( A.end(j) );
406  const auto rend( B.end(j) );
407 
408  auto l( A.begin(j) );
409  auto r( B.begin(j) );
410 
411  while( l != lend && r != rend )
412  {
413  if( l->index() < r->index() ) {
414  ++nonzeros[l->index()];
415  ++l;
416  }
417  else if( l->index() > r->index() ) {
418  ++nonzeros[r->index()];
419  ++r;
420  }
421  else {
422  ++nonzeros[l->index()];
423  ++l;
424  ++r;
425  }
426  }
427 
428  while( l != lend ) {
429  ++nonzeros[l->index()];
430  ++l;
431  }
432 
433  while( r != rend ) {
434  ++nonzeros[r->index()];
435  ++r;
436  }
437  }
438 
439  // Resizing the left-hand side sparse matrix
440  for( size_t i=0UL; i<m; ++i ) {
441  (~lhs).reserve( i, nonzeros[i] );
442  }
443 
444  // Performing the matrix addition
445  for( size_t j=0UL; j<n; ++j )
446  {
447  const auto lend( A.end(j) );
448  const auto rend( B.end(j) );
449 
450  auto l( A.begin(j) );
451  auto r( B.begin(j) );
452 
453  while( l != lend && r != rend )
454  {
455  if( l->index() < r->index() ) {
456  (~lhs).append( l->index(), j, l->value() );
457  ++l;
458  }
459  else if( l->index() > r->index() ) {
460  (~lhs).append( r->index(), j, r->value() );
461  ++r;
462  }
463  else {
464  (~lhs).append( l->index(), j, l->value() + r->value() );
465  ++l;
466  ++r;
467  }
468  }
469 
470  while( l != lend ) {
471  (~lhs).append( l->index(), j, l->value() );
472  ++l;
473  }
474 
475  while( r != rend ) {
476  (~lhs).append( r->index(), j, r->value() );
477  ++r;
478  }
479  }
480  }
482  //**********************************************************************************************
483 
484  //**Assignment to row-major sparse matrices*****************************************************
497  template< typename MT > // Type of the target sparse matrix
498  friend inline auto assign( SparseMatrix<MT,false>& lhs, const TSMatTSMatAddExpr& rhs )
499  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
500  {
502 
504 
505  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
506  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
507 
508  assign( ~lhs, trans( rhs.lhs_ ) + trans( rhs.rhs_ ) );
509  }
511  //**********************************************************************************************
512 
513  //**Assignment to column-major sparse matrices**************************************************
526  template< typename MT > // Type of the target sparse matrix
527  friend inline void assign( SparseMatrix<MT,true>& lhs, const TSMatTSMatAddExpr& rhs )
528  {
530 
531  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
532  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
533 
534  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
535  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
536 
537  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
538  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
539  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
540  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
541  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
542  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
543 
544  // Final memory allocation (based on the evaluated operands)
545  (~lhs).reserve( A.nonZeros() + B.nonZeros() );
546 
547  // Performing the matrix addition
548  for( size_t j=0UL; j<(~lhs).columns(); ++j )
549  {
550  const auto lend( A.end(j) );
551  const auto rend( B.end(j) );
552 
553  auto l( A.begin(j) );
554  auto r( B.begin(j) );
555 
556  while( l != lend && r != rend )
557  {
558  if( l->index() < r->index() ) {
559  (~lhs).append( l->index(), j, l->value() );
560  ++l;
561  }
562  else if( l->index() > r->index() ) {
563  (~lhs).append( r->index(), j, r->value() );
564  ++r;
565  }
566  else {
567  (~lhs).append( l->index(), j, l->value() + r->value() );
568  ++l;
569  ++r;
570  }
571  }
572 
573  while( l != lend ) {
574  (~lhs).append( l->index(), j, l->value() );
575  ++l;
576  }
577 
578  while( r != rend ) {
579  (~lhs).append( r->index(), j, r->value() );
580  ++r;
581  }
582 
583  (~lhs).finalize( j );
584  }
585  }
587  //**********************************************************************************************
588 
589  //**Addition assignment to dense matrices*******************************************************
602  template< typename MT // Type of the target dense matrix
603  , bool SO > // Storage order of the target dense matrix
604  friend inline void addAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatAddExpr& rhs )
605  {
607 
608  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
609  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
610 
611  addAssign( ~lhs, rhs.lhs_ );
612  addAssign( ~lhs, rhs.rhs_ );
613  }
615  //**********************************************************************************************
616 
617  //**Addition assignment to sparse matrices******************************************************
618  // No special implementation for the addition assignment to sparse matrices.
619  //**********************************************************************************************
620 
621  //**Subtraction assignment to dense matrices****************************************************
634  template< typename MT // Type of the target dense matrix
635  , bool SO > // Storage order of the target dense matrix
636  friend inline void subAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatAddExpr& rhs )
637  {
639 
640  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
641  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
642 
643  subAssign( ~lhs, rhs.lhs_ );
644  subAssign( ~lhs, rhs.rhs_ );
645  }
647  //**********************************************************************************************
648 
649  //**Subtraction assignment to sparse matrices***************************************************
650  // No special implementation for the subtraction assignment to sparse matrices.
651  //**********************************************************************************************
652 
653  //**Schur product assignment to dense matrices**************************************************
666  template< typename MT // Type of the target dense matrix
667  , bool SO > // Storage order of the target dense matrix
668  friend inline void schurAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatAddExpr& rhs )
669  {
671 
675 
676  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
677  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
678 
679  const ResultType tmp( serial( rhs ) );
680  schurAssign( ~lhs, tmp );
681  }
683  //**********************************************************************************************
684 
685  //**Schur product assignment to sparse matrices*************************************************
686  // No special implementation for the Schur product assignment to sparse matrices.
687  //**********************************************************************************************
688 
689  //**Multiplication assignment to dense matrices*************************************************
690  // No special implementation for the multiplication assignment to dense matrices.
691  //**********************************************************************************************
692 
693  //**Multiplication assignment to sparse matrices************************************************
694  // No special implementation for the multiplication assignment to sparse matrices.
695  //**********************************************************************************************
696 
697  //**SMP assignment to dense matrices************************************************************
698  // No special implementation for the SMP assignment to dense matrices.
699  //**********************************************************************************************
700 
701  //**SMP assignment to sparse matrices***********************************************************
702  // No special implementation for the SMP assignment to sparse matrices.
703  //**********************************************************************************************
704 
705  //**SMP addition assignment to dense matrices***************************************************
720  template< typename MT // Type of the target dense matrix
721  , bool SO > // Storage order of the target dense matrix
722  friend inline auto smpAddAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatAddExpr& rhs )
723  -> EnableIf_t< UseSMPAssign_v<MT> >
724  {
726 
727  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
728  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
729 
730  smpAddAssign( ~lhs, rhs.lhs_ );
731  smpAddAssign( ~lhs, rhs.rhs_ );
732  }
734  //**********************************************************************************************
735 
736  //**SMP addition assignment to sparse matrices**************************************************
737  // No special implementation for the SMP addition assignment to sparse matrices.
738  //**********************************************************************************************
739 
740  //**SMP subtraction assignment to dense matrices************************************************
755  template< typename MT // Type of the target dense matrix
756  , bool SO > // Storage order of the target dense matrix
757  friend inline auto smpSubAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatAddExpr& rhs )
758  -> EnableIf_t< UseSMPAssign_v<MT> >
759  {
761 
762  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
763  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
764 
765  smpSubAssign( ~lhs, rhs.lhs_ );
766  smpSubAssign( ~lhs, rhs.rhs_ );
767  }
769  //**********************************************************************************************
770 
771  //**SMP subtraction assignment to sparse matrices***********************************************
772  // No special implementation for the SMP subtraction assignment to sparse matrices.
773  //**********************************************************************************************
774 
775  //**SMP Schur product assignment to dense matrices**********************************************
791  template< typename MT // Type of the target dense matrix
792  , bool SO > // Storage order of the target dense matrix
793  friend inline auto smpSchurAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatAddExpr& rhs )
794  -> EnableIf_t< UseSMPAssign_v<MT> >
795  {
797 
801 
802  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
803  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
804 
805  const ResultType tmp( rhs );
806  smpSchurAssign( ~lhs, tmp );
807  }
809  //**********************************************************************************************
810 
811  //**SMP Schur product assignment to sparse matrices*********************************************
812  // No special implementation for the SMP Schur product assignment to sparse matrices.
813  //**********************************************************************************************
814 
815  //**SMP multiplication assignment to dense matrices*********************************************
816  // No special implementation for the SMP multiplication assignment to dense matrices.
817  //**********************************************************************************************
818 
819  //**SMP multiplication assignment to sparse matrices********************************************
820  // No special implementation for the SMP multiplication assignment to sparse matrices.
821  //**********************************************************************************************
822 
823  //**Compile time checks*************************************************************************
831  //**********************************************************************************************
832 };
833 //*************************************************************************************************
834 
835 
836 
837 
838 //=================================================================================================
839 //
840 // GLOBAL BINARY ARITHMETIC OPERATORS
841 //
842 //=================================================================================================
843 
844 //*************************************************************************************************
856 template< typename MT1 // Type of the left-hand side sparse matrix
857  , typename MT2 // Type of the right-hand side sparse matrix
858  , DisableIf_t< ( ( IsZero_v<MT1> || IsZero_v<MT2> ) &&
859  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
860  ( IsZero_v<MT1> && IsZero_v<MT2> ) >* = nullptr >
861 inline const TSMatTSMatAddExpr<MT1,MT2>
862  tsmattsmatadd( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
863 {
865 
866  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
867  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
868 
869  return TSMatTSMatAddExpr<MT1,MT2>( ~lhs, ~rhs );
870 }
872 //*************************************************************************************************
873 
874 
875 //*************************************************************************************************
889 template< typename MT1 // Type of the left-hand side sparse matrix
890  , typename MT2 // Type of the right-hand side sparse matrix
891  , EnableIf_t< !IsZero_v<MT1> && IsZero_v<MT2> &&
892  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
893 inline const MT1&
894  tsmattsmatadd( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
895 {
897 
898  UNUSED_PARAMETER( rhs );
899 
900  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
901  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
902 
903  return (~lhs);
904 }
906 //*************************************************************************************************
907 
908 
909 //*************************************************************************************************
923 template< typename MT1 // Type of the left-hand side sparse matrix
924  , typename MT2 // Type of the right-hand side sparse matrix
925  , EnableIf_t< IsZero_v<MT1> && !IsZero_v<MT2> &&
926  IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
927 inline const MT2&
928  tsmattsmatadd( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
929 {
931 
932  UNUSED_PARAMETER( lhs );
933 
934  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
935  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
936 
937  return (~rhs);
938 }
940 //*************************************************************************************************
941 
942 
943 //*************************************************************************************************
955 template< typename MT1 // Type of the left-hand side sparse matrix
956  , typename MT2 // Type of the right-hand side sparse matrix
957  , EnableIf_t< IsZero_v<MT1> && IsZero_v<MT2> >* = nullptr >
958 inline decltype(auto)
959  tsmattsmatadd( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
960 {
962 
963  UNUSED_PARAMETER( rhs );
964 
965  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
966  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
967 
968  using ReturnType = const AddTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
969 
972 
973  return ReturnType( (~lhs).rows(), (~lhs).columns() );
974 }
976 //*************************************************************************************************
977 
978 
979 //*************************************************************************************************
1005 template< typename MT1 // Type of the left-hand side sparse matrix
1006  , typename MT2 > // Type of the right-hand side sparse matrix
1007 inline decltype(auto)
1008  operator+( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
1009 {
1011 
1012  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() ) {
1013  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1014  }
1015 
1016  return tsmattsmatadd( ~lhs, ~rhs );
1017 }
1018 //*************************************************************************************************
1019 
1020 } // namespace blaze
1021 
1022 #endif
#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
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatTSMatAddExpr.h:158
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:103
Header file for auxiliary alias declarations.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatTSMatAddExpr.h:153
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatTSMatAddExpr.h:259
Header file for the UNUSED_PARAMETER function template.
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: TSMatTSMatAddExpr.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.
LeftOperand lhs_
Left-hand side sparse matrix of the addition expression.
Definition: TSMatTSMatAddExpr.h:310
Header file for the IsSame and IsStrictlySame type traits.
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Constraint on the data type.
Header file for the Computation base class.
decltype(std::declval< RN1 >()+std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatTSMatAddExpr.h:119
If_t< IsExpression_v< MT2 >, const MT2, const MT2 &> RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:167
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
TSMatTSMatAddExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatTSMatAddExpr class.
Definition: TSMatTSMatAddExpr.h:181
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.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatTSMatAddExpr.h:248
Header file for the SparseMatrix base class.
Constraint on the data type.
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatTSMatAddExpr.h:161
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
If_t< IsExpression_v< MT1 >, const MT1, const MT1 &> LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:164
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
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatTSMatAddExpr.h:291
Header file for the If class template.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatTSMatAddExpr.h:238
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:61
Expression object for transpose sparse matrix-transpose sparse matrix additions.The TSMatTSMatAddExpr...
Definition: Forward.h:178
AddTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatTSMatAddExpr.h:152
#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
RightOperand rhs_
Right-hand side sparse matrix of the addition expression.
Definition: TSMatTSMatAddExpr.h:311
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatTSMatAddExpr.h:116
#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
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatTSMatAddExpr.h:303
typename AddTrait< T1, T2 >::Type AddTrait_t
Auxiliary alias declaration for the AddTrait class template.The AddTrait_t alias declaration provides...
Definition: AddTrait.h:238
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatTSMatAddExpr.h:155
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
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATADDEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: MatMatAddExpr.h:103
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
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:105
#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
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
Header file for the addition trait.
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
Constraint on the data type.
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatTSMatAddExpr.h:228
Header file for the IsZero type trait.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatTSMatAddExpr.h:172
#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.
Constraint on the data type.
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the MatMatAddExpr base class.
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
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
Header file for the IsRowMajorMatrix type trait.
Header file for the IsComputation type trait class.
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:104
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatTSMatAddExpr.h:197
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
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:101
Header file for the IntegralConstant class template.
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:102
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatTSMatAddExpr.h:212
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:631
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: TSMatTSMatAddExpr.h:279
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
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatAddExpr.h:106
LeftOperand leftOperand() const noexcept
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatTSMatAddExpr.h:269
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.
Header file for the function trace functionality.