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>
49 #include <blaze/system/Inline.h>
50 #include <blaze/util/Assert.h>
51 #include <blaze/util/DisableIf.h>
52 #include <blaze/util/EnableIf.h>
54 #include <blaze/util/mpl/And.h>
55 #include <blaze/util/mpl/Not.h>
56 #include <blaze/util/Types.h>
58 #include <blaze/util/Unused.h>
59 
60 
61 namespace blaze {
62 
63 //=================================================================================================
64 //
65 // CLASS DEFINITION
66 //
67 //=================================================================================================
68 
69 //*************************************************************************************************
80 template< typename MT // Type of the matrix
81  , bool SO > // Storage order
82 struct Matrix
83 {
84  //**Type definitions****************************************************************************
85  typedef MT MatrixType;
86  //**********************************************************************************************
87 
88  //**Non-const conversion operator***************************************************************
93  BLAZE_ALWAYS_INLINE MatrixType& operator~() noexcept {
94  return *static_cast<MatrixType*>( this );
95  }
96  //**********************************************************************************************
97 
98  //**Const conversion operator*******************************************************************
103  BLAZE_ALWAYS_INLINE const MatrixType& operator~() const noexcept {
104  return *static_cast<const MatrixType*>( this );
105  }
106  //**********************************************************************************************
107 };
108 //*************************************************************************************************
109 
110 
111 
112 
113 //=================================================================================================
114 //
115 // GLOBAL FUNCTIONS
116 //
117 //=================================================================================================
118 
119 //*************************************************************************************************
122 template< typename MT, bool SO >
123 BLAZE_ALWAYS_INLINE typename MT::Iterator begin( Matrix<MT,SO>& matrix, size_t i );
124 
125 template< typename MT, bool SO >
126 BLAZE_ALWAYS_INLINE typename MT::ConstIterator begin( const Matrix<MT,SO>& matrix, size_t i );
127 
128 template< typename MT, bool SO >
129 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cbegin( const Matrix<MT,SO>& matrix, size_t i );
130 
131 template< typename MT, bool SO >
132 BLAZE_ALWAYS_INLINE typename MT::Iterator end( Matrix<MT,SO>& matrix, size_t i );
133 
134 template< typename MT, bool SO >
135 BLAZE_ALWAYS_INLINE typename MT::ConstIterator end( const Matrix<MT,SO>& matrix, size_t i );
136 
137 template< typename MT, bool SO >
138 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cend( const Matrix<MT,SO>& matrix, size_t i );
139 
140 template< typename MT, bool SO >
141 BLAZE_ALWAYS_INLINE size_t rows( const Matrix<MT,SO>& matrix ) noexcept;
142 
143 template< typename MT, bool SO >
144 BLAZE_ALWAYS_INLINE size_t columns( const Matrix<MT,SO>& matrix ) noexcept;
145 
146 template< typename MT, bool SO >
147 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix ) noexcept;
148 
149 template< typename MT, bool SO >
150 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix, size_t i ) noexcept;
151 
152 template< typename MT, bool SO >
153 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix );
154 
155 template< typename MT, bool SO >
156 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix, size_t i );
157 
158 template< typename MT, bool SO >
159 BLAZE_ALWAYS_INLINE void resize( Matrix<MT,SO>& matrix, size_t rows, size_t columns, bool preserve=true );
160 
161 template< typename MT, bool SO >
163 
164 template< typename MT, bool SO >
166 
167 template< typename MT, bool SO >
168 inline const typename MT::ResultType evaluate( const Matrix<MT,SO>& matrix );
169 
170 template< typename MT, bool SO >
171 BLAZE_ALWAYS_INLINE bool isSquare( const Matrix<MT,SO>& matrix ) noexcept;
172 
173 template< typename MT1, bool SO1, typename MT2, bool SO2 >
174 BLAZE_ALWAYS_INLINE bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b ) noexcept;
176 //*************************************************************************************************
177 
178 
179 //*************************************************************************************************
192 template< typename MT // Type of the matrix
193  , bool SO > // Storage order of the matrix
195 {
196  return (~matrix).begin(i);
197 }
198 //*************************************************************************************************
199 
200 
201 //*************************************************************************************************
214 template< typename MT // Type of the matrix
215  , bool SO > // Storage order of the matrix
216 BLAZE_ALWAYS_INLINE typename MT::ConstIterator begin( const Matrix<MT,SO>& matrix, size_t i )
217 {
218  return (~matrix).begin(i);
219 }
220 //*************************************************************************************************
221 
222 
223 //*************************************************************************************************
236 template< typename MT // Type of the matrix
237  , bool SO > // Storage order of the matrix
238 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cbegin( const Matrix<MT,SO>& matrix, size_t i )
239 {
240  return (~matrix).cbegin(i);
241 }
242 //*************************************************************************************************
243 
244 
245 //*************************************************************************************************
258 template< typename MT // Type of the matrix
259  , bool SO > // Storage order of the matrix
260 BLAZE_ALWAYS_INLINE typename MT::Iterator end( Matrix<MT,SO>& matrix, size_t i )
261 {
262  return (~matrix).end(i);
263 }
264 //*************************************************************************************************
265 
266 
267 //*************************************************************************************************
280 template< typename MT // Type of the matrix
281  , bool SO > // Storage order of the matrix
282 BLAZE_ALWAYS_INLINE typename MT::ConstIterator end( const Matrix<MT,SO>& matrix, size_t i )
283 {
284  return (~matrix).end(i);
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
302 template< typename MT // Type of the matrix
303  , bool SO > // Storage order of the matrix
304 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cend( const Matrix<MT,SO>& matrix, size_t i )
305 {
306  return (~matrix).cend(i);
307 }
308 //*************************************************************************************************
309 
310 
311 //*************************************************************************************************
318 template< typename MT // Type of the matrix
319  , bool SO > // Storage order of the matrix
320 BLAZE_ALWAYS_INLINE size_t rows( const Matrix<MT,SO>& matrix ) noexcept
321 {
322  return (~matrix).rows();
323 }
324 //*************************************************************************************************
325 
326 
327 //*************************************************************************************************
334 template< typename MT // Type of the matrix
335  , bool SO > // Storage order of the matrix
336 BLAZE_ALWAYS_INLINE size_t columns( const Matrix<MT,SO>& matrix ) noexcept
337 {
338  return (~matrix).columns();
339 }
340 //*************************************************************************************************
341 
342 
343 //*************************************************************************************************
350 template< typename MT // Type of the matrix
351  , bool SO > // Storage order of the matrix
352 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix ) noexcept
353 {
354  return (~matrix).capacity();
355 }
356 //*************************************************************************************************
357 
358 
359 //*************************************************************************************************
372 template< typename MT // Type of the matrix
373  , bool SO > // Storage order of the matrix
374 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix, size_t i ) noexcept
375 {
376  return (~matrix).capacity( i );
377 }
378 //*************************************************************************************************
379 
380 
381 //*************************************************************************************************
388 template< typename MT // Type of the matrix
389  , bool SO > // Storage order of the matrix
391 {
392  return (~matrix).nonZeros();
393 }
394 //*************************************************************************************************
395 
396 
397 //*************************************************************************************************
410 template< typename MT // Type of the matrix
411  , bool SO > // Storage order of the matrix
412 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix, size_t i )
413 {
414  return (~matrix).nonZeros( i );
415 }
416 //*************************************************************************************************
417 
418 
419 //*************************************************************************************************
436 template< typename MT // Type of the matrix
437  , bool SO > // Storage order of the matrix
439  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
440 {
441  UNUSED_PARAMETER( preserve );
442 
443  if( (~matrix).rows() != m || (~matrix).columns() != n ) {
444  BLAZE_THROW_INVALID_ARGUMENT( "Matrix cannot be resized" );
445  }
446 }
448 //*************************************************************************************************
449 
450 
451 //*************************************************************************************************
464 template< typename MT // Type of the matrix
465  , bool SO > // Storage order of the matrix
467  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
468 {
469  (~matrix).resize( m, n, preserve );
470 }
472 //*************************************************************************************************
473 
474 
475 //*************************************************************************************************
489 template< typename MT // Type of the matrix
490  , bool SO > // Storage order of the matrix
491 BLAZE_ALWAYS_INLINE EnableIf_< And< IsResizable<MT>, IsSquare<MT> > >
492  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
493 {
494  if( m != n ) {
495  BLAZE_THROW_INVALID_ARGUMENT( "Invalid resize arguments for square matrix" );
496  }
497 
498  (~matrix).resize( m, preserve );
499 }
501 //*************************************************************************************************
502 
503 
504 //*************************************************************************************************
542 template< typename MT // Type of the matrix
543  , bool SO > // Storage order of the matrix
544 BLAZE_ALWAYS_INLINE void resize( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
545 {
546  resize_backend( matrix, m, n, preserve );
547 }
548 //*************************************************************************************************
549 
550 
551 //*************************************************************************************************
568 template< typename MT // Type of the matrix
569  , bool SO > // Storage order of the matrix
571 {
572  (~matrix).transpose();
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
594 template< typename MT // Type of the matrix
595  , bool SO > // Storage order of the matrix
597 {
598  (~matrix).ctranspose();
599 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
655 template< typename MT // Type of the matrix
656  , bool SO > // Storage order of the matrix
657 inline const typename MT::ResultType evaluate( const Matrix<MT,SO>& matrix )
658 {
659  const typename MT::ResultType tmp( ~matrix );
660  return tmp;
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
675 template< typename MT // Type of the matrix
676  , bool SO > // Storage order
677 BLAZE_ALWAYS_INLINE bool isSquare( const Matrix<MT,SO>& matrix ) noexcept
678 {
679  return ( IsSquare<MT>::value || (~matrix).rows() == (~matrix).columns() );
680 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
717 template< typename MT1 // Type of the left-hand side matrix
718  , bool SO1 // Storage order of the left-hand side matrix
719  , typename MT2 // Type of the right-hand side matrix
720  , bool SO2 > // Storage order of the right-hand side matrix
721 BLAZE_ALWAYS_INLINE bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b ) noexcept
722 {
723  return ( IsSame<MT1,MT2>::value &&
724  reinterpret_cast<const void*>( &a ) == reinterpret_cast<const void*>( &b ) );
725 }
726 //*************************************************************************************************
727 
728 
729 //*************************************************************************************************
738 template< typename MT1 // Type of the left-hand side matrix
739  , typename MT2 // Type of the right-hand side matrix
740  , bool SO > // Storage order of both matrices
741 BLAZE_ALWAYS_INLINE void assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
742 {
744 
745  (~lhs).assign( ~rhs );
746 }
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
760 template< typename MT1 // Type of the left-hand side matrix
761  , bool SO // Storage order of the left-hand side matrix
762  , typename MT2 > // Type of the right-hand side matrix
764  assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
765 {
767 
769 
770  (~lhs).assign( ~rhs );
771 }
773 //*************************************************************************************************
774 
775 
776 //*************************************************************************************************
786 template< typename MT1 // Type of the left-hand side matrix
787  , bool SO // Storage order of the left-hand side matrix
788  , typename MT2 > // Type of the right-hand side matrix
790  assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
791 {
793 
795 
796  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
797 
798  (~lhs).assign( trans( ~rhs ) );
799 }
801 //*************************************************************************************************
802 
803 
804 //*************************************************************************************************
819 template< typename MT1 // Type of the left-hand side matrix
820  , bool SO1 // Storage order of the left-hand side matrix
821  , typename MT2 // Type of the right-hand side matrix
822  , bool SO2 > // Storage order of the right-hand side matrix
823 BLAZE_ALWAYS_INLINE void assign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
824 {
826 
827  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
828  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
829 
830  assign_backend( ~lhs, ~rhs );
831 }
833 //*************************************************************************************************
834 
835 
836 //*************************************************************************************************
846 template< typename MT1 // Type of the left-hand side matrix
847  , typename MT2 // Type of the right-hand side matrix
848  , bool SO > // Storage order of both matrices
849 BLAZE_ALWAYS_INLINE void addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
850 {
852 
853  (~lhs).addAssign( ~rhs );
854 }
856 //*************************************************************************************************
857 
858 
859 //*************************************************************************************************
869 template< typename MT1 // Type of the left-hand side matrix
870  , bool SO // Storage order of the left-hand side matrix
871  , typename MT2 > // Type of the right-hand side matrix
873  addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
874 {
876 
878 
879  (~lhs).addAssign( ~rhs );
880 }
882 //*************************************************************************************************
883 
884 
885 //*************************************************************************************************
895 template< typename MT1 // Type of the left-hand side matrix
896  , bool SO // Storage order of the left-hand side matrix
897  , typename MT2 > // Type of the right-hand side matrix
899  addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
900 {
902 
904 
905  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
906 
907  (~lhs).addAssign( trans( ~rhs ) );
908 }
910 //*************************************************************************************************
911 
912 
913 //*************************************************************************************************
928 template< typename MT1 // Type of the left-hand side matrix
929  , bool SO1 // Storage order of the left-hand side matrix
930  , typename MT2 // Type of the right-hand side matrix
931  , bool SO2 > // Storage order of the right-hand side matrix
932 BLAZE_ALWAYS_INLINE void addAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
933 {
935 
936  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
937  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
938 
939  addAssign_backend( ~lhs, ~rhs );
940 }
942 //*************************************************************************************************
943 
944 
945 //*************************************************************************************************
955 template< typename MT1 // Type of the left-hand side matrix
956  , typename MT2 // Type of the right-hand side matrix
957  , bool SO > // Storage order of both matrices
958 BLAZE_ALWAYS_INLINE void subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
959 {
961 
962  (~lhs).subAssign( ~rhs );
963 }
965 //*************************************************************************************************
966 
967 
968 //*************************************************************************************************
978 template< typename MT1 // Type of the left-hand side matrix
979  , bool SO // Storage order of the left-hand side matrix
980  , typename MT2 > // Type of the right-hand side matrix
982  subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
983 {
985 
987 
988  (~lhs).subAssign( ~rhs );
989 }
991 //*************************************************************************************************
992 
993 
994 //*************************************************************************************************
1004 template< typename MT1 // Type of the left-hand side matrix
1005  , bool SO // Storage order of the left-hand side matrix
1006  , typename MT2 > // Type of the right-hand side matrix
1008  subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
1009 {
1011 
1013 
1014  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
1015 
1016  (~lhs).subAssign( trans( ~rhs ) );
1017 }
1019 //*************************************************************************************************
1020 
1021 
1022 //*************************************************************************************************
1037 template< typename MT1 // Type of the left-hand side matrix
1038  , bool SO1 // Storage order of the left-hand side matrix
1039  , typename MT2 // Type of the right-hand side matrix
1040  , bool SO2 > // Storage order of the right-hand side matrix
1041 BLAZE_ALWAYS_INLINE void subAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
1042 {
1044 
1045  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
1046  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
1047 
1048  subAssign_backend( ~lhs, ~rhs );
1049 }
1051 //*************************************************************************************************
1052 
1053 
1054 //*************************************************************************************************
1069 template< typename MT1 // Type of the left-hand side matrix
1070  , bool SO1 // Storage order of the left-hand side matrix
1071  , typename MT2 // Type of the right-hand side matrix
1072  , bool SO2 > // Storage order of the right-hand side matrix
1073 BLAZE_ALWAYS_INLINE void multAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
1074 {
1076 
1077  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).rows(), "Invalid matrix sizes" );
1078 
1079  (~lhs).multAssign( ~rhs );
1080 }
1082 //*************************************************************************************************
1083 
1084 
1085 //*************************************************************************************************
1101 template< typename MT // Type of the left-hand side matrix
1102  , bool SO // Storage order of the left-hand side matrix
1103  , typename VT // Type of the right-hand side vector
1104  , bool TF > // Transpose flag of the right-hand side vector
1105 BLAZE_ALWAYS_INLINE bool tryAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1106  size_t row, size_t column )
1107 {
1108  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1109  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1110  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1111  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1112 
1113  UNUSED_PARAMETER( lhs, rhs, row, column );
1114 
1115  return true;
1116 }
1118 //*************************************************************************************************
1119 
1120 
1121 //*************************************************************************************************
1137 template< typename MT1 // Type of the left-hand side matrix
1138  , bool SO1 // Storage order of the left-hand side matrix
1139  , typename MT2 // Type of the right-hand side matrix
1140  , bool SO2 > // Storage order of the right-hand side matrix
1141 BLAZE_ALWAYS_INLINE bool tryAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1142  size_t row, size_t column )
1143 {
1144  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1145  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1146  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1147  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1148 
1149  UNUSED_PARAMETER( lhs, rhs, row, column );
1150 
1151  return true;
1152 }
1154 //*************************************************************************************************
1155 
1156 
1157 //*************************************************************************************************
1173 template< typename MT // Type of the left-hand side matrix
1174  , bool SO // Storage order of the left-hand side matrix
1175  , typename VT // Type of the right-hand side vector
1176  , bool TF > // Transpose flag of the right-hand side vector
1177 BLAZE_ALWAYS_INLINE bool tryAddAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1178  size_t row, size_t column )
1179 {
1180  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1181  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1182  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1183  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1184 
1185  UNUSED_PARAMETER( lhs, rhs, row, column );
1186 
1187  return true;
1188 }
1190 //*************************************************************************************************
1191 
1192 
1193 //*************************************************************************************************
1209 template< typename MT1 // Type of the left-hand side matrix
1210  , bool SO1 // Storage order of the left-hand side matrix
1211  , typename MT2 // Type of the right-hand side matrix
1212  , bool SO2 > // Storage order of the right-hand side matrix
1213 BLAZE_ALWAYS_INLINE bool tryAddAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1214  size_t row, size_t column )
1215 {
1216  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1217  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1218  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1219  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1220 
1221  UNUSED_PARAMETER( lhs, rhs, row, column );
1222 
1223  return true;
1224 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1245 template< typename MT // Type of the left-hand side matrix
1246  , bool SO // Storage order of the left-hand side matrix
1247  , typename VT // Type of the right-hand side vector
1248  , bool TF > // Transpose flag of the right-hand side vector
1249 BLAZE_ALWAYS_INLINE bool trySubAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1250  size_t row, size_t column )
1251 {
1252  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1253  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1254  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1255  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1256 
1257  UNUSED_PARAMETER( lhs, rhs, row, column );
1258 
1259  return true;
1260 }
1262 //*************************************************************************************************
1263 
1264 
1265 //*************************************************************************************************
1281 template< typename MT1 // Type of the left-hand side matrix
1282  , bool SO1 // Storage order of the left-hand side matrix
1283  , typename MT2 // Type of the right-hand side matrix
1284  , bool SO2 > // Storage order of the right-hand side matrix
1285 BLAZE_ALWAYS_INLINE bool trySubAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1286  size_t row, size_t column )
1287 {
1288  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1289  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1290  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1291  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1292 
1293  UNUSED_PARAMETER( lhs, rhs, row, column );
1294 
1295  return true;
1296 }
1298 //*************************************************************************************************
1299 
1300 
1301 //*************************************************************************************************
1317 template< typename MT // Type of the left-hand side matrix
1318  , bool SO // Storage order of the left-hand side matrix
1319  , typename VT // Type of the right-hand side vector
1320  , bool TF > // Transpose flag of the right-hand side vector
1321 BLAZE_ALWAYS_INLINE bool tryMultAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1322  size_t row, size_t column )
1323 {
1324  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1325  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1326  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1327  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1328 
1329  UNUSED_PARAMETER( lhs, rhs, row, column );
1330 
1331  return true;
1332 }
1334 //*************************************************************************************************
1335 
1336 
1337 //*************************************************************************************************
1353 template< typename MT // Type of the left-hand side matrix
1354  , bool SO // Storage order of the left-hand side matrix
1355  , typename VT // Type of the right-hand side vector
1356  , bool TF > // Transpose flag of the right-hand side vector
1357 BLAZE_ALWAYS_INLINE bool tryDivAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1358  size_t row, size_t column )
1359 {
1360  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1361  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1362  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1363  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1364 
1365  UNUSED_PARAMETER( lhs, rhs, row, column );
1366 
1367  return true;
1368 }
1370 //*************************************************************************************************
1371 
1372 
1373 //*************************************************************************************************
1388 template< typename MT // Type of the matrix
1389  , bool SO > // Storage order
1390 BLAZE_ALWAYS_INLINE MT& derestrict( Matrix<MT,SO>& matrix )
1391 {
1392  return ~matrix;
1393 }
1395 //*************************************************************************************************
1396 
1397 } // namespace blaze
1398 
1399 #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:352
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:721
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:261
MT MatrixType
Type of the matrix.
Definition: Matrix.h:85
Header file for the IsSame and IsStrictlySame type traits.
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:194
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
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:596
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:390
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:138
const MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:657
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:304
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:238
Header file for the IsSquare type trait.
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
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2939
Header file for the Not class template.
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:336
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT >, IsDeclExpr< MT > >, RowExprTrait_< MT > > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:128
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:544
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:260
Header file for all forward declarations for expression class templates.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT >, IsDeclExpr< MT > >, ColumnExprTrait_< MT > > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:128
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:103
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:93
Compile time type negation.The Not class template negates the given compile time condition. In case the given condition would evaluate to true, the nested member enumeration is set to false and vice versa:
Definition: Not.h:70
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2938
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:94
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:223
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:320
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:733
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2930
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:677
Header file for the IsResizable type trait.
BLAZE_ALWAYS_INLINE MatrixType & operator~() noexcept
Conversion operator for non-constant matrices.
Definition: Matrix.h:93
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:570