35 #ifndef _BLAZE_MATH_HERMITIANMATRIX_H_ 36 #define _BLAZE_MATH_HERMITIANMATRIX_H_ 81 class Rand< HermitianMatrix<MT,SO,DF> >
87 inline const HermitianMatrix<MT,SO,DF>
generate()
const;
88 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n )
const;
89 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
91 template<
typename Arg >
92 inline const HermitianMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
94 template<
typename Arg >
95 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
97 template<
typename Arg >
98 inline const HermitianMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
99 const Arg&
min,
const Arg&
max )
const;
106 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix )
const;
107 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const;
109 template<
typename Arg >
110 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
112 template<
typename Arg >
113 inline void randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros,
114 const Arg&
min,
const Arg&
max )
const;
125 template<
typename Arg >
128 template<
typename Arg >
143 template<
typename MT
146 inline const HermitianMatrix<MT,SO,DF> Rand< HermitianMatrix<MT,SO,DF> >::generate()
const 150 HermitianMatrix<MT,SO,DF> matrix;
165 template<
typename MT
168 inline const HermitianMatrix<MT,SO,DF>
169 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n )
const 173 HermitianMatrix<MT,SO,DF> matrix( n );
190 template<
typename MT
193 inline const HermitianMatrix<MT,SO,DF>
194 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const 199 if( nonzeros > n*n ) {
203 HermitianMatrix<MT,SO,DF> matrix( n );
220 template<
typename MT
223 template<
typename Arg >
224 inline const HermitianMatrix<MT,SO,DF>
225 Rand< HermitianMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const 229 HermitianMatrix<MT,SO,DF> matrix;
246 template<
typename MT
249 template<
typename Arg >
250 inline const HermitianMatrix<MT,SO,DF>
251 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const 255 HermitianMatrix<MT,SO,DF> matrix( n );
274 template<
typename MT
277 template<
typename Arg >
278 inline const HermitianMatrix<MT,SO,DF>
279 Rand< HermitianMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
280 const Arg&
min,
const Arg&
max )
const 285 if( nonzeros > n*n ) {
289 HermitianMatrix<MT,SO,DF> matrix( n );
305 template<
typename MT
308 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix )
const 310 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
323 template<
typename MT
326 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
TrueType )
const 330 using ET = ElementType_t<MT>;
331 using BT = UnderlyingBuiltin_t<ET>;
333 const size_t n( matrix.rows() );
335 for(
size_t i=0UL; i<n; ++i ) {
336 for(
size_t j=0UL; j<i; ++j ) {
337 matrix(i,j) = rand<ET>();
339 matrix(i,i) = rand<BT>();
353 template<
typename MT
356 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
FalseType )
const 360 const size_t n( matrix.rows() );
362 if( n == 0UL )
return;
364 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
381 template<
typename MT
384 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const 388 using ET = ElementType_t<MT>;
389 using BT = UnderlyingBuiltin_t<ET>;
391 const size_t n( matrix.rows() );
393 if( nonzeros > n*n ) {
397 if( n == 0UL )
return;
400 matrix.reserve( nonzeros );
402 while( matrix.nonZeros() < nonzeros )
404 const size_t row ( rand<size_t>( 0UL, n-1UL ) );
405 const size_t column( rand<size_t>( 0UL, n-1UL ) );
426 template<
typename MT
429 template<
typename Arg >
430 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
431 const Arg&
min,
const Arg&
max )
const 448 template<
typename MT
451 template<
typename Arg >
452 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
457 using ET = ElementType_t<MT>;
458 using BT = UnderlyingBuiltin_t<ET>;
460 const size_t n( matrix.rows() );
462 for(
size_t i=0UL; i<n; ++i ) {
463 for(
size_t j=0UL; j<i; ++j ) {
464 matrix(i,j) = rand<ET>(
min,
max );
482 template<
typename MT
485 template<
typename Arg >
486 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
491 const size_t n( matrix.rows() );
493 if( n == 0UL )
return;
495 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
514 template<
typename MT
517 template<
typename Arg >
518 inline void Rand< HermitianMatrix<MT,SO,DF> >
::randomize( HermitianMatrix<MT,SO,DF>& matrix,
519 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const 523 using ET = ElementType_t<MT>;
524 using BT = UnderlyingBuiltin_t<ET>;
526 const size_t n( matrix.rows() );
528 if( nonzeros > n*n ) {
532 if( n == 0UL )
return;
534 std::vector<size_t> dist( n );
535 std::vector<bool> structure( n*n );
538 while( nz < nonzeros )
540 const size_t row = rand<size_t>( 0UL, n-1UL );
541 const size_t col = rand<size_t>( 0UL, n-1UL );
543 if( structure[
row*n+col] )
continue;
546 structure[
row*n+col] =
true;
551 structure[col*n+
row] =
true;
557 matrix.reserve( nz );
559 for(
size_t i=0UL; i<n; ++i ) {
560 matrix.reserve( i, dist[i] );
563 for(
size_t i=0UL; i<n; ++i ) {
564 for(
size_t j=i; j<n; ++j ) {
565 if( structure[i*n+j] ) {
569 matrix.append( i, j, rand<ET>(
min,
max ) );
593 template<
typename MT
596 void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix )
598 using BT = UnderlyingBuiltin_t< ElementType_t<MT> >;
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>();
623 template<
typename MT
627 void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
629 using BT = UnderlyingBuiltin_t< ElementType_t<MT> >;
631 const size_t n( matrix.rows() );
633 for(
size_t i=0UL; i<n; ++i ) {
634 for(
size_t j=0UL; j<=i; ++j ) {
652 template<
typename MT
655 void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix )
674 template<
typename MT
678 void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
695 template<
typename MT
698 void makePositiveDefinite( HermitianMatrix<MT,SO,DF>& matrix )
702 using BT = UnderlyingBuiltin_t< ElementType_t<MT> >;
704 const size_t n( matrix.rows() );
709 for(
size_t i=0UL; i<n; ++i ) {
710 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: IntegralConstant.h:121
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Header file for basic type definitions.
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1389
#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
Constraint on the data type.
decltype(auto) ceil(const DenseMatrix< MT, SO > &dm)
Applies the ceil() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1240
void randomize(T &&value)
Randomization of a given variable.
Definition: Random.h:929
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: IntegralConstant.h:132
Header file for the implementation of a Hermitian matrix adaptor.
Constraint on the data type.
Constraint on the data type.
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:292
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for all basic SparseMatrix functionality.
Header file for the UnderlyingBuiltin type trait.
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:1162
Header file for the exception macros of the math module.
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:1198
Header file for the IsDenseMatrix type trait.
Header file for run time assertion macros.
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE_TYPE(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
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:1328
T generate() const
Generation of a random value in the range .
Definition: Random.h:252
Header file for all basic DenseMatrix functionality.
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE(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 implementation of a diagonal matrix adaptor.
Header file for the IntegralConstant class template.
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,...
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