35 #ifndef _BLAZE_MATH_HERMITIANMATRIX_H_
36 #define _BLAZE_MATH_HERMITIANMATRIX_H_
80 class Rand< HermitianMatrix<MT,SO,DF> >
86 inline const HermitianMatrix<MT,SO,DF>
generate()
const;
87 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n )
const;
88 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
90 template<
typename Arg >
91 inline const HermitianMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
93 template<
typename Arg >
94 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
96 template<
typename Arg >
97 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
98 const Arg&
min,
const Arg&
max )
const;
105 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix )
const;
106 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const;
108 template<
typename Arg >
109 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
111 template<
typename Arg >
112 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros,
113 const Arg&
min,
const Arg&
max )
const;
124 template<
typename Arg >
127 template<
typename Arg >
142 template<
typename MT
145 inline const HermitianMatrix<MT,SO,DF> Rand< HermitianMatrix<MT,SO,DF> >::generate()
const
149 HermitianMatrix<MT,SO,DF> matrix;
164 template<
typename MT
167 inline const HermitianMatrix<MT,SO,DF>
168 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n )
const
172 HermitianMatrix<MT,SO,DF> matrix( n );
189 template<
typename MT
192 inline const HermitianMatrix<MT,SO,DF>
193 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const
199 throw std::invalid_argument(
"Invalid number of non-zero elements" );
201 HermitianMatrix<MT,SO,DF> matrix( n );
218 template<
typename MT
221 template<
typename Arg >
222 inline const HermitianMatrix<MT,SO,DF>
223 Rand< HermitianMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const
227 HermitianMatrix<MT,SO,DF> matrix;
244 template<
typename MT
247 template<
typename Arg >
248 inline const HermitianMatrix<MT,SO,DF>
249 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
253 HermitianMatrix<MT,SO,DF> matrix( n );
272 template<
typename MT
275 template<
typename Arg >
276 inline const HermitianMatrix<MT,SO,DF>
277 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
278 const Arg&
min,
const Arg&
max )
const
284 throw std::invalid_argument(
"Invalid number of non-zero elements" );
286 HermitianMatrix<MT,SO,DF> matrix( n );
302 template<
typename MT
305 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix )
const
307 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
320 template<
typename MT
323 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
TrueType )
const
327 typedef ElementType_<MT> ET;
328 typedef UnderlyingBuiltin_<ET> BT;
330 const size_t n( matrix.rows() );
332 for(
size_t i=0UL; i<n; ++i ) {
333 for(
size_t j=0UL; j<i; ++j ) {
334 matrix(i,j) = rand<ET>();
336 matrix(i,i) = rand<BT>();
350 template<
typename MT
353 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
FalseType )
const
357 const size_t n( matrix.rows() );
359 if( n == 0UL )
return;
361 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
378 template<
typename MT
381 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const
385 typedef ElementType_<MT> ET;
386 typedef UnderlyingBuiltin_<ET> BT;
388 const size_t n( matrix.rows() );
391 throw std::invalid_argument(
"Invalid number of non-zero elements" );
393 if( n == 0UL )
return;
396 matrix.reserve( nonzeros );
398 while( matrix.nonZeros() < nonzeros )
400 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
401 const size_t column( rand<size_t>( 0UL, n-1UL ) );
422 template<
typename MT
425 template<
typename Arg >
426 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
427 const Arg& min,
const Arg& max )
const
429 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
444 template<
typename MT
447 template<
typename Arg >
448 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
449 const Arg& min,
const Arg& max,
TrueType )
const
453 typedef ElementType_<MT> ET;
454 typedef UnderlyingBuiltin_<ET> BT;
456 const size_t n( matrix.rows() );
458 for(
size_t i=0UL; i<n; ++i ) {
459 for(
size_t j=0UL; j<i; ++j ) {
460 matrix(i,j) = rand<ET>(
min,
max );
462 matrix(i,i) = rand<BT>(
real( min ),
real( max ) );
478 template<
typename MT
481 template<
typename Arg >
482 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
483 const Arg& min,
const Arg& max,
FalseType )
const
487 const size_t n( matrix.rows() );
489 if( n == 0UL )
return;
491 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
510 template<
typename MT
513 template<
typename Arg >
514 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
515 size_t nonzeros,
const Arg& min,
const Arg& max )
const
519 typedef ElementType_<MT> ET;
520 typedef UnderlyingBuiltin_<ET> BT;
522 const size_t n( matrix.rows() );
525 throw std::invalid_argument(
"Invalid number of non-zero elements" );
527 if( n == 0UL )
return;
530 matrix.reserve( nonzeros );
532 while( matrix.nonZeros() < nonzeros )
534 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
535 const size_t column( rand<size_t>( 0UL, n-1UL ) );
562 template<
typename MT
565 void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix )
567 typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
569 const size_t n( matrix.rows() );
571 for(
size_t i=0UL; i<n; ++i ) {
572 for(
size_t j=0UL; j<=i; ++j ) {
573 matrix(i,j) = rand<BT>();
592 template<
typename MT
596 void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
598 typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
600 const size_t n( matrix.rows() );
602 for(
size_t i=0UL; i<n; ++i ) {
603 for(
size_t j=0UL; j<=i; ++j ) {
604 matrix(i,j) = rand<BT>(
real( min ),
real( max ) );
621 template<
typename MT
624 void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix )
643 template<
typename MT
647 void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
664 template<
typename MT
667 void makePositiveDefinite( HermitianMatrix<MT,SO,DF>& matrix )
671 typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
673 const size_t n( matrix.rows() );
678 for(
size_t i=0UL; i<n; ++i ) {
679 matrix(i,i) += BT(n);
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
Header file for auxiliary alias declarations.
Header file for basic type definitions.
Header file for the FalseType type/value trait base class.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:61
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:926
Constraint on the data type.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:689
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
Implementation of a random number generator.
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1716
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
Header file for the implementation of a Hermitian matrix adaptor.
Constraint on the data type.
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for all basic SparseMatrix functionality.
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:289
Header file for the UnderlyingBuiltin type trait.
Header file for the IsDenseMatrix type trait.
const DMatForEachExpr< MT, Real, SO > real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatForEachExpr.h:1223
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
Header file for run time assertion macros.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE(T)
Constraint on the data type.In case the given data type T is resizable, i.e. has a 'resize' member fu...
Definition: Resizable.h:81
T generate() const
Generation of a random value in the range .
Definition: Random.h:249
Header file for all basic DenseMatrix functionality.
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE(T)
Constraint on the data type.In case the given data type T is not resizable, i.e. does not have a 'res...
Definition: Resizable.h:61
Header file for the real shim.
#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
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:61
Header file for the TrueType type/value trait base class.
const DMatForEachExpr< MT, Ceil, SO > ceil(const DenseMatrix< MT, SO > &dm)
Applies the ceil() function to each single element of the dense matrix dm.
Definition: DMatForEachExpr.h:1130