StaticMatrix.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_STATICMATRIX_H_
36 #define _BLAZE_MATH_STATICMATRIX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/math/DenseMatrix.h>
47 #include <blaze/math/shims/Real.h>
50 #include <blaze/system/Precision.h>
51 #include <blaze/util/Assert.h>
53 #include <blaze/util/Random.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // RAND SPECIALIZATION
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
72 template< typename Type // Data type of the matrix
73  , size_t M // Number of rows
74  , size_t N // Number of columns
75  , bool SO > // Storage order
76 class Rand< StaticMatrix<Type,M,N,SO> >
77 {
78  public:
79  //**Generate functions**************************************************************************
82  inline const StaticMatrix<Type,M,N,SO> generate() const;
83 
84  template< typename Arg >
85  inline const StaticMatrix<Type,M,N,SO> generate( const Arg& min, const Arg& max ) const;
87  //**********************************************************************************************
88 
89  //**Randomize functions*************************************************************************
92  inline void randomize( StaticMatrix<Type,M,N,SO>& matrix ) const;
93 
94  template< typename Arg >
95  inline void randomize( StaticMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max ) const;
97  //**********************************************************************************************
98 };
100 //*************************************************************************************************
101 
102 
103 //*************************************************************************************************
109 template< typename Type // Data type of the matrix
110  , size_t M // Number of rows
111  , size_t N // Number of columns
112  , bool SO > // Storage order
113 inline const StaticMatrix<Type,M,N,SO> Rand< StaticMatrix<Type,M,N,SO> >::generate() const
114 {
115  StaticMatrix<Type,M,N,SO> matrix;
116  randomize( matrix );
117  return matrix;
118 }
120 //*************************************************************************************************
121 
122 
123 //*************************************************************************************************
131 template< typename Type // Data type of the matrix
132  , size_t M // Number of rows
133  , size_t N // Number of columns
134  , bool SO > // Storage order
135 template< typename Arg > // Min/max argument type
136 inline const StaticMatrix<Type,M,N,SO>
137  Rand< StaticMatrix<Type,M,N,SO> >::generate( const Arg& min, const Arg& max ) const
138 {
139  StaticMatrix<Type,M,N,SO> matrix;
140  randomize( matrix, min, max );
141  return matrix;
142 }
144 //*************************************************************************************************
145 
146 
147 //*************************************************************************************************
154 template< typename Type // Data type of the matrix
155  , size_t M // Number of rows
156  , size_t N // Number of columns
157  , bool SO > // Storage order
158 inline void Rand< StaticMatrix<Type,M,N,SO> >::randomize( StaticMatrix<Type,M,N,SO>& matrix ) const
159 {
160  using blaze::randomize;
161 
162  for( size_t i=0UL; i<M; ++i ) {
163  for( size_t j=0UL; j<N; ++j ) {
164  randomize( matrix(i,j) );
165  }
166  }
167 }
169 //*************************************************************************************************
170 
171 
172 //*************************************************************************************************
181 template< typename Type // Data type of the matrix
182  , size_t M // Number of rows
183  , size_t N // Number of columns
184  , bool SO > // Storage order
185 template< typename Arg > // Min/max argument type
186 inline void Rand< StaticMatrix<Type,M,N,SO> >::randomize( StaticMatrix<Type,M,N,SO>& matrix,
187  const Arg& min, const Arg& max ) const
188 {
189  using blaze::randomize;
190 
191  for( size_t i=0UL; i<M; ++i ) {
192  for( size_t j=0UL; j<N; ++j ) {
193  randomize( matrix(i,j), min, max );
194  }
195  }
196 }
198 //*************************************************************************************************
199 
200 
201 
202 
203 //=================================================================================================
204 //
205 // MAKE FUNCTIONS
206 //
207 //=================================================================================================
208 
209 //*************************************************************************************************
217 template< typename Type // Data type of the matrix
218  , size_t M // Number of rows
219  , size_t N // Number of columns
220  , bool SO > // Storage order
221 void makeSymmetric( StaticMatrix<Type,M,N,SO>& matrix )
222 {
223  using blaze::randomize;
224 
225  BLAZE_STATIC_ASSERT( M == N );
226 
227  for( size_t i=0UL; i<N; ++i ) {
228  for( size_t j=0UL; j<i; ++j ) {
229  randomize( matrix(i,j) );
230  matrix(j,i) = matrix(i,j);
231  }
232  randomize( matrix(i,i) );
233  }
234 
235  BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
236 }
238 //*************************************************************************************************
239 
240 
241 //*************************************************************************************************
251 template< typename Type // Data type of the matrix
252  , size_t M // Number of rows
253  , size_t N // Number of columns
254  , bool SO // Storage order
255  , typename Arg > // Min/max argument type
256 void makeSymmetric( StaticMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max )
257 {
258  using blaze::randomize;
259 
260  BLAZE_STATIC_ASSERT( M == N );
261 
262  for( size_t i=0UL; i<N; ++i ) {
263  for( size_t j=0UL; j<i; ++j ) {
264  randomize( matrix(i,j), min, max );
265  matrix(j,i) = matrix(i,j);
266  }
267  randomize( matrix(i,i), min, max );
268  }
269 
270  BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
271 }
273 //*************************************************************************************************
274 
275 
276 //*************************************************************************************************
284 template< typename Type // Data type of the matrix
285  , size_t M // Number of rows
286  , size_t N // Number of columns
287  , bool SO > // Storage order
288 void makeHermitian( StaticMatrix<Type,M,N,SO>& matrix )
289 {
290  using blaze::randomize;
291 
292  BLAZE_STATIC_ASSERT( M == N );
294 
295  typedef typename UnderlyingBuiltin<Type>::Type BT;
296 
297  for( size_t i=0UL; i<N; ++i ) {
298  for( size_t j=0UL; j<i; ++j ) {
299  randomize( matrix(i,j) );
300  matrix(j,i) = conj( matrix(i,j) );
301  }
302  matrix(i,i) = rand<BT>();
303  }
304 
305  BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
306 }
308 //*************************************************************************************************
309 
310 
311 //*************************************************************************************************
321 template< typename Type // Data type of the matrix
322  , size_t M // Number of rows
323  , size_t N // Number of columns
324  , bool SO // Storage order
325  , typename Arg > // Min/max argument type
326 void makeHermitian( StaticMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max )
327 {
328  using blaze::randomize;
329 
330  BLAZE_STATIC_ASSERT( M == N );
332 
333  typedef typename UnderlyingBuiltin<Type>::Type BT;
334 
335  for( size_t i=0UL; i<N; ++i ) {
336  for( size_t j=0UL; j<i; ++j ) {
337  randomize( matrix(i,j), min, max );
338  matrix(j,i) = conj( matrix(i,j) );
339  }
340  matrix(i,i) = rand<BT>( real( min ), real( max ) );
341  }
342 
343  BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
344 }
346 //*************************************************************************************************
347 
348 
349 //*************************************************************************************************
357 template< typename Type // Data type of the matrix
358  , size_t M // Number of rows
359  , size_t N // Number of columns
360  , bool SO > // Storage order
361 void makePositiveDefinite( StaticMatrix<Type,M,N,SO>& matrix )
362 {
363  using blaze::randomize;
364 
365  BLAZE_STATIC_ASSERT( M == N );
367 
368  randomize( matrix );
369  matrix *= ctrans( matrix );
370 
371  for( size_t i=0UL; i<N; ++i ) {
372  matrix(i,i) += Type(N);
373  }
374 
375  BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-symmetric matrix detected" );
376 }
378 //*************************************************************************************************
379 
380 
381 
382 
383 //=================================================================================================
384 //
385 // TYPE DEFINITIONS
386 //
387 //=================================================================================================
388 
389 //*************************************************************************************************
394 //*************************************************************************************************
395 
396 
397 //*************************************************************************************************
402 //*************************************************************************************************
403 
404 
405 //*************************************************************************************************
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
418 //*************************************************************************************************
419 
420 
421 //*************************************************************************************************
426 //*************************************************************************************************
427 
428 
429 //*************************************************************************************************
434 //*************************************************************************************************
435 
436 
437 //*************************************************************************************************
442 //*************************************************************************************************
443 
444 
445 //*************************************************************************************************
450 //*************************************************************************************************
451 
452 
453 //*************************************************************************************************
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
466 //*************************************************************************************************
467 
468 
469 //*************************************************************************************************
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
482 //*************************************************************************************************
483 
484 
485 //*************************************************************************************************
490 //*************************************************************************************************
491 
492 
493 //*************************************************************************************************
498 //*************************************************************************************************
499 
500 
501 //*************************************************************************************************
506 //*************************************************************************************************
507 
508 } // namespace blaze
509 
510 #endif
Header file for the complete HybridMatrix implementation.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Constraint on the data type.
StaticMatrix< double, 6UL, 6UL, false > Mat6x6d
6x6 double precision matrix.
Definition: StaticMatrix.h:497
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1041
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:697
StaticMatrix< real_t, 2UL, 2UL, false > Mat2x2
2x2 matrix with system-specific precision.
Definition: StaticMatrix.h:409
Implementation of a random number generator.
StaticMatrix< double, 3UL, 3UL, false > Mat3x3d
3x3 double precision matrix.
Definition: StaticMatrix.h:425
StaticMatrix< double, 5UL, 5UL, false > Mat5x5d
5x5 double precision matrix.
Definition: StaticMatrix.h:473
StaticMatrix< float, 5UL, 5UL, false > Mat5x5f
5x5 single precision matrix.
Definition: StaticMatrix.h:465
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
Header file for the floating point precision of the Blaze library.
StaticMatrix< float, 2UL, 2UL, false > Mat2x2f
2x2 single precision matrix.
Definition: StaticMatrix.h:393
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Compile time assertion.
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:260
Header file for the UnderlyingBuiltin type trait.
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
Efficient implementation of a fixed-sized matrix.The StaticMatrix class template is the representatio...
Definition: Forward.h:60
Header file for the implementation of a fixed-size matrix.
const CTransExprTrait< MT >::Type ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatConjExpr.h:974
const RealExprTrait< MT >::Type real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatRealExpr.h:920
StaticMatrix< float, 3UL, 3UL, false > Mat3x3f
3x3 single precision matrix.
Definition: StaticMatrix.h:417
StaticMatrix< real_t, 3UL, 3UL, false > Mat3x3
3x3 matrix with system-specific precision.
Definition: StaticMatrix.h:433
Header file for the real shim.
StaticMatrix< real_t, 5UL, 5UL, false > Mat5x5
5x5 matrix with system-specific precision.
Definition: StaticMatrix.h:481
Header file for the conjugate shim.
Header file for run time assertion macros.
StaticMatrix< real_t, 4UL, 4UL, false > Mat4x4
4x4 matrix with system-specific precision.
Definition: StaticMatrix.h:457
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
Header file for the complete StaticVector implementation.
StaticMatrix< float, 4UL, 4UL, false > Mat4x4f
4x4 single precision matrix.
Definition: StaticMatrix.h:441
T generate() const
Generation of a random value in the range .
Definition: Random.h:220
Header file for all basic DenseMatrix functionality.
StaticMatrix< double, 2UL, 2UL, false > Mat2x2d
2x2 double precision matrix.
Definition: StaticMatrix.h:401
StaticMatrix< double, 4UL, 4UL, false > Mat4x4d
4x4 double precision matrix.
Definition: StaticMatrix.h:449
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:767
StaticMatrix< float, 6UL, 6UL, false > Mat6x6f
6x6 single precision matrix.
Definition: StaticMatrix.h:489
StaticMatrix< real_t, 6UL, 6UL, false > Mat6x6
6x6 matrix with system-specific precision.
Definition: StaticMatrix.h:505
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
#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