35 #ifndef _BLAZE_MATH_SYMMETRICMATRIX_H_ 36 #define _BLAZE_MATH_SYMMETRICMATRIX_H_ 81 class Rand< SymmetricMatrix<MT,SO,DF,NF> >
87 inline const SymmetricMatrix<MT,SO,DF,NF>
generate()
const;
88 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n )
const;
89 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
size_t nonzeros )
const;
91 template<
typename Arg >
92 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
const Arg&
min,
const Arg&
max )
const;
94 template<
typename Arg >
95 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
97 template<
typename Arg >
98 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
size_t nonzeros,
99 const Arg&
min,
const Arg&
max )
const;
106 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix )
const;
107 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros )
const;
109 template<
typename Arg >
110 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
const Arg&
min,
const Arg&
max )
const;
112 template<
typename Arg >
113 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros,
114 const Arg&
min,
const Arg&
max )
const;
125 template<
typename Arg >
128 template<
typename Arg >
143 template<
typename MT
147 inline const SymmetricMatrix<MT,SO,DF,NF> Rand< SymmetricMatrix<MT,SO,DF,NF> >
::generate()
const 151 SymmetricMatrix<MT,SO,DF,NF> matrix;
166 template<
typename MT
170 inline const SymmetricMatrix<MT,SO,DF,NF>
171 Rand< SymmetricMatrix<MT,SO,DF,NF> >
::generate(
size_t n )
const 175 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
192 template<
typename MT
196 inline const SymmetricMatrix<MT,SO,DF,NF>
197 Rand< SymmetricMatrix<MT,SO,DF,NF> >
::generate(
size_t n,
size_t nonzeros )
const 202 if( nonzeros > n*n ) {
206 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
223 template<
typename MT
227 template<
typename Arg >
228 inline const SymmetricMatrix<MT,SO,DF,NF>
229 Rand< SymmetricMatrix<MT,SO,DF,NF> >
::generate(
const Arg&
min,
const Arg&
max )
const 233 SymmetricMatrix<MT,SO,DF,NF> matrix;
250 template<
typename MT
254 template<
typename Arg >
255 inline const SymmetricMatrix<MT,SO,DF,NF>
256 Rand< SymmetricMatrix<MT,SO,DF,NF> >
::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const 260 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
279 template<
typename MT
283 template<
typename Arg >
284 inline const SymmetricMatrix<MT,SO,DF,NF>
285 Rand< SymmetricMatrix<MT,SO,DF,NF> >
::generate(
size_t n,
size_t nonzeros,
286 const Arg&
min,
const Arg&
max )
const 291 if( nonzeros > n*n ) {
295 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
311 template<
typename MT
315 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix )
const 317 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
330 template<
typename MT
334 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
TrueType )
const 338 typedef ElementType_<MT> ET;
340 const size_t n( matrix.rows() );
342 for(
size_t i=0UL; i<n; ++i ) {
343 for(
size_t j=0UL; j<=i; ++j ) {
344 matrix(i,j) = rand<ET>();
359 template<
typename MT
363 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
FalseType )
const 367 const size_t n( matrix.rows() );
369 if( n == 0UL )
return;
371 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
388 template<
typename MT
392 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros )
const 396 typedef ElementType_<MT> ET;
398 const size_t n( matrix.rows() );
400 if( nonzeros > n*n ) {
404 if( n == 0UL )
return;
407 matrix.reserve( nonzeros+1UL );
409 while( matrix.nonZeros() < nonzeros ) {
410 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>();
426 template<
typename MT
430 template<
typename Arg >
431 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
432 const Arg& min,
const Arg& max )
const 434 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
449 template<
typename MT
453 template<
typename Arg >
454 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
455 const Arg& min,
const Arg& max,
TrueType )
const 459 typedef ElementType_<MT> ET;
461 const size_t n( matrix.rows() );
463 for(
size_t i=0UL; i<n; ++i ) {
464 for(
size_t j=0UL; j<=i; ++j ) {
465 matrix(i,j) = rand<ET>(
min,
max );
482 template<
typename MT
486 template<
typename Arg >
487 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
488 const Arg& min,
const Arg& max,
FalseType )
const 492 const size_t n( matrix.rows() );
494 if( n == 0UL )
return;
496 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
515 template<
typename MT
519 template<
typename Arg >
520 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
521 size_t nonzeros,
const Arg& min,
const Arg& max )
const 525 typedef ElementType_<MT> ET;
527 const size_t n( matrix.rows() );
529 if( nonzeros > n*n ) {
533 if( n == 0UL )
return;
536 matrix.reserve( nonzeros+1UL );
538 while( matrix.nonZeros() < nonzeros ) {
539 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>(
min,
max );
561 template<
typename MT
564 void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix )
583 template<
typename MT
587 void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix,
const Arg& min,
const Arg& max )
604 template<
typename MT
607 void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix )
609 typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
611 const size_t n( matrix.rows() );
613 for(
size_t i=0UL; i<n; ++i ) {
614 for(
size_t j=0UL; j<=i; ++j ) {
615 matrix(i,j) = rand<BT>();
634 template<
typename MT
638 void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix,
const Arg& min,
const Arg& max )
640 typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
642 const size_t n( matrix.rows() );
644 for(
size_t i=0UL; i<n; ++i ) {
645 for(
size_t j=0UL; j<=i; ++j ) {
646 matrix(i,j) = rand<BT>(
real( min ),
real( max ) );
663 template<
typename MT
666 void makePositiveDefinite( SymmetricMatrix<MT,SO,true,NF>& matrix )
668 typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
670 const size_t n( matrix.rows() );
672 makeHermitian( matrix );
675 for(
size_t i=0UL; i<n; ++i ) {
676 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
#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.
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.
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1755
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:1802
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:289
Header file for the implementation of a symmetric matrix adaptor.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for all basic SparseMatrix functionality.
Header file for the UnderlyingBuiltin type trait.
Header file for the exception macros of the math module.
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:1279
Header file for run time assertion macros.
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:775
#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