Blaze 3.9
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>
65#include <blaze/math/SIMD.h>
77#include <blaze/util/Assert.h>
78#include <blaze/util/EnableIf.h>
80#include <blaze/util/mpl/If.h>
82#include <blaze/util/Types.h>
87
88
89namespace blaze {
90
91//=================================================================================================
92//
93// CLASS DEFINITION
94//
95//=================================================================================================
96
97//*************************************************************************************************
104template< typename MT // Type of the dense matrix
105 , typename OP // Type of the reduction operation
106 , ReductionFlag RF > // Reduction flag
108{};
109//*************************************************************************************************
110
111
112
113
114//=================================================================================================
115//
116// CLASS TEMPLATE SPECIALIZATION FOR COLUMN-WISE REDUCTION OPERATIONS OF ROW-MAJOR MATRICES
117//
118//=================================================================================================
119
120//*************************************************************************************************
127template< typename MT // Type of the dense matrix
128 , typename OP > // Type of the reduction operation
130 : public MatReduceExpr< DenseVector< DMatReduceExpr<MT,OP,columnwise>, true >, columnwise >
131 , private Computation
132{
133 private:
134 //**Type definitions****************************************************************************
137 //**********************************************************************************************
138
139 //**Parallel evaluation strategy****************************************************************
141
146 template< typename VT >
147 static constexpr bool UseSMPAssign_v = ( !MT::smpAssignable && RequiresEvaluation_v<MT> );
149 //**********************************************************************************************
150
151 public:
152 //**Type definitions****************************************************************************
155
158
163 using ReturnType = const ElementType;
164 using CompositeType = const ResultType;
165
167 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
168
170 using Operation = OP;
171 //**********************************************************************************************
172
173 //**Compilation flags***************************************************************************
175 static constexpr bool simdEnabled = false;
176
178 static constexpr bool smpAssignable = MT::smpAssignable;
179 //**********************************************************************************************
180
181 //**Constructor*********************************************************************************
187 inline DMatReduceExpr( const MT& dm, OP op ) noexcept
188 : dm_( dm ) // Dense matrix of the reduction expression
189 , op_( std::move(op) ) // The reduction operation
190 {}
191 //**********************************************************************************************
192
193 //**Subscript operator**************************************************************************
199 inline ReturnType operator[]( size_t index ) const {
200 BLAZE_INTERNAL_ASSERT( index < dm_.columns(), "Invalid vector access index" );
201 return reduce( column( dm_, index, unchecked ), op_ );
202 }
203 //**********************************************************************************************
204
205 //**At function*********************************************************************************
212 inline ReturnType at( size_t index ) const {
213 if( index >= dm_.columns() ) {
214 BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
215 }
216 return (*this)[index];
217 }
218 //**********************************************************************************************
219
220 //**Size function*******************************************************************************
225 inline size_t size() const noexcept {
226 return dm_.columns();
227 }
228 //**********************************************************************************************
229
230 //**Operand access******************************************************************************
235 inline Operand operand() const noexcept {
236 return dm_;
237 }
238 //**********************************************************************************************
239
240 //**Operation access****************************************************************************
245 inline Operation operation() const {
246 return op_;
247 }
248 //**********************************************************************************************
249
250 //**********************************************************************************************
256 template< typename T >
257 inline bool canAlias( const T* alias ) const noexcept {
258 return ( dm_.isAliased( alias ) );
259 }
260 //**********************************************************************************************
261
262 //**********************************************************************************************
268 template< typename T >
269 inline bool isAliased( const T* alias ) const noexcept {
270 return ( dm_.isAliased( alias ) );
271 }
272 //**********************************************************************************************
273
274 //**********************************************************************************************
279 inline bool isAligned() const noexcept {
280 return false;
281 }
282 //**********************************************************************************************
283
284 //**********************************************************************************************
289 inline bool canSMPAssign() const noexcept {
290 return dm_.canSMPAssign() || ( size() > SMP_DMATREDUCE_THRESHOLD );
291 }
292 //**********************************************************************************************
293
294 private:
295 //**Member variables****************************************************************************
298 //**********************************************************************************************
299
300 //**Assignment to dense vectors*****************************************************************
312 template< typename VT1 > // Type of the target dense vector
313 friend inline void assign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
314 {
316
317 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
318
319 const size_t M( rhs.dm_.rows() );
320
321 if( M == 0UL ) {
322 reset( *lhs );
323 return;
324 }
325
326 CT tmp( serial( rhs.dm_ ) );
327
328 assign( *lhs, row( tmp, 0UL, unchecked ) );
329 for( size_t i=1UL; i<M; ++i ) {
330 assign( *lhs, map( *lhs, row( tmp, i, unchecked ), rhs.op_ ) );
331 }
332 }
334 //**********************************************************************************************
335
336 //**Assignment to sparse vectors****************************************************************
348 template< typename VT1 > // Type of the target dense vector
349 friend inline void assign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
350 {
352
356
357 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
358
359 const ResultType tmp( serial( rhs ) );
360 assign( *lhs, tmp );
361 }
363 //**********************************************************************************************
364
365 //**Addition assignment to dense vectors********************************************************
378 template< typename VT1 > // Type of the target dense vector
379 friend inline void addAssign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
380 {
382
383 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
384
385 if( rhs.dm_.rows() == 0UL ) {
386 return;
387 }
388 else if( IsSame_v<OP,Add> ) {
389 CT tmp( serial( rhs.dm_ ) );
390 const size_t M( tmp.rows() );
391 for( size_t i=0UL; i<M; ++i ) {
392 addAssign( (*lhs), row( tmp, i, unchecked ) );
393 }
394 }
395 else {
396 const ResultType tmp( serial( rhs ) );
397 addAssign( *lhs, tmp );
398 }
399 }
401 //**********************************************************************************************
402
403 //**Addition assignment to sparse vectors*******************************************************
416 template< typename VT1 > // Type of the target dense vector
417 friend inline void addAssign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
418 {
420
424
425 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
426
427 const ResultType tmp( serial( rhs ) );
428 addAssign( *lhs, tmp );
429 }
431 //**********************************************************************************************
432
433 //**Subtraction assignment to dense vectors*****************************************************
446 template< typename VT1 > // Type of the target dense vector
447 friend inline void subAssign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
448 {
450
451 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
452
453 if( rhs.dm_.rows() == 0UL ) {
454 return;
455 }
456 else if( IsSame_v<OP,Add> ) {
457 CT tmp( serial( rhs.dm_ ) );
458 const size_t M( tmp.rows() );
459 for( size_t i=0UL; i<M; ++i ) {
460 subAssign( (*lhs), row( tmp, i, unchecked ) );
461 }
462 }
463 else {
464 const ResultType tmp( serial( rhs ) );
465 subAssign( *lhs, tmp );
466 }
467 }
469 //**********************************************************************************************
470
471 //**Subtraction assignment to sparse vectors****************************************************
484 template< typename VT1 > // Type of the target dense vector
485 friend inline void subAssign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
486 {
488
492
493 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
494
495 const ResultType tmp( serial( rhs ) );
496 subAssign( *lhs, tmp );
497 }
499 //**********************************************************************************************
500
501 //**Multiplication assignment to dense vectors**************************************************
514 template< typename VT1 > // Type of the target dense vector
515 friend inline void multAssign( DenseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
516 {
518
519 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
520
521 if( rhs.dm_.rows() == 0UL ) {
522 reset( *lhs );
523 }
524 else if( IsSame_v<OP,Mult> ) {
525 CT tmp( serial( rhs.dm_ ) );
526 const size_t M( tmp.rows() );
527 for( size_t i=0UL; i<M; ++i ) {
528 multAssign( (*lhs), row( tmp, i, unchecked ) );
529 }
530 }
531 else {
532 const ResultType tmp( serial( rhs ) );
533 multAssign( *lhs, tmp );
534 }
535 }
537 //**********************************************************************************************
538
539 //**Multiplication assignment to sparse vectors*************************************************
552 template< typename VT1 > // Type of the target dense vector
553 friend inline void multAssign( SparseVector<VT1,true>& lhs, const DMatReduceExpr& rhs )
554 {
556
560
561 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
562
563 const ResultType tmp( serial( rhs ) );
564 multAssign( *lhs, tmp );
565 }
567 //**********************************************************************************************
568
569 //**Division assignment to vectors**************************************************************
582 template< typename VT1 > // Type of the target vector
583 friend inline void divAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
584 {
586
590
591 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
592
593 const ResultType tmp( serial( rhs ) );
594 divAssign( *lhs, tmp );
595 }
597 //**********************************************************************************************
598
599 //**SMP assignment to vectors*******************************************************************
613 template< typename VT1 > // Type of the target vector
614 friend inline auto smpAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
615 -> EnableIf_t< UseSMPAssign_v<VT1> >
616 {
618
619 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
620
621 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
622 smpAssign( *lhs, reduce<columnwise>( tmp, rhs.op_ ) );
623 }
625 //**********************************************************************************************
626
627 //**SMP addition assignment to vectors**********************************************************
642 template< typename VT1 > // Type of the target vector
643 friend inline auto smpAddAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
644 -> EnableIf_t< UseSMPAssign_v<VT1> >
645 {
647
648 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
649
650 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
651 smpAddAssign( *lhs, reduce<columnwise>( tmp, rhs.op_ ) );
652 }
654 //**********************************************************************************************
655
656 //**SMP subtraction assignment to vectors*******************************************************
671 template< typename VT1 > // Type of the target vector
672 friend inline auto smpSubAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
673 -> EnableIf_t< UseSMPAssign_v<VT1> >
674 {
676
677 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
678
679 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
680 smpSubAssign( *lhs, reduce<columnwise>( tmp, rhs.op_ ) );
681 }
683 //**********************************************************************************************
684
685 //**SMP multiplication assignment to vectors****************************************************
700 template< typename VT1 > // Type of the target vector
701 friend inline auto smpMultAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
702 -> EnableIf_t< UseSMPAssign_v<VT1> >
703 {
705
706 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
707
708 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
709 smpMultAssign( *lhs, reduce<columnwise>( tmp, rhs.op_ ) );
710 }
712 //**********************************************************************************************
713
714 //**SMP division assignment to vectors**********************************************************
729 template< typename VT1 > // Type of the target vector
730 friend inline auto smpDivAssign( Vector<VT1,true>& lhs, const DMatReduceExpr& rhs )
731 -> EnableIf_t< UseSMPAssign_v<VT1> >
732 {
734
735 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
736
737 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
738 smpDivAssign( *lhs, reduce<columnwise>( tmp, rhs.op_ ) );
739 }
741 //**********************************************************************************************
742
743 //**Compile time checks*************************************************************************
748 //**********************************************************************************************
749};
750//*************************************************************************************************
751
752
753
754
755//=================================================================================================
756//
757// CLASS TEMPLATE SPECIALIZATION FOR ROW-WISE REDUCTION OPERATIONS OF ROW-MAJOR MATRICES
758//
759//=================================================================================================
760
761//*************************************************************************************************
768template< typename MT // Type of the dense matrix
769 , typename OP > // Type of the reduction operation
771 : public MatReduceExpr< DenseVector< DMatReduceExpr<MT,OP,rowwise>, false >, rowwise >
772 , private Computation
773{
774 private:
775 //**Type definitions****************************************************************************
777 //**********************************************************************************************
778
779 //**Serial evaluation strategy******************************************************************
781
787 static constexpr bool useAssign = RequiresEvaluation_v<MT>;
788
791 template< typename VT >
792 static constexpr bool UseAssign_v = useAssign;
794 //**********************************************************************************************
795
796 //**Parallel evaluation strategy****************************************************************
798
803 template< typename VT >
804 static constexpr bool UseSMPAssign_v = ( !MT::smpAssignable && useAssign );
806 //**********************************************************************************************
807
808 public:
809 //**Type definitions****************************************************************************
812
815
820 using ReturnType = const ElementType;
821
824
826 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
827
829 using Operation = OP;
830 //**********************************************************************************************
831
832 //**ConstIterator class definition**************************************************************
835 class ConstIterator
836 {
837 public:
838 //**Type definitions*************************************************************************
839 using IteratorCategory = std::random_access_iterator_tag;
843 using DifferenceType = ptrdiff_t;
844
845 // STL iterator requirements
851 //*******************************************************************************************
852
853 //**Constructor******************************************************************************
860 inline ConstIterator( Operand dm, size_t index, OP op )
861 : dm_ ( dm ) // Dense matrix of the reduction expression
862 , index_( index ) // Index to the current matrix row
863 , op_ ( std::move(op) ) // The reduction operation
864 {}
865 //*******************************************************************************************
866
867 //**Addition assignment operator*************************************************************
873 inline BLAZE_DEVICE_CALLABLE ConstIterator& operator+=( size_t inc ) {
874 index_ += inc;
875 return *this;
876 }
877 //*******************************************************************************************
878
879 //**Subtraction assignment operator**********************************************************
885 inline BLAZE_DEVICE_CALLABLE ConstIterator& operator-=( size_t dec ) {
886 index_ -= dec;
887 return *this;
888 }
889 //*******************************************************************************************
890
891 //**Prefix increment operator****************************************************************
896 inline BLAZE_DEVICE_CALLABLE ConstIterator& operator++() {
897 ++index_;
898 return *this;
899 }
900 //*******************************************************************************************
901
902 //**Postfix increment operator***************************************************************
907 inline BLAZE_DEVICE_CALLABLE const ConstIterator operator++( int ) {
908 return ConstIterator( index_++ );
909 }
910 //*******************************************************************************************
911
912 //**Prefix decrement operator****************************************************************
917 inline BLAZE_DEVICE_CALLABLE ConstIterator& operator--() {
918 --index_;
919 return *this;
920 }
921 //*******************************************************************************************
922
923 //**Postfix decrement operator***************************************************************
928 inline BLAZE_DEVICE_CALLABLE const ConstIterator operator--( int ) {
929 return ConstIterator( index_-- );
930 }
931 //*******************************************************************************************
932
933 //**Element access operator******************************************************************
938 inline ReturnType operator*() const {
939 return reduce( row( dm_, index_, unchecked ), op_ );
940 }
941 //*******************************************************************************************
942
943 //**Equality operator************************************************************************
949 inline bool operator==( const ConstIterator& rhs ) const {
950 return index_ == rhs.index_;
951 }
952 //*******************************************************************************************
953
954 //**Inequality operator**********************************************************************
960 inline bool operator!=( const ConstIterator& rhs ) const {
961 return index_ != rhs.index_;
962 }
963 //*******************************************************************************************
964
965 //**Less-than operator***********************************************************************
971 inline bool operator<( const ConstIterator& rhs ) const {
972 return index_ < rhs.index_;
973 }
974 //*******************************************************************************************
975
976 //**Greater-than operator********************************************************************
982 inline bool operator>( const ConstIterator& rhs ) const {
983 return index_ > rhs.index_;
984 }
985 //*******************************************************************************************
986
987 //**Less-or-equal-than operator**************************************************************
993 inline bool operator<=( const ConstIterator& rhs ) const {
994 return index_ <= rhs.index_;
995 }
996 //*******************************************************************************************
997
998 //**Greater-or-equal-than operator***********************************************************
1004 inline bool operator>=( const ConstIterator& rhs ) const {
1005 return index_ >= rhs.index_;
1006 }
1007 //*******************************************************************************************
1008
1009 //**Subtraction operator*********************************************************************
1015 inline DifferenceType operator-( const ConstIterator& rhs ) const {
1016 return index_ - rhs.index_;
1017 }
1018 //*******************************************************************************************
1019
1020 //**Addition operator************************************************************************
1027 friend inline const ConstIterator operator+( const ConstIterator& it, size_t inc ) {
1028 return ConstIterator( it.index_ + inc );
1029 }
1030 //*******************************************************************************************
1031
1032 //**Addition operator************************************************************************
1039 friend inline const ConstIterator operator+( size_t inc, const ConstIterator& it ) {
1040 return ConstIterator( it.index_ + inc );
1041 }
1042 //*******************************************************************************************
1043
1044 //**Subtraction operator*********************************************************************
1051 friend inline const ConstIterator operator-( const ConstIterator& it, size_t dec ) {
1052 return ConstIterator( it.index_ - dec );
1053 }
1054 //*******************************************************************************************
1055
1056 private:
1057 //**Member variables*************************************************************************
1059 size_t index_;
1060 OP op_;
1061 //*******************************************************************************************
1062 };
1063 //**********************************************************************************************
1064
1065 //**Compilation flags***************************************************************************
1067 static constexpr bool simdEnabled = false;
1068
1070 static constexpr bool smpAssignable = MT::smpAssignable;
1071 //**********************************************************************************************
1072
1073 //**Constructor*********************************************************************************
1079 inline DMatReduceExpr( const MT& dm, OP op ) noexcept
1080 : dm_( dm ) // Dense matrix of the reduction expression
1081 , op_( std::move(op) ) // The reduction operation
1082 {}
1083 //**********************************************************************************************
1084
1085 //**Subscript operator**************************************************************************
1091 inline ReturnType operator[]( size_t index ) const {
1092 BLAZE_INTERNAL_ASSERT( index < dm_.rows(), "Invalid vector access index" );
1093 return reduce( row( dm_, index, unchecked ), op_ );
1094 }
1095 //**********************************************************************************************
1096
1097 //**At function*********************************************************************************
1104 inline ReturnType at( size_t index ) const {
1105 if( index >= dm_.rows() ) {
1106 BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
1107 }
1108 return (*this)[index];
1109 }
1110 //**********************************************************************************************
1111
1112 //**Begin function******************************************************************************
1117 inline ConstIterator begin() const {
1118 return ConstIterator( dm_, 0UL, op_ );
1119 }
1120 //**********************************************************************************************
1121
1122 //**End function********************************************************************************
1127 inline ConstIterator end() const {
1128 return ConstIterator( dm_, size(), op_ );
1129 }
1130 //**********************************************************************************************
1131
1132 //**Size function*******************************************************************************
1137 inline size_t size() const noexcept {
1138 return dm_.rows();
1139 }
1140 //**********************************************************************************************
1141
1142 //**Operand access******************************************************************************
1147 inline Operand operand() const noexcept {
1148 return dm_;
1149 }
1150 //**********************************************************************************************
1151
1152 //**Operation access****************************************************************************
1157 inline Operation operation() const {
1158 return op_;
1159 }
1160 //**********************************************************************************************
1161
1162 //**********************************************************************************************
1168 template< typename T >
1169 inline bool canAlias( const T* alias ) const noexcept {
1170 return ( dm_.isAliased( alias ) );
1171 }
1172 //**********************************************************************************************
1173
1174 //**********************************************************************************************
1180 template< typename T >
1181 inline bool isAliased( const T* alias ) const noexcept {
1182 return ( dm_.isAliased( alias ) );
1183 }
1184 //**********************************************************************************************
1185
1186 //**********************************************************************************************
1191 inline bool isAligned() const noexcept {
1192 return false;
1193 }
1194 //**********************************************************************************************
1195
1196 //**********************************************************************************************
1201 inline bool canSMPAssign() const noexcept {
1202 return dm_.canSMPAssign() || ( size() > SMP_DMATREDUCE_THRESHOLD );
1203 }
1204 //**********************************************************************************************
1205
1206 private:
1207 //**Member variables****************************************************************************
1210 //**********************************************************************************************
1211
1212 //**Assignment to vectors***********************************************************************
1226 template< typename VT1 > // Type of the target vector
1227 friend inline auto assign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1229 {
1231
1232 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1233
1234 const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1235 assign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1236 }
1238 //**********************************************************************************************
1239
1240 //**Addition assignment to vectors**************************************************************
1254 template< typename VT1 > // Type of the target vector
1255 friend inline auto addAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1257 {
1259
1260 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1261
1262 const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1263 addAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1264 }
1266 //**********************************************************************************************
1267
1268 //**Subtraction assignment to vectors***********************************************************
1283 template< typename VT1 > // Type of the target vector
1284 friend inline auto subAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1285 -> EnableIf_t< UseAssign_v<VT1> >
1286 {
1288
1289 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1290
1291 const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1292 subAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1293 }
1295 //**********************************************************************************************
1296
1297 //**Multiplication assignment to vectors********************************************************
1312 template< typename VT1 > // Type of the target vector
1313 friend inline auto multAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1314 -> EnableIf_t< UseAssign_v<VT1> >
1315 {
1317
1318 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1319
1320 const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1321 multAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1322 }
1324 //**********************************************************************************************
1325
1326 //**Division assignment to vectors**************************************************************
1340 template< typename VT1 > // Type of the target vector
1341 friend inline auto divAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1342 -> EnableIf_t< UseAssign_v<VT1> >
1343 {
1345
1346 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1347
1348 const RT tmp( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
1349 divAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1350 }
1352 //**********************************************************************************************
1353
1354 //**SMP assignment to vectors*******************************************************************
1368 template< typename VT1 > // Type of the target vector
1369 friend inline auto smpAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1370 -> EnableIf_t< UseSMPAssign_v<VT1> >
1371 {
1373
1374 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1375
1376 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1377 smpAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1378 }
1380 //**********************************************************************************************
1381
1382 //**SMP addition assignment to vectors**********************************************************
1397 template< typename VT1 > // Type of the target vector
1398 friend inline auto smpAddAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1399 -> EnableIf_t< UseSMPAssign_v<VT1> >
1400 {
1402
1403 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1404
1405 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1406 smpAddAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1407 }
1409 //**********************************************************************************************
1410
1411 //**SMP subtraction assignment to vectors*******************************************************
1426 template< typename VT1 > // Type of the target vector
1427 friend inline auto smpSubAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1428 -> EnableIf_t< UseSMPAssign_v<VT1> >
1429 {
1431
1432 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1433
1434 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1435 smpSubAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1436 }
1438 //**********************************************************************************************
1439
1440 //**SMP multiplication assignment to vectors****************************************************
1455 template< typename VT1 > // Type of the target vector
1456 friend inline auto smpMultAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1457 -> EnableIf_t< UseSMPAssign_v<VT1> >
1458 {
1460
1461 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1462
1463 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1464 smpMultAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1465 }
1467 //**********************************************************************************************
1468
1469 //**SMP division assignment to vectors**********************************************************
1484 template< typename VT1 > // Type of the target vector
1485 friend inline auto smpDivAssign( Vector<VT1,false>& lhs, const DMatReduceExpr& rhs )
1486 -> EnableIf_t< UseSMPAssign_v<VT1> >
1487 {
1489
1490 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
1491
1492 const RT tmp( rhs.dm_ ); // Evaluation of the dense matrix operand
1493 smpDivAssign( *lhs, reduce<rowwise>( tmp, rhs.op_ ) );
1494 }
1496 //**********************************************************************************************
1497
1498 //**Compile time checks*************************************************************************
1503 //**********************************************************************************************
1504};
1505//*************************************************************************************************
1506
1507
1508
1509
1510//=================================================================================================
1511//
1512// CLASS DEFINITION
1513//
1514//=================================================================================================
1515
1516//*************************************************************************************************
1521template< typename MT // Type of the dense matrix
1522 , typename OP > // Type of the reduction operation
1523struct DMatReduceExprHelper
1524{
1525 //**Type definitions****************************************************************************
1527 using CT = RemoveReference_t< CompositeType_t<MT> >;
1528
1530 using ET = RemoveCV_t< ElementType_t<CT> >;
1531 //**********************************************************************************************
1532
1533 //**********************************************************************************************
1534 static constexpr bool value =
1535 ( CT::simdEnabled &&
1536 If_t< HasSIMDEnabled_v<OP>, GetSIMDEnabled<OP,ET,ET>, HasLoad<OP> >::value );
1537 //**********************************************************************************************
1538};
1540//*************************************************************************************************
1541
1542
1543
1544
1545//=================================================================================================
1546//
1547// GLOBAL FUNCTIONS
1548//
1549//=================================================================================================
1550
1551//*************************************************************************************************
1564template< typename MT // Type of the dense matrix
1565 , typename OP > // Type of the reduction operation
1566inline auto dmatreduce( const DenseMatrix<MT,false>& dm, OP op )
1567 -> DisableIf_t< DMatReduceExprHelper<MT,OP>::value, RemoveCV_t< ReduceTrait_t<MT,OP> > >
1568{
1569 using CT = CompositeType_t<MT>;
1570 using RT = RemoveCV_t< ReduceTrait_t<MT,OP> >;
1571
1572 const size_t M( (*dm).rows() );
1573 const size_t N( (*dm).columns() );
1574
1575 if( M == 0UL || N == 0UL ) return RT{};
1576 if( M == 1UL && N == 1UL ) return (*dm)(0UL,0UL);
1577
1578 CT tmp( *dm );
1579
1580 BLAZE_INTERNAL_ASSERT( tmp.rows() == M, "Invalid number of rows" );
1581 BLAZE_INTERNAL_ASSERT( tmp.columns() == N, "Invalid number of columns" );
1582
1583 RT redux0{};
1584
1585 {
1586 redux0 = tmp(0UL,0UL);
1587
1588 for( size_t j=1UL; j<N; ++j ) {
1589 redux0 = op( redux0, tmp(0UL,j) );
1590 }
1591 }
1592
1593 size_t i( 1UL );
1594
1595 for( ; (i+2UL) <= M; i+=2UL )
1596 {
1597 RT redux1( tmp(i ,0UL) );
1598 RT redux2( tmp(i+1UL,0UL) );
1599
1600 for( size_t j=1UL; j<N; ++j ) {
1601 redux1 = op( redux1, tmp(i ,j) );
1602 redux2 = op( redux2, tmp(i+1UL,j) );
1603 }
1604
1605 redux1 = op( redux1, redux2 );
1606 redux0 = op( redux0, redux1 );
1607 }
1608
1609 if( i < M )
1610 {
1611 RT redux1( tmp(i,0UL) );
1612
1613 for( size_t j=1UL; j<N; ++j ) {
1614 redux1 = op( redux1, tmp(i,j) );
1615 }
1616
1617 redux0 = op( redux0, redux1 );
1618 }
1619
1620 return redux0;
1621}
1623//*************************************************************************************************
1624
1625
1626//*************************************************************************************************
1639template< typename MT // Type of the dense matrix
1640 , typename OP > // Type of the reduction operation
1641inline auto dmatreduce( const DenseMatrix<MT,false>& dm, OP op )
1642 -> EnableIf_t< DMatReduceExprHelper<MT,OP>::value, RemoveCV_t< ElementType_t<MT> > >
1643{
1644 using CT = CompositeType_t<MT>;
1645 using ET = RemoveCV_t< ElementType_t<MT> >;
1646
1647 const size_t M( (*dm).rows() );
1648 const size_t N( (*dm).columns() );
1649
1650 if( M == 0UL || N == 0UL ) return ET{};
1651
1652 CT tmp( *dm );
1653
1654 BLAZE_INTERNAL_ASSERT( tmp.rows() == M, "Invalid number of rows" );
1655 BLAZE_INTERNAL_ASSERT( tmp.columns() == N, "Invalid number of columns" );
1656
1657 constexpr size_t SIMDSIZE = SIMDTrait<ET>::size;
1658
1659 alignas( AlignmentOf_v<ET> ) ET array1[SIMDSIZE];
1660 alignas( AlignmentOf_v<ET> ) ET array2[SIMDSIZE];
1661 alignas( AlignmentOf_v<ET> ) ET array3[SIMDSIZE];
1662 alignas( AlignmentOf_v<ET> ) ET array4[SIMDSIZE];
1663
1664 ET redux{};
1665
1666 if( N >= SIMDSIZE )
1667 {
1668 const size_t jpos( prevMultiple( N, SIMDSIZE ) );
1669 BLAZE_INTERNAL_ASSERT( jpos <= N, "Invalid end calculation" );
1670
1671 SIMDTrait_t<ET> xmm1;
1672
1673 {
1674 xmm1 = tmp.load(0UL,0UL);
1675 size_t j( SIMDSIZE );
1676
1677 for( ; j<jpos; j+=SIMDSIZE ) {
1678 xmm1 = op( xmm1, tmp.load(0UL,j) );
1679 }
1680
1681 if( jpos < N )
1682 {
1683 storea( array1, xmm1 );
1684
1685 for( ; j<N; ++j ) {
1686 array1[0UL] = op( array1[0UL], tmp(0UL,j) );
1687 }
1688
1689 xmm1 = loada( array1 );
1690 }
1691 }
1692
1693 size_t i( 1UL );
1694
1695 for( ; (i+4UL) <= M; i+=4UL )
1696 {
1697 xmm1 = op( xmm1, tmp.load(i,0UL) );
1698 SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1699 SIMDTrait_t<ET> xmm3( tmp.load(i+2UL,0UL) );
1700 SIMDTrait_t<ET> xmm4( tmp.load(i+3UL,0UL) );
1701 size_t j( SIMDSIZE );
1702
1703 for( ; j<jpos; j+=SIMDSIZE ) {
1704 xmm1 = op( xmm1, tmp.load(i ,j) );
1705 xmm2 = op( xmm2, tmp.load(i+1UL,j) );
1706 xmm3 = op( xmm3, tmp.load(i+2UL,j) );
1707 xmm4 = op( xmm4, tmp.load(i+3UL,j) );
1708 }
1709
1710 if( jpos < N )
1711 {
1712 storea( array1, xmm1 );
1713 storea( array2, xmm2 );
1714 storea( array3, xmm3 );
1715 storea( array4, xmm4 );
1716
1717 for( ; j<N; ++j ) {
1718 array1[0UL] = op( array1[0UL], tmp(i ,j) );
1719 array2[0UL] = op( array2[0UL], tmp(i+1UL,j) );
1720 array3[0UL] = op( array3[0UL], tmp(i+2UL,j) );
1721 array4[0UL] = op( array4[0UL], tmp(i+3UL,j) );
1722 }
1723
1724 xmm1 = loada( array1 );
1725 xmm2 = loada( array2 );
1726 xmm3 = loada( array3 );
1727 xmm4 = loada( array4 );
1728 }
1729
1730 xmm1 = op( xmm1, xmm2 );
1731 xmm3 = op( xmm3, xmm4 );
1732 xmm1 = op( xmm1, xmm3 );
1733 }
1734
1735 if( i+2UL <= M )
1736 {
1737 xmm1 = op( xmm1, tmp.load(i,0UL) );
1738 SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1739 size_t j( SIMDSIZE );
1740
1741 for( ; j<jpos; j+=SIMDSIZE ) {
1742 xmm1 = op( xmm1, tmp.load(i ,j) );
1743 xmm2 = op( xmm2, tmp.load(i+1UL,j) );
1744 }
1745
1746 if( jpos < N )
1747 {
1748 storea( array1, xmm1 );
1749 storea( array2, xmm2 );
1750
1751 for( ; j<N; ++j ) {
1752 array1[0UL] = op( array1[0UL], tmp(i ,j) );
1753 array2[0UL] = op( array2[0UL], tmp(i+1UL,j) );
1754 }
1755
1756 xmm1 = loada( array1 );
1757 xmm2 = loada( array2 );
1758 }
1759
1760 xmm1 = op( xmm1, xmm2 );
1761
1762 i += 2UL;
1763 }
1764
1765 if( i < M )
1766 {
1767 xmm1 = op( xmm1, tmp.load(i,0UL) );
1768 size_t j( SIMDSIZE );
1769
1770 for( ; j<jpos; j+=SIMDSIZE ) {
1771 xmm1 = op( xmm1, tmp.load(i,j) );
1772 }
1773
1774 if( jpos < N )
1775 {
1776 storea( array1, xmm1 );
1777
1778 for( ; j<N; ++j ) {
1779 array1[0] = op( array1[0], tmp(i,j) );
1780 }
1781
1782 xmm1 = loada( array1 );
1783 }
1784 }
1785
1786 redux = reduce( xmm1, op );
1787 }
1788 else
1789 {
1790 {
1791 redux = tmp(0UL,0UL);
1792 for( size_t j=1UL; j<N; ++j ) {
1793 redux = op( redux, tmp(0UL,j) );
1794 }
1795 }
1796 for( size_t i=1UL; i<M; ++i ) {
1797 for( size_t j=0UL; j<N; ++j ) {
1798 redux = op( redux, tmp(i,j) );
1799 }
1800 }
1801 }
1802
1803 return redux;
1804}
1806//*************************************************************************************************
1807
1808
1809//*************************************************************************************************
1821template< typename MT > // Type of the dense matrix
1822inline auto dmatreduce( const DenseMatrix<MT,false>& dm, Add /*op*/ )
1823 -> EnableIf_t< DMatReduceExprHelper<MT,Add>::value, RemoveCV_t< ElementType_t<MT> > >
1824{
1825 using CT = CompositeType_t<MT>;
1826 using ET = RemoveCV_t< ElementType_t<MT> >;
1827
1828 const size_t M( (*dm).rows() );
1829 const size_t N( (*dm).columns() );
1830
1831 if( M == 0UL || N == 0UL ) return ET{};
1832
1833 CT tmp( *dm );
1834
1835 BLAZE_INTERNAL_ASSERT( tmp.rows() == M, "Invalid number of rows" );
1836 BLAZE_INTERNAL_ASSERT( tmp.columns() == N, "Invalid number of columns" );
1837
1838 constexpr bool remainder( !IsPadded_v< RemoveReference_t<CT> > );
1839 constexpr size_t SIMDSIZE = SIMDTrait<ET>::size;
1840
1841 ET redux{};
1842
1843 if( !remainder || N >= SIMDSIZE )
1844 {
1845 const size_t jpos( remainder ? prevMultiple( N, SIMDSIZE ) : N );
1846 BLAZE_INTERNAL_ASSERT( jpos <= N, "Invalid end calculation" );
1847
1848 SIMDTrait_t<ET> xmm1;
1849 size_t i( 0UL );
1850
1851 for( ; (i+4UL) <= M; i+=4UL )
1852 {
1853 xmm1 += tmp.load(i,0UL);
1854 SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1855 SIMDTrait_t<ET> xmm3( tmp.load(i+2UL,0UL) );
1856 SIMDTrait_t<ET> xmm4( tmp.load(i+3UL,0UL) );
1857 size_t j( SIMDSIZE );
1858
1859 for( ; j<jpos; j+=SIMDSIZE ) {
1860 xmm1 += tmp.load(i ,j);
1861 xmm2 += tmp.load(i+1UL,j);
1862 xmm3 += tmp.load(i+2UL,j);
1863 xmm4 += tmp.load(i+3UL,j);
1864 }
1865 for( ; remainder && j<N; ++j ) {
1866 redux += tmp(i ,j);
1867 redux += tmp(i+1UL,j);
1868 redux += tmp(i+2UL,j);
1869 redux += tmp(i+3UL,j);
1870 }
1871
1872 xmm1 += xmm2;
1873 xmm3 += xmm4;
1874 xmm1 += xmm3;
1875 }
1876
1877 if( i+2UL <= M )
1878 {
1879 xmm1 += tmp.load(i,0UL);
1880 SIMDTrait_t<ET> xmm2( tmp.load(i+1UL,0UL) );
1881 size_t j( SIMDSIZE );
1882
1883 for( ; j<jpos; j+=SIMDSIZE ) {
1884 xmm1 += tmp.load(i ,j);
1885 xmm2 += tmp.load(i+1UL,j);
1886 }
1887 for( ; remainder && j<N; ++j ) {
1888 redux += tmp(i ,j);
1889 redux += tmp(i+1UL,j);
1890 }
1891
1892 xmm1 += xmm2;
1893
1894 i += 2UL;
1895 }
1896
1897 if( i < M )
1898 {
1899 xmm1 += tmp.load(i,0UL);
1900 size_t j( SIMDSIZE );
1901
1902 for( ; j<jpos; j+=SIMDSIZE ) {
1903 xmm1 += tmp.load(i,j);
1904 }
1905 for( ; remainder && j<N; ++j ) {
1906 redux += tmp(i,j);
1907 }
1908 }
1909
1910 redux += sum( xmm1 );
1911 }
1912 else
1913 {
1914 for( size_t i=0UL; i<M; ++i ) {
1915 for( size_t j=0UL; j<N; ++j ) {
1916 redux += tmp(i,j);
1917 }
1918 }
1919 }
1920
1921 return redux;
1922
1923}
1925//*************************************************************************************************
1926
1927
1928//*************************************************************************************************
1939template< typename MT > // Type of the dense matrix
1940inline auto dmatreduce( const DenseMatrix<MT,false>& dm, Min /*op*/ )
1941 -> EnableIf_t< IsUniform_v<MT>, RemoveCV_t< ElementType_t<MT> > >
1942{
1943 return (*dm)(0UL,0UL);
1944}
1946//*************************************************************************************************
1947
1948
1949//*************************************************************************************************
1960template< typename MT > // Type of the dense matrix
1961inline auto dmatreduce( const DenseMatrix<MT,false>& dm, Max /*op*/ )
1962 -> EnableIf_t< IsUniform_v<MT>, RemoveCV_t< ElementType_t<MT> > >
1963{
1964 return (*dm)(0UL,0UL);
1965}
1967//*************************************************************************************************
1968
1969
1970//*************************************************************************************************
1983template< typename MT // Type of the dense matrix
1984 , typename OP > // Type of the reduction operation
1985inline RemoveCV_t< ElementType_t<MT> > dmatreduce( const DenseMatrix<MT,true>& dm, OP op )
1986{
1987 return dmatreduce( trans( *dm ), std::move(op) );
1988}
1990//*************************************************************************************************
1991
1992
1993//*************************************************************************************************
2022template< typename MT // Type of the dense matrix
2023 , bool SO // Storage order
2024 , typename OP > // Type of the reduction operation
2025inline decltype(auto) reduce( const DenseMatrix<MT,SO>& dm, OP op )
2026{
2028
2029 return dmatreduce( *dm, std::move(op) );
2030}
2031//*************************************************************************************************
2032
2033
2034//*************************************************************************************************
2043template< ReductionFlag RF // Reduction flag
2044 , typename MT // Type of the dense matrix
2045 , typename OP > // Type of the reduction operation
2046inline const DMatReduceExpr<MT,OP,RF> reduce_backend( const DenseMatrix<MT,false>& dm, OP op )
2047{
2048 using ReturnType = const DMatReduceExpr<MT,OP,RF>;
2049 return ReturnType( *dm, std::move(op) );
2050}
2052//*************************************************************************************************
2053
2054
2055//*************************************************************************************************
2064template< ReductionFlag RF // Reduction flag
2065 , typename MT // Type of the dense matrix
2066 , typename OP > // Type of the reduction operation
2067inline decltype(auto) reduce_backend( const DenseMatrix<MT,true>& dm, OP op )
2068{
2069 constexpr ReductionFlag RF2( RF == rowwise ? columnwise : rowwise );
2070 return trans( reduce<RF2>( trans( *dm ), std::move(op) ) );
2071}
2073//*************************************************************************************************
2074
2075
2076//*************************************************************************************************
2122template< ReductionFlag RF // Reduction flag
2123 , typename MT // Type of the dense matrix
2124 , bool SO // Storage order
2125 , typename OP > // Type of the reduction operation
2126inline decltype(auto) reduce( const DenseMatrix<MT,SO>& dm, OP op )
2127{
2129
2130 BLAZE_STATIC_ASSERT_MSG( RF < 2UL, "Invalid reduction flag" );
2131
2132 return reduce_backend<RF>( *dm, std::move(op) );
2133}
2134//*************************************************************************************************
2135
2136
2137//*************************************************************************************************
2154template< typename MT // Type of the dense matrix
2155 , bool SO > // Storage order
2156inline decltype(auto) sum( const DenseMatrix<MT,SO>& dm )
2157{
2159
2160 return reduce( *dm, Add() );
2161}
2162//*************************************************************************************************
2163
2164
2165//*************************************************************************************************
2198template< ReductionFlag RF // Reduction flag
2199 , typename MT // Type of the dense matrix
2200 , bool SO > // Storage order
2201inline decltype(auto) sum( const DenseMatrix<MT,SO>& dm )
2202{
2204
2205 return reduce<RF>( *dm, Add() );
2206}
2207//*************************************************************************************************
2208
2209
2210//*************************************************************************************************
2227template< typename MT // Type of the dense matrix
2228 , bool SO > // Storage order
2229inline decltype(auto) prod( const DenseMatrix<MT,SO>& dm )
2230{
2232
2233 return reduce( *dm, Mult() );
2234}
2235//*************************************************************************************************
2236
2237
2238//*************************************************************************************************
2271template< ReductionFlag RF // Reduction flag
2272 , typename MT // Type of the dense matrix
2273 , bool SO > // Storage order
2274inline decltype(auto) prod( const DenseMatrix<MT,SO>& dm )
2275{
2277
2278 return reduce<RF>( *dm, Mult() );
2279}
2280//*************************************************************************************************
2281
2282
2283//*************************************************************************************************
2301template< typename MT // Type of the dense matrix
2302 , bool SO > // Storage order
2303inline decltype(auto) min( const DenseMatrix<MT,SO>& dm )
2304{
2306
2307 return reduce( *dm, Min() );
2308}
2309//*************************************************************************************************
2310
2311
2312//*************************************************************************************************
2342template< ReductionFlag RF // Reduction flag
2343 , typename MT // Type of the dense matrix
2344 , bool SO > // Storage order
2345inline decltype(auto) min( const DenseMatrix<MT,SO>& dm )
2346{
2348
2349 return reduce<RF>( *dm, Min() );
2350}
2351//*************************************************************************************************
2352
2353
2354//*************************************************************************************************
2372template< typename MT // Type of the dense matrix
2373 , bool SO > // Storage order
2374inline decltype(auto) max( const DenseMatrix<MT,SO>& dm )
2375{
2377
2378 return reduce( *dm, Max() );
2379}
2380//*************************************************************************************************
2381
2382
2383//*************************************************************************************************
2413template< ReductionFlag RF // Reduction flag
2414 , typename MT // Type of the dense matrix
2415 , bool SO > // Storage order
2416inline decltype(auto) max( const DenseMatrix<MT,SO>& dm )
2417{
2419
2420 return reduce<RF>( *dm, Max() );
2421}
2422//*************************************************************************************************
2423
2424} // namespace blaze
2425
2426#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Constraints on the storage order of matrix types.
Constraint on the transpose flag of vector types.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Header file for the HasLoad type trait.
Header file for the HasMember type traits.
Macro for CUDA compatibility.
Header file for the If class template.
Header file for the IsExpression type trait class.
Header file for the IsPadded type trait.
Header file for the IsSIMDEnabled type trait.
Header file for the IsSame and IsStrictlySame type traits.
Header file for the IsUniform type trait.
Deactivation of problematic macros.
Header file for the prevMultiple shim.
Header file for the reduce trait.
Header file for the reduction flags.
constexpr ReductionFlag columnwise
Reduction flag for column-wise reduction operations.
Definition: ReductionFlag.h:97
constexpr ReductionFlag rowwise
Reduction flag for row-wise reduction operations.
Definition: ReductionFlag.h:77
size_t ReductionFlag
Type of the reduction flags.
Definition: ReductionFlag.h:57
Header file for the RemoveCV type trait.
Header file for the RemoveReference type trait.
Constraints on the storage order of matrix types.
Constraint on the transpose flag of vector types.
Header file for all SIMD functionality.
Compile time assertion.
Expression object for column-wise row-major dense matrix reduction operations.
Definition: DMatReduceExpr.h:132
ReduceTrait_t< RT, OP, columnwise > ResultType
Result type for expression template evaluations.
Definition: DMatReduceExpr.h:159
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatReduceExpr.h:164
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatReduceExpr.h:269
ResultType_t< MT > RT
Result type of the dense matrix expression.
Definition: DMatReduceExpr.h:135
const ElementType ReturnType
Return type for expression template evaluations.
Definition: DMatReduceExpr.h:163
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatReduceExpr.h:161
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatReduceExpr.h:279
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatReduceExpr.h:289
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatReduceExpr.h:160
Operation op_
The reduction operation.
Definition: DMatReduceExpr.h:297
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatReduceExpr.h:235
SIMDTrait_t< ElementType > SIMDType
Resulting SIMD element type.
Definition: DMatReduceExpr.h:162
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DMatReduceExpr.h:225
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DMatReduceExpr.h:199
DMatReduceExpr(const MT &dm, OP op) noexcept
Constructor for the DMatReduceExpr class.
Definition: DMatReduceExpr.h:187
CompositeType_t< MT > CT
Composite type of the dense matrix expression.
Definition: DMatReduceExpr.h:136
Operation operation() const
Returns a copy of the reduction operation.
Definition: DMatReduceExpr.h:245
Operand dm_
Dense matrix of the reduction expression.
Definition: DMatReduceExpr.h:296
OP Operation
Data type of the custom unary operation.
Definition: DMatReduceExpr.h:170
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatReduceExpr.h:257
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DMatReduceExpr.h:212
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite type of the left-hand side dense matrix expression.
Definition: DMatReduceExpr.h:167
BLAZE_DEVICE_CALLABLE ConstIterator & operator--()
Pre-decrement operator.
Definition: DMatReduceExpr.h:917
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:949
bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:993
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: DMatReduceExpr.h:1015
bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:982
BLAZE_DEVICE_CALLABLE ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DMatReduceExpr.h:873
BLAZE_DEVICE_CALLABLE const ConstIterator operator++(int)
Post-increment operator.
Definition: DMatReduceExpr.h:907
BLAZE_DEVICE_CALLABLE ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DMatReduceExpr.h:885
ReturnType operator*() const
Direct access to the element at the current iterator position.
Definition: DMatReduceExpr.h:938
OP op_
The reduction operation.
Definition: DMatReduceExpr.h:1060
friend const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: DMatReduceExpr.h:1027
ConstIterator(Operand dm, size_t index, OP op)
Constructor for the ConstIterator class.
Definition: DMatReduceExpr.h:860
ReferenceType reference
Reference return type.
Definition: DMatReduceExpr.h:849
ElementType * PointerType
Pointer return type.
Definition: DMatReduceExpr.h:841
Operand dm_
Dense matrix of the reduction expression.
Definition: DMatReduceExpr.h:1058
friend const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: DMatReduceExpr.h:1051
bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:971
size_t index_
Index to the current matrix row.
Definition: DMatReduceExpr.h:1059
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DMatReduceExpr.h:839
friend const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: DMatReduceExpr.h:1039
PointerType pointer
Pointer return type.
Definition: DMatReduceExpr.h:848
ElementType & ReferenceType
Reference return type.
Definition: DMatReduceExpr.h:842
ValueType value_type
Type of the underlying elements.
Definition: DMatReduceExpr.h:847
IteratorCategory iterator_category
The iterator category.
Definition: DMatReduceExpr.h:846
bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:1004
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DMatReduceExpr.h:960
ElementType ValueType
Type of the underlying elements.
Definition: DMatReduceExpr.h:840
DifferenceType difference_type
Difference between two iterators.
Definition: DMatReduceExpr.h:850
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DMatReduceExpr.h:843
BLAZE_DEVICE_CALLABLE const ConstIterator operator--(int)
Post-decrement operator.
Definition: DMatReduceExpr.h:928
BLAZE_DEVICE_CALLABLE ConstIterator & operator++()
Pre-increment operator.
Definition: DMatReduceExpr.h:896
Expression object for row-wise row-major dense matrix reduction operations.
Definition: DMatReduceExpr.h:773
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatReduceExpr.h:1147
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite type of the left-hand side dense matrix expression.
Definition: DMatReduceExpr.h:826
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DMatReduceExpr.h:1104
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatReduceExpr.h:818
ResultType_t< MT > RT
Result type of the dense matrix expression.
Definition: DMatReduceExpr.h:776
Operation operation() const
Returns a copy of the reduction operation.
Definition: DMatReduceExpr.h:1157
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatReduceExpr.h:1191
ReduceTrait_t< RT, OP, rowwise > ResultType
Result type for expression template evaluations.
Definition: DMatReduceExpr.h:816
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: DMatReduceExpr.h:1117
SIMDTrait_t< ElementType > SIMDType
Resulting SIMD element type.
Definition: DMatReduceExpr.h:819
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DMatReduceExpr.h:1137
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DMatReduceExpr.h:1091
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatReduceExpr.h:817
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatReduceExpr.h:1169
If_t< useAssign, const ResultType, const DMatReduceExpr & > CompositeType
Data type for composite expression templates.
Definition: DMatReduceExpr.h:823
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatReduceExpr.h:1201
const ElementType ReturnType
Return type for expression template evaluations.
Definition: DMatReduceExpr.h:820
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: DMatReduceExpr.h:1127
Operation op_
The reduction operation.
Definition: DMatReduceExpr.h:1209
OP Operation
Data type of the custom unary operation.
Definition: DMatReduceExpr.h:829
Operand dm_
Dense matrix of the reduction expression.
Definition: DMatReduceExpr.h:1208
DMatReduceExpr(const MT &dm, OP op) noexcept
Constructor for the DMatReduceExpr class.
Definition: DMatReduceExpr.h:1079
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatReduceExpr.h:1181
Base template for row-major dense matrix partial reduction operations.
Definition: DMatReduceExpr.h:108
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Base class for N-dimensional vectors.
Definition: Vector.h:82
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the DenseVector base class.
Header file for the MatReduceExpr base class.
Header file for the Add functor.
Header file for the Mult functor.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
decltype(auto) max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of each row/columns of the dense matrix.
Definition: DMatReduceExpr.h:2416
decltype(auto) prod(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of multiplication.
Definition: DMatReduceExpr.h:2274
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) map(const DenseMatrix< MT1, SO > &lhs, const DenseMatrix< MT2, SO > &rhs, OP op)
Elementwise evaluation of the given binary operation on each single element of the dense matrices lhs...
Definition: DMatDMatMapExpr.h:1144
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
decltype(auto) reduce(const DenseMatrix< MT, SO > &dm, OP op)
Performs a custom reduction operation on the given dense matrix.
Definition: DMatReduceExpr.h:2126
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2201
decltype(auto) min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of each row/columns of the dense matrix.
Definition: DMatReduceExpr.h:2345
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: DenseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.
Definition: RowVector.h:61
typename ReduceTrait< T, OP, RF... >::Type ReduceTrait_t
Auxiliary alias declaration for the ReduceTrait class template.
Definition: ReduceTrait.h:150
constexpr bool IsPadded_v
Auxiliary variable template for the IsPadded type trait.
Definition: IsPadded.h:134
BLAZE_ALWAYS_INLINE constexpr auto prevMultiple(T1 value, T2 factor) noexcept
Rounds down an integral value to the previous multiple of a given factor.
Definition: PrevMultiple.h:68
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
typename SIMDTrait< T >::Type SIMDTrait_t
Auxiliary alias declaration for the SIMDTrait class template.
Definition: SIMDTrait.h:315
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
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
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:221
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto 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
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:192
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
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.
Definition: StaticAssert.h:123
#define BLAZE_DEVICE_CALLABLE
Conditional macro that sets host and device attributes when compiled with CUDA.
Definition: HostDevice.h:94
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Header file for the Max functor.
Header file for the Min functor.
Header file for the serial shim.
Generic wrapper for the addition operator.
Definition: Add.h:85
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix reduction expression templates.
Definition: MatReduceExpr.h:70
Generic wrapper for the max() function.
Definition: Max.h:82
Generic wrapper for the min() function.
Definition: Min.h:82
Generic wrapper for the multiplication operator.
Definition: Mult.h:82
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.