Blaze 3.9
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
53#include <blaze/util/Assert.h>
54#include <blaze/util/Random.h>
56
57
58namespace blaze {
59
60//=================================================================================================
61//
62// RAND SPECIALIZATION
63//
64//=================================================================================================
65
66//*************************************************************************************************
73template< typename Type // Data type of the matrix
74 , size_t M // Number of rows
75 , size_t N // Number of columns
76 , bool SO // Storage order
77 , AlignmentFlag AF // Alignment flag
78 , PaddingFlag PF // Padding flag
79 , typename Tag > // Type tag
80class Rand< StaticMatrix<Type,M,N,SO,AF,PF,Tag> >
81{
82 public:
83 //**********************************************************************************************
88 inline const StaticMatrix<Type,M,N,SO,AF,PF,Tag> generate() const
89 {
90 StaticMatrix<Type,M,N,SO,AF,PF,Tag> matrix;
91 randomize( matrix );
92 return matrix;
93 }
94 //**********************************************************************************************
95
96 //**********************************************************************************************
103 template< typename Arg > // Min/max argument type
104 inline const StaticMatrix<Type,M,N,SO,AF,PF,Tag>
105 generate( const Arg& min, const Arg& max ) const
106 {
107 StaticMatrix<Type,M,N,SO,AF,PF,Tag> matrix;
108 randomize( matrix, min, max );
109 return matrix;
110 }
111 //**********************************************************************************************
112
113 //**********************************************************************************************
119 inline void randomize( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix ) const
120 {
121 using blaze::randomize;
122
123 for( size_t i=0UL; i<M; ++i ) {
124 for( size_t j=0UL; j<N; ++j ) {
125 randomize( matrix(i,j) );
126 }
127 }
128 }
129 //**********************************************************************************************
130
131 //**********************************************************************************************
139 template< typename Arg > // Min/max argument type
140 inline void randomize( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix,
141 const Arg& min, const Arg& max ) const
142 {
143 using blaze::randomize;
144
145 for( size_t i=0UL; i<M; ++i ) {
146 for( size_t j=0UL; j<N; ++j ) {
147 randomize( matrix(i,j), min, max );
148 }
149 }
150 }
151 //**********************************************************************************************
152};
154//*************************************************************************************************
155
156
157
158
159//=================================================================================================
160//
161// MAKE FUNCTIONS
162//
163//=================================================================================================
164
165//*************************************************************************************************
173template< typename Type // Data type of the matrix
174 , size_t M // Number of rows
175 , size_t N // Number of columns
176 , bool SO // Storage order
177 , AlignmentFlag AF // Alignment flag
178 , PaddingFlag PF // Padding flag
179 , typename Tag > // Type tag
180void makeSymmetric( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix )
181{
182 using blaze::randomize;
183
184 BLAZE_STATIC_ASSERT( M == N );
185
186 for( size_t i=0UL; i<N; ++i ) {
187 for( size_t j=0UL; j<i; ++j ) {
188 randomize( matrix(i,j) );
189 matrix(j,i) = matrix(i,j);
190 }
191 randomize( matrix(i,i) );
192 }
193
194 BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
195}
197//*************************************************************************************************
198
199
200//*************************************************************************************************
210template< typename Type // Data type of the matrix
211 , size_t M // Number of rows
212 , size_t N // Number of columns
213 , bool SO // Storage order
214 , AlignmentFlag AF // Alignment flag
215 , PaddingFlag PF // Padding flag
216 , typename Tag // Type tag
217 , typename Arg > // Min/max argument type
218void makeSymmetric( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix, const Arg& min, const Arg& max )
219{
220 using blaze::randomize;
221
222 BLAZE_STATIC_ASSERT( M == N );
223
224 for( size_t i=0UL; i<N; ++i ) {
225 for( size_t j=0UL; j<i; ++j ) {
226 randomize( matrix(i,j), min, max );
227 matrix(j,i) = matrix(i,j);
228 }
229 randomize( matrix(i,i), min, max );
230 }
231
232 BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
233}
235//*************************************************************************************************
236
237
238//*************************************************************************************************
246template< typename Type // Data type of the matrix
247 , size_t M // Number of rows
248 , size_t N // Number of columns
249 , bool SO // Storage order
250 , AlignmentFlag AF // Alignment flag
251 , PaddingFlag PF // Padding flag
252 , typename Tag > // Type tag
253void makeHermitian( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix )
254{
255 using blaze::randomize;
256
257 BLAZE_STATIC_ASSERT( M == N );
259
260 using BT = UnderlyingBuiltin_t<Type>;
261
262 for( size_t i=0UL; i<N; ++i ) {
263 for( size_t j=0UL; j<i; ++j ) {
264 randomize( matrix(i,j) );
265 matrix(j,i) = conj( matrix(i,j) );
266 }
267 matrix(i,i) = rand<BT>();
268 }
269
270 BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
271}
273//*************************************************************************************************
274
275
276//*************************************************************************************************
286template< typename Type // Data type of the matrix
287 , size_t M // Number of rows
288 , size_t N // Number of columns
289 , bool SO // Storage order
290 , AlignmentFlag AF // Alignment flag
291 , PaddingFlag PF // Padding flag
292 , typename Tag // Type tag
293 , typename Arg > // Min/max argument type
294void makeHermitian( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix, const Arg& min, const Arg& max )
295{
296 using blaze::randomize;
297
298 BLAZE_STATIC_ASSERT( M == N );
300
301 using BT = UnderlyingBuiltin_t<Type>;
302
303 for( size_t i=0UL; i<N; ++i ) {
304 for( size_t j=0UL; j<i; ++j ) {
305 randomize( matrix(i,j), min, max );
306 matrix(j,i) = conj( matrix(i,j) );
307 }
308 matrix(i,i) = rand<BT>( real( min ), real( max ) );
309 }
310
311 BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
312}
314//*************************************************************************************************
315
316
317//*************************************************************************************************
325template< typename Type // Data type of the matrix
326 , size_t M // Number of rows
327 , size_t N // Number of columns
328 , bool SO // Storage order
329 , AlignmentFlag AF // Alignment flag
330 , PaddingFlag PF // Padding flag
331 , typename Tag > // Type tag
332void makePositiveDefinite( StaticMatrix<Type,M,N,SO,AF,PF,Tag>& matrix )
333{
334 using blaze::randomize;
335
336 BLAZE_STATIC_ASSERT( M == N );
338
339 randomize( matrix );
340 matrix *= ctrans( matrix );
341
342 for( size_t i=0UL; i<N; ++i ) {
343 matrix(i,i) += Type(N);
344 }
345
346 BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-symmetric matrix detected" );
347}
349//*************************************************************************************************
350
351} // namespace blaze
352
353#endif
Header file for run time assertion macros.
Header file for the conjugate shim.
Header file for all basic DenseMatrix functionality.
Header file for the complete HybridMatrix implementation.
Header file for the complete IdentityMatrix implementation.
Constraint on the data type.
Compile time assertion.
Header file for the complete StaticVector implementation.
Header file for the UnderlyingBuiltin type trait.
Header file for the complete ZeroMatrix implementation.
Header file for the implementation of a fixed-size matrix.
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1339
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1529
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1464
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1501
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:1534
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:1456
decltype(auto) generate(size_t m, size_t n, OP op)
Generates a new dense matrix filled via the given custom binary operation.
Definition: DMatGenExpr.h:675
#define BLAZE_CONSTRAINT_MUST_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:61
PaddingFlag
Padding flag for (un-)padded vectors and matrices.
Definition: PaddingFlag.h:77
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.
Definition: AlignmentFlag.h:63
void randomize(T &&value)
Randomization of a given variable.
Definition: Random.h:626
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.
Definition: StaticAssert.h:112
Header file for the real shim.
Implementation of a random number generator.