35 #ifndef _BLAZE_MATH_SPARSECOLUMN_H_
36 #define _BLAZE_MATH_SPARSECOLUMN_H_
68 class Rand< SparseColumn<MT,SO> >
75 inline void randomize( SparseColumn<MT,SO>&
column,
size_t nonzeros )
const;
77 template<
typename Arg >
80 template<
typename Arg >
81 inline void randomize( SparseColumn<MT,SO>&
column,
size_t nonzeros,
const Arg&
min,
const Arg&
max )
const;
98 inline void Rand< SparseColumn<MT,SO> >
::randomize( SparseColumn<MT,SO>&
column )
const
102 const size_t size( column.size() );
104 if(
size == 0UL )
return;
106 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*
size ) ) );
109 column.reserve( nonzeros );
111 while( column.nonZeros() < nonzeros ) {
112 column[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>();
128 template<
typename MT
130 inline void Rand< SparseColumn<MT,SO> >
::randomize( SparseColumn<MT,SO>& column,
size_t nonzeros )
const
134 const size_t size( column.size() );
136 if( nonzeros >
size )
137 throw std::invalid_argument(
"Invalid number of non-zero elements" );
139 if(
size == 0UL )
return;
142 column.reserve( nonzeros );
144 while( column.nonZeros() < nonzeros ) {
145 column[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>();
161 template<
typename MT
163 template<
typename Arg >
164 inline void Rand< SparseColumn<MT,SO> >
::randomize( SparseColumn<MT,SO>& column,
165 const Arg&
min,
const Arg&
max )
const
169 const size_t size( column.size() );
171 if(
size == 0UL )
return;
173 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*
size ) ) );
176 column.reserve( nonzeros );
178 while( column.nonZeros() < nonzeros ) {
179 column[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>( min, max );
197 template<
typename MT
199 template<
typename Arg >
200 inline void Rand< SparseColumn<MT,SO> >
::randomize( SparseColumn<MT,SO>& column,
size_t nonzeros,
201 const Arg& min,
const Arg& max )
const
205 const size_t size( column.size() );
207 if( nonzeros >
size )
208 throw std::invalid_argument(
"Invalid number of non-zero elements" );
210 if(
size == 0UL )
return;
213 column.reserve( nonzeros );
215 while( column.nonZeros() < nonzeros ) {
216 column[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>( min, max );
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:994
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1043
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:103
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
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:947
Header file for the SparseColumn class template.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Header file for all restructuring column functions.
Header file for the SparseRow class template.
Header file for all restructuring row functions.