Blaze 3.9
SMatDMatSchurExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATDMATSCHUREXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATDMATSCHUREXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <utility>
45#include <blaze/math/Aliases.h>
72#include <blaze/util/Assert.h>
73#include <blaze/util/EnableIf.h>
77#include <blaze/util/mpl/If.h>
78#include <blaze/util/mpl/Max.h>
79#include <blaze/util/Types.h>
81
82
83namespace blaze {
84
85//=================================================================================================
86//
87// CLASS SMATDMATSCHUREXPR
88//
89//=================================================================================================
90
91//*************************************************************************************************
98template< typename MT1 // Type of the left-hand side sparse matrix
99 , typename MT2 > // Type of the right-hand side dense matrix
101 : public SchurExpr< SparseMatrix< SMatDMatSchurExpr<MT1,MT2>, false > >
102 , private Computation
103{
104 private:
105 //**Type definitions****************************************************************************
112 //**********************************************************************************************
113
114 //**Return type evaluation**********************************************************************
116
121 static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
122
124 using ExprReturnType = decltype( std::declval<RN1>() * std::declval<RN2>() );
125 //**********************************************************************************************
126
127 //**Evaluation strategy*************************************************************************
129
135 static constexpr bool useAssign = ( RequiresEvaluation_v<MT1> || RequiresEvaluation_v<MT2> );
136
139 template< typename MT >
140 static constexpr bool UseAssign_v = useAssign;
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 //**ConstIterator class definition**************************************************************
174 {
175 public:
176 //**Type definitions*************************************************************************
179
182
183 using IteratorCategory = std::forward_iterator_tag;
187 using DifferenceType = ptrdiff_t;
188
189 // STL iterator requirements
195 //*******************************************************************************************
196
197 //**Constructor******************************************************************************
204 inline ConstIterator( LeftIterator left, RightOperand right, size_t row )
205 : left_ ( left ) // Iterator over the elements of the left-hand side sparse matrix expression
206 , right_( right ) // Right-hand side dense matrix expression
207 , row_ ( row ) // The row index of the iterator
208 {}
209 //*******************************************************************************************
210
211 //**Prefix increment operator****************************************************************
217 ++left_;
218 return *this;
219 }
220 //*******************************************************************************************
221
222 //**Element access operator******************************************************************
227 inline const Element operator*() const {
228 return Element( left_->value() * right_(row_,left_->index()), left_->index() );
229 }
230 //*******************************************************************************************
231
232 //**Element access operator******************************************************************
237 inline const ConstIterator* operator->() const {
238 return this;
239 }
240 //*******************************************************************************************
241
242 //**Value function***************************************************************************
247 inline ReturnType value() const {
248 return left_->value() * right_(row_,left_->index());
249 }
250 //*******************************************************************************************
251
252 //**Index function***************************************************************************
257 inline size_t index() const {
258 return left_->index();
259 }
260 //*******************************************************************************************
261
262 //**Equality operator************************************************************************
268 inline bool operator==( const ConstIterator& rhs ) const {
269 return left_ == rhs.left_;
270 }
271 //*******************************************************************************************
272
273 //**Inequality operator**********************************************************************
279 inline bool operator!=( const ConstIterator& rhs ) const {
280 return left_ != rhs.left_;
281 }
282 //*******************************************************************************************
283
284 //**Subtraction operator*********************************************************************
290 inline DifferenceType operator-( const ConstIterator& rhs ) const {
291 return left_ - rhs.left_;
292 }
293 //*******************************************************************************************
294
295 private:
296 //**Member variables*************************************************************************
299 size_t row_;
300 //*******************************************************************************************
301 };
302 //**********************************************************************************************
303
304 //**Compilation flags***************************************************************************
306 static constexpr bool smpAssignable = false;
307 //**********************************************************************************************
308
309 //**Constructor*********************************************************************************
315 inline SMatDMatSchurExpr( const MT1& lhs, const MT2& rhs ) noexcept
316 : lhs_( lhs ) // Left-hand side sparse matrix of the Schur product expression
317 , rhs_( rhs ) // Right-hand side dense matrix of the Schur product expression
318 {
319 BLAZE_INTERNAL_ASSERT( lhs.rows() == rhs.rows() , "Invalid number of rows" );
320 BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.columns(), "Invalid number of columns" );
321 }
322 //**********************************************************************************************
323
324 //**Access operator*****************************************************************************
331 inline ReturnType operator()( size_t i, size_t j ) const {
332 BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
333 BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
334 return lhs_(i,j) * rhs_(i,j);
335 }
336 //**********************************************************************************************
337
338 //**At function*********************************************************************************
346 inline ReturnType at( size_t i, size_t j ) const {
347 if( i >= lhs_.rows() ) {
348 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
349 }
350 if( j >= lhs_.columns() ) {
351 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
352 }
353 return (*this)(i,j);
354 }
355 //**********************************************************************************************
356
357 //**Begin function******************************************************************************
363 inline ConstIterator begin( size_t i ) const {
364 return ConstIterator( lhs_.begin(i), rhs_, i );
365 }
366 //**********************************************************************************************
367
368 //**End function********************************************************************************
374 inline ConstIterator end( size_t i ) const {
375 return ConstIterator( lhs_.end(i), rhs_, i );
376 }
377 //**********************************************************************************************
378
379 //**Rows function*******************************************************************************
384 inline size_t rows() const noexcept {
385 return lhs_.rows();
386 }
387 //**********************************************************************************************
388
389 //**Columns function****************************************************************************
394 inline size_t columns() const noexcept {
395 return lhs_.columns();
396 }
397 //**********************************************************************************************
398
399 //**NonZeros function***************************************************************************
404 inline size_t nonZeros() const {
405 return lhs_.nonZeros();
406 }
407 //**********************************************************************************************
408
409 //**NonZeros function***************************************************************************
415 inline size_t nonZeros( size_t i ) const {
416 return lhs_.nonZeros(i);
417 }
418 //**********************************************************************************************
419
420 //**Find function*******************************************************************************
427 inline ConstIterator find( size_t i, size_t j ) const {
429 return ConstIterator( lhs_.find( i, j ), rhs_, i );
430 }
431 //**********************************************************************************************
432
433 //**LowerBound function*************************************************************************
440 inline ConstIterator lowerBound( size_t i, size_t j ) const {
442 return ConstIterator( lhs_.lowerBound( i, j ), rhs_, i );
443 }
444 //**********************************************************************************************
445
446 //**UpperBound function*************************************************************************
453 inline ConstIterator upperBound( size_t i, size_t j ) const {
455 return ConstIterator( lhs_.upperBound( i, j ), rhs_, i );
456 }
457 //**********************************************************************************************
458
459 //**Left operand access*************************************************************************
464 inline LeftOperand leftOperand() const noexcept {
465 return lhs_;
466 }
467 //**********************************************************************************************
468
469 //**Right operand access************************************************************************
474 inline RightOperand rightOperand() const noexcept {
475 return rhs_;
476 }
477 //**********************************************************************************************
478
479 //**********************************************************************************************
485 template< typename T >
486 inline bool canAlias( const T* alias ) const noexcept {
487 return ( lhs_.canAlias( alias ) || rhs_.isAliased( alias ) );
488 }
489 //**********************************************************************************************
490
491 //**********************************************************************************************
497 template< typename T >
498 inline bool isAliased( const T* alias ) const noexcept {
499 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
500 }
501 //**********************************************************************************************
502
503 private:
504 //**Member variables****************************************************************************
507 //**********************************************************************************************
508
509 //**Assignment to dense matrices****************************************************************
521 template< typename MT // Type of the target dense matrix
522 , bool SO2 > // Storage order of the target dense matrix
523 friend inline auto assign( DenseMatrix<MT,SO2>& lhs, const SMatDMatSchurExpr& rhs )
525 {
527
528 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
529 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
530
531 CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
532 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
533
534 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
535 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
536 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
537 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
538 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
539 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
540
541 for( size_t i=0UL; i<(*lhs).rows(); ++i ) {
542 for( auto element=A.begin(i); element!=A.end(i); ++element )
543 (*lhs)(i,element->index()) = element->value() * B(i,element->index());
544 }
545 }
547 //**********************************************************************************************
548
549 //**Assignment to row-major sparse matrices*****************************************************
561 template< typename MT > // Type of the target sparse matrix
562 friend inline auto assign( SparseMatrix<MT,false>& lhs, const SMatDMatSchurExpr& rhs )
564 {
566
567 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
568 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
569
570 CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
571 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
572
573 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
574 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
575 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
576 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
577 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
578 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
579
580 // Final memory allocation (based on the evaluated operands)
581 (*lhs).reserve( A.nonZeros() );
582
583 // Performing the Schur product
584 for( size_t i=0UL; i<(*lhs).rows(); ++i ) {
585 for( auto element=A.begin(i); element!=A.end(i); ++element )
586 (*lhs).append( i, element->index(), element->value() * B(i,element->index()) );
587 (*lhs).finalize( i );
588 }
589 }
591 //**********************************************************************************************
592
593 //**Assignment to column-major sparse matrices**************************************************
606 template< typename MT > // Type of the target sparse matrix
607 friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatDMatSchurExpr& rhs )
608 -> EnableIf_t< UseAssign_v<MT> >
609 {
611
612 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
613 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
614
615 CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
616 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
617
618 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
619 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
620 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
621 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
622 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
623 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
624
625 const size_t m( rhs.rows() );
626 const size_t n( rhs.columns() );
627
628 // Counting the number of elements per column
629 std::vector<size_t> nonzeros( n, 0UL );
630 for( size_t i=0UL; i<m; ++i ) {
631 const auto lend( A.end(i) );
632 for( auto l=A.begin(i); l!=lend; ++l ) {
633 ++nonzeros[l->index()];
634 }
635 }
636
637 // Resizing the left-hand side sparse matrix
638 for( size_t j=0UL; j<n; ++j ) {
639 (*lhs).reserve( j, nonzeros[j] );
640 }
641
642 // Performing the Schur product
643 for( size_t i=0UL; i<m; ++i ) {
644 for( auto element=A.begin(i); element!=A.end(i); ++element )
645 (*lhs).append( i, element->index(), element->value() * B(i,element->index()) );
646 }
647 }
649 //**********************************************************************************************
650
651 //**Addition assignment to dense matrices*******************************************************
663 template< typename MT // Type of the target dense matrix
664 , bool SO2 > // Storage order of the target dense matrix
665 friend inline auto addAssign( DenseMatrix<MT,SO2>& lhs, const SMatDMatSchurExpr& rhs )
666 -> EnableIf_t< UseAssign_v<MT> >
667 {
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 CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
674 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
675
676 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
677 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
678 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
679 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
680 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
681 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
682
683 for( size_t i=0UL; i<(*lhs).rows(); ++i ) {
684 for( auto element=A.begin(i); element!=A.end(i); ++element )
685 (*lhs)(i,element->index()) += element->value() * B(i,element->index());
686 }
687 }
689 //**********************************************************************************************
690
691 //**Addition assignment to sparse matrices******************************************************
692 // No special implementation for the addition assignment to sparse matrices.
693 //**********************************************************************************************
694
695 //**Subtraction assignment to dense matrices****************************************************
707 template< typename MT // Type of the target dense matrix
708 , bool SO2 > // Storage order of the target dense matrix
709 friend inline auto subAssign( DenseMatrix<MT,SO2>& lhs, const SMatDMatSchurExpr& rhs )
710 -> EnableIf_t< UseAssign_v<MT> >
711 {
713
714 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
715 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
716
717 CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
718 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
719
720 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
721 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
722 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
723 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
724 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
725 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
726
727 for( size_t i=0UL; i<(*lhs).rows(); ++i ) {
728 for( auto element=A.begin(i); element!=A.end(i); ++element )
729 (*lhs)(i,element->index()) -= element->value() * B(i,element->index());
730 }
731 }
733 //**********************************************************************************************
734
735 //**Subtraction assignment to sparse matrices***************************************************
736 // No special implementation for the subtraction assignment to sparse matrices.
737 //**********************************************************************************************
738
739 //**Schur product assignment to dense matrices**************************************************
752 template< typename MT // Type of the target dense matrix
753 , bool SO2 > // Storage order of the target dense matrix
754 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs, const SMatDMatSchurExpr& rhs )
755 {
757
758 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
759 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
760
761 CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
762 CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
763
764 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
765 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
766 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
767 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
768 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
769 BLAZE_INTERNAL_ASSERT( A.columns() == (*lhs).columns() , "Invalid number of columns" );
770
771 for( size_t i=0UL; i<(*lhs).rows(); ++i )
772 {
773 const auto end( A.end(i) );
774 auto begin( A.begin(i) );
775 size_t j( 0UL );
776
777 for( ; begin!=end; ++begin ) {
778 const size_t index( begin->index() );
779 for( ; j<index; ++j )
780 reset( (*lhs)(i,j) );
781 (*lhs)(i,index) *= begin->value() * B(i,index);
782 ++j;
783 }
784
785 for( ; j<(*lhs).columns(); ++j )
786 reset( (*lhs)(i,j) );
787 }
788 }
790 //**********************************************************************************************
791
792 //**Schur product assignment to sparse matrices*************************************************
793 // No special implementation for the Schur product assignment to sparse matrices.
794 //**********************************************************************************************
795
796 //**Multiplication assignment to dense matrices*************************************************
797 // No special implementation for the multiplication assignment to dense matrices.
798 //**********************************************************************************************
799
800 //**Multiplication assignment to sparse matrices************************************************
801 // No special implementation for the multiplication assignment to sparse matrices.
802 //**********************************************************************************************
803
804 //**SMP assignment to dense matrices************************************************************
805 // No special implementation for the SMP assignment to dense matrices.
806 //**********************************************************************************************
807
808 //**SMP assignment to sparse matrices***********************************************************
809 // No special implementation for the SMP assignment to sparse matrices.
810 //**********************************************************************************************
811
812 //**SMP addition assignment to dense matrices***************************************************
813 // No special implementation for the SMP addition assignment to dense matrices.
814 //**********************************************************************************************
815
816 //**SMP addition assignment to sparse matrices**************************************************
817 // No special implementation for the SMP addition assignment to sparse matrices.
818 //**********************************************************************************************
819
820 //**SMP subtraction assignment to dense matrices************************************************
821 // No special implementation for the SMP subtraction assignment to dense matrices.
822 //**********************************************************************************************
823
824 //**SMP subtraction assignment to sparse matrices***********************************************
825 // No special implementation for the SMP subtraction assignment to sparse matrices.
826 //**********************************************************************************************
827
828 //**SMP Schur product assignment to dense matrices**********************************************
841 template< typename MT // Type of the target dense matrix
842 , bool SO > // Storage order of the target dense matrix
843 friend inline void smpSchurAssign( DenseMatrix<MT,SO>& lhs, const SMatDMatSchurExpr& rhs )
844 {
846
847 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
848 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
849
850 smpSchurAssign( *lhs, rhs.lhs_ );
851 smpSchurAssign( *lhs, rhs.rhs_ );
852 }
854 //**********************************************************************************************
855
856 //**SMP Schur product assignment to sparse matrices*********************************************
857 // No special implementation for the SMP Schur product assignment to sparse matrices.
858 //**********************************************************************************************
859
860 //**SMP multiplication assignment to dense matrices*********************************************
861 // No special implementation for the SMP multiplication assignment to dense matrices.
862 //**********************************************************************************************
863
864 //**SMP multiplication assignment to sparse matrices********************************************
865 // No special implementation for the SMP multiplication assignment to sparse matrices.
866 //**********************************************************************************************
867
868 //**Compile time checks*************************************************************************
876 //**********************************************************************************************
877};
878//*************************************************************************************************
879
880
881
882
883//=================================================================================================
884//
885// GLOBAL BINARY ARITHMETIC OPERATORS
886//
887//=================================================================================================
888
889//*************************************************************************************************
902template< typename MT1 // Type of the left-hand side sparse matrix
903 , typename MT2 // Type of the right-hand side dense matrix
904 , DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
905 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
906 ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
907 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
908 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
909 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
910 IsZero_v<MT1> >* = nullptr >
911inline const SMatDMatSchurExpr<MT1,MT2>
912 smatdmatschur( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,false>& rhs )
913{
915
916 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
917 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
918
919 return SMatDMatSchurExpr<MT1,MT2>( *lhs, *rhs );
920}
922//*************************************************************************************************
923
924
925//*************************************************************************************************
939template< typename MT1 // Type of the left-hand side sparse matrix
940 , typename MT2 // Type of the right-hand side dense matrix
941 , EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
942 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* = nullptr >
943inline decltype(auto)
944 smatdmatschur( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,false>& rhs )
945{
947
948 MAYBE_UNUSED( rhs );
949
950 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
951 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
952
953 using ReturnType = const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
954
957
958 return ReturnType( (*lhs).rows() );
959}
961//*************************************************************************************************
962
963
964//*************************************************************************************************
978template< typename MT1 // Type of the left-hand side sparse matrix
979 , typename MT2 // Type of the right-hand side dense matrix
980 , EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
981 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
982 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
983 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
984 IsZero_v<MT1> >* = nullptr >
985inline decltype(auto)
986 smatdmatschur( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,false>& rhs )
987{
989
990 MAYBE_UNUSED( rhs );
991
992 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
993 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
994
995 using ReturnType = const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
996
999
1000 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1001}
1003//*************************************************************************************************
1004
1005
1006//*************************************************************************************************
1035template< typename MT1 // Type of the left-hand side sparse matrix
1036 , typename MT2 > // Type of the right-hand side dense matrix
1037inline decltype(auto)
1038 operator%( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,false>& rhs )
1039{
1041
1042 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1043 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1044 }
1045
1046 return smatdmatschur( *lhs, *rhs );
1047}
1048//*************************************************************************************************
1049
1050
1051//*************************************************************************************************
1064template< typename MT1 // Type of the left-hand side sparse matrix
1065 , typename MT2 // Type of the right-hand side dense matrix
1066 , DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
1067 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
1068 ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
1069 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
1070 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
1071 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
1072 IsZero_v<MT1> >* = nullptr >
1073inline const SMatDMatSchurExpr<MT1,MT2>
1074 smattdmatschur( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs )
1075{
1077
1078 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1079 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1080
1081 return SMatDMatSchurExpr<MT1,MT2>( *lhs, *rhs );
1082}
1084//*************************************************************************************************
1085
1086
1087//*************************************************************************************************
1101template< typename MT1 // Type of the left-hand side sparse matrix
1102 , typename MT2 // Type of the right-hand side dense matrix
1103 , EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
1104 ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* = nullptr >
1105inline decltype(auto)
1106 smattdmatschur( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs )
1107{
1109
1110 MAYBE_UNUSED( rhs );
1111
1112 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1113 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1114
1115 using ReturnType = const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1116
1119
1120 return ReturnType( (*lhs).rows() );
1121}
1123//*************************************************************************************************
1124
1125
1126//*************************************************************************************************
1140template< typename MT1 // Type of the left-hand side sparse matrix
1141 , typename MT2 // Type of the right-hand side dense matrix
1142 , EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
1143 ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
1144 ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
1145 ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
1146 IsZero_v<MT1> >* = nullptr >
1147inline decltype(auto)
1148 smattdmatschur( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs )
1149{
1151
1152 MAYBE_UNUSED( rhs );
1153
1154 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1155 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1156
1157 using ReturnType = const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1158
1161
1162 return ReturnType( (*lhs).rows(), (*lhs).columns() );
1163}
1165//*************************************************************************************************
1166
1167
1168//*************************************************************************************************
1198template< typename MT1 // Type of the left-hand side sparse matrix
1199 , typename MT2 > // Type of the right-hand side dense matrix
1200inline decltype(auto)
1201 operator%( const SparseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs )
1202{
1204
1205 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1206 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1207 }
1208
1209 return smattdmatschur( *lhs, *rhs );
1210}
1211//*************************************************************************************************
1212
1213
1214
1215
1216//=================================================================================================
1217//
1218// SIZE SPECIALIZATIONS
1219//
1220//=================================================================================================
1221
1222//*************************************************************************************************
1224template< typename MT1, typename MT2 >
1225struct Size< SMatDMatSchurExpr<MT1,MT2>, 0UL >
1226 : public Max_t< Size<MT1,0UL>, Size<MT2,0UL> >
1227{};
1228
1229template< typename MT1, typename MT2 >
1230struct Size< SMatDMatSchurExpr<MT1,MT2>, 1UL >
1231 : public Max_t< Size<MT1,1UL>, Size<MT2,1UL> >
1232{};
1234//*************************************************************************************************
1235
1236} // namespace blaze
1237
1238#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.
Definition: Aliases.h:130
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.
Constraint on the data type.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsExpression type trait class.
Header file for the IsLower type trait.
Header file for the IsStrictlyLower type trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsTemporary type trait class.
Header file for the IsUniLower type trait.
Header file for the IsUniUpper type trait.
Header file for the IsUpper type trait.
Header file for the MAYBE_UNUSED function template.
Header file for the RemoveReference type trait.
Constraints on the storage order of matrix types.
Header file for the Schur product trait.
Header file for the ValueIndexPair class.
Constraint on the data type.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Iterator over the elements of the sparse matrix/dense matrix Schur product expression.
Definition: SMatDMatSchurExpr.h:174
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatDMatSchurExpr.h:279
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatDMatSchurExpr.h:268
ValueType & ReferenceType
Reference return type.
Definition: SMatDMatSchurExpr.h:186
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatDMatSchurExpr.h:216
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SMatDMatSchurExpr.h:183
ConstIterator_t< RemoveReference_t< LeftOperand > > LeftIterator
Iterator type of the sparse matrix expression.
Definition: SMatDMatSchurExpr.h:181
RightOperand right_
Right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:298
Element ValueType
Type of the underlying pointers.
Definition: SMatDMatSchurExpr.h:184
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SMatDMatSchurExpr.h:187
ReturnType value() const
Access to the current value of the sparse element.
Definition: SMatDMatSchurExpr.h:247
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: SMatDMatSchurExpr.h:178
DifferenceType difference_type
Difference between two iterators.
Definition: SMatDMatSchurExpr.h:194
ConstIterator(LeftIterator left, RightOperand right, size_t row)
Constructor for the ConstIterator class.
Definition: SMatDMatSchurExpr.h:204
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatDMatSchurExpr.h:237
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatDMatSchurExpr.h:227
LeftIterator left_
Iterator over the elements of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:297
size_t row_
The row index of the iterator.
Definition: SMatDMatSchurExpr.h:299
IteratorCategory iterator_category
The iterator category.
Definition: SMatDMatSchurExpr.h:190
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SMatDMatSchurExpr.h:290
size_t index() const
Access to the current index of the sparse element.
Definition: SMatDMatSchurExpr.h:257
ValueType * PointerType
Pointer return type.
Definition: SMatDMatSchurExpr.h:185
Expression object for sparse matrix-dense matrix Schur product.
Definition: SMatDMatSchurExpr.h:103
RightOperand rhs_
Right-hand side dense matrix of the Schur product expression.
Definition: SMatDMatSchurExpr.h:506
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SMatDMatSchurExpr.h:453
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatDMatSchurExpr.h:306
If_t< useAssign, const ResultType, const SMatDMatSchurExpr & > CompositeType
Data type for composite expression templates.
Definition: SMatDMatSchurExpr.h:161
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:109
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatDMatSchurExpr.h:486
LeftOperand lhs_
Left-hand side sparse matrix of the Schur product expression.
Definition: SMatDMatSchurExpr.h:505
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: SMatDMatSchurExpr.h:374
static constexpr bool useAssign
Compilation switch for the evaluation strategy of the Schur product expression.
Definition: SMatDMatSchurExpr.h:135
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SMatDMatSchurExpr.h:427
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatDMatSchurExpr.h:124
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatDMatSchurExpr.h:394
SMatDMatSchurExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatDMatSchurExpr class.
Definition: SMatDMatSchurExpr.h:315
SchurTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatDMatSchurExpr.h:152
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatDMatSchurExpr.h:154
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:110
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatDMatSchurExpr.h:464
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatDMatSchurExpr.h:384
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:111
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatDMatSchurExpr.h:415
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatDMatSchurExpr.h:153
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:167
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatDMatSchurExpr.h:158
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatDMatSchurExpr.h:498
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatDMatSchurExpr.h:346
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SMatDMatSchurExpr.h:440
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: SMatDMatSchurExpr.h:363
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: SMatDMatSchurExpr.h:474
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatDMatSchurExpr.h:155
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: SMatDMatSchurExpr.h:107
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:164
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:106
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatDMatSchurExpr.h:331
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: SMatDMatSchurExpr.h:108
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatDMatSchurExpr.h:121
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatDMatSchurExpr.h:404
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Index-value-pair for sparse vectors and matrices.
Definition: ValueIndexPair.h:75
Constraint on the data type.
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 SchurExpr base class.
Header file for the SparseMatrix base class.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#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_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:81
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Identity.h:60
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_SCHUREXPR(T1, T2)
Constraint on the data type.
Definition: SchurExpr.h:103
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
typename SchurTrait< T1, T2 >::Type SchurTrait_t
Auxiliary alias declaration for the SchurTrait class template.
Definition: SchurTrait.h:137
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
If_t< Less_t< T1, T2 >::value, T2, T1 > Max_t
Compile time value evaluation.
Definition: Max.h:73
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
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
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
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 all forward declarations for sparse vectors and matrices.
Header file for the Size type trait.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all Schur product expression templates.
Definition: SchurExpr.h:68
Header file for the IsZero type trait.
Header file for basic type definitions.
Header file for the Max_t alias template.