35 #ifndef _BLAZE_MATH_UPPERMATRIX_H_
36 #define _BLAZE_MATH_UPPERMATRIX_H_
77 class Rand< UpperMatrix<MT,SO,DF> >
83 inline const UpperMatrix<MT,SO,DF>
generate()
const;
84 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n )
const;
85 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
87 template<
typename Arg >
88 inline const UpperMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
90 template<
typename Arg >
91 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
93 template<
typename Arg >
94 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
95 const Arg&
min,
const Arg&
max )
const;
102 inline void randomize( UpperMatrix<MT,SO,DF>& matrix )
const;
103 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const;
105 template<
typename Arg >
106 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
108 template<
typename Arg >
109 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
size_t nonzeros,
110 const Arg&
min,
const Arg&
max )
const;
121 template<
typename Arg >
124 template<
typename Arg >
139 template<
typename MT
142 inline const UpperMatrix<MT,SO,DF> Rand< UpperMatrix<MT,SO,DF> >::generate()
const
146 UpperMatrix<MT,SO,DF> matrix;
161 template<
typename MT
164 inline const UpperMatrix<MT,SO,DF>
165 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n )
const
169 UpperMatrix<MT,SO,DF> matrix( n );
186 template<
typename MT
189 inline const UpperMatrix<MT,SO,DF>
190 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const
195 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) )
196 throw std::invalid_argument(
"Invalid number of non-zero elements" );
198 UpperMatrix<MT,SO,DF> matrix( n );
215 template<
typename MT
218 template<
typename Arg >
219 inline const UpperMatrix<MT,SO,DF>
220 Rand< UpperMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const
224 UpperMatrix<MT,SO,DF> matrix;
241 template<
typename MT
244 template<
typename Arg >
245 inline const UpperMatrix<MT,SO,DF>
246 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
250 UpperMatrix<MT,SO,DF> matrix( n );
269 template<
typename MT
272 template<
typename Arg >
273 inline const UpperMatrix<MT,SO,DF>
274 Rand< UpperMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
275 const Arg&
min,
const Arg&
max )
const
280 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) )
281 throw std::invalid_argument(
"Invalid number of non-zero elements" );
283 UpperMatrix<MT,SO,DF> matrix( n );
299 template<
typename MT
302 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix )
const
304 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
317 template<
typename MT
320 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
TrueType )
const
326 const size_t n( matrix.rows() );
328 for(
size_t i=0UL; i<n; ++i ) {
329 for(
size_t j=i; j<n; ++j ) {
330 matrix(i,j) = rand<ET>();
345 template<
typename MT
348 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
FalseType )
const
354 const size_t n( matrix.rows() );
356 if( n == 0UL )
return;
358 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.3*n*n ) ) );
361 matrix.reserve( nonzeros );
363 while( matrix.nonZeros() < nonzeros ) {
364 const size_t row( rand<size_t>( 0UL, n-1UL ) );
365 const size_t col( rand<size_t>(
row, n-1UL ) );
366 matrix(
row,col) = rand<ET>();
382 template<
typename MT
385 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const
391 const size_t n( matrix.rows() );
393 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) )
394 throw std::invalid_argument(
"Invalid number of non-zero elements" );
396 if( n == 0UL )
return;
399 matrix.reserve( nonzeros );
401 while( matrix.nonZeros() < nonzeros ) {
402 const size_t row( rand<size_t>( 0UL, n-1UL ) );
403 const size_t col( rand<size_t>(
row, n-1UL ) );
404 matrix(
row,col) = rand<ET>();
420 template<
typename MT
423 template<
typename Arg >
424 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
425 const Arg& min,
const Arg& max )
const
427 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
442 template<
typename MT
445 template<
typename Arg >
446 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
447 const Arg& min,
const Arg& max,
TrueType )
const
453 const size_t n( matrix.rows() );
455 for(
size_t i=0UL; i<n; ++i ) {
456 for(
size_t j=i; j<n; ++j ) {
457 matrix(i,j) = rand<ET>(
min,
max );
474 template<
typename MT
477 template<
typename Arg >
478 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
479 const Arg& min,
const Arg& max,
FalseType )
const
485 const size_t n( matrix.rows() );
487 if( n == 0UL )
return;
489 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.3*n*n ) ) );
492 matrix.reserve( nonzeros );
494 while( matrix.nonZeros() < nonzeros ) {
495 const size_t row( rand<size_t>( 0UL, n-1UL ) );
496 const size_t col( rand<size_t>(
row, n-1UL ) );
515 template<
typename MT
518 template<
typename Arg >
519 inline void Rand< UpperMatrix<MT,SO,DF> >
::randomize( UpperMatrix<MT,SO,DF>& matrix,
520 size_t nonzeros,
const Arg& min,
const Arg& max )
const
526 const size_t n( matrix.rows() );
528 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) )
529 throw std::invalid_argument(
"Invalid number of non-zero elements" );
531 if( n == 0UL )
return;
534 matrix.reserve( nonzeros );
536 while( matrix.nonZeros() < nonzeros ) {
537 const size_t row( rand<size_t>( 0UL, n-1UL ) );
538 const size_t col( rand<size_t>(
row, n-1UL ) );
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
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:79
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1043
Constraint on the data type.
Implementation of a random number generator.
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:262
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
Header file for the complete LowerMatrix implementation.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Header file for the IsDenseMatrix type trait.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:103
Header file for the implementation of a upper matrix adaptor.
#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:118
T generate() const
Generation of a random value in the range .
Definition: Random.h:222
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:79
boost::false_type FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
#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:79
Header file for the TrueType type/value trait base class.