All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
43 #include <blaze/util/Assert.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
67 template< typename MT // Type of the matrix
68  , bool SO > // Storage order
69 struct Matrix
70 {
71  //**Type definitions****************************************************************************
72  typedef MT MatrixType;
73  //**********************************************************************************************
74 
75  //**Non-const conversion operator***************************************************************
80  inline MatrixType& operator~() {
81  return *static_cast<MatrixType*>( this );
82  }
83  //**********************************************************************************************
84 
85  //**Const conversion operator*******************************************************************
90  inline const MatrixType& operator~() const {
91  return *static_cast<const MatrixType*>( this );
92  }
93  //**********************************************************************************************
94 };
95 //*************************************************************************************************
96 
97 
98 
99 
100 //=================================================================================================
101 //
102 // GLOBAL FUNCTIONS
103 //
104 //=================================================================================================
105 
106 //*************************************************************************************************
109 template< typename MT, bool SO >
110 inline size_t rows( const Matrix<MT,SO>& m );
111 
112 template< typename MT, bool SO >
113 inline size_t columns( const Matrix<MT,SO>& m );
114 
115 template< typename MT, bool SO >
116 inline size_t capacity( const Matrix<MT,SO>& m );
117 
118 template< typename MT, bool SO >
119 inline size_t capacity( const Matrix<MT,SO>& m, size_t i );
120 
121 template< typename MT, bool SO >
122 inline size_t nonZeros( const Matrix<MT,SO>& m );
123 
124 template< typename MT, bool SO >
125 inline size_t nonZeros( const Matrix<MT,SO>& m, size_t i );
126 
127 template< typename MT1, bool SO1, typename MT2, bool SO2 >
128 inline void assign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs );
129 
130 template< typename MT1, bool SO1, typename MT2, bool SO2 >
131 inline void addAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs );
132 
133 template< typename MT1, bool SO1, typename MT2, bool SO2 >
134 inline void subAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs );
135 
136 template< typename MT1, bool SO1, typename MT2, bool SO2 >
137 inline void multAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs );
138 
139 template< typename MT1, bool SO1, typename MT2, bool SO2 >
140 inline bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b );
142 //*************************************************************************************************
143 
144 
145 //*************************************************************************************************
152 template< typename MT // Type of the matrix
153  , bool SO > // Storage order of the matrix
154 inline size_t rows( const Matrix<MT,SO>& m )
155 {
156  return (~m).rows();
157 }
158 //*************************************************************************************************
159 
160 
161 //*************************************************************************************************
168 template< typename MT // Type of the matrix
169  , bool SO > // Storage order of the matrix
170 inline size_t columns( const Matrix<MT,SO>& m )
171 {
172  return (~m).columns();
173 }
174 //*************************************************************************************************
175 
176 
177 //*************************************************************************************************
184 template< typename MT // Type of the matrix
185  , bool SO > // Storage order of the matrix
186 inline size_t capacity( const Matrix<MT,SO>& m )
187 {
188  return (~m).capacity();
189 }
190 //*************************************************************************************************
191 
192 
193 //*************************************************************************************************
206 template< typename MT // Type of the matrix
207  , bool SO > // Storage order of the matrix
208 inline size_t capacity( const Matrix<MT,SO>& m, size_t i )
209 {
210  return (~m).capacity( i );
211 }
212 //*************************************************************************************************
213 
214 
215 //*************************************************************************************************
222 template< typename MT // Type of the matrix
223  , bool SO > // Storage order of the matrix
224 inline size_t nonZeros( const Matrix<MT,SO>& m )
225 {
226  return (~m).nonZeros();
227 }
228 //*************************************************************************************************
229 
230 
231 //*************************************************************************************************
244 template< typename MT // Type of the matrix
245  , bool SO > // Storage order of the matrix
246 inline size_t nonZeros( const Matrix<MT,SO>& m, size_t i )
247 {
248  return (~m).nonZeros( i );
249 }
250 //*************************************************************************************************
251 
252 
253 //*************************************************************************************************
267 template< typename MT1 // Type of the left-hand side matrix
268  , bool SO1 // Storage order of the left-hand side matrix
269  , typename MT2 // Type of the right-hand side matrix
270  , bool SO2 > // Storage order of the right-hand side matrix
271 inline void assign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
272 {
274 
275  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
276  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
277 
278  (~lhs).assign( ~rhs );
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
297 template< typename MT1 // Type of the left-hand side matrix
298  , bool SO1 // Storage order of the left-hand side matrix
299  , typename MT2 // Type of the right-hand side matrix
300  , bool SO2 > // Storage order of the right-hand side matrix
301 inline void addAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
302 {
304 
305  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
306  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
307 
308  (~lhs).addAssign( ~rhs );
309 }
310 //*************************************************************************************************
311 
312 
313 //*************************************************************************************************
327 template< typename MT1 // Type of the left-hand side matrix
328  , bool SO1 // Storage order of the left-hand side matrix
329  , typename MT2 // Type of the right-hand side matrix
330  , bool SO2 > // Storage order of the right-hand side matrix
331 inline void subAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
332 {
334 
335  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == (~rhs).rows() , "Invalid number of rows" );
336  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).columns(), "Invalid number of columns" );
337 
338  (~lhs).subAssign( ~rhs );
339 }
340 //*************************************************************************************************
341 
342 
343 //*************************************************************************************************
357 template< typename MT1 // Type of the left-hand side matrix
358  , bool SO1 // Storage order of the left-hand side matrix
359  , typename MT2 // Type of the right-hand side matrix
360  , bool SO2 > // Storage order of the right-hand side matrix
361 inline void multAssign( Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
362 {
364 
365  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == (~rhs).rows(), "Invalid matrix sizes" );
366 
367  (~lhs).multAssign( ~rhs );
368 }
369 //*************************************************************************************************
370 
371 
372 //*************************************************************************************************
405 template< typename MT1 // Type of the left-hand side matrix
406  , bool SO1 // Storage order of the left-hand side matrix
407  , typename MT2 // Type of the right-hand side matrix
408  , bool SO2 > // Storage order of the right-hand side matrix
409 inline bool isSame( const Matrix<MT1,SO1>& a, const Matrix<MT2,SO2>& b )
410 {
411  return ( IsSame<MT1,MT2>::value &&
412  reinterpret_cast<const void*>( &a ) == reinterpret_cast<const void*>( &b ) );
413 }
414 //*************************************************************************************************
415 
416 } // namespace blaze
417 
418 #endif
MT MatrixType
Type of the matrix.
Definition: Matrix.h:72
Header file for the IsSame and IsStrictlySame type traits.
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 enumeration is set to 1, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to 0, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:158
bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:409
size_t nonZeros(const Matrix< MT, SO > &m)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:224
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:271
void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:361
Header file for run time assertion macros.
MatrixType & operator~()
Conversion operator for non-constant matrices.
Definition: Matrix.h:80
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:301
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:331
#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
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:170
const MatrixType & operator~() const
Conversion operator for constant matrices.
Definition: Matrix.h:90
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:154
#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
size_t capacity(const Matrix< MT, SO > &m)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:186
Header file for the FunctionTrace class.