SMatSMatSchurExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATSCHUREXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATSCHUREXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
44 #include <blaze/math/Aliases.h>
51 #include <blaze/math/Exception.h>
73 #include <blaze/util/Assert.h>
74 #include <blaze/util/DisableIf.h>
75 #include <blaze/util/EnableIf.h>
78 #include <blaze/util/mpl/If.h>
79 #include <blaze/util/Types.h>
80 #include <blaze/util/Unused.h>
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 // CLASS SMATSMATSCHUREXPR
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
98 template< typename MT1 // Type of the left-hand side sparse matrix
99  , typename MT2 > // Type of the right-hand side sparse matrix
100 class SMatSMatSchurExpr
101  : public SchurExpr< SparseMatrix< SMatSMatSchurExpr<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  //**Serial evaluation strategy******************************************************************
129 
134  template< typename T1, typename T2, typename T3 >
135  static constexpr bool UseSymmetricKernel_v =
136  ( IsColumnMajorMatrix_v<T1> && IsSymmetric_v<T2> && IsSymmetric_v<T3> );
138  //**********************************************************************************************
139 
140  public:
141  //**Type definitions****************************************************************************
148 
151 
153  using CompositeType = const ResultType;
154 
156  using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
157 
159  using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
160  //**********************************************************************************************
161 
162  //**Compilation flags***************************************************************************
164  static constexpr bool smpAssignable = false;
165  //**********************************************************************************************
166 
167  //**Constructor*********************************************************************************
173  explicit inline SMatSMatSchurExpr( const MT1& lhs, const MT2& rhs ) noexcept
174  : lhs_( lhs ) // Left-hand side sparse matrix of the Schur product expression
175  , rhs_( rhs ) // Right-hand side sparse matrix of the Schur product expression
176  {
177  BLAZE_INTERNAL_ASSERT( lhs.rows() == rhs.rows() , "Invalid number of rows" );
178  BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.columns(), "Invalid number of columns" );
179  }
180  //**********************************************************************************************
181 
182  //**Access operator*****************************************************************************
189  inline ReturnType operator()( size_t i, size_t j ) const {
190  BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
191  BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
192  return lhs_(i,j) * rhs_(i,j);
193  }
194  //**********************************************************************************************
195 
196  //**At function*********************************************************************************
204  inline ReturnType at( size_t i, size_t j ) const {
205  if( i >= lhs_.rows() ) {
206  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
207  }
208  if( j >= lhs_.columns() ) {
209  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
210  }
211  return (*this)(i,j);
212  }
213  //**********************************************************************************************
214 
215  //**Rows function*******************************************************************************
220  inline size_t rows() const noexcept {
221  return lhs_.rows();
222  }
223  //**********************************************************************************************
224 
225  //**Columns function****************************************************************************
230  inline size_t columns() const noexcept {
231  return lhs_.columns();
232  }
233  //**********************************************************************************************
234 
235  //**NonZeros function***************************************************************************
240  inline size_t nonZeros() const {
241  return min( lhs_.nonZeros(), rhs_.nonZeros() );
242  }
243  //**********************************************************************************************
244 
245  //**NonZeros function***************************************************************************
251  inline size_t nonZeros( size_t i ) const {
252  return min( lhs_.nonZeros(i), rhs_.nonZeros(i) );
253  }
254  //**********************************************************************************************
255 
256  //**Left operand access*************************************************************************
261  inline LeftOperand leftOperand() const noexcept {
262  return lhs_;
263  }
264  //**********************************************************************************************
265 
266  //**Right operand access************************************************************************
271  inline RightOperand rightOperand() const noexcept {
272  return rhs_;
273  }
274  //**********************************************************************************************
275 
276  //**********************************************************************************************
282  template< typename T >
283  inline bool canAlias( const T* alias ) const noexcept {
284  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
285  }
286  //**********************************************************************************************
287 
288  //**********************************************************************************************
294  template< typename T >
295  inline bool isAliased( const T* alias ) const noexcept {
296  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
297  }
298  //**********************************************************************************************
299 
300  private:
301  //**Member variables****************************************************************************
304  //**********************************************************************************************
305 
306  //**Assignment to dense matrices****************************************************************
318  template< typename MT // Type of the target dense matrix
319  , bool SO > // Storage order of the target dense matrix
320  friend inline auto assign( DenseMatrix<MT,SO>& lhs, const SMatSMatSchurExpr& rhs )
322  {
324 
325  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
326  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
327 
328  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
329  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
330 
331  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
332  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
333  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
334  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
335  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
336  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
337 
338  for( size_t i=0UL; i<(~lhs).rows(); ++i )
339  {
340  const auto lend( A.end(i) );
341  const auto rend( B.end(i) );
342 
343  auto l( A.begin(i) );
344  auto r( B.begin(i) );
345 
346  for( ; l!=lend; ++l ) {
347  while( r!=rend && r->index() < l->index() ) ++r;
348  if( r==rend ) break;
349  if( l->index() == r->index() ) {
350  (~lhs)(i,l->index()) = l->value() * r->value();
351  ++r;
352  }
353  }
354  }
355  }
357  //**********************************************************************************************
358 
359  //**Assignment to row-major sparse matrices*****************************************************
371  template< typename MT > // Type of the target sparse matrix
372  friend inline void assign( SparseMatrix<MT,false>& lhs, const SMatSMatSchurExpr& rhs )
373  {
375 
376  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
377  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
378 
379  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
380  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
381 
382  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
383  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
384  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
385  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
386  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
387  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
388 
389  // Final memory allocation (based on the evaluated operands)
390  (~lhs).reserve( min( A.nonZeros(), B.nonZeros() ) );
391 
392  // Performing the Schur product
393  for( size_t i=0UL; i<(~lhs).rows(); ++i )
394  {
395  const auto lend( A.end(i) );
396  const auto rend( B.end(i) );
397 
398  auto l( A.begin(i) );
399  auto r( B.begin(i) );
400 
401  for( ; l!=lend; ++l ) {
402  while( r!=rend && r->index() < l->index() ) ++r;
403  if( r==rend ) break;
404  if( l->index() == r->index() ) {
405  (~lhs).append( i, l->index(), l->value() * r->value() );
406  ++r;
407  }
408  }
409 
410  (~lhs).finalize( i );
411  }
412  }
414  //**********************************************************************************************
415 
416  //**Assignment to column-major sparse matrices**************************************************
429  template< typename MT > // Type of the target sparse matrix
430  friend inline auto assign( SparseMatrix<MT,true>& lhs, const SMatSMatSchurExpr& rhs )
431  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
432  {
434 
436 
437  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
438  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
439 
440  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
441  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
442 
443  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
444  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
445  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
446  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
447  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
448  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
449 
450  const size_t m( rhs.rows() );
451  const size_t n( rhs.columns() );
452 
453  // Counting the number of elements per column
454  std::vector<size_t> nonzeros( n, 0UL );
455  for( size_t i=0UL; i<m; ++i )
456  {
457  const auto lend( A.end(i) );
458  const auto rend( B.end(i) );
459 
460  auto l( A.begin(i) );
461  auto r( B.begin(i) );
462 
463  for( ; l!=lend; ++l ) {
464  while( r!=rend && r->index() < l->index() ) ++r;
465  if( r==rend ) break;
466  if( l->index() == r->index() ) {
467  ++nonzeros[l->index()];
468  ++r;
469  }
470  }
471  }
472 
473  // Resizing the left-hand side sparse matrix
474  for( size_t j=0UL; j<n; ++j ) {
475  (~lhs).reserve( j, nonzeros[j] );
476  }
477 
478  // Performing the Schur product
479  for( size_t i=0UL; i<m; ++i )
480  {
481  const auto lend( A.end(i) );
482  const auto rend( B.end(i) );
483 
484  auto l( A.begin(i) );
485  auto r( B.begin(i) );
486 
487  for( ; l!=lend; ++l ) {
488  while( r!=rend && r->index() < l->index() ) ++r;
489  if( r==rend ) break;
490  if( l->index() == r->index() ) {
491  (~lhs).append( i, l->index(), l->value() * r->value() );
492  ++r;
493  }
494  }
495  }
496  }
498  //**********************************************************************************************
499 
500  //**Restructuring assignment to column-major matrices*******************************************
513  template< typename MT > // Type of the target matrix
514  friend inline auto assign( Matrix<MT,true>& lhs, const SMatSMatSchurExpr& rhs )
515  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
516  {
518 
520 
521  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
522  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
523 
524  assign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
525  }
527  //**********************************************************************************************
528 
529  //**Addition assignment to dense matrices*******************************************************
541  template< typename MT // Type of the target dense matrix
542  , bool SO > // Storage order of the target dense matrix
543  friend inline auto addAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSchurExpr& rhs )
544  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
545  {
547 
548  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
549  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
550 
551  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
552  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
553 
554  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
555  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
556  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
557  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
558  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
559  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
560 
561  for( size_t i=0UL; i<(~lhs).rows(); ++i )
562  {
563  const auto lend( A.end(i) );
564  const auto rend( B.end(i) );
565 
566  auto l( A.begin(i) );
567  auto r( B.begin(i) );
568 
569  for( ; l!=lend; ++l ) {
570  while( r!=rend && r->index() < l->index() ) ++r;
571  if( r==rend ) break;
572  if( l->index() == r->index() ) {
573  (~lhs)(i,l->index()) += l->value() * r->value();
574  ++r;
575  }
576  }
577  }
578  }
580  //**********************************************************************************************
581 
582  //**Restructuring addition assignment to column-major matrices**********************************
595  template< typename MT > // Type of the target matrix
596  friend inline auto addAssign( Matrix<MT,true>& lhs, const SMatSMatSchurExpr& rhs )
597  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
598  {
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, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
607  }
609  //**********************************************************************************************
610 
611  //**Addition assignment to sparse matrices******************************************************
612  // No special implementation for the addition assignment to sparse matrices.
613  //**********************************************************************************************
614 
615  //**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 auto subAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSchurExpr& rhs )
631  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
632  {
634 
635  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
636  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
637 
638  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
639  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
640 
641  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
642  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
643  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
644  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
645  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
646  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
647 
648  for( size_t i=0UL; i<(~lhs).rows(); ++i )
649  {
650  const auto lend( A.end(i) );
651  const auto rend( B.end(i) );
652 
653  auto l( A.begin(i) );
654  auto r( B.begin(i) );
655 
656  for( ; l!=lend; ++l ) {
657  while( r!=rend && r->index() < l->index() ) ++r;
658  if( r==rend ) break;
659  if( l->index() == r->index() ) {
660  (~lhs)(i,l->index()) -= l->value() * r->value();
661  ++r;
662  }
663  }
664  }
665  }
667  //**********************************************************************************************
668 
669  //**Restructuring subtraction assignment to column-major matrices*******************************
682  template< typename MT > // Type of the target matrix
683  friend inline auto subAssign( Matrix<MT,true>& lhs, const SMatSMatSchurExpr& rhs )
684  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
685  {
687 
689 
690  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
691  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
692 
693  subAssign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
694  }
696  //**********************************************************************************************
697 
698  //**Subtraction assignment to sparse matrices***************************************************
699  // No special implementation for the subtraction assignment to sparse matrices.
700  //**********************************************************************************************
701 
702  //**Schur product assignment to dense matrices**************************************************
715  template< typename MT // Type of the target dense matrix
716  , bool SO > // Storage order of the target dense matrix
717  friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSchurExpr& rhs )
718  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
719  {
721 
722  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
723  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
724 
725  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
726  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
727 
728  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
729  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
730  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
731  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
732  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
733  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
734 
735  for( size_t i=0UL; i<(~lhs).rows(); ++i )
736  {
737  const auto lend( A.end(i) );
738  const auto rend( B.end(i) );
739 
740  auto l( A.begin(i) );
741  auto r( B.begin(i) );
742 
743  size_t j( 0 );
744 
745  for( ; l!=lend; ++l ) {
746  while( r!=rend && r->index() < l->index() ) ++r;
747  if( r==rend ) break;
748  if( l->index() == r->index() ) {
749  for( ; j<l->index(); ++j )
750  reset( (~lhs)(i,j) );
751  (~lhs)(i,l->index()) *= l->value() * r->value();
752  ++r;
753  ++j;
754  }
755  }
756 
757  for( ; j<(~lhs).columns(); ++j )
758  reset( (~lhs)(i,j) );
759  }
760  }
762  //**********************************************************************************************
763 
764  //**Restructuring Schur product assignment to column-major matrices*****************************
777  template< typename MT > // Type of the target matrix
778  friend inline auto schurAssign( Matrix<MT,true>& lhs, const SMatSMatSchurExpr& rhs )
779  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
780  {
782 
784 
785  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
786  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
787 
788  schurAssign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
789  }
791  //**********************************************************************************************
792 
793  //**Schur product assignment to sparse matrices*************************************************
794  // No special implementation for the Schur product assignment to sparse matrices.
795  //**********************************************************************************************
796 
797  //**Multiplication assignment to dense matrices*************************************************
798  // No special implementation for the multiplication assignment to dense matrices.
799  //**********************************************************************************************
800 
801  //**Multiplication assignment to sparse matrices************************************************
802  // No special implementation for the multiplication assignment to sparse matrices.
803  //**********************************************************************************************
804 
805  //**SMP assignment to dense matrices************************************************************
806  // No special implementation for the SMP assignment to dense matrices.
807  //**********************************************************************************************
808 
809  //**SMP assignment to sparse matrices***********************************************************
810  // No special implementation for the SMP assignment to sparse matrices.
811  //**********************************************************************************************
812 
813  //**SMP addition assignment to dense matrices***************************************************
814  // No special implementation for the SMP addition assignment to dense matrices.
815  //**********************************************************************************************
816 
817  //**SMP addition assignment to sparse matrices**************************************************
818  // No special implementation for the SMP addition assignment to sparse matrices.
819  //**********************************************************************************************
820 
821  //**SMP subtraction assignment to dense matrices************************************************
822  // No special implementation for the SMP subtraction assignment to dense matrices.
823  //**********************************************************************************************
824 
825  //**SMP subtraction assignment to sparse matrices***********************************************
826  // No special implementation for the SMP subtraction assignment to sparse matrices.
827  //**********************************************************************************************
828 
829  //**SMP Schur product assignment to dense matrices**********************************************
842  template< typename MT // Type of the target dense matrix
843  , bool SO > // Storage order of the target dense matrix
844  friend inline void smpSchurAssign( DenseMatrix<MT,SO>& lhs, const SMatSMatSchurExpr& rhs )
845  {
847 
848  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
849  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
850 
851  smpSchurAssign( ~lhs, rhs.lhs_ );
852  smpSchurAssign( ~lhs, rhs.rhs_ );
853  }
855  //**********************************************************************************************
856 
857  //**SMP Schur product assignment to sparse matrices*********************************************
858  // No special implementation for the SMP Schur product assignment to sparse matrices.
859  //**********************************************************************************************
860 
861  //**SMP multiplication assignment to dense matrices*********************************************
862  // No special implementation for the SMP multiplication assignment to dense matrices.
863  //**********************************************************************************************
864 
865  //**SMP multiplication assignment to sparse matrices********************************************
866  // No special implementation for the SMP multiplication assignment to sparse matrices.
867  //**********************************************************************************************
868 
869  //**Compile time checks*************************************************************************
879  //**********************************************************************************************
880 };
881 //*************************************************************************************************
882 
883 
884 
885 
886 //=================================================================================================
887 //
888 // GLOBAL BINARY ARITHMETIC OPERATORS
889 //
890 //=================================================================================================
891 
892 //*************************************************************************************************
905 template< typename MT1 // Type of the left-hand side sparse matrix
906  , typename MT2 // Type of the right-hand side sparse matrix
907  , DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
908  ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
909  ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
910  ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
911  ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
912  ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
913  ( IsZero_v<MT1> || IsZero_v<MT2> ) >* = nullptr >
914 inline const SMatSMatSchurExpr<MT1,MT2>
915  smatsmatschur( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
916 {
918 
919  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
920  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
921 
922  return SMatSMatSchurExpr<MT1,MT2>( ~lhs, ~rhs );
923 }
925 //*************************************************************************************************
926 
927 
928 //*************************************************************************************************
941 template< typename MT1 // Type of the left-hand side sparse matrix
942  , typename MT2 // Type of the right-hand side sparse matrix
943  , EnableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
944  ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) >* = nullptr >
945 inline decltype(auto)
946  smatsmatschur( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
947 {
949 
950  UNUSED_PARAMETER( rhs );
951 
952  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
953  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
954 
955  using ReturnType = const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
956 
959 
960  return ReturnType( (~lhs).rows() );
961 }
963 //*************************************************************************************************
964 
965 
966 //*************************************************************************************************
979 template< typename MT1 // Type of the left-hand side sparse matrix
980  , typename MT2 // Type of the right-hand side sparse matrix
981  , EnableIf_t< ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
982  ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
983  ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
984  ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
985  ( IsZero_v<MT1> || IsZero_v<MT2> ) >* = nullptr >
986 inline decltype(auto)
987  smatsmatschur( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
988 {
990 
991  UNUSED_PARAMETER( rhs );
992 
993  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
994  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
995 
996  using ReturnType = const SchurTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
997 
1000 
1001  return ReturnType( (~lhs).rows(), (~lhs).columns() );
1002 }
1004 //*************************************************************************************************
1005 
1006 
1007 //*************************************************************************************************
1033 template< typename MT1 // Type of the left-hand side sparse matrix
1034  , typename MT2 > // Type of the right-hand side sparse matrix
1035 inline decltype(auto)
1036  operator%( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
1037 {
1039 
1040  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() ) {
1041  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1042  }
1043 
1044  return smatsmatschur( ~lhs, ~rhs );
1045 }
1046 //*************************************************************************************************
1047 
1048 } // namespace blaze
1049 
1050 #endif
Constraint on the data type.
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatSchurExpr.h:295
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not an identity matrix type...
Definition: Identity.h:60
Header file for the Schur product trait.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatSchurExpr.h:251
Header file for the UNUSED_PARAMETER function template.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatSchurExpr.h:189
Header file for the IsUniUpper type trait.
Header file for basic type definitions.
SchurTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatSMatSchurExpr.h:144
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
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.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatSchurExpr.h:145
ReturnType_t< MT1 > RN1
ReturnType type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:108
Header file for the IsColumnMajorMatrix type trait.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:111
Constraint on the data type.
Header file for the Computation base class.
Constraints on the storage order of matrix types.
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatSchurExpr.h:153
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the IsUniLower type trait.
RightOperand rhs_
Right-hand side sparse matrix of the Schur product expression.
Definition: SMatSMatSchurExpr.h:303
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_SCHUREXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: SchurExpr.h:103
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
ReturnType_t< MT2 > RN2
ReturnType type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:109
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 all forward declarations for sparse vectors and matrices.
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:107
Header file for the SparseMatrix base class.
Constraint on the data type.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatSMatSchurExpr.h:164
Headerfile for the generic max algorithm.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatSchurExpr.h:261
If_t< IsExpression_v< MT2 >, const MT2, const MT2 &> RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:159
#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
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
#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
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatSchurExpr.h:146
Header file for the IsLower type trait.
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:106
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatSMatSchurExpr.h:121
Header file for the exception macros of the math module.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatSMatSchurExpr.h:230
Header file for all forward declarations for expression class templates.
SMatSMatSchurExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatSMatSchurExpr class.
Definition: SMatSMatSchurExpr.h:173
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
Expression object for sparse matrix-sparse matrix Schur product.The SMatSMatSchurExpr class represent...
Definition: Forward.h:126
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:61
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatSchurExpr.h:240
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
LeftOperand lhs_
Left-hand side sparse matrix of the Schur product expression.
Definition: SMatSMatSchurExpr.h:302
Header file for the SchurExpr base class.
typename SchurTrait< T1, T2 >::Type SchurTrait_t
Auxiliary alias declaration for the SchurTrait class template.The SchurTrait_t alias declaration prov...
Definition: SchurTrait.h:164
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:110
Header file for the IsZero type trait.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatSchurExpr.h:204
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatSchurExpr.h:283
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatSMatSchurExpr.h:150
Constraint on the data type.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatSMatSchurExpr.h:147
If_t< IsExpression_v< MT1 >, const MT1, const MT1 &> LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatSchurExpr.h:156
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 IsComputation type trait class.
Header file for the IntegralConstant class template.
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatSMatSchurExpr.h:124
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatSMatSchurExpr.h:220
Header file for the IsUpper type trait.
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
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatSchurExpr.h:271
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is a zero vector or matrix type...
Definition: Zero.h:81
#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.
Constraint on the data type.