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 >
162 BLAZE_ALWAYS_INLINE void transpose( Matrix<MT,SO>& matrix );
163 
164 template< typename MT, bool SO >
165 BLAZE_ALWAYS_INLINE bool isSquare( const Matrix<MT,SO>& matrix ) noexcept;
166 
167 template< typename MT1, bool SO1, typename MT2, bool SO2 >
168 BLAZE_ALWAYS_INLINE bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b ) noexcept;
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
186 template< typename MT // Type of the matrix
187  , bool SO > // Storage order of the matrix
189 {
190  return (~matrix).begin(i);
191 }
192 //*************************************************************************************************
193 
194 
195 //*************************************************************************************************
208 template< typename MT // Type of the matrix
209  , bool SO > // Storage order of the matrix
210 BLAZE_ALWAYS_INLINE typename MT::ConstIterator begin( const Matrix<MT,SO>& matrix, size_t i )
211 {
212  return (~matrix).begin(i);
213 }
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
230 template< typename MT // Type of the matrix
231  , bool SO > // Storage order of the matrix
232 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cbegin( const Matrix<MT,SO>& matrix, size_t i )
233 {
234  return (~matrix).cbegin(i);
235 }
236 //*************************************************************************************************
237 
238 
239 //*************************************************************************************************
252 template< typename MT // Type of the matrix
253  , bool SO > // Storage order of the matrix
254 BLAZE_ALWAYS_INLINE typename MT::Iterator end( Matrix<MT,SO>& matrix, size_t i )
255 {
256  return (~matrix).end(i);
257 }
258 //*************************************************************************************************
259 
260 
261 //*************************************************************************************************
274 template< typename MT // Type of the matrix
275  , bool SO > // Storage order of the matrix
276 BLAZE_ALWAYS_INLINE typename MT::ConstIterator end( const Matrix<MT,SO>& matrix, size_t i )
277 {
278  return (~matrix).end(i);
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
296 template< typename MT // Type of the matrix
297  , bool SO > // Storage order of the matrix
298 BLAZE_ALWAYS_INLINE typename MT::ConstIterator cend( const Matrix<MT,SO>& matrix, size_t i )
299 {
300  return (~matrix).cend(i);
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
312 template< typename MT // Type of the matrix
313  , bool SO > // Storage order of the matrix
314 BLAZE_ALWAYS_INLINE size_t rows( const Matrix<MT,SO>& matrix ) noexcept
315 {
316  return (~matrix).rows();
317 }
318 //*************************************************************************************************
319 
320 
321 //*************************************************************************************************
328 template< typename MT // Type of the matrix
329  , bool SO > // Storage order of the matrix
330 BLAZE_ALWAYS_INLINE size_t columns( const Matrix<MT,SO>& matrix ) noexcept
331 {
332  return (~matrix).columns();
333 }
334 //*************************************************************************************************
335 
336 
337 //*************************************************************************************************
344 template< typename MT // Type of the matrix
345  , bool SO > // Storage order of the matrix
346 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix ) noexcept
347 {
348  return (~matrix).capacity();
349 }
350 //*************************************************************************************************
351 
352 
353 //*************************************************************************************************
366 template< typename MT // Type of the matrix
367  , bool SO > // Storage order of the matrix
368 BLAZE_ALWAYS_INLINE size_t capacity( const Matrix<MT,SO>& matrix, size_t i ) noexcept
369 {
370  return (~matrix).capacity( i );
371 }
372 //*************************************************************************************************
373 
374 
375 //*************************************************************************************************
382 template< typename MT // Type of the matrix
383  , bool SO > // Storage order of the matrix
385 {
386  return (~matrix).nonZeros();
387 }
388 //*************************************************************************************************
389 
390 
391 //*************************************************************************************************
404 template< typename MT // Type of the matrix
405  , bool SO > // Storage order of the matrix
406 BLAZE_ALWAYS_INLINE size_t nonZeros( const Matrix<MT,SO>& matrix, size_t i )
407 {
408  return (~matrix).nonZeros( i );
409 }
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
430 template< typename MT // Type of the matrix
431  , bool SO > // Storage order of the matrix
432 BLAZE_ALWAYS_INLINE DisableIf_< IsResizable<MT> >
433  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
434 {
435  UNUSED_PARAMETER( preserve );
436 
437  if( (~matrix).rows() != m || (~matrix).columns() != n ) {
438  BLAZE_THROW_INVALID_ARGUMENT( "Matrix cannot be resized" );
439  }
440 }
442 //*************************************************************************************************
443 
444 
445 //*************************************************************************************************
458 template< typename MT // Type of the matrix
459  , bool SO > // Storage order of the matrix
460 BLAZE_ALWAYS_INLINE EnableIf_< And< IsResizable<MT>, Not< IsSquare<MT> > > >
461  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
462 {
463  (~matrix).resize( m, n, preserve );
464 }
466 //*************************************************************************************************
467 
468 
469 //*************************************************************************************************
483 template< typename MT // Type of the matrix
484  , bool SO > // Storage order of the matrix
485 BLAZE_ALWAYS_INLINE EnableIf_< And< IsResizable<MT>, IsSquare<MT> > >
486  resize_backend( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
487 {
488  if( m != n ) {
489  BLAZE_THROW_INVALID_ARGUMENT( "Invalid resize arguments for square matrix" );
490  }
491 
492  (~matrix).resize( m, preserve );
493 }
495 //*************************************************************************************************
496 
497 
498 //*************************************************************************************************
536 template< typename MT // Type of the matrix
537  , bool SO > // Storage order of the matrix
538 BLAZE_ALWAYS_INLINE void resize( Matrix<MT,SO>& matrix, size_t m, size_t n, bool preserve )
539 {
540  resize_backend( matrix, m, n, preserve );
541 }
542 //*************************************************************************************************
543 
544 
545 //*************************************************************************************************
562 template< typename MT // Type of the matrix
563  , bool SO > // Storage order of the matrix
565 {
566  (~matrix).transpose();
567 }
568 //*************************************************************************************************
569 
570 
571 //*************************************************************************************************
588 template< typename MT // Type of the matrix
589  , bool SO > // Storage order of the matrix
591 {
592  (~matrix).ctranspose();
593 }
594 //*************************************************************************************************
595 
596 
597 //*************************************************************************************************
607 template< typename MT // Type of the matrix
608  , bool SO > // Storage order
609 BLAZE_ALWAYS_INLINE bool isSquare( const Matrix<MT,SO>& matrix ) noexcept
610 {
611  return ( IsSquare<MT>::value || (~matrix).rows() == (~matrix).columns() );
612 }
613 //*************************************************************************************************
614 
615 
616 //*************************************************************************************************
649 template< typename MT1 // Type of the left-hand side matrix
650  , bool SO1 // Storage order of the left-hand side matrix
651  , typename MT2 // Type of the right-hand side matrix
652  , bool SO2 > // Storage order of the right-hand side matrix
653 BLAZE_ALWAYS_INLINE bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b ) noexcept
654 {
655  return ( IsSame<MT1,MT2>::value &&
656  reinterpret_cast<const void*>( &a ) == reinterpret_cast<const void*>( &b ) );
657 }
658 //*************************************************************************************************
659 
660 
661 //*************************************************************************************************
670 template< typename MT1 // Type of the left-hand side matrix
671  , typename MT2 // Type of the right-hand side matrix
672  , bool SO > // Storage order of both matrices
673 BLAZE_ALWAYS_INLINE void assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
674 {
676 
677  (~lhs).assign( ~rhs );
678 }
680 //*************************************************************************************************
681 
682 
683 //*************************************************************************************************
692 template< typename MT1 // Type of the left-hand side matrix
693  , bool SO // Storage order of the left-hand side matrix
694  , typename MT2 > // Type of the right-hand side matrix
695 BLAZE_ALWAYS_INLINE DisableIf_< IsSymmetric<MT2> >
696  assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
697 {
699 
701 
702  (~lhs).assign( ~rhs );
703 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
718 template< typename MT1 // Type of the left-hand side matrix
719  , bool SO // Storage order of the left-hand side matrix
720  , typename MT2 > // Type of the right-hand side matrix
721 BLAZE_ALWAYS_INLINE EnableIf_< IsSymmetric<MT2> >
722  assign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
723 {
725 
727 
728  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
729 
730  (~lhs).assign( trans( ~rhs ) );
731 }
733 //*************************************************************************************************
734 
735 
736 //*************************************************************************************************
751 template< typename MT1 // Type of the left-hand side matrix
752  , bool SO1 // Storage order of the left-hand side matrix
753  , typename MT2 // Type of the right-hand side matrix
754  , bool SO2 > // Storage order of the right-hand side matrix
755 BLAZE_ALWAYS_INLINE void assign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
756 {
758 
759  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
760  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
761 
762  assign_backend( ~lhs, ~rhs );
763 }
765 //*************************************************************************************************
766 
767 
768 //*************************************************************************************************
778 template< typename MT1 // Type of the left-hand side matrix
779  , typename MT2 // Type of the right-hand side matrix
780  , bool SO > // Storage order of both matrices
781 BLAZE_ALWAYS_INLINE void addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
782 {
784 
785  (~lhs).addAssign( ~rhs );
786 }
788 //*************************************************************************************************
789 
790 
791 //*************************************************************************************************
801 template< typename MT1 // Type of the left-hand side matrix
802  , bool SO // Storage order of the left-hand side matrix
803  , typename MT2 > // Type of the right-hand side matrix
804 BLAZE_ALWAYS_INLINE DisableIf_< IsSymmetric<MT2> >
805  addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
806 {
808 
810 
811  (~lhs).addAssign( ~rhs );
812 }
814 //*************************************************************************************************
815 
816 
817 //*************************************************************************************************
827 template< typename MT1 // Type of the left-hand side matrix
828  , bool SO // Storage order of the left-hand side matrix
829  , typename MT2 > // Type of the right-hand side matrix
830 BLAZE_ALWAYS_INLINE EnableIf_< IsSymmetric<MT2> >
831  addAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
832 {
834 
836 
837  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
838 
839  (~lhs).addAssign( trans( ~rhs ) );
840 }
842 //*************************************************************************************************
843 
844 
845 //*************************************************************************************************
860 template< typename MT1 // Type of the left-hand side matrix
861  , bool SO1 // Storage order of the left-hand side matrix
862  , typename MT2 // Type of the right-hand side matrix
863  , bool SO2 > // Storage order of the right-hand side matrix
864 BLAZE_ALWAYS_INLINE void addAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
865 {
867 
868  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
869  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
870 
871  addAssign_backend( ~lhs, ~rhs );
872 }
874 //*************************************************************************************************
875 
876 
877 //*************************************************************************************************
887 template< typename MT1 // Type of the left-hand side matrix
888  , typename MT2 // Type of the right-hand side matrix
889  , bool SO > // Storage order of both matrices
890 BLAZE_ALWAYS_INLINE void subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,SO>& rhs )
891 {
893 
894  (~lhs).subAssign( ~rhs );
895 }
897 //*************************************************************************************************
898 
899 
900 //*************************************************************************************************
910 template< typename MT1 // Type of the left-hand side matrix
911  , bool SO // Storage order of the left-hand side matrix
912  , typename MT2 > // Type of the right-hand side matrix
913 BLAZE_ALWAYS_INLINE DisableIf_< IsSymmetric<MT2> >
914  subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
915 {
917 
919 
920  (~lhs).subAssign( ~rhs );
921 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
936 template< typename MT1 // Type of the left-hand side matrix
937  , bool SO // Storage order of the left-hand side matrix
938  , typename MT2 > // Type of the right-hand side matrix
939 BLAZE_ALWAYS_INLINE EnableIf_< IsSymmetric<MT2> >
940  subAssign_backend( Matrix<MT1,SO>& lhs, const Matrix<MT2,!SO>& rhs )
941 {
943 
945 
946  BLAZE_INTERNAL_ASSERT( isSquare( ~rhs ), "Non-square symmetric matrix detected" );
947 
948  (~lhs).subAssign( trans( ~rhs ) );
949 }
951 //*************************************************************************************************
952 
953 
954 //*************************************************************************************************
969 template< typename MT1 // Type of the left-hand side matrix
970  , bool SO1 // Storage order of the left-hand side matrix
971  , typename MT2 // Type of the right-hand side matrix
972  , bool SO2 > // Storage order of the right-hand side matrix
973 BLAZE_ALWAYS_INLINE void subAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
974 {
976 
977  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
978  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
979 
980  subAssign_backend( ~lhs, ~rhs );
981 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
1001 template< typename MT1 // Type of the left-hand side matrix
1002  , bool SO1 // Storage order of the left-hand side matrix
1003  , typename MT2 // Type of the right-hand side matrix
1004  , bool SO2 > // Storage order of the right-hand side matrix
1005 BLAZE_ALWAYS_INLINE void multAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
1006 {
1008 
1009  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).rows(), "Invalid matrix sizes" );
1010 
1011  (~lhs).multAssign( ~rhs );
1012 }
1014 //*************************************************************************************************
1015 
1016 
1017 //*************************************************************************************************
1033 template< typename MT // Type of the left-hand side matrix
1034  , bool SO // Storage order of the left-hand side matrix
1035  , typename VT // Type of the right-hand side vector
1036  , bool TF > // Transpose flag of the right-hand side vector
1037 BLAZE_ALWAYS_INLINE bool tryAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1038  size_t row, size_t column )
1039 {
1040  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1041  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1042  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1043  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1044 
1045  UNUSED_PARAMETER( lhs, rhs, row, column );
1046 
1047  return true;
1048 }
1050 //*************************************************************************************************
1051 
1052 
1053 //*************************************************************************************************
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 bool tryAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1074  size_t row, size_t column )
1075 {
1076  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1077  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1078  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1079  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1080 
1081  UNUSED_PARAMETER( lhs, rhs, row, column );
1082 
1083  return true;
1084 }
1086 //*************************************************************************************************
1087 
1088 
1089 //*************************************************************************************************
1105 template< typename MT // Type of the left-hand side matrix
1106  , bool SO // Storage order of the left-hand side matrix
1107  , typename VT // Type of the right-hand side vector
1108  , bool TF > // Transpose flag of the right-hand side vector
1109 BLAZE_ALWAYS_INLINE bool tryAddAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1110  size_t row, size_t column )
1111 {
1112  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1113  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1114  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1115  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1116 
1117  UNUSED_PARAMETER( lhs, rhs, row, column );
1118 
1119  return true;
1120 }
1122 //*************************************************************************************************
1123 
1124 
1125 //*************************************************************************************************
1141 template< typename MT1 // Type of the left-hand side matrix
1142  , bool SO1 // Storage order of the left-hand side matrix
1143  , typename MT2 // Type of the right-hand side matrix
1144  , bool SO2 > // Storage order of the right-hand side matrix
1145 BLAZE_ALWAYS_INLINE bool tryAddAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1146  size_t row, size_t column )
1147 {
1148  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1149  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1150  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1151  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1152 
1153  UNUSED_PARAMETER( lhs, rhs, row, column );
1154 
1155  return true;
1156 }
1158 //*************************************************************************************************
1159 
1160 
1161 //*************************************************************************************************
1177 template< typename MT // Type of the left-hand side matrix
1178  , bool SO // Storage order of the left-hand side matrix
1179  , typename VT // Type of the right-hand side vector
1180  , bool TF > // Transpose flag of the right-hand side vector
1181 BLAZE_ALWAYS_INLINE bool trySubAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1182  size_t row, size_t column )
1183 {
1184  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1185  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1186  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1187  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1188 
1189  UNUSED_PARAMETER( lhs, rhs, row, column );
1190 
1191  return true;
1192 }
1194 //*************************************************************************************************
1195 
1196 
1197 //*************************************************************************************************
1213 template< typename MT1 // Type of the left-hand side matrix
1214  , bool SO1 // Storage order of the left-hand side matrix
1215  , typename MT2 // Type of the right-hand side matrix
1216  , bool SO2 > // Storage order of the right-hand side matrix
1217 BLAZE_ALWAYS_INLINE bool trySubAssign( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs,
1218  size_t row, size_t column )
1219 {
1220  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1221  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1222  BLAZE_INTERNAL_ASSERT( (~rhs).rows() <= (~lhs).rows() - row, "Invalid number of rows" );
1223  BLAZE_INTERNAL_ASSERT( (~rhs).columns() <= (~lhs).columns() - column, "Invalid number of columns" );
1224 
1225  UNUSED_PARAMETER( lhs, rhs, row, column );
1226 
1227  return true;
1228 }
1230 //*************************************************************************************************
1231 
1232 
1233 //*************************************************************************************************
1249 template< typename MT // Type of the left-hand side matrix
1250  , bool SO // Storage order of the left-hand side matrix
1251  , typename VT // Type of the right-hand side vector
1252  , bool TF > // Transpose flag of the right-hand side vector
1253 BLAZE_ALWAYS_INLINE bool tryMultAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1254  size_t row, size_t column )
1255 {
1256  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1257  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1258  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1259  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1260 
1261  UNUSED_PARAMETER( lhs, rhs, row, column );
1262 
1263  return true;
1264 }
1266 //*************************************************************************************************
1267 
1268 
1269 //*************************************************************************************************
1285 template< typename MT // Type of the left-hand side matrix
1286  , bool SO // Storage order of the left-hand side matrix
1287  , typename VT // Type of the right-hand side vector
1288  , bool TF > // Transpose flag of the right-hand side vector
1289 BLAZE_ALWAYS_INLINE bool tryDivAssign( const Matrix<MT,SO>& lhs, const Vector<VT,TF>& rhs,
1290  size_t row, size_t column )
1291 {
1292  BLAZE_INTERNAL_ASSERT( row <= (~lhs).rows(), "Invalid row access index" );
1293  BLAZE_INTERNAL_ASSERT( column <= (~lhs).columns(), "Invalid column access index" );
1294  BLAZE_INTERNAL_ASSERT( TF || ( (~rhs).size() <= (~lhs).rows() - row ), "Invalid number of rows" );
1295  BLAZE_INTERNAL_ASSERT( !TF || ( (~rhs).size() <= (~lhs).columns() - column ), "Invalid number of columns" );
1296 
1297  UNUSED_PARAMETER( lhs, rhs, row, column );
1298 
1299  return true;
1300 }
1302 //*************************************************************************************************
1303 
1304 
1305 //*************************************************************************************************
1320 template< typename MT // Type of the matrix
1321  , bool SO > // Storage order
1322 BLAZE_ALWAYS_INLINE MT& derestrict( Matrix<MT,SO>& matrix )
1323 {
1324  return ~matrix;
1325 }
1327 //*************************************************************************************************
1328 
1329 } // namespace blaze
1330 
1331 #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:346
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:653
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:258
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:188
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:590
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:384
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
DisableIf_< Or< IsComputation< MT >, IsTransExpr< 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:126
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:298
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:232
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:2647
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:330
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE const MatrixType & operator~() const noexcept
Conversion operator for constant matrices.
Definition: Matrix.h:103
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:538
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:254
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< 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:126
#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.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2646
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:89
Constraint on the data type.
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:314
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:950
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
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:609
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 FunctionTrace class.
BLAZE_ALWAYS_INLINE void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:564