35 #ifndef _BLAZE_MATH_UNIUPPERMATRIX_H_ 36 #define _BLAZE_MATH_UNIUPPERMATRIX_H_ 80 class Rand< UniUpperMatrix<MT,SO,DF> >
86 inline const UniUpperMatrix<MT,SO,DF>
generate()
const;
87 inline const UniUpperMatrix<MT,SO,DF>
generate(
size_t n )
const;
88 inline const UniUpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
90 template<
typename Arg >
91 inline const UniUpperMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
93 template<
typename Arg >
94 inline const UniUpperMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
96 template<
typename Arg >
97 inline const UniUpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
98 const Arg&
min,
const Arg&
max )
const;
105 inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix )
const;
106 inline void randomize( UniUpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const;
107 inline void randomize( UniUpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const;
109 template<
typename Arg >
110 inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
112 template<
typename Arg >
113 inline void randomize( UniUpperMatrix<MT,false,DF>& matrix,
size_t nonzeros,
114 const Arg&
min,
const Arg&
max )
const;
116 template<
typename Arg >
117 inline void randomize( UniUpperMatrix<MT,true,DF>& matrix,
size_t nonzeros,
118 const Arg&
min,
const Arg&
max )
const;
129 template<
typename Arg >
132 template<
typename Arg >
147 template<
typename MT
150 inline const UniUpperMatrix<MT,SO,DF> Rand< UniUpperMatrix<MT,SO,DF> >
::generate()
const 154 UniUpperMatrix<MT,SO,DF> matrix;
169 template<
typename MT
172 inline const UniUpperMatrix<MT,SO,DF>
173 Rand< UniUpperMatrix<MT,SO,DF> >
::generate(
size_t n )
const 177 UniUpperMatrix<MT,SO,DF> matrix( n );
194 template<
typename MT
197 inline const UniUpperMatrix<MT,SO,DF>
198 Rand< UniUpperMatrix<MT,SO,DF> >
::generate(
size_t n,
size_t nonzeros )
const 203 if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
207 UniUpperMatrix<MT,SO,DF> matrix( n );
224 template<
typename MT
227 template<
typename Arg >
228 inline const UniUpperMatrix<MT,SO,DF>
229 Rand< UniUpperMatrix<MT,SO,DF> >
::generate(
const Arg&
min,
const Arg&
max )
const 233 UniUpperMatrix<MT,SO,DF> matrix;
250 template<
typename MT
253 template<
typename Arg >
254 inline const UniUpperMatrix<MT,SO,DF>
255 Rand< UniUpperMatrix<MT,SO,DF> >
::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const 259 UniUpperMatrix<MT,SO,DF> matrix( n );
278 template<
typename MT
281 template<
typename Arg >
282 inline const UniUpperMatrix<MT,SO,DF>
283 Rand< UniUpperMatrix<MT,SO,DF> >
::generate(
size_t n,
size_t nonzeros,
284 const Arg&
min,
const Arg&
max )
const 289 if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
293 UniUpperMatrix<MT,SO,DF> matrix( n );
309 template<
typename MT
312 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,SO,DF>& matrix )
const 314 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
327 template<
typename MT
330 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
TrueType )
const 334 typedef ElementType_<MT> ET;
336 const size_t n( matrix.rows() );
338 for(
size_t i=0UL; i<n; ++i ) {
339 for(
size_t j=i+1UL; j<n; ++j ) {
340 matrix(i,j) = rand<ET>();
355 template<
typename MT
358 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
FalseType )
const 362 const size_t n( matrix.rows() );
364 if( n == 0UL || n == 1UL )
return;
366 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.2*n*n ) ) );
383 template<
typename MT
386 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const 390 typedef ElementType_<MT> ET;
392 const size_t n( matrix.rows() );
394 if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
398 if( n == 0UL || n == 1UL )
return;
401 matrix.reserve( nonzeros );
403 std::vector<size_t> dist( n-1UL );
405 for(
size_t nz=0UL; nz<nonzeros; ) {
406 const size_t index = rand<size_t>( 0UL, n-2UL );
407 if( dist[index] == n - index - 1UL )
continue;
412 for(
size_t i=0UL; i<n-1UL; ++i ) {
413 const Indices indices( i+1UL, n-1UL, dist[i] );
414 for(
size_t j : indices ) {
415 matrix.append( i, j, rand<ET>() );
417 matrix.finalize( i );
420 matrix.finalize( n-1UL );
435 template<
typename MT
438 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const 442 typedef ElementType_<MT> ET;
444 const size_t n( matrix.rows() );
446 if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
450 if( n == 0UL || n == 1UL )
return;
453 matrix.reserve( nonzeros );
454 matrix.finalize( 0UL );
456 std::vector<size_t> dist( n );
458 for(
size_t nz=0UL; nz<nonzeros; ) {
459 const size_t index = rand<size_t>( 1UL, n-1UL );
460 if( dist[index] == index )
continue;
465 for(
size_t j=1UL; j<n; ++j ) {
466 const Indices indices( 0UL, j-1UL, dist[j] );
467 for(
size_t i : indices ) {
468 matrix.append( i, j, rand<ET>() );
470 matrix.finalize( j );
486 template<
typename MT
489 template<
typename Arg >
490 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
491 const Arg& min,
const Arg& max )
const 493 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
508 template<
typename MT
511 template<
typename Arg >
512 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
513 const Arg& min,
const Arg& max,
TrueType )
const 517 typedef ElementType_<MT> ET;
519 const size_t n( matrix.rows() );
521 for(
size_t i=0UL; i<n; ++i ) {
522 for(
size_t j=i+1UL; j<n; ++j ) {
523 matrix(i,j) = rand<ET>(
min,
max );
540 template<
typename MT
543 template<
typename Arg >
544 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
545 const Arg& min,
const Arg& max,
FalseType )
const 549 const size_t n( matrix.rows() );
551 if( n == 0UL || n == 1UL )
return;
553 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.2*n*n ) ) );
572 template<
typename MT
575 template<
typename Arg >
576 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,false,DF>& matrix,
577 size_t nonzeros,
const Arg& min,
const Arg& max )
const 581 typedef ElementType_<MT> ET;
583 const size_t n( matrix.rows() );
585 if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
589 if( n == 0UL || n == 1UL )
return;
592 matrix.reserve( nonzeros );
594 std::vector<size_t> dist( n-1UL );
596 for(
size_t nz=0UL; nz<nonzeros; ) {
597 const size_t index = rand<size_t>( 0UL, n-2UL );
598 if( dist[index] == n - index - 1UL )
continue;
603 for(
size_t i=0UL; i<n-1UL; ++i ) {
604 const Indices indices( i+1UL, n-1UL, dist[i] );
605 for(
size_t j : indices ) {
606 matrix.append( i, j, rand<ET>( min, max ) );
608 matrix.finalize( i );
611 matrix.finalize( n-1UL );
628 template<
typename MT
631 template<
typename Arg >
632 inline void Rand< UniUpperMatrix<MT,SO,DF> >
::randomize( UniUpperMatrix<MT,true,DF>& matrix,
633 size_t nonzeros,
const Arg& min,
const Arg& max )
const 637 typedef ElementType_<MT> ET;
639 const size_t n( matrix.rows() );
641 if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
645 if( n == 0UL || n == 1UL )
return;
648 matrix.reserve( nonzeros );
649 matrix.finalize( 0UL );
651 std::vector<size_t> dist( n );
653 for(
size_t nz=0UL; nz<nonzeros; ) {
654 const size_t index = rand<size_t>( 1UL, n-1UL );
655 if( dist[index] == index )
continue;
660 for(
size_t j=1UL; j<n; ++j ) {
661 const Indices indices( 0UL, j-1UL, dist[j] );
662 for(
size_t i : indices ) {
663 matrix.append( i, j, rand<ET>( min, max ) );
665 matrix.finalize( j );
687 template<
typename MT
690 void makeSymmetric( UniUpperMatrix<MT,SO,DF>& matrix )
709 template<
typename MT
713 void makeSymmetric( UniUpperMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
717 makeSymmetric( matrix );
730 template<
typename MT
733 void makeHermitian( UniUpperMatrix<MT,SO,DF>& matrix )
752 template<
typename MT
756 void makeHermitian( UniUpperMatrix<MT,SO,DF>& matrix,
const Arg& min,
const Arg& max )
760 makeHermitian( matrix );
773 template<
typename MT
776 void makePositiveDefinite( UniUpperMatrix<MT,SO,DF>& matrix )
778 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 the complete UniLowerMatrix implementation.
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.
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: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
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for all basic SparseMatrix functionality.
Header file for the exception macros of the math module.
Header file for the IsDenseMatrix type trait.
Header file for the Indices class.
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:775
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:697
#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.
Header file for the implementation of a upper unitriangular matrix adaptor.
#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
void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
#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