35 #ifndef _BLAZE_MATH_SYMMETRICMATRIX_H_ 36 #define _BLAZE_MATH_SYMMETRICMATRIX_H_ 82 class Rand< SymmetricMatrix<MT,SO,DF,NF> >
88 inline const SymmetricMatrix<MT,SO,DF,NF>
generate()
const;
89 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n )
const;
90 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
size_t nonzeros )
const;
92 template<
typename Arg >
93 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
const Arg&
min,
const Arg&
max )
const;
95 template<
typename Arg >
96 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
98 template<
typename Arg >
99 inline const SymmetricMatrix<MT,SO,DF,NF>
generate(
size_t n,
size_t nonzeros,
100 const Arg&
min,
const Arg&
max )
const;
107 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix )
const;
108 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros )
const;
110 template<
typename Arg >
111 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
const Arg&
min,
const Arg&
max )
const;
113 template<
typename Arg >
114 inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros,
115 const Arg&
min,
const Arg&
max )
const;
126 template<
typename Arg >
129 template<
typename Arg >
144 template<
typename MT
148 inline const SymmetricMatrix<MT,SO,DF,NF> Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate()
const 152 SymmetricMatrix<MT,SO,DF,NF> matrix;
167 template<
typename MT
171 inline const SymmetricMatrix<MT,SO,DF,NF>
172 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n )
const 176 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
193 template<
typename MT
197 inline const SymmetricMatrix<MT,SO,DF,NF>
198 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n,
size_t nonzeros )
const 203 if( nonzeros > n*n ) {
207 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
224 template<
typename MT
228 template<
typename Arg >
229 inline const SymmetricMatrix<MT,SO,DF,NF>
230 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
const Arg&
min,
const Arg&
max )
const 234 SymmetricMatrix<MT,SO,DF,NF> matrix;
251 template<
typename MT
255 template<
typename Arg >
256 inline const SymmetricMatrix<MT,SO,DF,NF>
257 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const 261 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
280 template<
typename MT
284 template<
typename Arg >
285 inline const SymmetricMatrix<MT,SO,DF,NF>
286 Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate(
size_t n,
size_t nonzeros,
287 const Arg&
min,
const Arg&
max )
const 292 if( nonzeros > n*n ) {
296 SymmetricMatrix<MT,SO,DF,NF> matrix( n );
312 template<
typename MT
316 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix )
const 318 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
331 template<
typename MT
335 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
TrueType )
const 339 using ET = ElementType_t<MT>;
341 const size_t n( matrix.rows() );
343 for(
size_t i=0UL; i<n; ++i ) {
344 for(
size_t j=0UL; j<=i; ++j ) {
345 matrix(i,j) = rand<ET>();
360 template<
typename MT
364 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 ) ) );
389 template<
typename MT
393 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros )
const 397 using ET = ElementType_t<MT>;
399 const size_t n( matrix.rows() );
401 if( nonzeros > n*n ) {
405 if( n == 0UL )
return;
408 matrix.reserve( nonzeros+1UL );
410 while( matrix.nonZeros() < nonzeros ) {
411 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>();
427 template<
typename MT
431 template<
typename Arg >
432 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
433 const Arg&
min,
const Arg&
max )
const 450 template<
typename MT
454 template<
typename Arg >
455 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
460 using ET = ElementType_t<MT>;
462 const size_t n( matrix.rows() );
464 for(
size_t i=0UL; i<n; ++i ) {
465 for(
size_t j=0UL; j<=i; ++j ) {
466 matrix(i,j) = rand<ET>(
min,
max );
483 template<
typename MT
487 template<
typename Arg >
488 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
493 const size_t n( matrix.rows() );
495 if( n == 0UL )
return;
497 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*n*n ) ) );
516 template<
typename MT
520 template<
typename Arg >
521 inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >
::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
522 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const 526 using ET = ElementType_t<MT>;
528 const size_t n( matrix.rows() );
530 if( nonzeros > n*n ) {
534 if( n == 0UL )
return;
537 matrix.reserve( nonzeros+1UL );
539 while( matrix.nonZeros() < nonzeros ) {
540 matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>(
min,
max );
562 template<
typename MT
565 void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix )
584 template<
typename MT
588 void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix,
const Arg&
min,
const Arg&
max )
605 template<
typename MT
608 void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix )
610 using BT = UnderlyingBuiltin_t< ElementType_t<MT> >;
612 const size_t n( matrix.rows() );
614 for(
size_t i=0UL; i<n; ++i ) {
615 for(
size_t j=0UL; j<=i; ++j ) {
616 matrix(i,j) = rand<BT>();
635 template<
typename MT
639 void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix,
const Arg&
min,
const Arg&
max )
641 using BT = UnderlyingBuiltin_t< ElementType_t<MT> >;
643 const size_t n( matrix.rows() );
645 for(
size_t i=0UL; i<n; ++i ) {
646 for(
size_t j=0UL; j<=i; ++j ) {
664 template<
typename MT
667 void makePositiveDefinite( SymmetricMatrix<MT,SO,true,NF>& matrix )
669 using BT = UnderlyingBuiltin_t< ElementType_t<MT> >;
671 const size_t n( matrix.rows() );
673 makeHermitian( matrix );
676 for(
size_t i=0UL; i<n; ++i ) {
677 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.
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1392
#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:1239
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: TrueType.h:61
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
Header file for the implementation of a symmetric matrix adaptor.
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:1147
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:1179
Header file for the IsDenseMatrix type trait.
Header file for run time assertion macros.
#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 isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:617
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 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.