35 #ifndef _BLAZE_MATH_SPARSEROW_H_
36 #define _BLAZE_MATH_SPARSEROW_H_
68 class Rand< SparseRow<MT,SO> >
75 inline void randomize( SparseRow<MT,SO>&
row,
size_t nonzeros )
const;
77 template<
typename Arg >
78 inline void randomize( SparseRow<MT,SO>&
row,
const Arg& min,
const Arg& max )
const;
80 template<
typename Arg >
81 inline void randomize( SparseRow<MT,SO>&
row,
size_t nonzeros,
const Arg& min,
const Arg& max )
const;
98 inline void Rand< SparseRow<MT,SO> >
::randomize( SparseRow<MT,SO>&
row )
const
102 const size_t size( row.size() );
104 if( size == 0UL )
return;
106 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
109 row.reserve( nonzeros );
111 while( row.nonZeros() < nonzeros ) {
112 row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
128 template<
typename MT
130 inline void Rand< SparseRow<MT,SO> >
::randomize( SparseRow<MT,SO>& row,
size_t nonzeros )
const
134 const size_t size( row.size() );
136 if( nonzeros > size )
137 throw std::invalid_argument(
"Invalid number of non-zero elements" );
139 if( size == 0UL )
return;
142 row.reserve( nonzeros );
144 while( row.nonZeros() < nonzeros ) {
145 row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
161 template<
typename MT
163 template<
typename Arg >
164 inline void Rand< SparseRow<MT,SO> >
::randomize( SparseRow<MT,SO>& row,
165 const Arg& min,
const Arg& max )
const
169 const size_t size( row.size() );
171 if( size == 0UL )
return;
173 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
176 row.reserve( nonzeros );
178 while( row.nonZeros() < nonzeros ) {
179 row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
197 template<
typename MT
199 template<
typename Arg >
200 inline void Rand< SparseRow<MT,SO> >
::randomize( SparseRow<MT,SO>& row,
size_t nonzeros,
201 const Arg& min,
const Arg& max )
const
205 const size_t size( row.size() );
207 if( nonzeros > size )
208 throw std::invalid_argument(
"Invalid number of non-zero elements" );
210 if( size == 0UL )
return;
213 row.reserve( nonzeros );
215 while( row.nonZeros() < nonzeros ) {
216 row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1043
Implementation of a random number generator.
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:262
Header file for the SparseColumn class template.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
Header file for all restructuring column functions.
Header file for the SparseRow class template.
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 all restructuring row functions.