Blaze 3.9
SMatSMatAddExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATADDEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATSMATADDEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <utility>
44#include <blaze/math/Aliases.h>
65#include <blaze/util/Assert.h>
66#include <blaze/util/EnableIf.h>
70#include <blaze/util/mpl/If.h>
71#include <blaze/util/Types.h>
73
74
75namespace blaze {
76
77//=================================================================================================
78//
79// CLASS SMATSMATADDEXPR
80//
81//=================================================================================================
82
83//*************************************************************************************************
90template< typename MT1 // Type of the left-hand side sparse matrix
91 , typename MT2 > // Type of the right-hand side sparse matrix
93 : public MatMatAddExpr< SparseMatrix< SMatSMatAddExpr<MT1,MT2>, false > >
94 , private Computation
95{
96 private:
97 //**Type definitions****************************************************************************
104 //**********************************************************************************************
105
106 //**Return type evaluation**********************************************************************
108
113 static constexpr bool returnExpr = !IsTemporary_v<RN1> && !IsTemporary_v<RN2>;
114
116 using ExprReturnType = decltype( std::declval<RN1>() + std::declval<RN2>() );
117 //**********************************************************************************************
118
119 //**Serial evaluation strategy******************************************************************
121
126 template< typename T1, typename T2, typename T3 >
127 static constexpr bool UseSymmetricKernel_v =
128 ( IsColumnMajorMatrix_v<T1> && IsSymmetric_v<T2> && IsSymmetric_v<T3> );
130 //**********************************************************************************************
131
132 //**Parallel evaluation strategy****************************************************************
134
139 template< typename MT >
140 static constexpr bool UseSMPAssign_v = MT::smpAssignable;
142 //**********************************************************************************************
143
144 public:
145 //**Type definitions****************************************************************************
148
151
156
159
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 inline SMatSMatAddExpr( 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****************************************************************
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 SMatSMatAddExpr& 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
338 addAssign( *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 SMatSMatAddExpr& 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 addition
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 SMatSMatAddExpr& 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( A.rows() );
472 const size_t n( A.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 addition
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 SMatSMatAddExpr& 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 SMatSMatAddExpr& 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 addAssign( *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 SMatSMatAddExpr& 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 subAssign( *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**************************************************
659 template< typename MT // Type of the target dense matrix
660 , bool SO > // Storage order of the target dense matrix
661 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatAddExpr& rhs )
662 {
664
668
669 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
670 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
671
672 const ResultType tmp( serial( rhs ) );
673 schurAssign( *lhs, tmp );
674 }
676 //**********************************************************************************************
677
678 //**Schur product assignment to sparse matrices******************************************************
679 // No special implementation for the Schur product assignment to sparse matrices.
680 //**********************************************************************************************
681
682 //**Multiplication assignment to dense matrices*************************************************
683 // No special implementation for the multiplication assignment to dense matrices.
684 //**********************************************************************************************
685
686 //**Multiplication assignment to sparse matrices************************************************
687 // No special implementation for the multiplication assignment to sparse matrices.
688 //**********************************************************************************************
689
690 //**SMP assignment to dense matrices************************************************************
691 // No special implementation for the SMP assignment to dense matrices.
692 //**********************************************************************************************
693
694 //**SMP assignment to sparse matrices***********************************************************
695 // No special implementation for the SMP assignment to sparse matrices.
696 //**********************************************************************************************
697
698 //**SMP addition assignment to dense matrices***************************************************
712 template< typename MT // Type of the target dense matrix
713 , bool SO > // Storage order of the target dense matrix
714 friend inline auto smpAddAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatAddExpr& rhs )
715 -> EnableIf_t< UseSMPAssign_v<MT> >
716 {
718
719 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
720 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
721
722 smpAddAssign( *lhs, rhs.lhs_ );
723 smpAddAssign( *lhs, rhs.rhs_ );
724 }
726 //**********************************************************************************************
727
728 //**SMP addition assignment to sparse matrices**************************************************
729 // No special implementation for the SMP addition assignment to sparse matrices.
730 //**********************************************************************************************
731
732 //**SMP subtraction assignment to dense matrices************************************************
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 SMatSMatAddExpr& 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 smpSubAssign( *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 SMatSMatAddExpr& 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//*************************************************************************************************
846template< 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 >
851inline const SMatSMatAddExpr<MT1,MT2>
852 smatsmatadd( 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 SMatSMatAddExpr<MT1,MT2>( *lhs, *rhs );
860}
862//*************************************************************************************************
863
864
865//*************************************************************************************************
879template< 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 >
883inline const MT1&
884 smatsmatadd( 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//*************************************************************************************************
913template< 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 >
917inline const MT2&
918 smatsmatadd( 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//*************************************************************************************************
945template< 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 >
948inline decltype(auto)
949 smatsmatadd( 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 AddTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
959
962
963 return ReturnType( (*lhs).rows(), (*lhs).columns() );
964}
966//*************************************************************************************************
967
968
969//*************************************************************************************************
995template< typename MT1 // Type of the left-hand side sparse matrix
996 , typename MT2 > // Type of the right-hand side sparse matrix
997inline 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 smatsmatadd( *lhs, *rhs );
1007}
1008//*************************************************************************************************
1009
1010} // namespace blaze
1011
1012#endif
Header file for the addition trait.
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsColumnMajorMatrix type trait.
Header file for the isDefault shim.
Header file for the IsExpression type trait class.
Header file for the IsResizable type trait.
Header file for the IsSame and IsStrictlySame type traits.
Header file for the IsSymmetric type trait.
Header file for the IsTemporary type trait class.
Header file for the MAYBE_UNUSED function template.
Constraints on the storage order of matrix types.
Constraint on the data type.
Constraint on the data type.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Expression object for sparse matrix-sparse matrix additions.
Definition: SMatSMatAddExpr.h:95
RightOperand rhs_
Right-hand side sparse matrix of the addition expression.
Definition: SMatSMatAddExpr.h:311
AddTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatSMatAddExpr.h:152
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatAddExpr.h:154
SMatSMatAddExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatSMatAddExpr class.
Definition: SMatSMatAddExpr.h:181
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatAddExpr.h:291
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatSMatAddExpr.h:172
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatAddExpr.h:269
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatAddExpr.h:248
decltype(std::declval< RN1 >()+std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatSMatAddExpr.h:116
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:98
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatAddExpr.h:153
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:100
LeftOperand lhs_
Left-hand side sparse matrix of the addition expression.
Definition: SMatSMatAddExpr.h:310
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatAddExpr.h:279
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatSMatAddExpr.h:158
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:164
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatSMatAddExpr.h:155
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatSMatAddExpr.h:228
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatAddExpr.h:212
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:103
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatSMatAddExpr.h:238
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatAddExpr.h:259
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatAddExpr.h:303
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatSMatAddExpr.h:113
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:167
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:99
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatAddExpr.h:197
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatAddExpr.h:161
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:102
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatAddExpr.h:101
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the MatMatAddExpr base class.
Header file for the SparseMatrix base class.
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATADDEXPR(T1, T2)
Constraint on the data type.
Definition: MatMatAddExpr.h:103
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
typename AddTrait< T1, T2 >::Type AddTrait_t
Auxiliary alias declaration for the AddTrait class template.
Definition: AddTrait.h:163
constexpr bool IsResizable_v
Auxiliary variable template for the IsResizable type trait.
Definition: IsResizable.h:136
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:584
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
constexpr bool IsSame_v
Auxiliary variable template for the IsSame type trait.
Definition: IsSame.h:159
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix/matrix addition expression templates.
Definition: MatMatAddExpr.h:68
Header file for the IsZero type trait.
Header file for basic type definitions.