35 #ifndef _BLAZE_MATH_SYMMETRICMATRIX_H_
36 #define _BLAZE_MATH_SYMMETRICMATRIX_H_
80 class Rand< SymmetricMatrix<MT,SO,DF,NF> >
86 inline const SymmetricMatrix<MT,SO,DF,NF>
generate()
const;
87 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n )
const;
88 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
size_t nonzeros )
const;
90 template<
typename Arg >
91 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
const Arg&
min,
const Arg&
max )
const;
93 template<
typename Arg >
94 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
96 template<
typename Arg >
97 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
size_t nonzeros,
98 const Arg&
min,
const Arg&
max )
const;
105 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix )
const;
106 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros )
const;
108 template<
typename Arg >
109 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
const Arg&
min,
const Arg&
max )
const;
111 template<
typename Arg >
112 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros,
113 const Arg&
min,
const Arg&
max )
const;
124 template<
typename Arg >
127 template<
typename Arg >
142 template<
typename MT
146 inline const SymmetricMatrix<MT,SO,DF,NF> Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate()
const
150 SymmetricMatrix<MT,SO,DF,NF> matrix;
165 template<
typename MT
169 inline const SymmetricMatrix<MT,SO,DF,NF>
170 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n )
const
174 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
191 template<
typename MT
195 inline const SymmetricMatrix<MT,SO,DF,NF>
196 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n,
size_t nonzeros )
const
201 if( nonzeros > n*n ) {
205 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
222 template<
typename MT
226 template<
typename Arg >
227 inline const SymmetricMatrix<MT,SO,DF,NF>
228 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
const Arg&
min,
const Arg&
max )
const
232 SymmetricMatrix<MT,SO,DF,NF> matrix;
249 template<
typename MT
253 template<
typename Arg >
254 inline const SymmetricMatrix<MT,SO,DF,NF>
255 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
259 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
278 template<
typename MT
282 template<
typename Arg >
283 inline const SymmetricMatrix<MT,SO,DF,NF>
284 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n,
size_t nonzeros,
285 const Arg&
min,
const Arg&
max )
const
290 if( nonzeros > n*n ) {
294 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
310 template<
typename MT
314 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix )
const
316 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
329 template<
typename MT
333 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
TrueType )
const
339 const size_t n( matrix.rows() );
341 for(
size_t i=0UL; i<n; ++i ) {
342 for(
size_t j=0UL; j<=i; ++j ) {
343 matrix(i,j) = rand<ET>();
358 template<
typename MT
362 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
FalseType )
const
368 const size_t n( matrix.rows() );
370 if( n == 0UL )
return;
372 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
375 matrix.reserve( nonzeros );
377 while( matrix.nonZeros() < nonzeros ) {
378 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>();
394 template<
typename MT
398 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros )
const
404 const size_t n( matrix.rows() );
406 if( nonzeros > n*n ) {
410 if( n == 0UL )
return;
413 matrix.reserve( nonzeros );
415 while( matrix.nonZeros() < nonzeros ) {
416 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>();
432 template<
typename MT
436 template<
typename Arg >
437 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
438 const Arg& min,
const Arg& max )
const
440 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
455 template<
typename MT
459 template<
typename Arg >
460 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
461 const Arg& min,
const Arg& max,
TrueType )
const
467 const size_t n( matrix.rows() );
469 for(
size_t i=0UL; i<n; ++i ) {
470 for(
size_t j=0UL; j<=i; ++j ) {
471 matrix(i,j) = rand<ET>(
min,
max );
488 template<
typename MT
492 template<
typename Arg >
493 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
494 const Arg& min,
const Arg& max,
FalseType )
const
500 const size_t n( matrix.rows() );
502 if( n == 0UL )
return;
504 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
507 matrix.reserve( nonzeros );
509 while( matrix.nonZeros() < nonzeros ) {
510 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>(
min,
max );
528 template<
typename MT
532 template<
typename Arg >
533 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
534 size_t nonzeros,
const Arg& min,
const Arg& max )
const
540 const size_t n( matrix.rows() );
542 if( nonzeros > n*n ) {
546 if( n == 0UL )
return;
549 matrix.reserve( nonzeros );
551 while( matrix.nonZeros() < nonzeros ) {
552 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>(
min,
max );
574 template<
typename MT
577 void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix )
596 template<
typename MT
600 void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix,
const Arg& min,
const Arg& max )
617 template<
typename MT
620 void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix )
622 typedef typename UnderlyingBuiltin<typename MT::ElementType>::Type BT;
624 const size_t n( matrix.rows() );
626 for(
size_t i=0UL; i<n; ++i ) {
627 for(
size_t j=0UL; j<=i; ++j ) {
628 matrix(i,j) = rand<BT>();
647 template<
typename MT
651 void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix,
const Arg& min,
const Arg& max )
653 typedef typename UnderlyingBuiltin<typename MT::ElementType>::Type BT;
655 const size_t n( matrix.rows() );
657 for(
size_t i=0UL; i<n; ++i ) {
658 for(
size_t j=0UL; j<=i; ++j ) {
659 matrix(i,j) = rand<BT>(
real( min ),
real( max ) );
676 template<
typename MT
679 void makePositiveDefinite( SymmetricMatrix<MT,SO,true,NF>& matrix )
681 typedef typename UnderlyingBuiltin<typename MT::ElementType>::Type BT;
683 const size_t n( matrix.rows() );
685 makeHermitian( matrix );
688 for(
size_t i=0UL; i<n; ++i ) {
689 matrix(i,i) += BT(n);
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
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.
Implementation of a random number generator.
Constraint on the data type.
Constraint on the data type.
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.
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.
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
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:767
Header file for exception macros.
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.