35 #ifndef _BLAZE_MATH_UPPERMATRIX_H_ 36 #define _BLAZE_MATH_UPPERMATRIX_H_ 82 class Rand< UpperMatrix<MT,SO,DF> >
88 inline const UpperMatrix<MT,SO,DF>
generate()
const;
89 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n )
const;
90 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
92 template<
typename Arg >
93 inline const UpperMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
95 template<
typename Arg >
96 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
98 template<
typename Arg >
99 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
100 const Arg&
min,
const Arg&
max )
const;
107 inline void randomize( UpperMatrix<MT,SO,DF>& matrix )
const;
108 inline void randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const;
109 inline void randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const;
111 template<
typename Arg >
112 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
114 template<
typename Arg >
115 inline void randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros,
116 const Arg&
min,
const Arg&
max )
const;
118 template<
typename Arg >
119 inline void randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros,
120 const Arg&
min,
const Arg&
max )
const;
131 template<
typename Arg >
134 template<
typename Arg >
149 template<
typename MT
152 inline const UpperMatrix<MT,SO,DF> Rand< UpperMatrix<MT,SO,DF> >
::generate()
const 156 UpperMatrix<MT,SO,DF> matrix;
171 template<
typename MT
174 inline const UpperMatrix<MT,SO,DF>
175 Rand< UpperMatrix<MT,SO,DF> >
::generate(
size_t n )
const 179 UpperMatrix<MT,SO,DF> matrix( n );
196 template<
typename MT
199 inline const UpperMatrix<MT,SO,DF>
200 Rand< UpperMatrix<MT,SO,DF> >
::generate(
size_t n,
size_t nonzeros )
const 205 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
209 UpperMatrix<MT,SO,DF> matrix( n );
226 template<
typename MT
229 template<
typename Arg >
230 inline const UpperMatrix<MT,SO,DF>
231 Rand< UpperMatrix<MT,SO,DF> >
::generate(
const Arg&
min,
const Arg&
max )
const 235 UpperMatrix<MT,SO,DF> matrix;
252 template<
typename MT
255 template<
typename Arg >
256 inline const UpperMatrix<MT,SO,DF>
257 Rand< UpperMatrix<MT,SO,DF> >
::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const 261 UpperMatrix<MT,SO,DF> matrix( n );
280 template<
typename MT
283 template<
typename Arg >
284 inline const UpperMatrix<MT,SO,DF>
285 Rand< UpperMatrix<MT,SO,DF> >
::generate(
size_t n,
size_t nonzeros,
286 const Arg&
min,
const Arg&
max )
const 291 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
295 UpperMatrix<MT,SO,DF> matrix( n );
311 template<
typename MT
314 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix )
const 316 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
329 template<
typename MT
332 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
TrueType )
const 336 using ET = ElementType_<MT>;
338 const size_t n( matrix.rows() );
340 for(
size_t i=0UL; i<n; ++i ) {
341 for(
size_t j=i; j<n; ++j ) {
342 matrix(i,j) = rand<ET>();
357 template<
typename MT
360 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
FalseType )
const 364 const size_t n( matrix.rows() );
366 if( n == 0UL )
return;
368 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.3*n*n ) ) );
385 template<
typename MT
388 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const 392 using ET = ElementType_<MT>;
394 const size_t n( matrix.rows() );
396 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
400 if( n == 0UL )
return;
403 matrix.reserve( nonzeros );
405 std::vector<size_t> dist( n );
407 for(
size_t nz=0UL; nz<nonzeros; ) {
408 const size_t index = rand<size_t>( 0UL, n-1UL );
409 if( dist[index] == n - index )
continue;
414 for(
size_t i=0UL; i<n; ++i ) {
415 const Indices indices( i, n-1UL, dist[i] );
416 for(
size_t j : indices ) {
417 matrix.append( i, j, rand<ET>() );
419 matrix.finalize( i );
435 template<
typename MT
438 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const 442 using ET = ElementType_<MT>;
444 const size_t n( matrix.rows() );
446 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
450 if( n == 0UL )
return;
453 matrix.reserve( nonzeros );
455 std::vector<size_t> dist( n );
457 for(
size_t nz=0UL; nz<nonzeros; ) {
458 const size_t index = rand<size_t>( 0UL, n-1UL );
459 if( dist[index] == index+1UL )
continue;
464 for(
size_t j=0UL; j<n; ++j ) {
465 const Indices indices( 0UL, j, dist[j] );
466 for(
size_t i : indices ) {
467 matrix.append( i, j, rand<ET>() );
469 matrix.finalize( j );
485 template<
typename MT
488 template<
typename Arg >
489 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
490 const Arg& min,
const Arg& max )
const 492 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
507 template<
typename MT
510 template<
typename Arg >
511 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
512 const Arg& min,
const Arg& max,
TrueType )
const 516 using ET = ElementType_<MT>;
518 const size_t n( matrix.rows() );
520 for(
size_t i=0UL; i<n; ++i ) {
521 for(
size_t j=i; j<n; ++j ) {
522 matrix(i,j) = rand<ET>(
min,
max );
539 template<
typename MT
542 template<
typename Arg >
543 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
544 const Arg& min,
const Arg& max,
FalseType )
const 548 const size_t n( matrix.rows() );
550 if( n == 0UL )
return;
552 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.3*n*n ) ) );
571 template<
typename MT
574 template<
typename Arg >
575 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,false,DF>& matrix,
576 size_t nonzeros,
const Arg& min,
const Arg& max )
const 580 using ET = ElementType_<MT>;
582 const size_t n( matrix.rows() );
584 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
588 if( n == 0UL )
return;
591 matrix.reserve( nonzeros );
593 std::vector<size_t> dist( n );
595 for(
size_t nz=0UL; nz<nonzeros; ) {
596 const size_t index = rand<size_t>( 0UL, n-1UL );
597 if( dist[index] == n - index )
continue;
602 for(
size_t i=0UL; i<n; ++i ) {
603 const Indices indices( i, n-1UL, dist[i] );
604 for(
size_t j : indices ) {
605 matrix.append( i, j, rand<ET>( min, max ) );
607 matrix.finalize( i );
625 template<
typename MT
628 template<
typename Arg >
629 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,true,DF>& matrix,
630 size_t nonzeros,
const Arg& min,
const Arg& max )
const 634 using ET = ElementType_<MT>;
636 const size_t n( matrix.rows() );
638 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
642 if( n == 0UL )
return;
645 matrix.reserve( nonzeros );
647 std::vector<size_t> dist( n );
649 for(
size_t nz=0UL; nz<nonzeros; ) {
650 const size_t index = rand<size_t>( 0UL, n-1UL );
651 if( dist[index] == index+1UL )
continue;
656 for(
size_t j=0UL; j<n; ++j ) {
657 const Indices indices( 0UL, j, dist[j] );
658 for(
size_t i : indices ) {
659 matrix.append( i, j, rand<ET>( min, max ) );
661 matrix.finalize( j );
683 template<
typename MT
686 void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix )
688 const size_t n( matrix.rows() );
692 for(
size_t i=0UL; i<n; ++i ) {
693 matrix(i,i) = rand< ElementType_<MT> >();
711 template<
typename MT
715 void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
717 using Type = ElementType_<MT>;
719 const size_t n( matrix.rows() );
723 for(
size_t i=0UL; i<n; ++i ) {
724 matrix(i,i) = rand<Type>(
min,
max );
740 template<
typename MT
743 void makeHermitian( UpperMatrix<MT,SO,DF>& matrix )
745 using Type = UnderlyingBuiltin_< ElementType_<MT> >;
747 const size_t n( matrix.rows() );
751 for(
size_t i=0UL; i<n; ++i ) {
752 matrix(i,i) = rand<Type>();
770 template<
typename MT
774 void makeHermitian( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
776 using Type = UnderlyingBuiltin_< ElementType_<MT> >;
778 const size_t n( matrix.rows() );
782 for(
size_t i=0UL; i<n; ++i ) {
783 matrix(i,i) = rand<Type>(
min,
max );
799 template<
typename MT
802 void makePositiveDefinite( UpperMatrix<MT,SO,DF>& matrix )
804 makeHermitian( matrix );
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
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:1234
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:560
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1762
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:1809
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:290
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 complete LowerMatrix implementation.
Header file for the exception macros of the math module.
Header file for the IsDenseMatrix type trait.
Header file for the implementation of a upper matrix adaptor.
Header file for the Indices class.
#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:778
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:700
T generate() const
Generation of a random value in the range .
Definition: Random.h:250
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.
#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.