35 #ifndef _BLAZE_MATH_DIAGONALMATRIX_H_
36 #define _BLAZE_MATH_DIAGONALMATRIX_H_
75 class Rand< DiagonalMatrix<MT,SO,DF> >
81 inline const DiagonalMatrix<MT,SO,DF>
generate()
const;
82 inline const DiagonalMatrix<MT,SO,DF>
generate(
size_t n )
const;
83 inline const DiagonalMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const;
85 template<
typename Arg >
86 inline const DiagonalMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const;
88 template<
typename Arg >
89 inline const DiagonalMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const;
91 template<
typename Arg >
92 inline const DiagonalMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros,
93 const Arg&
min,
const Arg&
max )
const;
100 inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix )
const;
101 inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const;
103 template<
typename Arg >
104 inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const;
106 template<
typename Arg >
107 inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix,
size_t nonzeros,
108 const Arg&
min,
const Arg&
max )
const;
119 template<
typename Arg >
122 template<
typename Arg >
137 template<
typename MT
140 inline const DiagonalMatrix<MT,SO,DF> Rand< DiagonalMatrix<MT,SO,DF> >::generate()
const
144 DiagonalMatrix<MT,SO,DF> matrix;
159 template<
typename MT
162 inline const DiagonalMatrix<MT,SO,DF>
163 Rand< DiagonalMatrix<MT,SO,DF> >::generate(
size_t n )
const
167 DiagonalMatrix<MT,SO,DF> matrix( n );
184 template<
typename MT
187 inline const DiagonalMatrix<MT,SO,DF>
188 Rand< DiagonalMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros )
const
194 throw std::invalid_argument(
"Invalid number of non-zero elements" );
196 DiagonalMatrix<MT,SO,DF> matrix( n );
213 template<
typename MT
216 template<
typename Arg >
217 inline const DiagonalMatrix<MT,SO,DF>
218 Rand< DiagonalMatrix<MT,SO,DF> >::generate(
const Arg&
min,
const Arg&
max )
const
222 DiagonalMatrix<MT,SO,DF> matrix;
239 template<
typename MT
242 template<
typename Arg >
243 inline const DiagonalMatrix<MT,SO,DF>
244 Rand< DiagonalMatrix<MT,SO,DF> >::generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
248 DiagonalMatrix<MT,SO,DF> matrix( n );
267 template<
typename MT
270 template<
typename Arg >
271 inline const DiagonalMatrix<MT,SO,DF>
272 Rand< DiagonalMatrix<MT,SO,DF> >::generate(
size_t n,
size_t nonzeros,
273 const Arg&
min,
const Arg&
max )
const
278 if( nonzeros > DiagonalMatrix<MT,SO,DF>::maxNonZeros( n ) )
279 throw std::invalid_argument(
"Invalid number of non-zero elements" );
281 DiagonalMatrix<MT,SO,DF> matrix( n );
297 template<
typename MT
300 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix )
const
302 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
315 template<
typename MT
318 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
TrueType )
const
324 const size_t n( matrix.rows() );
326 for(
size_t i=0UL; i<n; ++i ) {
327 matrix(i,i) = rand<ET>();
341 template<
typename MT
344 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
FalseType )
const
350 const size_t n( matrix.rows() );
352 if( n == 0UL )
return;
354 const size_t nonzeros( rand<size_t>( 1UL, n ) );
357 matrix.reserve( nonzeros );
359 while( matrix.nonZeros() < nonzeros ) {
360 const size_t i( rand<size_t>( 0UL, n-1UL ) );
361 matrix(i,i) = rand<ET>();
377 template<
typename MT
380 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
size_t nonzeros )
const
386 const size_t n( matrix.rows() );
389 throw std::invalid_argument(
"Invalid number of non-zero elements" );
391 if( n == 0UL )
return;
394 matrix.reserve( nonzeros );
396 while( matrix.nonZeros() < nonzeros ) {
397 const size_t i( rand<size_t>( 0UL, n-1UL ) );
398 matrix(i,i) = rand<ET>();
414 template<
typename MT
417 template<
typename Arg >
418 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
419 const Arg& min,
const Arg& max )
const
421 randomize( matrix, min, max,
typename IsDenseMatrix<MT>::Type() );
436 template<
typename MT
439 template<
typename Arg >
440 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
441 const Arg& min,
const Arg& max,
TrueType )
const
447 const size_t n( matrix.rows() );
449 for(
size_t i=0UL; i<n; ++i ) {
450 matrix(i,i) = rand<ET>(
min,
max );
466 template<
typename MT
469 template<
typename Arg >
470 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
471 const Arg& min,
const Arg& max,
FalseType )
const
477 const size_t n( matrix.rows() );
479 if( n == 0UL )
return;
481 const size_t nonzeros( rand<size_t>( 1UL, n ) );
484 matrix.reserve( nonzeros );
486 while( matrix.nonZeros() < nonzeros ) {
487 const size_t i( rand<size_t>( 0UL, n-1UL ) );
488 matrix(i,i) = rand<ET>(
min,
max );
506 template<
typename MT
509 template<
typename Arg >
510 inline void Rand< DiagonalMatrix<MT,SO,DF> >
::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
511 size_t nonzeros,
const Arg& min,
const Arg& max )
const
517 const size_t n( matrix.rows() );
520 throw std::invalid_argument(
"Invalid number of non-zero elements" );
522 if( n == 0UL )
return;
525 matrix.reserve( nonzeros );
527 while( matrix.nonZeros() < nonzeros ) {
528 const size_t i( rand<size_t>( 0UL, n-1UL ) );
529 matrix(i,i) = rand<ET>(
min,
max );
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
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Header file for the IsDenseMatrix type trait.
#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
Header file for the implementation of a diagonal matrix adaptor.
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.