35 #ifndef _BLAZE_MATH_HERMITIANMATRIX_H_
36 #define _BLAZE_MATH_HERMITIANMATRIX_H_
79 class Rand< HermitianMatrix<MT,SO,DF> >
85 inline const HermitianMatrix<MT,SO,DF>
generate()
const;
86 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n )
const;
87 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
89 template<
typename Arg >
90 inline const HermitianMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
92 template<
typename Arg >
93 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
95 template<
typename Arg >
96 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
97 const Arg&
min,
const Arg&
max )
const;
104 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix )
const;
105 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const;
107 template<
typename Arg >
108 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
110 template<
typename Arg >
111 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros,
112 const Arg&
min,
const Arg&
max )
const;
123 template<
typename Arg >
126 template<
typename Arg >
141 template<
typename MT
144 inline const HermitianMatrix<MT,SO,DF> Rand< HermitianMatrix<MT,SO,DF> >::generate()
const
148 HermitianMatrix<MT,SO,DF> matrix;
163 template<
typename MT
166 inline const HermitianMatrix<MT,SO,DF>
167 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n )
const
171 HermitianMatrix<MT,SO,DF> matrix( n );
188 template<
typename MT
191 inline const HermitianMatrix<MT,SO,DF>
192 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const
198 throw std::invalid_argument(
"Invalid number of non-zero elements" );
200 HermitianMatrix<MT,SO,DF> matrix( n );
217 template<
typename MT
220 template<
typename Arg >
221 inline const HermitianMatrix<MT,SO,DF>
222 Rand< HermitianMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const
226 HermitianMatrix<MT,SO,DF> matrix;
243 template<
typename MT
246 template<
typename Arg >
247 inline const HermitianMatrix<MT,SO,DF>
248 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
252 HermitianMatrix<MT,SO,DF> matrix( n );
271 template<
typename MT
274 template<
typename Arg >
275 inline const HermitianMatrix<MT,SO,DF>
276 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
277 const Arg&
min,
const Arg&
max )
const
283 throw std::invalid_argument(
"Invalid number of non-zero elements" );
285 HermitianMatrix<MT,SO,DF> matrix( n );
301 template<
typename MT
304 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix )
const
306 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
319 template<
typename MT
322 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
TrueType )
const
327 typedef typename UnderlyingBuiltin<ET>::Type BT;
329 const size_t n( matrix.rows() );
331 for(
size_t i=0UL; i<n; ++i ) {
332 for(
size_t j=0UL; j<i; ++j ) {
333 matrix(i,j) = rand<ET>();
335 matrix(i,i) = rand<BT>();
349 template<
typename MT
352 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
FalseType )
const
357 typedef typename UnderlyingBuiltin<ET>::Type BT;
359 const size_t n( matrix.rows() );
361 if( n == 0UL )
return;
363 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
366 matrix.reserve( nonzeros );
368 while( matrix.nonZeros() < nonzeros )
370 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
371 const size_t column( rand<size_t>( 0UL, n-1UL ) );
392 template<
typename MT
395 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const
400 typedef typename UnderlyingBuiltin<ET>::Type BT;
402 const size_t n( matrix.rows() );
405 throw std::invalid_argument(
"Invalid number of non-zero elements" );
407 if( n == 0UL )
return;
410 matrix.reserve( nonzeros );
412 while( matrix.nonZeros() < nonzeros )
414 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
415 const size_t column( rand<size_t>( 0UL, n-1UL ) );
436 template<
typename MT
439 template<
typename Arg >
440 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
441 const Arg& min,
const Arg& max )
const
443 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
458 template<
typename MT
461 template<
typename Arg >
462 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
463 const Arg& min,
const Arg& max,
TrueType )
const
468 typedef typename UnderlyingBuiltin<ET>::Type BT;
470 const size_t n( matrix.rows() );
472 for(
size_t i=0UL; i<n; ++i ) {
473 for(
size_t j=0UL; j<i; ++j ) {
474 matrix(i,j) = rand<ET>(
min,
max );
476 matrix(i,i) = rand<BT>(
real( min ),
real( max ) );
492 template<
typename MT
495 template<
typename Arg >
496 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
497 const Arg& min,
const Arg& max,
FalseType )
const
502 typedef typename UnderlyingBuiltin<ET>::Type BT;
504 const size_t n( matrix.rows() );
506 if( n == 0UL )
return;
508 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
511 matrix.reserve( nonzeros );
513 while( matrix.nonZeros() < nonzeros )
515 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
516 const size_t column( rand<size_t>( 0UL, n-1UL ) );
539 template<
typename MT
542 template<
typename Arg >
543 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
544 size_t nonzeros,
const Arg& min,
const Arg& max )
const
549 typedef typename UnderlyingBuiltin<ET>::Type BT;
551 const size_t n( matrix.rows() );
554 throw std::invalid_argument(
"Invalid number of non-zero elements" );
556 if( n == 0UL )
return;
559 matrix.reserve( nonzeros );
561 while( matrix.nonZeros() < nonzeros )
563 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
564 const size_t column( rand<size_t>( 0UL, n-1UL ) );
591 template<
typename MT
594 void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix )
596 typedef typename UnderlyingBuiltin<typename MT::ElementType>::Type BT;
598 const size_t n( matrix.rows() );
600 for(
size_t i=0UL; i<n; ++i ) {
601 for(
size_t j=0UL; j<=i; ++j ) {
602 matrix(i,j) = rand<BT>();
621 template<
typename MT
625 void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
627 typedef typename UnderlyingBuiltin<typename MT::ElementType>::Type BT;
629 const size_t n( matrix.rows() );
631 for(
size_t i=0UL; i<n; ++i ) {
632 for(
size_t j=0UL; j<=i; ++j ) {
633 matrix(i,j) = rand<BT>(
real( min ),
real( max ) );
650 template<
typename MT
653 void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix )
672 template<
typename MT
676 void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
693 template<
typename MT
696 void makePositiveDefinite( HermitianMatrix<MT,SO,DF>& matrix )
700 typedef typename UnderlyingBuiltin<typename MT::ElementType>::Type BT;
702 const size_t n( matrix.rows() );
707 for(
size_t i=0UL; i<n; ++i ) {
708 matrix(i,i) += BT(n);
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
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:79
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1041
Constraint on the data type.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:697
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
Implementation of a random number generator.
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: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
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
Header file for the real shim.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Header file for the IsDenseMatrix type trait.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
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:118
T generate() const
Generation of a random value in the range .
Definition: Random.h:220
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:79
boost::false_type FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
#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:79
Header file for the TrueType type/value trait base class.