35 #ifndef _BLAZE_MATH_LOWERMATRIX_H_ 36 #define _BLAZE_MATH_LOWERMATRIX_H_ 82 class Rand< LowerMatrix<MT,SO,DF> >
88 inline const LowerMatrix<MT,SO,DF>
generate()
const;
89 inline const LowerMatrix<MT,SO,DF>
generate(
size_t n )
const;
90 inline const LowerMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
92 template<
typename Arg >
93 inline const LowerMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
95 template<
typename Arg >
96 inline const LowerMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
98 template<
typename Arg >
99 inline const LowerMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
100 const Arg&
min,
const Arg&
max )
const;
107 inline void randomize( LowerMatrix<MT,SO,DF>& matrix )
const;
108 inline void randomize( LowerMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const;
109 inline void randomize( LowerMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const;
111 template<
typename Arg >
112 inline void randomize( LowerMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
114 template<
typename Arg >
115 inline void randomize( LowerMatrix<MT,false,DF>& matrix,
size_t nonzeros,
116 const Arg&
min,
const Arg&
max )
const;
118 template<
typename Arg >
119 inline void randomize( LowerMatrix<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 LowerMatrix<MT,SO,DF> Rand< LowerMatrix<MT,SO,DF> >::generate()
const 156 LowerMatrix<MT,SO,DF> matrix;
171 template<
typename MT
174 inline const LowerMatrix<MT,SO,DF>
175 Rand< LowerMatrix<MT,SO,DF> >::generate(
size_t n )
const 179 LowerMatrix<MT,SO,DF> matrix( n );
196 template<
typename MT
199 inline const LowerMatrix<MT,SO,DF>
200 Rand< LowerMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const 205 if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
209 LowerMatrix<MT,SO,DF> matrix( n );
226 template<
typename MT
229 template<
typename Arg >
230 inline const LowerMatrix<MT,SO,DF>
231 Rand< LowerMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const 235 LowerMatrix<MT,SO,DF> matrix;
252 template<
typename MT
255 template<
typename Arg >
256 inline const LowerMatrix<MT,SO,DF>
257 Rand< LowerMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const 261 LowerMatrix<MT,SO,DF> matrix( n );
280 template<
typename MT
283 template<
typename Arg >
284 inline const LowerMatrix<MT,SO,DF>
285 Rand< LowerMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
286 const Arg&
min,
const Arg&
max )
const 291 if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
295 LowerMatrix<MT,SO,DF> matrix( n );
311 template<
typename MT
314 inline void Rand< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,SO,DF>& matrix )
const 316 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
329 template<
typename MT
332 inline void Rand< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,SO,DF>& matrix,
TrueType )
const 336 using ET = ElementType_t<MT>;
338 const size_t n( matrix.rows() );
340 for(
size_t i=0UL; i<n; ++i ) {
341 for(
size_t j=0UL; j<=i; ++j ) {
342 matrix(i,j) = rand<ET>();
357 template<
typename MT
360 inline void Rand< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<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< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const 392 using ET = ElementType_t<MT>;
394 const size_t n( matrix.rows() );
396 if( nonzeros > LowerMatrix<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] == index+1UL )
continue;
414 for(
size_t i=0UL; i<n; ++i ) {
415 const Indices indices( 0UL, i, 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< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const 442 using ET = ElementType_t<MT>;
444 const size_t n( matrix.rows() );
446 if( nonzeros > LowerMatrix<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] == n - index )
continue;
464 for(
size_t j=0UL; j<n; ++j ) {
465 const Indices indices( j, n-1UL, 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< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,SO,DF>& matrix,
490 const Arg&
min,
const Arg&
max )
const 507 template<
typename MT
510 template<
typename Arg >
511 inline void Rand< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,SO,DF>& matrix,
516 using ET = ElementType_t<MT>;
518 const size_t n( matrix.rows() );
520 for(
size_t i=0UL; i<n; ++i ) {
521 for(
size_t j=0UL; j<=i; ++j ) {
522 matrix(i,j) = rand<ET>(
min,
max );
539 template<
typename MT
542 template<
typename Arg >
543 inline void Rand< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,SO,DF>& matrix,
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< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,false,DF>& matrix,
576 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const 580 using ET = ElementType_t<MT>;
582 const size_t n( matrix.rows() );
584 if( nonzeros > LowerMatrix<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] == index+1UL )
continue;
602 for(
size_t i=0UL; i<n; ++i ) {
603 const Indices indices( 0UL, i, 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< LowerMatrix<MT,SO,DF> >
::randomize( LowerMatrix<MT,true,DF>& matrix,
630 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const 634 using ET = ElementType_t<MT>;
636 const size_t n( matrix.rows() );
638 if( nonzeros > LowerMatrix<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] == n - index )
continue;
656 for(
size_t j=0UL; j<n; ++j ) {
657 const Indices indices( j, n-1UL, 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( LowerMatrix<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_t<MT> >();
711 template<
typename MT
715 void makeSymmetric( LowerMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
717 using Type = ElementType_t<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( LowerMatrix<MT,SO,DF>& matrix )
745 using Type = UnderlyingBuiltin_t< ElementType_t<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( LowerMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
776 using Type = UnderlyingBuiltin_t< ElementType_t<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( LowerMatrix<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:1239
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
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
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 the implementation of a lower 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:617
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:539
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 complete UpperMatrix implementation.
#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.