DMatReduceExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATREDUCEEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DMATREDUCEEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <blaze/math/Aliases.h>
52 #include <blaze/math/Exception.h>
64 #include <blaze/math/SIMD.h>
72 #include <blaze/math/views/Check.h>
74 #include <blaze/util/Assert.h>
75 #include <blaze/util/DisableIf.h>
76 #include <blaze/util/EnableIf.h>
78 #include <blaze/util/mpl/If.h>
80 #include <blaze/util/Types.h>
84 
85 
86 namespace blaze {
87 
88 //=================================================================================================
89 //
90 // CLASS DEFINITION
91 //
92 //=================================================================================================
93 
94 //*************************************************************************************************
101 template< typename MT // Type of the dense matrix
102  , typename OP // Type of the reduction operation
103  , size_t RF > // Reduction flag
105 {};
106 //*************************************************************************************************
107 
108 
109 
110 
111 //=================================================================================================
112 //
113 // CLASS TEMPLATE SPECIALIZATION FOR COLUMN-WISE REDUCTION OPERATIONS OF ROW-MAJOR MATRICES
114 //
115 //=================================================================================================
116 
117 //*************************************************************************************************
124 template< typename MT // Type of the dense matrix
125  , typename OP > // Type of the reduction operation
127  : public MatReduceExpr< DenseVector< DMatReduceExpr<MT,OP,columnwise>, true >, columnwise >
128  , private Computation
129 {
130  private:
131  //**Type definitions****************************************************************************
135  //**********************************************************************************************
136 
137  //**Parallel evaluation strategy****************************************************************
139 
144  template< typename VT >
145  static constexpr bool UseSMPAssign_v = ( !MT::smpAssignable && RequiresEvaluation_v<MT> );
147  //**********************************************************************************************
148 
149  public:
150  //**Type definitions****************************************************************************
157  using ReturnType = const ElementType;
158  using CompositeType = const ResultType;
159 
161  using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
162 
164  using Operation = OP;
165  //**********************************************************************************************
166 
167  //**Compilation flags***************************************************************************
169  static constexpr bool simdEnabled = false;
170 
172  static constexpr bool smpAssignable = MT::smpAssignable;
173  //**********************************************************************************************
174 
175  //**Constructor*********************************************************************************
181  explicit inline DMatReduceExpr( const MT& dm, OP op ) noexcept
182  : dm_( dm ) // Dense matrix of the reduction expression
183  , op_( op ) // The reduction operation
184  {}
185  //**********************************************************************************************
186 
187  //**Subscript operator**************************************************************************
193  inline ReturnType operator[]( size_t index ) const {
194  BLAZE_INTERNAL_ASSERT( index < dm_.columns(), "Invalid vector access index" );
195  return reduce( column( dm_, index, unchecked ), op_ );
196  }
197  //**********************************************************************************************
198 
199  //**At function*********************************************************************************
206  inline ReturnType at( size_t index ) const {
207  if( index >= dm_.columns() ) {
208  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
209  }
210  return (*this)[index];
211  }
212  //**********************************************************************************************
213 
214  //**Size function*******************************************************************************
219  inline size_t size() const noexcept {
220  return dm_.columns();
221  }
222  //**********************************************************************************************
223 
224  //**Operand access******************************************************************************
229  inline Operand operand() const noexcept {
230  return dm_;
231  }
232  //**********************************************************************************************
233 
234  //**Operation access****************************************************************************
239  inline Operation operation() const {
240  return op_;
241  }
242  //**********************************************************************************************
243 
244  //**********************************************************************************************
250  template< typename T >
251  inline bool canAlias( const T* alias ) const noexcept {
252  return ( dm_.isAliased( alias ) );
253  }
254  //**********************************************************************************************
255 
256  //**********************************************************************************************
262  template< typename T >
263  inline bool isAliased( const T* alias ) const noexcept {
264  return ( dm_.isAliased( alias ) );
265  }
266  //**********************************************************************************************
267 
268  //**********************************************************************************************
273  inline bool isAligned() const noexcept {
274  return false;
275  }
276  //**********************************************************************************************
277 
278  //**********************************************************************************************
283  inline bool canSMPAssign() const noexcept {
284  return dm_.canSMPAssign() || ( size() > SMP_DMATREDUCE_THRESHOLD );
285  }
286  //**********************************************************************************************
287 
288  private:
289  //**Member variables****************************************************************************
292  //**********************************************************************************************
293 
294  //**Assignment to dense vectors*****************************************************************
306  template< typename VT1 > // Type of the target dense vector
307  friend inline void assign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
308  {
310 
311  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
312 
313  const size_t M( rhs.dm_.rows() );
314 
315  if( M == 0UL ) {
316  reset( ~lhs );
317  return;
318  }
319 
320  CT tmp( serial( rhs.dm_ ) );
321 
322  assign( ~lhs, row( tmp, 0UL, unchecked ) );
323  for( size_t i=1UL; i<M; ++i ) {
324  assign( ~lhs, map( ~lhs, row( tmp, i, unchecked ), rhs.op_ ) );
325  }
326  }
328  //**********************************************************************************************
329 
330  //**Assignment to sparse vectors****************************************************************
342  template< typename VT1 > // Type of the target dense vector
343  friend inline void assign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
344  {
346 
350 
351  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
352 
353  const ResultType tmp( serial( rhs ) );
354  assign( ~lhs, tmp );
355  }
357  //**********************************************************************************************
358 
359  //**Addition assignment to dense vectors********************************************************
372  template< typename VT1 > // Type of the target dense vector
373  friend inline void addAssign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
374  {
376 
377  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
378 
379  if( rhs.dm_.rows() == 0UL ) {
380  return;
381  }
382  else if( IsSame_v<OP,Add> ) {
383  CT tmp( serial( rhs.dm_ ) );
384  const size_t M( tmp.rows() );
385  for( size_t i=0UL; i<M; ++i ) {
386  addAssign( (~lhs), row( tmp, i, unchecked ) );
387  }
388  }
389  else {
390  const ResultType tmp( serial( rhs ) );
391  addAssign( ~lhs, tmp );
392  }
393  }
395  //**********************************************************************************************
396 
397  //**Addition assignment to sparse vectors*******************************************************
410  template< typename VT1 > // Type of the target dense vector
411  friend inline void addAssign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
412  {
414 
418 
419  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
420 
421  const ResultType tmp( serial( rhs ) );
422  addAssign( ~lhs, tmp );
423  }
425  //**********************************************************************************************
426 
427  //**Subtraction assignment to dense vectors*****************************************************
440  template< typename VT1 > // Type of the target dense vector
441  friend inline void subAssign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
442  {
444 
445  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
446 
447  if( rhs.dm_.rows() == 0UL ) {
448  return;
449  }
450  else if( IsSame_v<OP,Add> ) {
451  CT tmp( serial( rhs.dm_ ) );
452  const size_t M( tmp.rows() );
453  for( size_t i=0UL; i<M; ++i ) {
454  subAssign( (~lhs), row( tmp, i, unchecked ) );
455  }
456  }
457  else {
458  const ResultType tmp( serial( rhs ) );
459  subAssign( ~lhs, tmp );
460  }
461  }
463  //**********************************************************************************************
464 
465  //**Subtraction assignment to sparse vectors****************************************************
478  template< typename VT1 > // Type of the target dense vector
479  friend inline void subAssign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
480  {
482 
486 
487  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
488 
489  const ResultType tmp( serial( rhs ) );
490  subAssign( ~lhs, tmp );
491  }
493  //**********************************************************************************************
494 
495  //**Multiplication assignment to dense vectors**************************************************
508  template< typename VT1 > // Type of the target dense vector
509  friend inline void multAssign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
510  {
512 
513  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
514 
515  if( rhs.dm_.rows() == 0UL ) {
516  reset( ~lhs );
517  }
518  else if( IsSame_v<OP,Mult> ) {
519  CT tmp( serial( rhs.dm_ ) );
520  const size_t M( tmp.rows() );
521  for( size_t i=0UL; i<M; ++i ) {
522  multAssign( (~lhs), row( tmp, i, unchecked ) );
523  }
524  }
525  else {
526  const ResultType tmp( serial( rhs ) );
527  multAssign( ~lhs, tmp );
528  }
529  }
531  //**********************************************************************************************
532 
533  //**Multiplication assignment to sparse vectors*************************************************
546  template< typename VT1 > // Type of the target dense vector
547  friend inline void multAssign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
548  {
550 
554 
555  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
556 
557  const ResultType tmp( serial( rhs ) );
558  multAssign( ~lhs, tmp );
559  }
561  //**********************************************************************************************
562 
563  //**Division assignment to vectors**************************************************************
576  template< typename VT1 > // Type of the target vector
577  friend inline void divAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
578  {
580 
584 
585  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
586 
587  const ResultType tmp( serial( rhs ) );
588  divAssign( ~lhs, tmp );
589  }
591  //**********************************************************************************************
592 
593  //**SMP assignment to vectors*******************************************************************
607  template< typename VT1 > // Type of the target vector
608  friend inline auto smpAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
609  -> EnableIf_t< UseSMPAssign_v<VT1> >
610  {
612 
613  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
614 
615  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
616  smpAssign( ~lhs, reduce<columnwise>( tmp, rhs.op_ ) );
617  }
619  //**********************************************************************************************
620 
621  //**SMP addition assignment to vectors**********************************************************
636  template< typename VT1 > // Type of the target vector
637  friend inline auto smpAddAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
638  -> EnableIf_t< UseSMPAssign_v<VT1> >
639  {
641 
642  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
643 
644  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
645  smpAddAssign( ~lhs, reduce<columnwise>( tmp, rhs.op_ ) );
646  }
648  //**********************************************************************************************
649 
650  //**SMP subtraction assignment to vectors*******************************************************
665  template< typename VT1 > // Type of the target vector
666  friend inline auto smpSubAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
667  -> EnableIf_t< UseSMPAssign_v<VT1> >
668  {
670 
671  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
672 
673  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
674  smpSubAssign( ~lhs, reduce<columnwise>( tmp, rhs.op_ ) );
675  }
677  //**********************************************************************************************
678 
679  //**SMP multiplication assignment to vectors****************************************************
694  template< typename VT1 > // Type of the target vector
695  friend inline auto smpMultAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
696  -> EnableIf_t< UseSMPAssign_v<VT1> >
697  {
699 
700  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
701 
702  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
703  smpMultAssign( ~lhs, reduce<columnwise>( tmp, rhs.op_ ) );
704  }
706  //**********************************************************************************************
707 
708  //**SMP division assignment to vectors**********************************************************
723  template< typename VT1 > // Type of the target vector
724  friend inline auto smpDivAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
725  -> EnableIf_t< UseSMPAssign_v<VT1> >
726  {
728 
729  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
730 
731  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
732  smpDivAssign( ~lhs, reduce<columnwise>( tmp, rhs.op_ ) );
733  }
735  //**********************************************************************************************
736 
737  //**Compile time checks*************************************************************************
742  //**********************************************************************************************
743 };
744 //*************************************************************************************************
745 
746 
747 
748 
749 //=================================================================================================
750 //
751 // CLASS TEMPLATE SPECIALIZATION FOR ROW-WISE REDUCTION OPERATIONS OF ROW-MAJOR MATRICES
752 //
753 //=================================================================================================
754 
755 //*************************************************************************************************
762 template< typename MT // Type of the dense matrix
763  , typename OP > // Type of the reduction operation
765  : public MatReduceExpr< DenseVector< DMatReduceExpr<MT,OP,rowwise>, false >, rowwise >
766  , private Computation
767 {
768  private:
769  //**Type definitions****************************************************************************
772  //**********************************************************************************************
773 
774  //**Serial evaluation strategy******************************************************************
776 
782  static constexpr bool useAssign = RequiresEvaluation_v<MT>;
783 
785  template< typename VT >
787  static constexpr bool UseAssign_v = useAssign;
789  //**********************************************************************************************
790 
791  //**Parallel evaluation strategy****************************************************************
793 
798  template< typename VT >
799  static constexpr bool UseSMPAssign_v = ( !MT::smpAssignable && useAssign );
801  //**********************************************************************************************
802 
803  public:
804  //**Type definitions****************************************************************************
811  using ReturnType = const ElementType;
812 
815 
817  using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
818 
820  using Operation = OP;
821  //**********************************************************************************************
822 
823  //**ConstIterator class definition**************************************************************
827  {
828  public:
829  //**Type definitions*************************************************************************
830  using IteratorCategory = std::random_access_iterator_tag;
835 
836  // STL iterator requirements
842  //*******************************************************************************************
843 
844  //**Constructor******************************************************************************
851  explicit inline ConstIterator( Operand dm, size_t index, OP op )
852  : dm_ ( dm ) // Dense matrix of the reduction expression
853  , index_( index ) // Index to the current matrix row
854  , op_ ( op ) // The reduction operation
855  {}
856  //*******************************************************************************************
857 
858  //**Addition assignment operator*************************************************************
864  inline ConstIterator& operator+=( size_t inc ) {
865  index_ += inc;
866  return *this;
867  }
868  //*******************************************************************************************
869 
870  //**Subtraction assignment operator**********************************************************
876  inline ConstIterator& operator-=( size_t dec ) {
877  index_ -= dec;
878  return *this;
879  }
880  //*******************************************************************************************
881 
882  //**Prefix increment operator****************************************************************
888  ++index_;
889  return *this;
890  }
891  //*******************************************************************************************
892 
893  //**Postfix increment operator***************************************************************
898  inline const ConstIterator operator++( int ) {
899  return ConstIterator( index_++ );
900  }
901  //*******************************************************************************************
902 
903  //**Prefix decrement operator****************************************************************
909  --index_;
910  return *this;
911  }
912  //*******************************************************************************************
913 
914  //**Postfix decrement operator***************************************************************
919  inline const ConstIterator operator--( int ) {
920  return ConstIterator( index_-- );
921  }
922  //*******************************************************************************************
923 
924  //**Element access operator******************************************************************
929  inline ReturnType operator*() const {
930  return reduce( row( dm_, index_, unchecked ), op_ );
931  }
932  //*******************************************************************************************
933 
934  //**Equality operator************************************************************************
940  inline bool operator==( const ConstIterator& rhs ) const {
941  return index_ == rhs.index_;
942  }
943  //*******************************************************************************************
944 
945  //**Inequality operator**********************************************************************
951  inline bool operator!=( const ConstIterator& rhs ) const {
952  return index_ != rhs.index_;
953  }
954  //*******************************************************************************************
955 
956  //**Less-than operator***********************************************************************
962  inline bool operator<( const ConstIterator& rhs ) const {
963  return index_ < rhs.index_;
964  }
965  //*******************************************************************************************
966 
967  //**Greater-than operator********************************************************************
973  inline bool operator>( const ConstIterator& rhs ) const {
974  return index_ > rhs.index_;
975  }
976  //*******************************************************************************************
977 
978  //**Less-or-equal-than operator**************************************************************
984  inline bool operator<=( const ConstIterator& rhs ) const {
985  return index_ <= rhs.index_;
986  }
987  //*******************************************************************************************
988 
989  //**Greater-or-equal-than operator***********************************************************
995  inline bool operator>=( const ConstIterator& rhs ) const {
996  return index_ >= rhs.index_;
997  }
998  //*******************************************************************************************
999 
1000  //**Subtraction operator*********************************************************************
1006  inline DifferenceType operator-( const ConstIterator& rhs ) const {
1007  return index_ - rhs.index_;
1008  }
1009  //*******************************************************************************************
1010 
1011  //**Addition operator************************************************************************
1018  friend inline const ConstIterator operator+( const ConstIterator& it, size_t inc ) {
1019  return ConstIterator( it.index_ + inc );
1020  }
1021  //*******************************************************************************************
1022 
1023  //**Addition operator************************************************************************
1030  friend inline const ConstIterator operator+( size_t inc, const ConstIterator& it ) {
1031  return ConstIterator( it.index_ + inc );
1032  }
1033  //*******************************************************************************************
1034 
1035  //**Subtraction operator*********************************************************************
1042  friend inline const ConstIterator operator-( const ConstIterator& it, size_t dec ) {
1043  return ConstIterator( it.index_ - dec );
1044  }
1045  //*******************************************************************************************
1046 
1047  private:
1048  //**Member variables*************************************************************************
1050  size_t index_;
1051  OP op_;
1052  //*******************************************************************************************
1053  };
1054  //**********************************************************************************************
1055 
1056  //**Compilation flags***************************************************************************
1058  static constexpr bool simdEnabled = false;
1059 
1061  static constexpr bool smpAssignable = MT::smpAssignable;
1062  //**********************************************************************************************
1063 
1064  //**Constructor*********************************************************************************
1070  explicit inline DMatReduceExpr( const MT& dm, OP op ) noexcept
1071  : dm_( dm ) // Dense matrix of the reduction expression
1072  , op_( op ) // The reduction operation
1073  {}
1074  //**********************************************************************************************
1075 
1076  //**Subscript operator**************************************************************************
1082  inline ReturnType operator[]( size_t index ) const {
1083  BLAZE_INTERNAL_ASSERT( index < dm_.rows(), "Invalid vector access index" );
1084  return reduce( row( dm_, index, unchecked ), op_ );
1085  }
1086  //**********************************************************************************************
1087 
1088  //**At function*********************************************************************************
1095  inline ReturnType at( size_t index ) const {
1096  if( index >= dm_.rows() ) {
1097  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
1098  }
1099  return (*this)[index];
1100  }
1101  //**********************************************************************************************
1102 
1103  //**Begin function******************************************************************************
1108  inline ConstIterator begin() const {
1109  return ConstIterator( dm_, 0UL, op_ );
1110  }
1111  //**********************************************************************************************
1112 
1113  //**End function********************************************************************************
1118  inline ConstIterator end() const {
1119  return ConstIterator( dm_, size(), op_ );
1120  }
1121  //**********************************************************************************************
1122 
1123  //**Size function*******************************************************************************
1128  inline size_t size() const noexcept {
1129  return dm_.rows();
1130  }
1131  //**********************************************************************************************
1132 
1133  //**Operand access******************************************************************************
1138  inline Operand operand() const noexcept {
1139  return dm_;
1140  }
1141  //**********************************************************************************************
1142 
1143  //**Operation access****************************************************************************
1148  inline Operation operation() const {
1149  return op_;
1150  }
1151  //**********************************************************************************************
1152 
1153  //**********************************************************************************************
1159  template< typename T >
1160  inline bool canAlias( const T* alias ) const noexcept {
1161  return ( dm_.isAliased( alias ) );
1162  }
1163  //**********************************************************************************************
1164 
1165  //**********************************************************************************************
1171  template< typename T >
1172  inline bool isAliased( const T* alias ) const noexcept {
1173  return ( dm_.isAliased( alias ) );
1174  }
1175  //**********************************************************************************************
1176 
1177  //**********************************************************************************************
1182  inline bool isAligned() const noexcept {
1183  return false;
1184  }
1185  //**********************************************************************************************
1186 
1187  //**********************************************************************************************
1192  inline bool canSMPAssign() const noexcept {
1193  return dm_.canSMPAssign() || ( size() > SMP_DMATREDUCE_THRESHOLD );
1194  }
1195  //**********************************************************************************************
1196 
1197  private:
1198  //**Member variables****************************************************************************
1201  //**********************************************************************************************
1202 
1203  //**Assignment to vectors***********************************************************************
1217  template< typename VT1 > // Type of the target vector
1218  friend inline auto assign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1220  {
1222 
1223  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1224 
1225  const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1226  assign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1227  }
1229  //**********************************************************************************************
1230 
1231  //**Addition assignment to vectors**************************************************************
1245  template< typename VT1 > // Type of the target vector
1246  friend inline auto addAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1248  {
1250 
1251  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1252 
1253  const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1254  addAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1255  }
1257  //**********************************************************************************************
1258 
1259  //**Subtraction assignment to vectors***********************************************************
1274  template< typename VT1 > // Type of the target vector
1275  friend inline auto subAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1276  -> EnableIf_t< UseAssign_v<VT1> >
1277  {
1279 
1280  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1281 
1282  const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1283  subAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1284  }
1286  //**********************************************************************************************
1287 
1288  //**Multiplication assignment to vectors********************************************************
1303  template< typename VT1 > // Type of the target vector
1304  friend inline auto multAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1305  -> EnableIf_t< UseAssign_v<VT1> >
1306  {
1308 
1309  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1310 
1311  const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1312  multAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1313  }
1315  //**********************************************************************************************
1316 
1317  //**Division assignment to vectors**************************************************************
1331  template< typename VT1 > // Type of the target vector
1332  friend inline auto divAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1333  -> EnableIf_t< UseAssign_v<VT1> >
1334  {
1336 
1337  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1338 
1339  const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1340  divAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1341  }
1343  //**********************************************************************************************
1344 
1345  //**SMP assignment to vectors*******************************************************************
1359  template< typename VT1 > // Type of the target vector
1360  friend inline auto smpAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1361  -> EnableIf_t< UseSMPAssign_v<VT1> >
1362  {
1364 
1365  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1366 
1367  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1368  smpAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1369  }
1371  //**********************************************************************************************
1372 
1373  //**SMP addition assignment to vectors**********************************************************
1388  template< typename VT1 > // Type of the target vector
1389  friend inline auto smpAddAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1390  -> EnableIf_t< UseSMPAssign_v<VT1> >
1391  {
1393 
1394  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1395 
1396  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1397  smpAddAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1398  }
1400  //**********************************************************************************************
1401 
1402  //**SMP subtraction assignment to vectors*******************************************************
1417  template< typename VT1 > // Type of the target vector
1418  friend inline auto smpSubAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1419  -> EnableIf_t< UseSMPAssign_v<VT1> >
1420  {
1422 
1423  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1424 
1425  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1426  smpSubAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1427  }
1429  //**********************************************************************************************
1430 
1431  //**SMP multiplication assignment to vectors****************************************************
1446  template< typename VT1 > // Type of the target vector
1447  friend inline auto smpMultAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1448  -> EnableIf_t< UseSMPAssign_v<VT1> >
1449  {
1451 
1452  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1453 
1454  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1455  smpMultAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1456  }
1458  //**********************************************************************************************
1459 
1460  //**SMP division assignment to vectors**********************************************************
1475  template< typename VT1 > // Type of the target vector
1476  friend inline auto smpDivAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1477  -> EnableIf_t< UseSMPAssign_v<VT1> >
1478  {
1480 
1481  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1482 
1483  const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1484  smpDivAssign( ~lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1485  }
1487  //**********************************************************************************************
1488 
1489  //**Compile time checks*************************************************************************
1494  //**********************************************************************************************
1495 };
1496 //*************************************************************************************************
1497 
1498 
1499 
1500 
1501 //=================================================================================================
1502 //
1503 // CLASS DEFINITION
1504 //
1505 //=================================================================================================
1506 
1507 //*************************************************************************************************
1512 template< typename MT // Type of the dense matrix
1513  , typename OP > // Type of the reduction operation
1514 struct DMatReduceExprHelper
1515 {
1516  //**Type definitions****************************************************************************
1518  using CT = RemoveReference_t< CompositeType_t<MT> >;
1519 
1521  using ET = ElementType_t<CT>;
1522  //**********************************************************************************************
1523 
1524  //**********************************************************************************************
1525  static constexpr bool value =
1526  ( CT::simdEnabled &&
1527  If_t< HasSIMDEnabled_v<OP>, GetSIMDEnabled<OP,ET,ET>, HasLoad<OP> >::value );
1528  //**********************************************************************************************
1529 };
1531 //*************************************************************************************************
1532 
1533 
1534 
1535 
1536 //=================================================================================================
1537 //
1538 // GLOBAL FUNCTIONS
1539 //
1540 //=================================================================================================
1541 
1542 //*************************************************************************************************
1555 template< typename MT // Type of the dense matrix
1556  , typename OP > // Type of the reduction operation
1557 inline auto dmatreduce( const DenseMatrix<MT,false>& dm, OP op )
1558  -> DisableIf_t< DMatReduceExprHelper<MT,OP>::value, ElementType_t<MT> >
1559 {
1560  using CT = CompositeType_t<MT>;
1561  using ET = ElementType_t<MT>;
1562 
1563  const size_t M( (~dm).rows() );
1564  const size_t N( (~dm).columns() );
1565 
1566  if( M == 0UL || N == 0UL ) return ET{};
1567  if( M == 1UL && N == 1UL ) return (~dm)(0UL,0UL);
1568 
1569  CT tmp( ~dm );
1570 
1571  BLAZE_INTERNAL_ASSERT( tmp.rows() == M, "Invalid number of rows" );
1572  BLAZE_INTERNAL_ASSERT( tmp.columns() == N, "Invalid number of columns" );
1573 
1574  ET redux0{};
1575 
1576  {
1577  redux0 = tmp(0UL,0UL);
1578 
1579  for( size_t j=1UL; j<N; ++j ) {
1580  redux0 = op( redux0, tmp(0UL,j) );
1581  }
1582  }
1583 
1584  size_t i( 1UL );
1585 
1586  for( ; (i+2UL) <= M; i+=2UL )
1587  {
1588  ET redux1( tmp(i ,0UL) );
1589  ET redux2( tmp(i+1UL,0UL) );
1590 
1591  for( size_t j=1UL; j<N; ++j ) {
1592  redux1 = op( redux1, tmp(i ,j) );
1593  redux2 = op( redux2, tmp(i+1UL,j) );
1594  }
1595 
1596  redux1 = op( redux1, redux2 );
1597  redux0 = op( redux0, redux1 );
1598  }
1599 
1600  if( i < M )
1601  {
1602  ET redux1( tmp(i,0UL) );
1603 
1604  for( size_t j=1UL; j<N; ++j ) {
1605  redux1 = op( redux1, tmp(i,j) );
1606  }
1607 
1608  redux0 = op( redux0, redux1 );
1609  }
1610 
1611  return redux0;
1612 }
1614 //*************************************************************************************************
1615 
1616 
1617 //*************************************************************************************************
1630 template< typename MT // Type of the dense matrix
1631  , typename OP > // Type of the reduction operation
1632 inline auto dmatreduce( const DenseMatrix<MT,false>& dm, OP op )
1633  -> EnableIf_t< DMatReduceExprHelper<MT,OP>::value, ElementType_t<MT> >
1634 {
1635  using CT = CompositeType_t<MT>;
1636  using ET = ElementType_t<MT>;
1637 
1638  const size_t M( (~dm).rows() );
1639  const size_t N( (~dm).columns() );
1640 
1641  if( M == 0UL || N == 0UL ) return ET{};
1642 
1643  CT tmp( ~dm );
1644 
1645  BLAZE_INTERNAL_ASSERT( tmp.rows() == M, "Invalid number of rows" );
1646  BLAZE_INTERNAL_ASSERT( tmp.columns() == N, "Invalid number of columns" );
1647 
1648  constexpr size_t SIMDSIZE = SIMDTrait<ET>::size;
1649 
1650  alignas( AlignmentOf_v<ET> ) ET array1[SIMDSIZE];
1651  alignas( AlignmentOf_v<ET> ) ET array2[SIMDSIZE];
1652  alignas( AlignmentOf_v<ET> ) ET array3[SIMDSIZE];
1653  alignas( AlignmentOf_v<ET> ) ET array4[SIMDSIZE];
1654 
1655  ET redux{};
1656 
1657  if( N >= SIMDSIZE )
1658  {
1659  const size_t jpos( N & size_t(-SIMDSIZE) );
1660  BLAZE_INTERNAL_ASSERT( ( N - ( N % SIMDSIZE ) ) == jpos, "Invalid end calculation" );
1661 
1662  SIMDTrait_t<ET> xmm1;
1663 
1664  {
1665  xmm1 = tmp.load(0UL,0UL);
1666  size_t j( SIMDSIZE );
1667 
1668  for( ; j<jpos; j+=SIMDSIZE ) {
1669  xmm1 = op( xmm1, tmp.load(0UL,j) );
1670  }
1671 
1672  if( jpos < N )
1673  {
1674  storea( array1, xmm1 );
1675 
1676  for( ; j<N; ++j ) {
1677  array1[0UL] = op( array1[0UL], tmp(0UL,j) );
1678  }
1679 
1680  xmm1 = loada( array1 );
1681  }
1682  }
1683 
1684  size_t i( 1UL );
1685 
1686  for( ; (i+4UL) <= M; i+=4UL )
1687  {
1688  xmm1 = op( xmm1, tmp.load(i,0UL) );
1689  SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1690  SIMDTrait_t<ET> xmm3( tmp.load(i+2UL,0UL) );
1691  SIMDTrait_t<ET> xmm4( tmp.load(i+3UL,0UL) );
1692  size_t j( SIMDSIZE );
1693 
1694  for( ; j<jpos; j+=SIMDSIZE ) {
1695  xmm1 = op( xmm1, tmp.load(i ,j) );
1696  xmm2 = op( xmm2, tmp.load(i+1UL,j) );
1697  xmm3 = op( xmm3, tmp.load(i+2UL,j) );
1698  xmm4 = op( xmm4, tmp.load(i+3UL,j) );
1699  }
1700 
1701  if( jpos < N )
1702  {
1703  storea( array1, xmm1 );
1704  storea( array2, xmm2 );
1705  storea( array3, xmm3 );
1706  storea( array4, xmm4 );
1707 
1708  for( ; j<N; ++j ) {
1709  array1[0UL] = op( array1[0UL], tmp(i ,j) );
1710  array2[0UL] = op( array2[0UL], tmp(i+1UL,j) );
1711  array3[0UL] = op( array3[0UL], tmp(i+2UL,j) );
1712  array4[0UL] = op( array4[0UL], tmp(i+3UL,j) );
1713  }
1714 
1715  xmm1 = loada( array1 );
1716  xmm2 = loada( array2 );
1717  xmm3 = loada( array3 );
1718  xmm4 = loada( array4 );
1719  }
1720 
1721  xmm1 = op( xmm1, xmm2 );
1722  xmm3 = op( xmm3, xmm4 );
1723  xmm1 = op( xmm1, xmm3 );
1724  }
1725 
1726  if( i+2UL <= M )
1727  {
1728  xmm1 = op( xmm1, tmp.load(i,0UL) );
1729  SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1730  size_t j( SIMDSIZE );
1731 
1732  for( ; j<jpos; j+=SIMDSIZE ) {
1733  xmm1 = op( xmm1, tmp.load(i ,j) );
1734  xmm2 = op( xmm2, tmp.load(i+1UL,j) );
1735  }
1736 
1737  if( jpos < N )
1738  {
1739  storea( array1, xmm1 );
1740  storea( array2, xmm2 );
1741 
1742  for( ; j<N; ++j ) {
1743  array1[0UL] = op( array1[0UL], tmp(i ,j) );
1744  array2[0UL] = op( array2[0UL], tmp(i+1UL,j) );
1745  }
1746 
1747  xmm1 = loada( array1 );
1748  xmm2 = loada( array2 );
1749  }
1750 
1751  xmm1 = op( xmm1, xmm2 );
1752 
1753  i += 2UL;
1754  }
1755 
1756  if( i < M )
1757  {
1758  xmm1 = op( xmm1, tmp.load(i,0UL) );
1759  size_t j( SIMDSIZE );
1760 
1761  for( ; j<jpos; j+=SIMDSIZE ) {
1762  xmm1 = op( xmm1, tmp.load(i,j) );
1763  }
1764 
1765  if( jpos < N )
1766  {
1767  storea( array1, xmm1 );
1768 
1769  for( ; j<N; ++j ) {
1770  array1[0] = op( array1[0], tmp(i,j) );
1771  }
1772 
1773  xmm1 = loada( array1 );
1774  }
1775  }
1776 
1777  redux = reduce( xmm1, op );
1778  }
1779  else
1780  {
1781  {
1782  redux = tmp(0UL,0UL);
1783  for( size_t j=1UL; j<N; ++j ) {
1784  redux = op( redux, tmp(0UL,j) );
1785  }
1786  }
1787  for( size_t i=1UL; i<M; ++i ) {
1788  for( size_t j=0UL; j<N; ++j ) {
1789  redux = op( redux, tmp(i,j) );
1790  }
1791  }
1792  }
1793 
1794  return redux;
1795 }
1797 //*************************************************************************************************
1798 
1799 
1800 //*************************************************************************************************
1812 template< typename MT > // Type of the dense matrix
1813 inline auto dmatreduce( const DenseMatrix<MT,false>& dm, Add /*op*/ )
1814  -> EnableIf_t< DMatReduceExprHelper<MT,Add>::value, ElementType_t<MT> >
1815 {
1816  using CT = CompositeType_t<MT>;
1817  using ET = ElementType_t<MT>;
1818 
1819  const size_t M( (~dm).rows() );
1820  const size_t N( (~dm).columns() );
1821 
1822  if( M == 0UL || N == 0UL ) return ET{};
1823 
1824  CT tmp( ~dm );
1825 
1826  BLAZE_INTERNAL_ASSERT( tmp.rows() == M, "Invalid number of rows" );
1827  BLAZE_INTERNAL_ASSERT( tmp.columns() == N, "Invalid number of columns" );
1828 
1829  constexpr bool remainder( !usePadding || !IsPadded_v< RemoveReference_t<CT> > );
1830  constexpr size_t SIMDSIZE = SIMDTrait<ET>::size;
1831 
1832  ET redux{};
1833 
1834  if( !remainder || N >= SIMDSIZE )
1835  {
1836  const size_t jpos( ( remainder )?( N & size_t(-SIMDSIZE) ):( N ) );
1837  BLAZE_INTERNAL_ASSERT( !remainder || ( N - ( N % SIMDSIZE ) ) == jpos, "Invalid end calculation" );
1838 
1839  SIMDTrait_t<ET> xmm1;
1840  size_t i( 0UL );
1841 
1842  for( ; (i+4UL) <= M; i+=4UL )
1843  {
1844  xmm1 += tmp.load(i,0UL);
1845  SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1846  SIMDTrait_t<ET> xmm3( tmp.load(i+2UL,0UL) );
1847  SIMDTrait_t<ET> xmm4( tmp.load(i+3UL,0UL) );
1848  size_t j( SIMDSIZE );
1849 
1850  for( ; j<jpos; j+=SIMDSIZE ) {
1851  xmm1 += tmp.load(i ,j);
1852  xmm2 += tmp.load(i+1UL,j);
1853  xmm3 += tmp.load(i+2UL,j);
1854  xmm4 += tmp.load(i+3UL,j);
1855  }
1856  for( ; remainder && j<N; ++j ) {
1857  redux += tmp(i ,j);
1858  redux += tmp(i+1UL,j);
1859  redux += tmp(i+2UL,j);
1860  redux += tmp(i+3UL,j);
1861  }
1862 
1863  xmm1 += xmm2;
1864  xmm3 += xmm4;
1865  xmm1 += xmm3;
1866  }
1867 
1868  if( i+2UL <= M )
1869  {
1870  xmm1 += tmp.load(i,0UL);
1871  SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1872  size_t j( SIMDSIZE );
1873 
1874  for( ; j<jpos; j+=SIMDSIZE ) {
1875  xmm1 += tmp.load(i ,j);
1876  xmm2 += tmp.load(i+1UL,j);
1877  }
1878  for( ; remainder && j<N; ++j ) {
1879  redux += tmp(i ,j);
1880  redux += tmp(i+1UL,j);
1881  }
1882 
1883  xmm1 += xmm2;
1884 
1885  i += 2UL;
1886  }
1887 
1888  if( i < M )
1889  {
1890  xmm1 += tmp.load(i,0UL);
1891  size_t j( SIMDSIZE );
1892 
1893  for( ; j<jpos; j+=SIMDSIZE ) {
1894  xmm1 += tmp.load(i,j);
1895  }
1896  for( ; remainder && j<N; ++j ) {
1897  redux += tmp(i,j);
1898  }
1899  }
1900 
1901  redux += sum( xmm1 );
1902  }
1903  else
1904  {
1905  for( size_t i=0UL; i<M; ++i ) {
1906  for( size_t j=0UL; j<N; ++j ) {
1907  redux += tmp(i,j);
1908  }
1909  }
1910  }
1911 
1912  return redux;
1913 
1914 }
1916 //*************************************************************************************************
1917 
1918 
1919 //*************************************************************************************************
1930 template< typename MT > // Type of the dense matrix
1931 inline auto dmatreduce( const DenseMatrix<MT,false>& dm, Min /*op*/ )
1932  -> EnableIf_t< IsUniform_v<MT>, ElementType_t<MT> >
1933 {
1934  return (~dm)(0UL,0UL);
1935 }
1937 //*************************************************************************************************
1938 
1939 
1940 //*************************************************************************************************
1951 template< typename MT > // Type of the dense matrix
1952 inline auto dmatreduce( const DenseMatrix<MT,false>& dm, Max /*op*/ )
1953  -> EnableIf_t< IsUniform_v<MT>, ElementType_t<MT> >
1954 {
1955  return (~dm)(0UL,0UL);
1956 }
1958 //*************************************************************************************************
1959 
1960 
1961 //*************************************************************************************************
1974 template< typename MT // Type of the dense matrix
1975  , typename OP > // Type of the reduction operation
1976 inline ElementType_t<MT> dmatreduce( const DenseMatrix<MT,true>& dm, OP op )
1977 {
1978  return dmatreduce( trans( ~dm ), op );
1979 }
1981 //*************************************************************************************************
1982 
1983 
1984 //*************************************************************************************************
2013 template< typename MT // Type of the dense matrix
2014  , bool SO // Storage order
2015  , typename OP > // Type of the reduction operation
2016 inline decltype(auto) reduce( const DenseMatrix<MT,SO>& dm, OP op )
2017 {
2019 
2020  return dmatreduce( ~dm, op );
2021 }
2022 //*************************************************************************************************
2023 
2024 
2025 //*************************************************************************************************
2034 template< size_t RF // Reduction flag
2035  , typename MT // Type of the dense matrix
2036  , typename OP > // Type of the reduction operation
2037 inline const DMatReduceExpr<MT,OP,RF> reduce_backend( const DenseMatrix<MT,false>& dm, OP op )
2038 {
2039  using ReturnType = const DMatReduceExpr<MT,OP,RF>;
2040  return ReturnType( ~dm, op );
2041 }
2043 //*************************************************************************************************
2044 
2045 
2046 //*************************************************************************************************
2055 template< size_t RF // Reduction flag
2056  , typename MT // Type of the dense matrix
2057  , typename OP > // Type of the reduction operation
2058 inline decltype(auto) reduce_backend( const DenseMatrix<MT,true>& dm, OP op )
2059 {
2060  return trans( reduce<1UL-RF>( trans( ~dm ), op ) );
2061 }
2063 //*************************************************************************************************
2064 
2065 
2066 //*************************************************************************************************
2112 template< size_t RF // Reduction flag
2113  , typename MT // Type of the dense matrix
2114  , bool SO // Storage order
2115  , typename OP > // Type of the reduction operation
2116 inline decltype(auto) reduce( const DenseMatrix<MT,SO>& dm, OP op )
2117 {
2119 
2120  BLAZE_STATIC_ASSERT_MSG( RF < 2UL, "Invalid reduction flag" );
2121 
2122  return reduce_backend<RF>( ~dm, op );
2123 }
2124 //*************************************************************************************************
2125 
2126 
2127 //*************************************************************************************************
2144 template< typename MT // Type of the dense matrix
2145  , bool SO > // Storage order
2146 inline decltype(auto) sum( const DenseMatrix<MT,SO>& dm )
2147 {
2149 
2150  return reduce( ~dm, Add() );
2151 }
2152 //*************************************************************************************************
2153 
2154 
2155 //*************************************************************************************************
2188 template< size_t RF // Reduction flag
2189  , typename MT // Type of the dense matrix
2190  , bool SO > // Storage order
2191 inline decltype(auto) sum( const DenseMatrix<MT,SO>& dm )
2192 {
2194 
2195  return reduce<RF>( ~dm, Add() );
2196 }
2197 //*************************************************************************************************
2198 
2199 
2200 //*************************************************************************************************
2217 template< typename MT // Type of the dense matrix
2218  , bool SO > // Storage order
2219 inline decltype(auto) prod( const DenseMatrix<MT,SO>& dm )
2220 {
2222 
2223  return reduce( ~dm, Mult() );
2224 }
2225 //*************************************************************************************************
2226 
2227 
2228 //*************************************************************************************************
2261 template< size_t RF // Reduction flag
2262  , typename MT // Type of the dense matrix
2263  , bool SO > // Storage order
2264 inline decltype(auto) prod( const DenseMatrix<MT,SO>& dm )
2265 {
2267 
2268  return reduce<RF>( ~dm, Mult() );
2269 }
2270 //*************************************************************************************************
2271 
2272 
2273 //*************************************************************************************************
2291 template< typename MT // Type of the dense matrix
2292  , bool SO > // Storage order
2293 inline decltype(auto) min( const DenseMatrix<MT,SO>& dm )
2294 {
2296 
2297  return reduce( ~dm, Min() );
2298 }
2299 //*************************************************************************************************
2300 
2301 
2302 //*************************************************************************************************
2332 template< size_t RF // Reduction flag
2333  , typename MT // Type of the dense matrix
2334  , bool SO > // Storage order
2335 inline decltype(auto) min( const DenseMatrix<MT,SO>& dm )
2336 {
2338 
2339  return reduce<RF>( ~dm, Min() );
2340 }
2341 //*************************************************************************************************
2342 
2343 
2344 //*************************************************************************************************
2362 template< typename MT // Type of the dense matrix
2363  , bool SO > // Storage order
2364 inline decltype(auto) max( const DenseMatrix<MT,SO>& dm )
2365 {
2367 
2368  return reduce( ~dm, Max() );
2369 }
2370 //*************************************************************************************************
2371 
2372 
2373 //*************************************************************************************************
2403 template< size_t RF // Reduction flag
2404  , typename MT // Type of the dense matrix
2405  , bool SO > // Storage order
2406 inline decltype(auto) max( const DenseMatrix<MT,SO>& dm )
2407 {
2409 
2410  return reduce<RF>( ~dm, Max() );
2411 }
2412 //*************************************************************************************************
2413 
2414 } // namespace blaze
2415 
2416 #endif
ElementType_t< MT > ET
Element type of the dense matrix expression.
Definition: DMatReduceExpr.h:133
Pointer difference type of the Blaze library.
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Header file for the blaze::checked and blaze::unchecked instances.
bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:973
ConstIterator & operator--()
Pre-decrement operator.
Definition: DMatReduceExpr.h:908
ConstIterator(Operand dm, size_t index, OP op)
Constructor for the ConstIterator class.
Definition: DMatReduceExpr.h:851
Header file for the HasLoad type trait.
DMatReduceExpr(const MT &dm, OP op) noexcept
Constructor for the DMatReduceExpr class.
Definition: DMatReduceExpr.h:181
Header file for basic type definitions.
ElementType * PointerType
Pointer return type.
Definition: DMatReduceExpr.h:832
Header file for the Add functor.
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
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatReduceExpr.h:1182
Header file for the MatReduceExpr base class.
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
SIMDTrait_t< ElementType > SIMDType
Resulting SIMD element type.
Definition: DMatReduceExpr.h:810
Header file for the serial shim.
Base class for all matrix reduction expression templates.The MatReduceExpr class serves as a tag for ...
Definition: MatReduceExpr.h:67
ResultType_t< MT > RT
Result type of the dense matrix expression.
Definition: DMatReduceExpr.h:132
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:224
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:61
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatReduceExpr.h:263
Header file for the IsSame and IsStrictlySame type traits.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:3077
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatReduceExpr.h:158
Expression object for row-wise row-major dense matrix reduction operations.This specialization of the...
Definition: DMatReduceExpr.h:764
typename SIMDTrait< T >::Type SIMDTrait_t
Auxiliary alias declaration for the SIMDTrait class template.The SIMDTrait_t alias declaration provid...
Definition: SIMDTrait.h:315
decltype(auto) prod(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of multiplication.
Definition: DMatReduceExpr.h:2219
Header file for the DenseVector base class.
Generic wrapper for the addition operator.
Definition: Add.h:80
PointerType pointer
Pointer return type.
Definition: DMatReduceExpr.h:839
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DMatReduceExpr.h:1095
Header file for the Computation base class.
ResultType_t< MT > RT
Result type of the dense matrix expression.
Definition: DMatReduceExpr.h:770
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatReduceExpr.h:283
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:123
OP Operation
Data type of the custom unary operation.
Definition: DMatReduceExpr.h:164
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatReduceExpr.h:809
Header file for the reduce trait.
friend const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: DMatReduceExpr.h:1042
DMatReduceExpr(const MT &dm, OP op) noexcept
Constructor for the DMatReduceExpr class.
Definition: DMatReduceExpr.h:1070
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Expression object for column-wise row-major dense matrix reduction operations.This specialization of ...
Definition: DMatReduceExpr.h:126
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
auto smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:220
ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DMatReduceExpr.h:876
size_t index_
Index to the current matrix row.
Definition: DMatReduceExpr.h:1050
const ElementType ReturnType
Return type for expression template evaluations.
Definition: DMatReduceExpr.h:811
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: DMatReduceExpr.h:1006
Constraint on the transpose flag of vector types.
bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:962
Base template for row-major dense matrix reduction operations.The DMatReduceExpr class represents the...
Definition: DMatReduceExpr.h:104
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatReduceExpr.h:1172
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DMatReduceExpr.h:193
decltype(auto) reduce(const DenseMatrix< MT, SO > &dm, OP op)
Performs a custom reduction operation on the given dense matrix.
Definition: DMatReduceExpr.h:2016
Header file for the DisableIf class template.
Header file for the IsUniform type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Compile time assertion.
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: DMatReduceExpr.h:1108
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DMatReduceExpr.h:1082
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:940
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3080
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
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatReduceExpr.h:154
const ConstIterator operator--(int)
Post-decrement operator.
Definition: DMatReduceExpr.h:919
#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
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2146
Header file for the Mult functor.
Header file for the DenseMatrix base class.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DMatReduceExpr.h:1128
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3086
Header file for all SIMD functionality.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Operation op_
The reduction operation.
Definition: DMatReduceExpr.h:1200
Operation operation() const
Returns a copy of the reduction operation.
Definition: DMatReduceExpr.h:1148
bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:995
BLAZE_ALWAYS_INLINE EnableIf_t< IsIntegral_v< T1 > &&HasSize_v< T1, 1UL > > storea(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned store of a vector of 1-byte integral values.
Definition: Storea.h:78
ReduceTrait_t< RT, OP, rowwise > ResultType
Result type for expression template evaluations.
Definition: DMatReduceExpr.h:807
bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:984
Constraint on the data type.
Header file for the exception macros of the math module.
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1179
Constraint on the data type.
Header file for all forward declarations for expression class templates.
ReferenceType reference
Reference return type.
Definition: DMatReduceExpr.h:840
Header file for the EnableIf class template.
Header file for the IsPadded type trait.
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatReduceExpr.h:273
ReduceTrait_t< RT, OP, columnwise > ResultType
Result type for expression template evaluations.
Definition: DMatReduceExpr.h:153
If_t< useAssign, const ResultType, const DMatReduceExpr &> CompositeType
Data type for composite expression templates.
Definition: DMatReduceExpr.h:814
If_t< IsExpression_v< MT >, const MT, const MT &> Operand
Composite type of the left-hand side dense matrix expression.
Definition: DMatReduceExpr.h:161
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DMatReduceExpr.h:206
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:951
ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DMatReduceExpr.h:864
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DMatReduceExpr.h:219
Header file for the IsSIMDEnabled type trait.
constexpr size_t columnwise
Reduction flag for column-wise reduction operations.
Definition: ReductionFlag.h:90
#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
typename ReduceTrait< T, OP, RF... >::Type ReduceTrait_t
Auxiliary alias declaration for the ReduceTrait class template.The ReduceTrait_t alias declaration pr...
Definition: ReduceTrait.h:174
Operand dm_
Dense matrix of the reduction expression.
Definition: DMatReduceExpr.h:1049
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
Generic wrapper for the max() function.
Definition: Max.h:79
ElementType_t< MT > ET
Element type of the dense matrix expression.
Definition: DMatReduceExpr.h:771
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
Operand dm_
Dense matrix of the reduction expression.
Definition: DMatReduceExpr.h:290
friend const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: DMatReduceExpr.h:1030
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
const ConstIterator operator++(int)
Post-increment operator.
Definition: DMatReduceExpr.h:898
constexpr bool IsPadded_v
Auxiliary variable template for the IsPadded type trait.The IsPadded_v variable template provides a c...
Definition: IsPadded.h:135
Operand dm_
Dense matrix of the reduction expression.
Definition: DMatReduceExpr.h:1199
#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
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DMatReduceExpr.h:830
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatReduceExpr.h:1160
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatReduceExpr.h:155
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Operation op_
The reduction operation.
Definition: DMatReduceExpr.h:291
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatReduceExpr.h:1138
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
Header file for the HasMember type traits.
ConstIterator & operator++()
Pre-increment operator.
Definition: DMatReduceExpr.h:887
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
Header file for the RemoveReference type trait.
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > loada(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loada.h:79
If_t< IsExpression_v< MT >, const MT, const MT &> Operand
Composite type of the left-hand side dense matrix expression.
Definition: DMatReduceExpr.h:817
ValueType value_type
Type of the underlying elements.
Definition: DMatReduceExpr.h:838
ReturnType operator*() const
Direct access to the element at the current iterator position.
Definition: DMatReduceExpr.h:929
Generic wrapper for the min() function.
Definition: Min.h:79
CompositeType_t< MT > CT
Composite type of the dense matrix expression.
Definition: DMatReduceExpr.h:134
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatReduceExpr.h:808
Header file for the Min functor.
IteratorCategory iterator_category
The iterator category.
Definition: DMatReduceExpr.h:837
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatReduceExpr.h:251
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:61
OP op_
The reduction operation.
Definition: DMatReduceExpr.h:1051
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatReduceExpr.h:1192
constexpr size_t rowwise
Reduction flag for row-wise reduction operations.
Definition: ReductionFlag.h:70
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:186
friend const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: DMatReduceExpr.h:1018
Generic wrapper for the multiplication operator.
Definition: Mult.h:77
const ElementType ReturnType
Return type for expression template evaluations.
Definition: DMatReduceExpr.h:157
ElementType ValueType
Type of the underlying elements.
Definition: DMatReduceExpr.h:831
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
ElementType & ReferenceType
Reference return type.
Definition: DMatReduceExpr.h:833
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: RowVector.h:61
Header file for the Max functor.
Operation operation() const
Returns a copy of the reduction operation.
Definition: DMatReduceExpr.h:239
SIMDTrait_t< ElementType > SIMDType
Resulting SIMD element type.
Definition: DMatReduceExpr.h:156
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: DMatReduceExpr.h:1118
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatReduceExpr.h:229
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#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
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:191
OP Operation
Data type of the custom unary operation.
Definition: DMatReduceExpr.h:820
Header file for the reduction flags.
Constraint on the transpose flag of vector types.
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
decltype(auto) map(const DenseMatrix< MT1, SO > &lhs, const DenseMatrix< MT2, SO > &rhs, OP op)
Evaluates the given binary operation on each single element of the dense matrices lhs and rhs...
Definition: DMatDMatMapExpr.h:1110