TSMatTSMatSchurExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATTSMATSCHUREXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATTSMATSCHUREXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
44 #include <blaze/math/Aliases.h>
50 #include <blaze/math/Exception.h>
72 #include <blaze/util/Assert.h>
73 #include <blaze/util/DisableIf.h>
74 #include <blaze/util/EnableIf.h>
77 #include <blaze/util/mpl/If.h>
78 #include <blaze/util/Types.h>
79 #include <blaze/util/Unused.h>
80 
81 
82 namespace blaze {
83 
84 //=================================================================================================
85 //
86 // CLASS TSMATTSMATSCHUREXPR
87 //
88 //=================================================================================================
89 
90 //*************************************************************************************************
97 template< typename MT1 // Type of the left-hand side sparse matrix
98  , typename MT2 > // Type of the right-hand side sparse matrix
99 class TSMatTSMatSchurExpr
100  : public SchurExpr< SparseMatrix< TSMatTSMatSchurExpr<MT1,MT2>, true > >
101  , private Computation
102 {
103  private:
104  //**Type definitions****************************************************************************
111  //**********************************************************************************************
112 
113  //**Return type evaluation**********************************************************************
115 
120  static constexpr bool returnExpr = !IsTemporary_v<RN1> && !IsTemporary_v<RN2>;
121 
123  using ExprReturnType = decltype( std::declval<RN1>() * std::declval<RN2>() );
124  //**********************************************************************************************
125 
126  //**Serial evaluation strategy******************************************************************
128 
133  template< typename T1, typename T2, typename T3 >
134  static constexpr bool UseSymmetricKernel_v =
135  ( IsRowMajorMatrix_v<T1> && IsSymmetric_v<T2> && IsSymmetric_v<T3> );
137  //**********************************************************************************************
138 
139  public:
140  //**Type definitions****************************************************************************
147 
150 
152  using CompositeType = const ResultType;
153 
155  using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
156 
158  using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
159  //**********************************************************************************************
160 
161  //**Compilation flags***************************************************************************
163  static constexpr bool smpAssignable = false;
164  //**********************************************************************************************
165 
166  //**Constructor*********************************************************************************
172  explicit inline TSMatTSMatSchurExpr( const MT1& lhs, const MT2& rhs ) noexcept
173  : lhs_( lhs ) // Left-hand side sparse matrix of the Schur product expression
174  , rhs_( rhs ) // Right-hand side sparse matrix of the Schur product expression
175  {
176  BLAZE_INTERNAL_ASSERT( lhs.rows() == rhs.rows() , "Invalid number of rows" );
177  BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.columns(), "Invalid number of columns" );
178  }
179  //**********************************************************************************************
180 
181  //**Access operator*****************************************************************************
188  inline ReturnType operator()( size_t i, size_t j ) const {
189  BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
190  BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
191  return lhs_(i,j) * rhs_(i,j);
192  }
193  //**********************************************************************************************
194 
195  //**At function*********************************************************************************
203  inline ReturnType at( size_t i, size_t j ) const {
204  if( i >= lhs_.rows() ) {
205  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
206  }
207  if( j >= lhs_.columns() ) {
208  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
209  }
210  return (*this)(i,j);
211  }
212  //**********************************************************************************************
213 
214  //**Rows function*******************************************************************************
219  inline size_t rows() const noexcept {
220  return lhs_.rows();
221  }
222  //**********************************************************************************************
223 
224  //**Columns function****************************************************************************
229  inline size_t columns() const noexcept {
230  return lhs_.columns();
231  }
232  //**********************************************************************************************
233 
234  //**NonZeros function***************************************************************************
239  inline size_t nonZeros() const {
240  return min( lhs_.nonZeros(), rhs_.nonZeros() );
241  }
242  //**********************************************************************************************
243 
244  //**NonZeros function***************************************************************************
250  inline size_t nonZeros( size_t i ) const {
251  return min( lhs_.nonZeros(i), rhs_.nonZeros(i) );
252  }
253  //**********************************************************************************************
254 
255  //**Left operand access*************************************************************************
260  inline LeftOperand leftOperand() const noexcept {
261  return lhs_;
262  }
263  //**********************************************************************************************
264 
265  //**Right operand access************************************************************************
270  inline RightOperand rightOperand() const noexcept {
271  return rhs_;
272  }
273  //**********************************************************************************************
274 
275  //**********************************************************************************************
281  template< typename T >
282  inline bool canAlias( const T* alias ) const noexcept {
283  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
284  }
285  //**********************************************************************************************
286 
287  //**********************************************************************************************
293  template< typename T >
294  inline bool isAliased( const T* alias ) const noexcept {
295  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
296  }
297  //**********************************************************************************************
298 
299  private:
300  //**Member variables****************************************************************************
303  //**********************************************************************************************
304 
305  //**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 TSMatTSMatSchurExpr& 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 j=0UL; j<(~lhs).columns(); ++j )
339  {
340  const auto lend( A.end(j) );
341  const auto rend( B.end(j) );
342 
343  auto l( A.begin(j) );
344  auto r( B.begin(j) );
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)(l->index(),j) = l->value() * r->value();
351  ++r;
352  }
353  }
354  }
355  }
357  //**********************************************************************************************
358 
359  //**Assignment to row-major sparse matrices*****************************************************
372  template< typename MT > // Type of the target sparse matrix
373  friend inline auto assign( SparseMatrix<MT,false>& lhs, const TSMatTSMatSchurExpr& rhs )
375  {
377 
379 
380  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
381  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
382 
383  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
384  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
385 
386  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
387  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
388  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
389  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
390  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
391  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
392 
393  const size_t m( rhs.rows() );
394  const size_t n( rhs.columns() );
395 
396  // Counting the number of elements per column
397  std::vector<size_t> nonzeros( m, 0UL );
398  for( size_t j=0UL; j<n; ++j )
399  {
400  const auto lend( A.end(j) );
401  const auto rend( B.end(j) );
402 
403  auto l( A.begin(j) );
404  auto r( B.begin(j) );
405 
406  for( ; l!=lend; ++l ) {
407  while( r!=rend && r->index() < l->index() ) ++r;
408  if( r==rend ) break;
409  if( l->index() == r->index() ) {
410  ++nonzeros[l->index()];
411  ++r;
412  }
413  }
414  }
415 
416  // Resizing the left-hand side sparse matrix
417  for( size_t i=0UL; i<m; ++i ) {
418  (~lhs).reserve( i, nonzeros[i] );
419  }
420 
421  // Performing the Schur product
422  for( size_t j=0UL; j<n; ++j )
423  {
424  const auto lend( A.end(j) );
425  const auto rend( B.end(j) );
426 
427  auto l( A.begin(j) );
428  auto r( B.begin(j) );
429 
430  for( ; l!=lend; ++l ) {
431  while( r!=rend && r->index() < l->index() ) ++r;
432  if( r==rend ) break;
433  if( l->index() == r->index() ) {
434  (~lhs).append( l->index(), j, l->value() * r->value() );
435  ++r;
436  }
437  }
438  }
439  }
441  //**********************************************************************************************
442 
443  //**Assignment to column-major sparse matrices**************************************************
456  template< typename MT > // Type of the target sparse matrix
457  friend inline void assign( SparseMatrix<MT,true>& lhs, const TSMatTSMatSchurExpr& rhs )
458  {
460 
461  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
462  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
463 
464  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
465  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
466 
467  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
468  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
469  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
470  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
471  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
472  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
473 
474  // Final memory allocation (based on the evaluated operands)
475  (~lhs).reserve( min( A.nonZeros(), B.nonZeros() ) );
476 
477  // Performing the Schur product
478  for( size_t j=0UL; j<(~lhs).columns(); ++j )
479  {
480  const auto lend( A.end(j) );
481  const auto rend( B.end(j) );
482 
483  auto l( A.begin(j) );
484  auto r( B.begin(j) );
485 
486  for( ; l!=lend; ++l ) {
487  while( r!=rend && r->index() < l->index() ) ++r;
488  if( r==rend ) break;
489  if( l->index() == r->index() ) {
490  (~lhs).append( l->index(), j, l->value() * r->value() );
491  ++r;
492  }
493  }
494 
495  (~lhs).finalize( j );
496  }
497  }
499  //**********************************************************************************************
500 
501  //**Restructuring assignment to row-major matrices**********************************************
514  template< typename MT > // Type of the target matrix
515  friend inline auto assign( Matrix<MT,false>& lhs, const TSMatTSMatSchurExpr& rhs )
516  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
517  {
519 
521 
522  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
523  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
524 
525  assign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
526  }
528  //**********************************************************************************************
529 
530  //**Addition assignment to dense matrices*******************************************************
543  template< typename MT // Type of the target dense matrix
544  , bool SO > // Storage order of the target dense matrix
545  friend inline auto addAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatSchurExpr& rhs )
546  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
547  {
549 
550  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
551  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
552 
553  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
554  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
555 
556  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
557  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
558  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
559  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
560  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
561  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
562 
563  for( size_t j=0UL; j<(~lhs).columns(); ++j )
564  {
565  const auto lend( A.end(j) );
566  const auto rend( B.end(j) );
567 
568  auto l( A.begin(j) );
569  auto r( B.begin(j) );
570 
571  for( ; l!=lend; ++l ) {
572  while( r!=rend && r->index() < l->index() ) ++r;
573  if( r==rend ) break;
574  if( l->index() == r->index() ) {
575  (~lhs)(l->index(),j) += l->value() * r->value();
576  ++r;
577  }
578  }
579  }
580  }
582  //**********************************************************************************************
583 
584  //**Restructuring addition assignment to row-major matrices*************************************
597  template< typename MT > // Type of the target matrix
598  friend inline auto addAssign( Matrix<MT,false>& lhs, const TSMatTSMatSchurExpr& rhs )
599  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
600  {
602 
604 
605  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
606  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
607 
608  addAssign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
609  }
611  //**********************************************************************************************
612 
613  //**Addition assignment to sparse matrices******************************************************
614  // No special implementation for the addition assignment to sparse matrices.
615  //**********************************************************************************************
616 
617  //**Subtraction assignment to dense matrices****************************************************
630  template< typename MT // Type of the target dense matrix
631  , bool SO > // Storage order of the target dense matrix
632  friend inline auto subAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatSchurExpr& rhs )
633  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
634  {
636 
637  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
638  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
639 
640  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
641  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
642 
643  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
644  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
645  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
646  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
647  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
648  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
649 
650  for( size_t j=0UL; j<(~lhs).columns(); ++j )
651  {
652  const auto lend( A.end(j) );
653  const auto rend( B.end(j) );
654 
655  auto l( A.begin(j) );
656  auto r( B.begin(j) );
657 
658  for( ; l!=lend; ++l ) {
659  while( r!=rend && r->index() < l->index() ) ++r;
660  if( r==rend ) break;
661  if( l->index() == r->index() ) {
662  (~lhs)(l->index(),j) -= l->value() * r->value();
663  ++r;
664  }
665  }
666  }
667  }
669  //**********************************************************************************************
670 
671  //**Restructuring subtraction assignment to row-major matrices**********************************
684  template< typename MT > // Type of the target matrix
685  friend inline auto subAssign( Matrix<MT,false>& lhs, const TSMatTSMatSchurExpr& rhs )
686  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
687  {
689 
691 
692  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
693  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
694 
695  subAssign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
696  }
698  //**********************************************************************************************
699 
700  //**Subtraction assignment to sparse matrices***************************************************
701  // No special implementation for the subtraction assignment to sparse matrices.
702  //**********************************************************************************************
703 
704  //**Schur product assignment to dense matrices**************************************************
717  template< typename MT // Type of the target dense matrix
718  , bool SO > // Storage order of the target dense matrix
719  friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatSchurExpr& rhs )
720  -> DisableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
721  {
723 
724  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
725  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
726 
727  CT1 A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse matrix operand
728  CT2 B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse matrix operand
729 
730  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
731  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
732  BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
733  BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
734  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).rows() , "Invalid number of rows" );
735  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).columns() , "Invalid number of columns" );
736 
737  for( size_t j=0UL; j<(~lhs).columns(); ++j )
738  {
739  const auto lend( A.end(j) );
740  const auto rend( B.end(j) );
741 
742  auto l( A.begin(j) );
743  auto r( B.begin(j) );
744 
745  size_t i( 0UL );
746 
747  for( ; l!=lend; ++l ) {
748  while( r!=rend && r->index() < l->index() ) ++r;
749  if( r==rend ) break;
750  if( l->index() == r->index() ) {
751  for( ; i<l->index(); ++i )
752  reset( (~lhs)(i,j) );
753  (~lhs)(l->index(),j) *= l->value() * r->value();
754  ++r;
755  ++i;
756  }
757  }
758 
759  for( ; i<(~lhs).rows(); ++i )
760  reset( (~lhs)(i,j) );
761  }
762  }
764  //**********************************************************************************************
765 
766  //**Restructuring Schur product assignment to row-major matrices********************************
779  template< typename MT > // Type of the target matrix
780  friend inline auto schurAssign( Matrix<MT,false>& lhs, const TSMatTSMatSchurExpr& rhs )
781  -> EnableIf_t< UseSymmetricKernel_v<MT,MT1,MT2> >
782  {
784 
786 
787  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
788  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
789 
790  schurAssign( ~lhs, trans( rhs.lhs_ ) % trans( rhs.rhs_ ) );
791  }
793  //**********************************************************************************************
794 
795  //**Schur product assignment to sparse matrices*************************************************
796  // No special implementation for the Schur product assignment to sparse matrices.
797  //**********************************************************************************************
798 
799  //**Multiplication assignment to dense matrices*************************************************
800  // No special implementation for the multiplication assignment to dense matrices.
801  //**********************************************************************************************
802 
803  //**Multiplication assignment to sparse matrices************************************************
804  // No special implementation for the multiplication assignment to sparse matrices.
805  //**********************************************************************************************
806 
807  //**SMP assignment to dense matrices************************************************************
808  // No special implementation for the SMP assignment to dense matrices.
809  //**********************************************************************************************
810 
811  //**SMP assignment to sparse matrices***********************************************************
812  // No special implementation for the SMP assignment to sparse matrices.
813  //**********************************************************************************************
814 
815  //**SMP addition assignment to dense matrices***************************************************
816  // No special implementation for the SMP addition assignment to dense matrices.
817  //**********************************************************************************************
818 
819  //**SMP addition assignment to sparse matrices**************************************************
820  // No special implementation for the SMP addition assignment to sparse matrices.
821  //**********************************************************************************************
822 
823  //**SMP subtraction assignment to dense matrices************************************************
824  // No special implementation for the SMP subtraction assignment to dense matrices.
825  //**********************************************************************************************
826 
827  //**SMP subtraction assignment to sparse matrices***********************************************
828  // No special implementation for the SMP subtraction assignment to sparse matrices.
829  //**********************************************************************************************
830 
831  //**SMP Schur product assignment to dense matrices**********************************************
844  template< typename MT // Type of the target dense matrix
845  , bool SO > // Storage order of the target dense matrix
846  friend inline void smpSchurAssign( DenseMatrix<MT,SO>& lhs, const TSMatTSMatSchurExpr& rhs )
847  {
849 
850  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
851  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
852 
853  smpSchurAssign( ~lhs, rhs.lhs_ );
854  smpSchurAssign( ~lhs, rhs.rhs_ );
855  }
857  //**********************************************************************************************
858 
859  //**SMP Schur product assignment to sparse matrices*********************************************
860  // No special implementation for the SMP Schur product assignment to sparse matrices.
861  //**********************************************************************************************
862 
863  //**SMP multiplication assignment to dense matrices*********************************************
864  // No special implementation for the SMP multiplication assignment to dense matrices.
865  //**********************************************************************************************
866 
867  //**SMP multiplication assignment to sparse matrices********************************************
868  // No special implementation for the SMP multiplication assignment to sparse matrices.
869  //**********************************************************************************************
870 
871  //**Compile time checks*************************************************************************
881  //**********************************************************************************************
882 };
883 //*************************************************************************************************
884 
885 
886 
887 
888 //=================================================================================================
889 //
890 // GLOBAL BINARY ARITHMETIC OPERATORS
891 //
892 //=================================================================================================
893 
894 //*************************************************************************************************
906 template< typename MT1 // Type of the left-hand side sparse matrix
907  , typename MT2 // Type of the right-hand side sparse matrix
908  , DisableIf_t< ( IsUniLower_v<MT1> && IsUniUpper_v<MT2> ) ||
909  ( IsUniUpper_v<MT1> && IsUniLower_v<MT2> ) ||
910  ( IsStrictlyLower_v<MT1> && IsUpper_v<MT2> ) ||
911  ( IsStrictlyUpper_v<MT1> && IsLower_v<MT2> ) ||
912  ( IsLower_v<MT1> && IsStrictlyUpper_v<MT2> ) ||
913  ( IsUpper_v<MT1> && IsStrictlyLower_v<MT2> ) ||
914  ( IsZero_v<MT1> || IsZero_v<MT2> ) >* = nullptr >
915 inline const TSMatTSMatSchurExpr<MT1,MT2>
917 {
919 
920  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
921  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
922 
923  return TSMatTSMatSchurExpr<MT1,MT2>( ~lhs, ~rhs );
924 }
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  tsmattsmatschur( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& 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  tsmattsmatschur( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& 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,true>& lhs, const SparseMatrix<MT2,true>& 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 tsmattsmatschur( ~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
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatTSMatSchurExpr.h:152
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
#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
SchurTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: TSMatTSMatSchurExpr.h:143
Header file for the Schur product trait.
Header file for the UNUSED_PARAMETER function template.
Header file for the IsUniUpper type trait.
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:110
Header file for basic type definitions.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatTSMatSchurExpr.h:239
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.
If_t< IsExpression_v< MT1 >, const MT1, const MT1 &> LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:155
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: TSMatTSMatSchurExpr.h:219
Constraint on the data type.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: TSMatTSMatSchurExpr.h:149
Header file for the Computation base class.
Expression object for transpose sparse matrix-transpose sparse matrix Schur product.The TSMatTSMatSchurExpr class represents the compile time expression for Schur products between two column-major sparse matrices.
Definition: Forward.h:180
const TSMatTSMatSchurExpr< MT1, MT2 > tsmattsmatschur(const SparseMatrix< MT1, true > &lhs, const SparseMatrix< MT2, true > &rhs)
Backend implementation of the Schur product between two column-major sparse matrices ( )...
Definition: TSMatTSMatSchurExpr.h:916
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:109
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the IsUniLower type trait.
#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
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.
Header file for the SparseMatrix base class.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSMatTSMatSchurExpr.h:163
Constraint on the data type.
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.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:61
#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
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:105
LeftOperand leftOperand() const noexcept
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatTSMatSchurExpr.h:260
Header file for the IsLower type trait.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatTSMatSchurExpr.h:144
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: TSMatTSMatSchurExpr.h:229
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSMatTSMatSchurExpr.h:282
Header file for the exception macros of the math module.
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: TSMatTSMatSchurExpr.h:270
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
If_t< IsExpression_v< MT2 >, const MT2, const MT2 &> RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:158
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
ReturnType_t< MT1 > RN1
Return type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:107
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
LeftOperand lhs_
Left-hand side sparse matrix of the Schur product expression.
Definition: TSMatTSMatSchurExpr.h:301
decltype(std::declval< RN1 >() *std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: TSMatTSMatSchurExpr.h:123
ReturnType_t< MT2 > RN2
Return type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:108
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
TSMatTSMatSchurExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the TSMatTSMatSchurExpr class.
Definition: TSMatTSMatSchurExpr.h:172
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSMatTSMatSchurExpr.h:294
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
Header file for the IsZero type trait.
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSMatTSMatSchurExpr.h:145
#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
Constraint on the data type.
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
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
RightOperand rhs_
Right-hand side sparse matrix of the Schur product expression.
Definition: TSMatTSMatSchurExpr.h:302
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Header file for the IsRowMajorMatrix type trait.
Header file for the IsComputation type trait class.
Header file for the IntegralConstant class template.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatTSMatSchurExpr.h:188
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
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: TSMatTSMatSchurExpr.h:120
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatTSMatSchurExpr.h:250
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSMatTSMatSchurExpr.h:146
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: TSMatTSMatSchurExpr.h:203
#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
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatSchurExpr.h:106
#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.