Matrix.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_MATRIX_H_
36 #define _BLAZE_MATH_EXPRESSIONS_MATRIX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/math/Exception.h>
50 #include <blaze/system/Inline.h>
51 #include <blaze/util/Assert.h>
52 #include <blaze/util/DisableIf.h>
53 #include <blaze/util/EnableIf.h>
55 #include <blaze/util/mpl/And.h>
56 #include <blaze/util/mpl/Not.h>
57 #include <blaze/util/Types.h>
59 #include <blaze/util/Unused.h>
60 
61 
62 namespace blaze {
63 
64 //=================================================================================================
65 //
66 // CLASS DEFINITION
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
81 template< typename MT // Type of the matrix
82  , bool SO > // Storage order
83 struct Matrix
84 {
85  //**Type definitions****************************************************************************
86  using MatrixType = MT;
87  //**********************************************************************************************
88 
89  //**Non-const conversion operator***************************************************************
95  return *static_cast<MatrixType*>( this );
96  }
97  //**********************************************************************************************
98 
99  //**Const conversion operator*******************************************************************
104  BLAZE_ALWAYS_INLINE const MatrixType& operator~() const noexcept {
105  return *static_cast<const MatrixType*>( this );
106  }
107  //**********************************************************************************************
108 };
109 //*************************************************************************************************
110 
111 
112 
113 
114 //=================================================================================================
115 //
116 // GLOBAL FUNCTIONS
117 //
118 //=================================================================================================
119 
120 //*************************************************************************************************
123 template< typename MT, bool SO >
124 BLAZE_ALWAYS_INLINE typename MT::Iterator begin( Matrix<MT,SO>& matrix, size_t i );
125 
126 template< typename MT, bool SO >
127 BLAZE_ALWAYS_INLINE typename MT::ConstIterator begin( const Matrix<MT,SO>& matrix, size_t i );
128 
129 template< typename MT, bool SO >
130 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cbegin( const Matrix<MT,SO>& matrix, size_t i );
131 
132 template< typename MT, bool SO >
133 BLAZE_ALWAYS_INLINE typename MT::Iterator end( Matrix<MT,SO>& matrix, size_t i );
134 
135 template< typename MT, bool SO >
136 BLAZE_ALWAYS_INLINE typename MT::ConstIterator end( const Matrix<MT,SO>& matrix, size_t i );
137 
138 template< typename MT, bool SO >
139 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cend( const Matrix<MT,SO>& matrix, size_t i );
140 
141 template< typename MT, bool SO >
142 BLAZE_ALWAYS_INLINE size_t rows( const Matrix<MT,SO>& matrix ) noexcept;
143 
144 template< typename MT, bool SO >
145 BLAZE_ALWAYS_INLINE size_t columns( const Matrix<MT,SO>& matrix ) noexcept;
146 
147 template< typename MT, bool SO >
148 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix ) noexcept;
149 
150 template< typename MT, bool SO >
151 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix, size_t i ) noexcept;
152 
153 template< typename MT, bool SO >
154 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix );
155 
156 template< typename MT, bool SO >
157 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix, size_t i );
158 
159 template< typename MT, bool SO >
160 BLAZE_ALWAYS_INLINE void resize( Matrix<MT,SO>& matrix, size_t rows, size_t columns, bool preserve=true );
161 
162 template< typename MT, bool SO >
164 
165 template< typename MT, bool SO >
167 
168 template< typename MT, bool SO >
170 
171 template< typename MT, bool SO >
172 inline const typename MT::ResultType evaluate( const Matrix<MT,SO>& matrix );
173 
174 template< typename MT, bool SO >
175 BLAZE_ALWAYS_INLINE bool isSquare( const Matrix<MT,SO>& matrix ) noexcept;
176 
177 template< typename MT1, bool SO1, typename MT2, bool SO2 >
178 BLAZE_ALWAYS_INLINE bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b ) noexcept;
180 //*************************************************************************************************
181 
182 
183 //*************************************************************************************************
196 template< typename MT // Type of the matrix
197  , bool SO > // Storage order of the matrix
199 {
200  return (~matrix).begin(i);
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
218 template< typename MT // Type of the matrix
219  , bool SO > // Storage order of the matrix
220 BLAZE_ALWAYS_INLINE typename MT::ConstIterator begin( const Matrix<MT,SO>& matrix, size_t i )
221 {
222  return (~matrix).begin(i);
223 }
224 //*************************************************************************************************
225 
226 
227 //*************************************************************************************************
240 template< typename MT // Type of the matrix
241  , bool SO > // Storage order of the matrix
242 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cbegin( const Matrix<MT,SO>& matrix, size_t i )
243 {
244  return (~matrix).cbegin(i);
245 }
246 //*************************************************************************************************
247 
248 
249 //*************************************************************************************************
262 template< typename MT // Type of the matrix
263  , bool SO > // Storage order of the matrix
264 BLAZE_ALWAYS_INLINE typename MT::Iterator end( Matrix<MT,SO>& matrix, size_t i )
265 {
266  return (~matrix).end(i);
267 }
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
284 template< typename MT // Type of the matrix
285  , bool SO > // Storage order of the matrix
286 BLAZE_ALWAYS_INLINE typename MT::ConstIterator end( const Matrix<MT,SO>& matrix, size_t i )
287 {
288  return (~matrix).end(i);
289 }
290 //*************************************************************************************************
291 
292 
293 //*************************************************************************************************
306 template< typename MT // Type of the matrix
307  , bool SO > // Storage order of the matrix
308 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cend( const Matrix<MT,SO>& matrix, size_t i )
309 {
310  return (~matrix).cend(i);
311 }
312 //*************************************************************************************************
313 
314 
315 //*************************************************************************************************
322 template< typename MT // Type of the matrix
323  , bool SO > // Storage order of the matrix
324 BLAZE_ALWAYS_INLINE size_t rows( const Matrix<MT,SO>& matrix ) noexcept
325 {
326  return (~matrix).rows();
327 }
328 //*************************************************************************************************
329 
330 
331 //*************************************************************************************************
338 template< typename MT // Type of the matrix
339  , bool SO > // Storage order of the matrix
340 BLAZE_ALWAYS_INLINE size_t columns( const Matrix<MT,SO>& matrix ) noexcept
341 {
342  return (~matrix).columns();
343 }
344 //*************************************************************************************************
345 
346 
347 //*************************************************************************************************
354 template< typename MT // Type of the matrix
355  , bool SO > // Storage order of the matrix
356 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix ) noexcept
357 {
358  return (~matrix).capacity();
359 }
360 //*************************************************************************************************
361 
362 
363 //*************************************************************************************************
376 template< typename MT // Type of the matrix
377  , bool SO > // Storage order of the matrix
378 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix, size_t i ) noexcept
379 {
380  return (~matrix).capacity( i );
381 }
382 //*************************************************************************************************
383 
384 
385 //*************************************************************************************************
392 template< typename MT // Type of the matrix
393  , bool SO > // Storage order of the matrix
395 {
396  return (~matrix).nonZeros();
397 }
398 //*************************************************************************************************
399 
400 
401 //*************************************************************************************************
414 template< typename MT // Type of the matrix
415  , bool SO > // Storage order of the matrix
416 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix, size_t i )
417 {
418  return (~matrix).nonZeros( i );
419 }
420 //*************************************************************************************************
421 
422 
423 //*************************************************************************************************
440 template< typename MT // Type of the matrix
441  , bool SO > // Storage order of the matrix
443  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
444 {
445  UNUSED_PARAMETER( preserve );
446 
447  if( (~matrix).rows() != m || (~matrix).columns() != n ) {
448  BLAZE_THROW_INVALID_ARGUMENT( "Matrix cannot be resized" );
449  }
450 }
452 //*************************************************************************************************
453 
454 
455 //*************************************************************************************************
468 template< typename MT // Type of the matrix
469  , bool SO > // Storage order of the matrix
471  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
472 {
473  (~matrix).resize( m, n, preserve );
474 }
476 //*************************************************************************************************
477 
478 
479 //*************************************************************************************************
493 template< typename MT // Type of the matrix
494  , bool SO > // Storage order of the matrix
495 BLAZE_ALWAYS_INLINE EnableIf_< And< IsResizable<MT>, IsSquare<MT> > >
496  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
497 {
498  if( m != n ) {
499  BLAZE_THROW_INVALID_ARGUMENT( "Invalid resize arguments for square matrix" );
500  }
501 
502  (~matrix).resize( m, preserve );
503 }
505 //*************************************************************************************************
506 
507 
508 //*************************************************************************************************
546 template< typename MT // Type of the matrix
547  , bool SO > // Storage order of the matrix
548 BLAZE_ALWAYS_INLINE void resize( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
549 {
550  resize_backend( matrix, m, n, preserve );
551 }
552 //*************************************************************************************************
553 
554 
555 //*************************************************************************************************
563 template< typename MT // Type of the matrix
564  , bool SO > // Storage order of the matrix
566  shrinkToFit_backend( Matrix<MT,SO>& matrix )
567 {
568  UNUSED_PARAMETER( matrix );
569 }
571 //*************************************************************************************************
572 
573 
574 //*************************************************************************************************
582 template< typename MT // Type of the matrix
583  , bool SO > // Storage order of the matrix
585  shrinkToFit_backend( Matrix<MT,SO>& matrix )
586 {
587  (~matrix).shrinkToFit();
588 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
607 template< typename MT // Type of the matrix
608  , bool SO > // Storage order of the matrix
610 {
611  shrinkToFit_backend( matrix );
612 }
613 //*************************************************************************************************
614 
615 
616 //*************************************************************************************************
633 template< typename MT // Type of the matrix
634  , bool SO > // Storage order of the matrix
636 {
637  (~matrix).transpose();
638 }
639 //*************************************************************************************************
640 
641 
642 //*************************************************************************************************
659 template< typename MT // Type of the matrix
660  , bool SO > // Storage order of the matrix
662 {
663  (~matrix).ctranspose();
664 }
665 //*************************************************************************************************
666 
667 
668 //*************************************************************************************************
720 template< typename MT // Type of the matrix
721  , bool SO > // Storage order of the matrix
722 inline const typename MT::ResultType evaluate( const Matrix<MT,SO>& matrix )
723 {
724  const typename MT::ResultType tmp( ~matrix );
725  return tmp;
726 }
727 //*************************************************************************************************
728 
729 
730 //*************************************************************************************************
740 template< typename MT // Type of the matrix
741  , bool SO > // Storage order
742 BLAZE_ALWAYS_INLINE bool isSquare( const Matrix<MT,SO>& matrix ) noexcept
743 {
744  return ( IsSquare<MT>::value || (~matrix).rows() == (~matrix).columns() );
745 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
782 template< typename MT1 // Type of the left-hand side matrix
783  , bool SO1 // Storage order of the left-hand side matrix
784  , typename MT2 // Type of the right-hand side matrix
785  , bool SO2 > // Storage order of the right-hand side matrix
786 BLAZE_ALWAYS_INLINE bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b ) noexcept
787 {
788  return ( IsSame<MT1,MT2>::value &&
789  reinterpret_cast<const void*>( &a ) == reinterpret_cast<const void*>( &b ) );
790 }
791 //*************************************************************************************************
792 
793 
794 //*************************************************************************************************
803 template< typename MT1 // Type of the left-hand side matrix
804  , typename MT2 // Type of the right-hand side matrix
805  , bool SO > // Storage order of both matrices
806 BLAZE_ALWAYS_INLINE void assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
807 {
809 
810  (~lhs).assign( ~rhs );
811 }
813 //*************************************************************************************************
814 
815 
816 //*************************************************************************************************
825 template< typename MT1 // Type of the left-hand side matrix
826  , bool SO // Storage order of the left-hand side matrix
827  , typename MT2 > // Type of the right-hand side matrix
829  assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
830 {
832 
834 
835  (~lhs).assign( ~rhs );
836 }
838 //*************************************************************************************************
839 
840 
841 //*************************************************************************************************
851 template< typename MT1 // Type of the left-hand side matrix
852  , bool SO // Storage order of the left-hand side matrix
853  , typename MT2 > // Type of the right-hand side matrix
855  assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
856 {
858 
860 
861  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
862 
863  (~lhs).assign( trans( ~rhs ) );
864 }
866 //*************************************************************************************************
867 
868 
869 //*************************************************************************************************
884 template< typename MT1 // Type of the left-hand side matrix
885  , bool SO1 // Storage order of the left-hand side matrix
886  , typename MT2 // Type of the right-hand side matrix
887  , bool SO2 > // Storage order of the right-hand side matrix
888 BLAZE_ALWAYS_INLINE void assign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
889 {
891 
892  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
893  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
894 
895  assign_backend( ~lhs, ~rhs );
896 }
898 //*************************************************************************************************
899 
900 
901 //*************************************************************************************************
911 template< typename MT1 // Type of the left-hand side matrix
912  , typename MT2 // Type of the right-hand side matrix
913  , bool SO > // Storage order of both matrices
914 BLAZE_ALWAYS_INLINE void addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
915 {
917 
918  (~lhs).addAssign( ~rhs );
919 }
921 //*************************************************************************************************
922 
923 
924 //*************************************************************************************************
934 template< typename MT1 // Type of the left-hand side matrix
935  , bool SO // Storage order of the left-hand side matrix
936  , typename MT2 > // Type of the right-hand side matrix
938  addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
939 {
941 
943 
944  (~lhs).addAssign( ~rhs );
945 }
947 //*************************************************************************************************
948 
949 
950 //*************************************************************************************************
960 template< typename MT1 // Type of the left-hand side matrix
961  , bool SO // Storage order of the left-hand side matrix
962  , typename MT2 > // Type of the right-hand side matrix
964  addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
965 {
967 
969 
970  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
971 
972  (~lhs).addAssign( trans( ~rhs ) );
973 }
975 //*************************************************************************************************
976 
977 
978 //*************************************************************************************************
993 template< typename MT1 // Type of the left-hand side matrix
994  , bool SO1 // Storage order of the left-hand side matrix
995  , typename MT2 // Type of the right-hand side matrix
996  , bool SO2 > // Storage order of the right-hand side matrix
997 BLAZE_ALWAYS_INLINE void addAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
998 {
1000 
1001  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
1002  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
1003 
1004  addAssign_backend( ~lhs, ~rhs );
1005 }
1007 //*************************************************************************************************
1008 
1009 
1010 //*************************************************************************************************
1020 template< typename MT1 // Type of the left-hand side matrix
1021  , typename MT2 // Type of the right-hand side matrix
1022  , bool SO > // Storage order of both matrices
1023 BLAZE_ALWAYS_INLINE void subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
1024 {
1026 
1027  (~lhs).subAssign( ~rhs );
1028 }
1030 //*************************************************************************************************
1031 
1032 
1033 //*************************************************************************************************
1043 template< typename MT1 // Type of the left-hand side matrix
1044  , bool SO // Storage order of the left-hand side matrix
1045  , typename MT2 > // Type of the right-hand side matrix
1047  subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
1048 {
1050 
1052 
1053  (~lhs).subAssign( ~rhs );
1054 }
1056 //*************************************************************************************************
1057 
1058 
1059 //*************************************************************************************************
1069 template< typename MT1 // Type of the left-hand side matrix
1070  , bool SO // Storage order of the left-hand side matrix
1071  , typename MT2 > // Type of the right-hand side matrix
1073  subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
1074 {
1076 
1078 
1079  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
1080 
1081  (~lhs).subAssign( trans( ~rhs ) );
1082 }
1084 //*************************************************************************************************
1085 
1086 
1087 //*************************************************************************************************
1102 template< typename MT1 // Type of the left-hand side matrix
1103  , bool SO1 // Storage order of the left-hand side matrix
1104  , typename MT2 // Type of the right-hand side matrix
1105  , bool SO2 > // Storage order of the right-hand side matrix
1106 BLAZE_ALWAYS_INLINE void subAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
1107 {
1109 
1110  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
1111  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
1112 
1113  subAssign_backend( ~lhs, ~rhs );
1114 }
1116 //*************************************************************************************************
1117 
1118 
1119 //*************************************************************************************************
1129 template< typename MT1 // Type of the left-hand side matrix
1130  , typename MT2 // Type of the right-hand side matrix
1131  , bool SO > // Storage order of both matrices
1132 BLAZE_ALWAYS_INLINE void schurAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
1133 {
1135 
1136  (~lhs).schurAssign( ~rhs );
1137 }
1139 //*************************************************************************************************
1140 
1141 
1142 //*************************************************************************************************
1152 template< typename MT1 // Type of the left-hand side matrix
1153  , bool SO // Storage order of the left-hand side matrix
1154  , typename MT2 > // Type of the right-hand side matrix
1156  schurAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
1157 {
1159 
1161 
1162  (~lhs).schurAssign( ~rhs );
1163 }
1165 //*************************************************************************************************
1166 
1167 
1168 //*************************************************************************************************
1178 template< typename MT1 // Type of the left-hand side matrix
1179  , bool SO // Storage order of the left-hand side matrix
1180  , typename MT2 > // Type of the right-hand side matrix
1182  schurAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
1183 {
1185 
1187 
1188  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
1189 
1190  (~lhs).schurAssign( trans( ~rhs ) );
1191 }
1193 //*************************************************************************************************
1194 
1195 
1196 //*************************************************************************************************
1211 template< typename MT1 // Type of the left-hand side matrix
1212  , bool SO1 // Storage order of the left-hand side matrix
1213  , typename MT2 // Type of the right-hand side matrix
1214  , bool SO2 > // Storage order of the right-hand side matrix
1215 BLAZE_ALWAYS_INLINE void schurAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
1216 {
1218 
1219  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
1220  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
1221 
1222  schurAssign_backend( ~lhs, ~rhs );
1223 }
1225 //*************************************************************************************************
1226 
1227 
1228 //*************************************************************************************************
1243 template< typename MT1 // Type of the left-hand side matrix
1244  , bool SO1 // Storage order of the left-hand side matrix
1245  , typename MT2 // Type of the right-hand side matrix
1246  , bool SO2 > // Storage order of the right-hand side matrix
1247 BLAZE_ALWAYS_INLINE void multAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
1248 {
1250 
1251  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).rows(), "Invalid matrix sizes" );
1252 
1253  (~lhs).multAssign( ~rhs );
1254 }
1256 //*************************************************************************************************
1257 
1258 
1259 //*************************************************************************************************
1275 template< typename MT // Type of the left-hand side matrix
1276  , bool SO // Storage order of the left-hand side matrix
1277  , typename VT // Type of the right-hand side vector
1278  , bool TF > // Transpose flag of the right-hand side vector
1279 BLAZE_ALWAYS_INLINE bool tryAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1280  size_t row, size_t column )
1281 {
1282  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1283  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1284  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1285  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1286 
1287  UNUSED_PARAMETER( lhs, rhs, row, column );
1288 
1289  return true;
1290 }
1292 //*************************************************************************************************
1293 
1294 
1295 //*************************************************************************************************
1311 template< typename MT1 // Type of the left-hand side matrix
1312  , bool SO1 // Storage order of the left-hand side matrix
1313  , typename MT2 // Type of the right-hand side matrix
1314  , bool SO2 > // Storage order of the right-hand side matrix
1315 BLAZE_ALWAYS_INLINE bool tryAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1316  size_t row, size_t column )
1317 {
1318  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1319  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1320  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1321  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1322 
1323  UNUSED_PARAMETER( lhs, rhs, row, column );
1324 
1325  return true;
1326 }
1328 //*************************************************************************************************
1329 
1330 
1331 //*************************************************************************************************
1347 template< typename MT // Type of the left-hand side matrix
1348  , bool SO // Storage order of the left-hand side matrix
1349  , typename VT // Type of the right-hand side vector
1350  , bool TF > // Transpose flag of the right-hand side vector
1351 BLAZE_ALWAYS_INLINE bool tryAddAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1352  size_t row, size_t column )
1353 {
1354  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1355  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1356  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1357  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1358 
1359  UNUSED_PARAMETER( lhs, rhs, row, column );
1360 
1361  return true;
1362 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1383 template< typename MT1 // Type of the left-hand side matrix
1384  , bool SO1 // Storage order of the left-hand side matrix
1385  , typename MT2 // Type of the right-hand side matrix
1386  , bool SO2 > // Storage order of the right-hand side matrix
1387 BLAZE_ALWAYS_INLINE bool tryAddAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1388  size_t row, size_t column )
1389 {
1390  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1391  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1392  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1393  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1394 
1395  UNUSED_PARAMETER( lhs, rhs, row, column );
1396 
1397  return true;
1398 }
1400 //*************************************************************************************************
1401 
1402 
1403 //*************************************************************************************************
1419 template< typename MT // Type of the left-hand side matrix
1420  , bool SO // Storage order of the left-hand side matrix
1421  , typename VT // Type of the right-hand side vector
1422  , bool TF > // Transpose flag of the right-hand side vector
1423 BLAZE_ALWAYS_INLINE bool trySubAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1424  size_t row, size_t column )
1425 {
1426  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1427  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1428  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1429  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1430 
1431  UNUSED_PARAMETER( lhs, rhs, row, column );
1432 
1433  return true;
1434 }
1436 //*************************************************************************************************
1437 
1438 
1439 //*************************************************************************************************
1455 template< typename MT1 // Type of the left-hand side matrix
1456  , bool SO1 // Storage order of the left-hand side matrix
1457  , typename MT2 // Type of the right-hand side matrix
1458  , bool SO2 > // Storage order of the right-hand side matrix
1459 BLAZE_ALWAYS_INLINE bool trySubAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1460  size_t row, size_t column )
1461 {
1462  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1463  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1464  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1465  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1466 
1467  UNUSED_PARAMETER( lhs, rhs, row, column );
1468 
1469  return true;
1470 }
1472 //*************************************************************************************************
1473 
1474 
1475 //*************************************************************************************************
1491 template< typename MT // Type of the left-hand side matrix
1492  , bool SO // Storage order of the left-hand side matrix
1493  , typename VT // Type of the right-hand side vector
1494  , bool TF > // Transpose flag of the right-hand side vector
1495 BLAZE_ALWAYS_INLINE bool tryMultAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1496  size_t row, size_t column )
1497 {
1498  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1499  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1500  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1501  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1502 
1503  UNUSED_PARAMETER( lhs, rhs, row, column );
1504 
1505  return true;
1506 }
1508 //*************************************************************************************************
1509 
1510 
1511 //*************************************************************************************************
1527 template< typename MT1 // Type of the left-hand side matrix
1528  , bool SO1 // Storage order of the left-hand side matrix
1529  , typename MT2 // Type of the right-hand side matrix
1530  , bool SO2 > // Storage order of the right-hand side matrix
1531 BLAZE_ALWAYS_INLINE bool trySchurAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1532  size_t row, size_t column )
1533 {
1534  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1535  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1536  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1537  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1538 
1539  UNUSED_PARAMETER( lhs, rhs, row, column );
1540 
1541  return true;
1542 }
1544 //*************************************************************************************************
1545 
1546 
1547 //*************************************************************************************************
1563 template< typename MT // Type of the left-hand side matrix
1564  , bool SO // Storage order of the left-hand side matrix
1565  , typename VT // Type of the right-hand side vector
1566  , bool TF > // Transpose flag of the right-hand side vector
1567 BLAZE_ALWAYS_INLINE bool tryDivAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1568  size_t row, size_t column )
1569 {
1570  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1571  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1572  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1573  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1574 
1575  UNUSED_PARAMETER( lhs, rhs, row, column );
1576 
1577  return true;
1578 }
1580 //*************************************************************************************************
1581 
1582 
1583 //*************************************************************************************************
1598 template< typename MT // Type of the matrix
1599  , bool SO > // Storage order
1600 BLAZE_ALWAYS_INLINE MT& derestrict( Matrix<MT,SO>& matrix )
1601 {
1602  return ~matrix;
1603 }
1605 //*************************************************************************************************
1606 
1607 } // namespace blaze
1608 
1609 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for the UNUSED_PARAMETER function template.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:356
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:786
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
Header file for the IsSame and IsStrictlySame type traits.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:3078
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:198
BLAZE_ALWAYS_INLINE void shrinkToFit(Matrix< MT, SO > &matrix)
Requesting the removal of unused capacity.
Definition: Matrix.h:609
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:224
Header file for the And class template.
BLAZE_ALWAYS_INLINE void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:661
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:394
Column< MT > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:124
Type relationship analysis.This class tests if the two data types A and B are equal. For this type comparison, the cv-qualifiers of both data types are ignored. If A and B are the same data type (ignoring the cv-qualifiers), then the value member constant is set to true, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to false, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:140
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3086
const MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:722
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:308
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:242
Header file for the IsSquare type trait.
Row< MT > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:124
Header file for the DisableIf class template.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Header file for the IsShrinkable type trait.
Header file for the Not class template.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3087
Compile time check for square matrices.This type trait tests whether or not the given template parame...
Definition: IsSquare.h:88
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:340
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:548
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:264
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
Header file for run time assertion macros.
BLAZE_ALWAYS_INLINE const MatrixType & operator~() const noexcept
Conversion operator for constant matrices.
Definition: Matrix.h:104
Expression object for sparse matrix-scalar divisions.The SMatScalarMult class represents the compile ...
Definition: Forward.h:113
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Compile time type negation.The Not alias declaration negates the given compile time condition...
Definition: Not.h:70
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:101
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:224
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:324
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:790
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:177
void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:742
Header file for the IsResizable type trait.
BLAZE_ALWAYS_INLINE MatrixType & operator~() noexcept
Conversion operator for non-constant matrices.
Definition: Matrix.h:94
System settings for the inline keywords.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the function trace functionality.
BLAZE_ALWAYS_INLINE void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:635