35 #ifndef _BLAZE_MATH_UPPERMATRIX_H_
36 #define _BLAZE_MATH_UPPERMATRIX_H_
81 class Rand< UpperMatrix<MT,SO,DF> >
87 inline const UpperMatrix<MT,SO,DF>
generate()
const;
88 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n )
const;
89 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
91 template<
typename Arg >
92 inline const UpperMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
94 template<
typename Arg >
95 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
97 template<
typename Arg >
98 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
99 const Arg&
min,
const Arg&
max )
const;
106 inline void randomize( UpperMatrix<MT,SO,DF>& matrix )
const;
107 inline void randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const;
108 inline void randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const;
110 template<
typename Arg >
111 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
113 template<
typename Arg >
114 inline void randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros,
115 const Arg&
min,
const Arg&
max )
const;
117 template<
typename Arg >
118 inline void randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros,
119 const Arg&
min,
const Arg&
max )
const;
130 template<
typename Arg >
133 template<
typename Arg >
148 template<
typename MT
151 inline const UpperMatrix<MT,SO,DF> Rand< UpperMatrix<MT,SO,DF> >::generate()
const
155 UpperMatrix<MT,SO,DF> matrix;
170 template<
typename MT
173 inline const UpperMatrix<MT,SO,DF>
174 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n )
const
178 UpperMatrix<MT,SO,DF> matrix( n );
195 template<
typename MT
198 inline const UpperMatrix<MT,SO,DF>
199 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const
204 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
208 UpperMatrix<MT,SO,DF> matrix( n );
225 template<
typename MT
228 template<
typename Arg >
229 inline const UpperMatrix<MT,SO,DF>
230 Rand< UpperMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const
234 UpperMatrix<MT,SO,DF> matrix;
251 template<
typename MT
254 template<
typename Arg >
255 inline const UpperMatrix<MT,SO,DF>
256 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
260 UpperMatrix<MT,SO,DF> matrix( n );
279 template<
typename MT
282 template<
typename Arg >
283 inline const UpperMatrix<MT,SO,DF>
284 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
285 const Arg&
min,
const Arg&
max )
const
290 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
294 UpperMatrix<MT,SO,DF> matrix( n );
310 template<
typename MT
313 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix )
const
315 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
328 template<
typename MT
331 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
TrueType )
const
335 typedef ElementType_<MT> ET;
337 const size_t n( matrix.rows() );
339 for(
size_t i=0UL; i<n; ++i ) {
340 for(
size_t j=i; j<n; ++j ) {
341 matrix(i,j) = rand<ET>();
356 template<
typename MT
359 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
FalseType )
const
363 const size_t n( matrix.rows() );
365 if( n == 0UL )
return;
367 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.3*n*n ) ) );
384 template<
typename MT
387 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const
391 typedef ElementType_<MT> ET;
393 const size_t n( matrix.rows() );
395 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
399 if( n == 0UL )
return;
402 matrix.reserve( nonzeros );
404 std::vector<size_t> dist( n );
406 for(
size_t nz=0UL; nz<nonzeros; ) {
407 const size_t index = rand<size_t>( 0UL, n-1UL );
408 if( dist[index] == n - index )
continue;
413 for(
size_t i=0UL; i<n; ++i ) {
414 const Indices indices( i, n-1UL, dist[i] );
415 for(
size_t j : indices ) {
416 matrix.append( i, j, rand<ET>() );
418 matrix.finalize( i );
434 template<
typename MT
437 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const
441 typedef ElementType_<MT> ET;
443 const size_t n( matrix.rows() );
445 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
449 if( n == 0UL )
return;
452 matrix.reserve( nonzeros );
454 std::vector<size_t> dist( n );
456 for(
size_t nz=0UL; nz<nonzeros; ) {
457 const size_t index = rand<size_t>( 0UL, n-1UL );
458 if( dist[index] == index+1UL )
continue;
463 for(
size_t j=0UL; j<n; ++j ) {
464 const Indices indices( 0UL, j, dist[j] );
465 for(
size_t i : indices ) {
466 matrix.append( i, j, rand<ET>() );
468 matrix.finalize( j );
484 template<
typename MT
487 template<
typename Arg >
488 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
489 const Arg& min,
const Arg& max )
const
491 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
506 template<
typename MT
509 template<
typename Arg >
510 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
511 const Arg& min,
const Arg& max,
TrueType )
const
515 typedef ElementType_<MT> ET;
517 const size_t n( matrix.rows() );
519 for(
size_t i=0UL; i<n; ++i ) {
520 for(
size_t j=i; j<n; ++j ) {
521 matrix(i,j) = rand<ET>(
min,
max );
538 template<
typename MT
541 template<
typename Arg >
542 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
543 const Arg& min,
const Arg& max,
FalseType )
const
547 const size_t n( matrix.rows() );
549 if( n == 0UL )
return;
551 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.3*n*n ) ) );
570 template<
typename MT
573 template<
typename Arg >
574 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,false,DF>& matrix,
575 size_t nonzeros,
const Arg& min,
const Arg& max )
const
579 typedef ElementType_<MT> ET;
581 const size_t n( matrix.rows() );
583 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
587 if( n == 0UL )
return;
590 matrix.reserve( nonzeros );
592 std::vector<size_t> dist( n );
594 for(
size_t nz=0UL; nz<nonzeros; ) {
595 const size_t index = rand<size_t>( 0UL, n-1UL );
596 if( dist[index] == n - index )
continue;
601 for(
size_t i=0UL; i<n; ++i ) {
602 const Indices indices( i, n-1UL, dist[i] );
603 for(
size_t j : indices ) {
604 matrix.append( i, j, rand<ET>( min, max ) );
606 matrix.finalize( i );
624 template<
typename MT
627 template<
typename Arg >
628 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,true,DF>& matrix,
629 size_t nonzeros,
const Arg& min,
const Arg& max )
const
633 typedef ElementType_<MT> ET;
635 const size_t n( matrix.rows() );
637 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
641 if( n == 0UL )
return;
644 matrix.reserve( nonzeros );
646 std::vector<size_t> dist( n );
648 for(
size_t nz=0UL; nz<nonzeros; ) {
649 const size_t index = rand<size_t>( 0UL, n-1UL );
650 if( dist[index] == index+1UL )
continue;
655 for(
size_t j=0UL; j<n; ++j ) {
656 const Indices indices( 0UL, j, dist[j] );
657 for(
size_t i : indices ) {
658 matrix.append( i, j, rand<ET>( min, max ) );
660 matrix.finalize( j );
682 template<
typename MT
685 void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix )
687 const size_t n( matrix.rows() );
691 for(
size_t i=0UL; i<n; ++i ) {
692 matrix(i,i) = rand< ElementType_<MT> >();
710 template<
typename MT
714 void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
716 typedef ElementType_<MT> Type;
718 const size_t n( matrix.rows() );
722 for(
size_t i=0UL; i<n; ++i ) {
723 matrix(i,i) = rand<Type>(
min,
max );
739 template<
typename MT
742 void makeHermitian( UpperMatrix<MT,SO,DF>& matrix )
744 typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
746 const size_t n( matrix.rows() );
750 for(
size_t i=0UL; i<n; ++i ) {
751 matrix(i,i) = rand<Type>();
769 template<
typename MT
773 void makeHermitian( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
775 typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
777 const size_t n( matrix.rows() );
781 for(
size_t i=0UL; i<n; ++i ) {
782 matrix(i,i) = rand<Type>(
min,
max );
798 template<
typename MT
801 void makePositiveDefinite( UpperMatrix<MT,SO,DF>& matrix )
803 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
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:926
Constraint on the data type.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:689
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
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:1716
Constraint on the data type.
Constraint on the data type.
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:289
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(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
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:759
#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