Blaze 3.9
DMatGenExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATGENEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATGENEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <utility>
45#include <blaze/math/Aliases.h>
60#include <blaze/util/Assert.h>
65#include <blaze/util/TypeList.h>
66#include <blaze/util/Types.h>
68
69
70namespace blaze {
71
72//=================================================================================================
73//
74// CLASS DMATGENEXPR
75//
76//=================================================================================================
77
78//*************************************************************************************************
85template< typename MT // Type of the dense matrix
86 , typename OP // Type of the custom binary operation
87 , bool SO > // Storage order
89 : public MatGenExpr< DenseMatrix< DMatGenExpr<MT,OP,SO>, SO > >
90 , private Computation
91{
92 public:
93 //**Type definitions****************************************************************************
96
99
103
105 using ReturnType = decltype( std::declval<OP>()( std::declval<size_t>(), std::declval<size_t>() ) );
106
109
111 using Operation = OP;
112 //**********************************************************************************************
113
114 //**ConstIterator class definition**************************************************************
118 {
119 public:
120 //**Type definitions*************************************************************************
121 using IteratorCategory = std::random_access_iterator_tag;
125 using DifferenceType = ptrdiff_t;
126
127 // STL iterator requirements
133 //*******************************************************************************************
134
135 //**Constructor******************************************************************************
142 inline BLAZE_DEVICE_CALLABLE ConstIterator( size_t m, size_t n, OP op )
143 : m_ ( m ) // Row index of the current matrix element
144 , n_ ( n ) // Column index of the current matrix element
145 , op_( std::move(op) ) // The custom binary operation
146 {}
147 //*******************************************************************************************
148
149 //**Addition assignment operator*************************************************************
156 if( SO )
157 m_ += inc;
158 else
159 n_ += inc;
160 return *this;
161 }
162 //*******************************************************************************************
163
164 //**Subtraction assignment operator**********************************************************
171 if( SO )
172 m_ += dec;
173 else
174 n_ += dec;
175 return *this;
176 }
177 //*******************************************************************************************
178
179 //**Prefix increment operator****************************************************************
185 if( SO )
186 ++m_;
187 else
188 ++n_;
189 return *this;
190 }
191 //*******************************************************************************************
192
193 //**Postfix increment operator***************************************************************
199 if( SO )
200 return ConstIterator( m_++, n_, op_ );
201 else
202 return ConstIterator( m_, n_++, op_ );
203 }
204 //*******************************************************************************************
205
206 //**Prefix decrement operator****************************************************************
212 if( SO )
213 --m_;
214 else
215 --n_;
216 return *this;
217 }
218 //*******************************************************************************************
219
220 //**Postfix decrement operator***************************************************************
226 if( SO )
227 return ConstIterator( m_--, n_, op_ );
228 else
229 return ConstIterator( m_, n_--, op_ );
230 }
231 //*******************************************************************************************
232
233 //**Element access operator******************************************************************
239 return op_( m_, n_ );
240 }
241 //*******************************************************************************************
242
243 //**Equality operator************************************************************************
249 inline BLAZE_DEVICE_CALLABLE bool operator==( const ConstIterator& rhs ) const noexcept {
250 if( SO )
251 return m_ == rhs.m_;
252 else
253 return n_ == rhs.n_;
254 }
255 //*******************************************************************************************
256
257 //**Inequality operator**********************************************************************
263 inline BLAZE_DEVICE_CALLABLE bool operator!=( const ConstIterator& rhs ) const noexcept {
264 if( SO )
265 return m_ != rhs.m_;
266 else
267 return n_ != rhs.n_;
268 }
269 //*******************************************************************************************
270
271 //**Less-than operator***********************************************************************
277 inline BLAZE_DEVICE_CALLABLE bool operator<( const ConstIterator& rhs ) const noexcept {
278 if( SO )
279 return m_ < rhs.m_;
280 else
281 return n_ < rhs.n_;
282 }
283 //*******************************************************************************************
284
285 //**Greater-than operator********************************************************************
291 inline BLAZE_DEVICE_CALLABLE bool operator>( const ConstIterator& rhs ) const noexcept {
292 if( SO )
293 return m_ > rhs.m_;
294 else
295 return n_ > rhs.n_;
296 }
297 //*******************************************************************************************
298
299 //**Less-or-equal-than operator**************************************************************
305 inline BLAZE_DEVICE_CALLABLE bool operator<=( const ConstIterator& rhs ) const noexcept {
306 if( SO )
307 return m_ <= rhs.m_;
308 else
309 return n_ <= rhs.n_;
310 }
311 //*******************************************************************************************
312
313 //**Greater-or-equal-than operator***********************************************************
319 inline BLAZE_DEVICE_CALLABLE bool operator>=( const ConstIterator& rhs ) const noexcept {
320 if( SO )
321 return m_ >= rhs.m_;
322 else
323 return n_ >= rhs.n_;
324 }
325 //*******************************************************************************************
326
327 //**Subtraction operator*********************************************************************
333 inline BLAZE_DEVICE_CALLABLE DifferenceType operator-( const ConstIterator& rhs ) const noexcept {
334 if( SO )
335 return m_ - rhs.m_;
336 else
337 return n_ - rhs.n_;
338 }
339 //*******************************************************************************************
340
341 //**Addition operator************************************************************************
348 friend inline BLAZE_DEVICE_CALLABLE const ConstIterator operator+( const ConstIterator& it, size_t inc ) {
349 if( SO )
350 return ConstIterator( it.m_ + inc, it.n_, it.op_ );
351 else
352 return ConstIterator( it.m_, it.n_ + inc, it.op_ );
353 }
354 //*******************************************************************************************
355
356 //**Addition operator************************************************************************
363 friend inline BLAZE_DEVICE_CALLABLE const ConstIterator operator+( size_t inc, const ConstIterator& it ) {
364 if( SO )
365 return ConstIterator( it.m_ + inc, it.n_, it.op_ );
366 else
367 return ConstIterator( it.m_, it.n_ + inc, it.op_ );
368 }
369 //*******************************************************************************************
370
371 //**Subtraction operator*********************************************************************
378 friend inline BLAZE_DEVICE_CALLABLE const ConstIterator operator-( const ConstIterator& it, size_t dec ) {
379 if( SO )
380 return ConstIterator( it.m_ - dec, it.n_, it.op_ );
381 else
382 return ConstIterator( it.m_, it.n_ - dec, it.op_ );
383 }
384 //*******************************************************************************************
385
386 private:
387 //**Member variables*************************************************************************
388 size_t m_;
389 size_t n_;
390 OP op_;
391 //*******************************************************************************************
392 };
393 //**********************************************************************************************
394
395 public:
396 //**Compilation flags***************************************************************************
398 static constexpr bool simdEnabled = false;
399
401 static constexpr bool smpAssignable = true;
402 //**********************************************************************************************
403
404 //**Constructor*********************************************************************************
411 inline DMatGenExpr( size_t m, size_t n, OP&& op ) noexcept
412 : m_ ( m ) // The number of rows of the dense matrix generator
413 , n_ ( n ) // The number of columns of the dense matrix generator
414 , op_( std::move( op ) ) // The custom binary operation
415 {}
416 //**********************************************************************************************
417
418 //**Access operator*****************************************************************************
425 inline ReturnType operator()( size_t i, size_t j ) const noexcept {
426 BLAZE_INTERNAL_ASSERT( i < m_, "Invalid row access index" );
427 BLAZE_INTERNAL_ASSERT( j < n_, "Invalid column access index" );
428 return op_(i,j);
429 }
430 //**********************************************************************************************
431
432 //**At function*********************************************************************************
440 inline ReturnType at( size_t i, size_t j ) const {
441 if( i >= m_ ) {
442 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
443 }
444 if( j >= n_ ) {
445 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
446 }
447 return (*this)(i,j);
448 }
449 //**********************************************************************************************
450
451 //**Begin function******************************************************************************
457 inline ConstIterator begin( size_t i ) const {
458 return ConstIterator( ( SO ? 0UL : i ), ( SO ? i : 0UL ), op_ );
459 }
460 //**********************************************************************************************
461
462 //**End function********************************************************************************
468 inline ConstIterator end( size_t i ) const {
469 return ConstIterator( ( SO ? m_ : i ), ( SO ? i : n_ ), op_ );
470 }
471 //**********************************************************************************************
472
473 //**Rows function*******************************************************************************
478 inline size_t rows() const noexcept {
479 return m_;
480 }
481 //**********************************************************************************************
482
483 //**Columns function****************************************************************************
488 inline size_t columns() const noexcept {
489 return n_;
490 }
491 //**********************************************************************************************
492
493 //**Operation access****************************************************************************
498 inline Operation operation() const {
499 return op_;
500 }
501 //**********************************************************************************************
502
503 //**********************************************************************************************
509 template< typename T >
510 inline bool canAlias( const T* alias ) const noexcept {
511 MAYBE_UNUSED( alias );
512 return false;
513 }
514 //**********************************************************************************************
515
516 //**********************************************************************************************
522 template< typename T >
523 inline bool isAliased( const T* alias ) const noexcept {
524 MAYBE_UNUSED( alias );
525 return false;
526 }
527 //**********************************************************************************************
528
529 //**********************************************************************************************
534 inline bool isAligned() const noexcept {
535 return true;
536 }
537 //**********************************************************************************************
538
539 //**********************************************************************************************
544 inline bool canSMPAssign() const noexcept {
545 return true;
546 }
547 //**********************************************************************************************
548
549 private:
550 //**Member variables****************************************************************************
551 size_t m_;
552 size_t n_;
554 //**********************************************************************************************
555
556 //**Compile time checks*************************************************************************
562 //**********************************************************************************************
563};
564//*************************************************************************************************
565
566
567
568
569//=================================================================================================
570//
571// GLOBAL FUNCTIONS
572//
573//=================================================================================================
574
575//*************************************************************************************************
617template< typename MT // Type of the dense matrix
618 , typename OP > // Type of the custom binary operation
619inline decltype(auto) generate( size_t m, size_t n, OP op )
620{
622
623 if( Size_v<MT,0UL> != DefaultSize_v && size_t( Size_v<MT,0UL> ) != m &&
624 Size_v<MT,1UL> != DefaultSize_v && size_t( Size_v<MT,1UL> ) != n ) {
625 BLAZE_THROW_INVALID_ARGUMENT( "Invalid size specification" );
626 }
627
628 using ReturnType = const DMatGenExpr< MT, OP, StorageOrder_v<MT> >;
629 return ReturnType( m, n, std::move( op ) );
630}
632//*************************************************************************************************
633
634
635//*************************************************************************************************
673template< bool SO = defaultStorageOrder // Storage order
674 , typename OP > // Type of the custom binary operation
675inline decltype(auto) generate( size_t m, size_t n, OP op )
676{
678
679 using ET = RemoveCVRef_t< decltype( std::declval<OP>()( std::declval<size_t>(), std::declval<size_t>() ) ) >;
680 using MT = DynamicMatrix<ET,SO>;
681
682 return generate<MT>( m, n, std::move( op ) );
683}
684//*************************************************************************************************
685
686
687
688
689//=================================================================================================
690//
691// GLOBAL RESTRUCTURING FUNCTIONS (SUBMATRIX)
692//
693//=================================================================================================
694
695//*************************************************************************************************
708template< AlignmentFlag AF // Alignment flag
709 , size_t I // Index of the first row
710 , size_t J // Index of the first column
711 , size_t M // Number of rows
712 , size_t N // Number of columns
713 , typename MT // Type of the dense matrix
714 , typename OP // Type of the custom binary operation
715 , bool SO // Storage order
716 , typename... RSAs > // Optional arguments
717inline decltype(auto) submatrix( const DMatGenExpr<MT,OP,SO>& expr, RSAs... args )
718{
720
721 MAYBE_UNUSED( args... );
722
723 constexpr bool isChecked( !Contains_v< TypeList<RSAs...>, Unchecked > );
724
725 if( isChecked ) {
726 if( ( I + M > expr.rows() ) || ( J + N > expr.columns() ) ) {
727 BLAZE_THROW_INVALID_ARGUMENT( "Invalid submatrix specification" );
728 }
729 }
730 else {
731 BLAZE_USER_ASSERT( I + M <= expr.rows() , "Invalid submatrix specification" );
732 BLAZE_USER_ASSERT( J + N <= expr.columns(), "Invalid submatrix specification" );
733 }
734
735 return generate( M, N, [op=expr.operation()]( size_t i, size_t j ) {
736 return op( i+I, j+J );
737 } );
738}
740//*************************************************************************************************
741
742
743//*************************************************************************************************
760template< AlignmentFlag AF // Alignment flag
761 , typename MT // Type of the dense matrix
762 , typename OP // Type of the custom binary operation
763 , bool SO // Storage order
764 , typename... RSAs > // Optional arguments
765inline decltype(auto)
766 submatrix( const DMatGenExpr<MT,OP,SO>& expr, size_t row, size_t column, size_t m, size_t n, RSAs... args )
767{
769
770 MAYBE_UNUSED( args... );
771
772 constexpr bool isChecked( !Contains_v< TypeList<RSAs...>, Unchecked > );
773
774 if( isChecked ) {
775 if( ( row + m > expr.rows() ) || ( column + n > expr.columns() ) ) {
776 BLAZE_THROW_INVALID_ARGUMENT( "Invalid submatrix specification" );
777 }
778 }
779 else {
780 BLAZE_USER_ASSERT( row + m <= expr.rows() , "Invalid submatrix specification" );
781 BLAZE_USER_ASSERT( column + n <= expr.columns(), "Invalid submatrix specification" );
782 }
783
784 return generate( m, n, [op=expr.operation(),row,column]( size_t i, size_t j ) {
785 return op( i+row, j+column );
786 } );
787}
789//*************************************************************************************************
790
791
792
793
794//=================================================================================================
795//
796// GLOBAL RESTRUCTURING FUNCTIONS (ROW)
797//
798//=================================================================================================
799
800//*************************************************************************************************
812template< size_t I // Row index
813 , typename MT // Type of the dense matrix
814 , typename OP // Type of the custom binary operation
815 , bool SO // Storage order
816 , typename... RRAs > // Optional row arguments
817inline decltype(auto) row( const DMatGenExpr<MT,OP,SO>& expr, RRAs... args )
818{
820
821 MAYBE_UNUSED( args... );
822
823 constexpr bool isChecked( !Contains_v< TypeList<RRAs...>, Unchecked > );
824
825 if( isChecked ) {
826 if( expr.rows() <= I ) {
827 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
828 }
829 }
830 else {
831 BLAZE_USER_ASSERT( I < expr.rows(), "Invalid row access index" );
832 }
833
834 return generate<rowVector>( expr.columns(), [op=expr.operation()]( size_t i ){
835 return op( I, i );
836 } );
837}
839//*************************************************************************************************
840
841
842//*************************************************************************************************
856template< typename MT // Type of the dense matrix
857 , typename OP // Type of the custom binary operation
858 , bool SO // Storage order
859 , typename... RRAs > // Runtime row arguments
860inline decltype(auto) row( const DMatGenExpr<MT,OP,SO>& expr, size_t index, RRAs... args )
861{
863
864 MAYBE_UNUSED( args... );
865
866 constexpr bool isChecked( !Contains_v< TypeList<RRAs...>, Unchecked > );
867
868 if( isChecked ) {
869 if( expr.rows() <= index ) {
870 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
871 }
872 }
873 else {
874 BLAZE_USER_ASSERT( index < expr.rows(), "Invalid row access index" );
875 }
876
877 return generate<rowVector>( expr.columns(), [op=expr.operation(),index]( size_t i ){
878 return op( index, i );
879 } );
880}
882//*************************************************************************************************
883
884
885
886
887//=================================================================================================
888//
889// GLOBAL RESTRUCTURING FUNCTIONS (ROWS)
890//
891//=================================================================================================
892
893//*************************************************************************************************
906template< size_t I // First required row index
907 , size_t... Is // Remaining required row indices
908 , typename MT // Type of the dense matrix
909 , typename OP // Type of the custom binary operation
910 , bool SO // Storage order
911 , typename... RRAs > // Optional row arguments
912inline decltype(auto) rows( const DMatGenExpr<MT,OP,SO>& expr, RRAs... args )
913{
915
916 MAYBE_UNUSED( args... );
917
918 constexpr bool isChecked( !Contains_v< TypeList<RRAs...>, Unchecked > );
919
920 if( isChecked ) {
921 static constexpr size_t indices[] = { I, Is... };
922 for( size_t i=0UL; i<sizeof...(Is)+1UL; ++i ) {
923 if( expr.rows() <= indices[i] ) {
924 BLAZE_THROW_INVALID_ARGUMENT( "Invalid elements specification" );
925 }
926 }
927 }
928
929 return generate( sizeof...(Is)+1UL, expr.columns(), [op=expr.operation()]( size_t i, size_t j ) {
930 static constexpr size_t indices[] = { I, Is... };
931 return op( indices[i], j );
932 } );
933}
935//*************************************************************************************************
936
937
938//*************************************************************************************************
953template< typename MT // Type of the dense matrix
954 , typename OP // Type of the custom binary operation
955 , bool SO // Storage order
956 , typename T // Type of the row indices
957 , typename... RRAs > // Optional row arguments
958inline decltype(auto) rows( const DMatGenExpr<MT,OP,SO> expr, T* indices, size_t n, RRAs... args )
959{
961
962 MAYBE_UNUSED( args... );
963
964 constexpr bool isChecked( !Contains_v< TypeList<RRAs...>, Unchecked > );
965
966 if( isChecked ) {
967 for( size_t i=0UL; i<n; ++i ) {
968 if( expr.rows() <= size_t( indices[i] ) ) {
969 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
970 }
971 }
972 }
973
974 SmallArray<size_t,128UL> newIndices( indices, indices+n );
975
976 return generate( n, expr.columns(), [op=expr.operation(),newIndices]( size_t i, size_t j ){
977 return op( newIndices[i], j );
978 } );
979}
981//*************************************************************************************************
982
983
984//*************************************************************************************************
999template< typename MT // Type of the dense matrix
1000 , typename OP // Type of the custom binary operation
1001 , bool SO // Storage order
1002 , typename P // Type of the index producer
1003 , typename... RRAs > // Optional row arguments
1004inline decltype(auto) rows( const DMatGenExpr<MT,OP,SO>& expr, P p, size_t n, RRAs... args )
1005{
1007
1008 MAYBE_UNUSED( args... );
1009
1010 constexpr bool isChecked( !Contains_v< TypeList<RRAs...>, Unchecked > );
1011
1012 if( isChecked ) {
1013 for( size_t i=0UL; i<n; ++i ) {
1014 if( expr.rows() <= size_t( p(i) ) ) {
1015 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
1016 }
1017 }
1018 }
1019
1020 return generate( n, expr.columns(), [op=expr.operation(),p]( size_t i, size_t j ){
1021 return op( p(i), j );
1022 } );
1023}
1025//*************************************************************************************************
1026
1027
1028
1029
1030//=================================================================================================
1031//
1032// GLOBAL RESTRUCTURING FUNCTIONS (COLUMN)
1033//
1034//=================================================================================================
1035
1036//*************************************************************************************************
1048template< size_t I // Column index
1049 , typename MT // Type of the dense matrix
1050 , typename OP // Type of the custom binary operation
1051 , bool SO // Storage order
1052 , typename... CRAs > // Optional column arguments
1053inline decltype(auto) column( const DMatGenExpr<MT,OP,SO>& expr, CRAs... args )
1054{
1056
1057 MAYBE_UNUSED( args... );
1058
1059 constexpr bool isChecked( !Contains_v< TypeList<CRAs...>, Unchecked > );
1060
1061 if( isChecked ) {
1062 if( expr.columns() <= I ) {
1063 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
1064 }
1065 }
1066 else {
1067 BLAZE_USER_ASSERT( I < expr.columns(), "Invalid column access index" );
1068 }
1069
1070 return generate<columnVector>( expr.rows(), [op=expr.operation()]( size_t i ){
1071 return op( i, I );
1072 } );
1073}
1075//*************************************************************************************************
1076
1077
1078//*************************************************************************************************
1092template< typename MT // Type of the dense matrix
1093 , typename OP // Type of the custom binary operation
1094 , bool SO // Storage order
1095 , typename... CRAs > // Runtime column arguments
1096inline decltype(auto) column( const DMatGenExpr<MT,OP,SO>& expr, size_t index, CRAs... args )
1097{
1099
1100 MAYBE_UNUSED( args... );
1101
1102 constexpr bool isChecked( !Contains_v< TypeList<CRAs...>, Unchecked > );
1103
1104 if( isChecked ) {
1105 if( expr.columns() <= index ) {
1106 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
1107 }
1108 }
1109 else {
1110 BLAZE_USER_ASSERT( index < expr.columns(), "Invalid column access index" );
1111 }
1112
1113 return generate<columnVector>( expr.rows(), [op=expr.operation(),index]( size_t i ){
1114 return op( i, index );
1115 } );
1116}
1118//*************************************************************************************************
1119
1120
1121
1122
1123//=================================================================================================
1124//
1125// GLOBAL RESTRUCTURING FUNCTIONS (COLUMNS)
1126//
1127//=================================================================================================
1128
1129//*************************************************************************************************
1142template< size_t I // First required column index
1143 , size_t... Is // Remaining required column indices
1144 , typename MT // Type of the dense matrix
1145 , typename OP // Type of the custom binary operation
1146 , bool SO // Storage order
1147 , typename... RCAs > // Optional column arguments
1148inline decltype(auto) columns( const DMatGenExpr<MT,OP,SO>& expr, RCAs... args )
1149{
1151
1152 MAYBE_UNUSED( args... );
1153
1154 constexpr bool isChecked( !Contains_v< TypeList<RCAs...>, Unchecked > );
1155
1156 if( isChecked ) {
1157 static constexpr size_t indices[] = { I, Is... };
1158 for( size_t i=0UL; i<sizeof...(Is)+1UL; ++i ) {
1159 if( expr.columns() <= indices[i] ) {
1160 BLAZE_THROW_INVALID_ARGUMENT( "Invalid elements specification" );
1161 }
1162 }
1163 }
1164
1165 return generate( expr.rows(), sizeof...(Is)+1UL, [op=expr.operation()]( size_t i, size_t j ) {
1166 static constexpr size_t indices[] = { I, Is... };
1167 return op( i, indices[j] );
1168 } );
1169}
1171//*************************************************************************************************
1172
1173
1174//*************************************************************************************************
1189template< typename MT // Type of the dense matrix
1190 , typename OP // Type of the custom binary operation
1191 , bool SO // Storage order
1192 , typename T // Type of the column indices
1193 , typename... RCAs > // Optional column arguments
1194inline decltype(auto) columns( const DMatGenExpr<MT,OP,SO> expr, T* indices, size_t n, RCAs... args )
1195{
1197
1198 MAYBE_UNUSED( args... );
1199
1200 constexpr bool isChecked( !Contains_v< TypeList<RCAs...>, Unchecked > );
1201
1202 if( isChecked ) {
1203 for( size_t i=0UL; i<n; ++i ) {
1204 if( expr.columns() <= size_t( indices[i] ) ) {
1205 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
1206 }
1207 }
1208 }
1209
1210 SmallArray<size_t,128UL> newIndices( indices, indices+n );
1211
1212 return generate( expr.rows(), n, [op=expr.operation(),newIndices]( size_t i, size_t j ){
1213 return op( i, newIndices[j] );
1214 } );
1215}
1217//*************************************************************************************************
1218
1219
1220//*************************************************************************************************
1235template< typename MT // Type of the dense matrix
1236 , typename OP // Type of the custom binary operation
1237 , bool SO // Storage order
1238 , typename P // Type of the index producer
1239 , typename... RCAs > // Optional column arguments
1240inline decltype(auto) columns( const DMatGenExpr<MT,OP,SO>& expr, P p, size_t n, RCAs... args )
1241{
1243
1244 MAYBE_UNUSED( args... );
1245
1246 constexpr bool isChecked( !Contains_v< TypeList<RCAs...>, Unchecked > );
1247
1248 if( isChecked ) {
1249 for( size_t i=0UL; i<n; ++i ) {
1250 if( expr.columns() <= size_t( p(i) ) ) {
1251 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
1252 }
1253 }
1254 }
1255
1256 return generate( expr.rows(), n, [op=expr.operation(),p]( size_t i, size_t j ){
1257 return op( i, p(j) );
1258 } );
1259}
1261//*************************************************************************************************
1262
1263
1264
1265
1266//=================================================================================================
1267//
1268// GLOBAL RESTRUCTURING FUNCTIONS (BAND)
1269//
1270//=================================================================================================
1271
1272//*************************************************************************************************
1284template< ptrdiff_t... CBAs // Compile time band arguments
1285 , typename MT // Type of the dense matrix
1286 , typename OP // Type of the custom binary operation
1287 , bool SO // Storage order
1288 , typename... RBAs > // Runtime band arguments
1289inline decltype(auto) band( const DMatGenExpr<MT,OP,SO>& expr, RBAs... args )
1290{
1292
1293 const BandData<CBAs...> bd( args... );
1294
1295 const size_t row ( bd.band() >= 0L ? 0UL : -bd.band() );
1296 const size_t column( bd.band() >= 0L ? bd.band() : 0UL );
1297 const size_t size ( min( expr.rows() - row, expr.columns() - column ) );
1298
1299 const bool isChecked( !Contains_v< TypeList<RBAs...>, Unchecked > );
1300
1301 if( isChecked ) {
1302 if( ( bd.band() > 0L && column >= expr.columns() ) ||
1303 ( bd.band() < 0L && row >= expr.rows() ) ) {
1304 BLAZE_THROW_INVALID_ARGUMENT( "Invalid band access index" );
1305 }
1306 }
1307 else {
1308 BLAZE_USER_ASSERT( bd.band() <= 0L || column < expr.columns(), "Invalid band access index" );
1309 BLAZE_USER_ASSERT( bd.band() >= 0L || row < expr.rows(), "Invalid band access index" );
1310 }
1311
1312 return generate( size, [op=expr.operation(),row,column]( size_t i ){
1313 return op( i+row, i+column );
1314 } );
1315}
1317//*************************************************************************************************
1318
1319} // namespace blaze
1320
1321#endif
Header file for auxiliary alias declarations.
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.
Header file for the function trace functionality.
Macro for CUDA compatibility.
Header file for the MAYBE_UNUSED function template.
Header file for the RemoveCVRef type trait.
Header file for the SmallArray implementation.
Compile time assertion.
Header file for the type list functionality.
Iterator over the elements of the dense matrix generator expression.
Definition: DMatGenExpr.h:118
size_t n_
Column index of the current matrix element.
Definition: DMatGenExpr.h:389
BLAZE_DEVICE_CALLABLE ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DMatGenExpr.h:155
ElementType ValueType
Type of the underlying elements.
Definition: DMatGenExpr.h:122
BLAZE_DEVICE_CALLABLE bool operator<=(const ConstIterator &rhs) const noexcept
Less-than comparison between two ConstIterator objects.
Definition: DMatGenExpr.h:305
friend BLAZE_DEVICE_CALLABLE const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: DMatGenExpr.h:348
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DMatGenExpr.h:121
OP op_
The custom binary operation.
Definition: DMatGenExpr.h:390
BLAZE_DEVICE_CALLABLE bool operator>=(const ConstIterator &rhs) const noexcept
Greater-than comparison between two ConstIterator objects.
Definition: DMatGenExpr.h:319
size_t m_
Row index of the current matrix element.
Definition: DMatGenExpr.h:388
PointerType pointer
Pointer return type.
Definition: DMatGenExpr.h:130
BLAZE_DEVICE_CALLABLE ConstIterator & operator--()
Pre-decrement operator.
Definition: DMatGenExpr.h:211
BLAZE_DEVICE_CALLABLE bool operator==(const ConstIterator &rhs) const noexcept
Equality comparison between two ConstIterator objects.
Definition: DMatGenExpr.h:249
BLAZE_DEVICE_CALLABLE bool operator<(const ConstIterator &rhs) const noexcept
Less-than comparison between two ConstIterator objects.
Definition: DMatGenExpr.h:277
BLAZE_DEVICE_CALLABLE DifferenceType operator-(const ConstIterator &rhs) const noexcept
Calculating the number of elements between two iterators.
Definition: DMatGenExpr.h:333
BLAZE_DEVICE_CALLABLE ReturnType operator*() const
Direct access to the element at the current iterator position.
Definition: DMatGenExpr.h:238
BLAZE_DEVICE_CALLABLE bool operator>(const ConstIterator &rhs) const noexcept
Greater-than comparison between two ConstIterator objects.
Definition: DMatGenExpr.h:291
DifferenceType difference_type
Difference between two iterators.
Definition: DMatGenExpr.h:132
BLAZE_DEVICE_CALLABLE ConstIterator & operator++()
Pre-increment operator.
Definition: DMatGenExpr.h:184
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DMatGenExpr.h:125
friend BLAZE_DEVICE_CALLABLE const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: DMatGenExpr.h:363
BLAZE_DEVICE_CALLABLE const ConstIterator operator++(int)
Post-increment operator.
Definition: DMatGenExpr.h:198
ValueType value_type
Type of the underlying elements.
Definition: DMatGenExpr.h:129
IteratorCategory iterator_category
The iterator category.
Definition: DMatGenExpr.h:128
BLAZE_DEVICE_CALLABLE ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DMatGenExpr.h:170
ElementType * PointerType
Pointer return type.
Definition: DMatGenExpr.h:123
BLAZE_DEVICE_CALLABLE bool operator!=(const ConstIterator &rhs) const noexcept
Inequality comparison between two ConstIterator objects.
Definition: DMatGenExpr.h:263
ElementType & ReferenceType
Reference return type.
Definition: DMatGenExpr.h:124
BLAZE_DEVICE_CALLABLE ConstIterator(size_t m, size_t n, OP op)
Constructor for the ConstIterator class.
Definition: DMatGenExpr.h:142
BLAZE_DEVICE_CALLABLE const ConstIterator operator--(int)
Post-decrement operator.
Definition: DMatGenExpr.h:225
friend BLAZE_DEVICE_CALLABLE const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: DMatGenExpr.h:378
ReferenceType reference
Reference return type.
Definition: DMatGenExpr.h:131
Expression object for the dense matrix generate() function.
Definition: DMatGenExpr.h:91
OP Operation
Data type of the custom binary operation.
Definition: DMatGenExpr.h:111
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatGenExpr.h:401
decltype(std::declval< OP >()(std::declval< size_t >(), std::declval< size_t >())) ReturnType
Return type for expression template evaluations.
Definition: DMatGenExpr.h:105
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatGenExpr.h:101
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatGenExpr.h:523
Operation op_
The custom binary operation.
Definition: DMatGenExpr.h:553
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatGenExpr.h:478
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatGenExpr.h:544
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatGenExpr.h:102
DMatGenExpr(size_t m, size_t n, OP &&op) noexcept
Constructor for the DMatGenExpr class.
Definition: DMatGenExpr.h:411
Operation operation() const
Returns a copy of the custom binary operation.
Definition: DMatGenExpr.h:498
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: DMatGenExpr.h:468
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: DMatGenExpr.h:457
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatGenExpr.h:510
size_t n_
The number of columns of the dense matrix generator.
Definition: DMatGenExpr.h:552
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatGenExpr.h:488
RemoveCVRef_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatGenExpr.h:100
ReturnType operator()(size_t i, size_t j) const noexcept
2D-access to the matrix elements.
Definition: DMatGenExpr.h:425
size_t m_
The number of rows of the dense matrix generator.
Definition: DMatGenExpr.h:551
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatGenExpr.h:534
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatGenExpr.h:440
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatGenExpr.h:398
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
Pointer difference type of the Blaze library.
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 MatGenExpr base class.
decltype(auto) band(Matrix< MT, SO > &matrix, RBAs... args)
Creating a view on a specific band of the given matrix.
Definition: Band.h:140
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) 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:1339
decltype(auto) generate(size_t m, size_t n, OP op)
Generates a new dense matrix filled via the given custom binary operation.
Definition: DMatGenExpr.h:675
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.
Definition: Expression.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_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
constexpr ptrdiff_t DefaultSize_v
Default size of the Size type trait.
Definition: Size.h:72
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.
Definition: AlignmentFlag.h:63
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
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
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
decltype(auto) submatrix(Matrix< MT, SO > &, RSAs...)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:181
#define BLAZE_DEVICE_CALLABLE
Conditional macro that sets host and device attributes when compiled with CUDA.
Definition: HostDevice.h:94
constexpr bool defaultStorageOrder
The default storage order for all matrices of the Blaze library.
Definition: StorageOrder.h:75
typename RemoveCVRef< T >::Type RemoveCVRef_t
Auxiliary alias declaration for the RemoveCVRef type trait.
Definition: RemoveCVRef.h:99
constexpr bool Contains_v
Auxiliary variable template for the Contains type trait.
Definition: Contains.h:138
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Check< false > Unchecked
Type of the blaze::unchecked instance.
Definition: Check.h:104
constexpr bool isChecked(const Ts &... args)
Extracting blaze::Check arguments from a given list of arguments.
Definition: Check.h:225
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for all forward declarations for dense vectors and matrices.
Header file for all forward declarations for expression class templates.
Header file for the Size type trait.
Header file for the StorageOrder type trait.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix generator expression templates.
Definition: MatGenExpr.h:68
Header file for the default storage order for all vectors of the Blaze library.
Header file for basic type definitions.