35 #ifndef _BLAZE_MATH_SPARSESUBVECTOR_H_
36 #define _BLAZE_MATH_SPARSESUBVECTOR_H_
70 class Rand< SparseSubvector<VT,AF,TF> >
79 template<
typename Arg >
82 template<
typename Arg >
83 inline void randomize( SparseSubvector<VT,AF,TF>&
subvector,
size_t nonzeros,
const Arg&
min,
const Arg&
max )
const;
101 inline void Rand< SparseSubvector<VT,AF,TF> >
::randomize( SparseSubvector<VT,AF,TF>&
subvector )
const
105 const size_t size( subvector.size() );
107 if(
size == 0UL )
return;
109 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*
size ) ) );
112 subvector.reserve( nonzeros );
114 while( subvector.nonZeros() < nonzeros ) {
115 subvector[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>();
131 template<
typename VT
134 inline void Rand< SparseSubvector<VT,AF,TF> >
::randomize( SparseSubvector<VT,AF,TF>& subvector,
size_t nonzeros )
const
138 const size_t size( subvector.size() );
140 if( nonzeros >
size )
141 throw std::invalid_argument(
"Invalid number of non-zero elements" );
143 if(
size == 0UL )
return;
146 subvector.reserve( nonzeros );
148 while( subvector.nonZeros() < nonzeros ) {
149 subvector[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>();
165 template<
typename VT
168 template<
typename Arg >
169 inline void Rand< SparseSubvector<VT,AF,TF> >
::randomize( SparseSubvector<VT,AF,TF>& subvector,
170 const Arg&
min,
const Arg&
max )
const
174 const size_t size( subvector.size() );
176 if(
size == 0UL )
return;
178 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*
size ) ) );
181 subvector.reserve( nonzeros );
183 while( subvector.nonZeros() < nonzeros ) {
184 subvector[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>( min, max );
202 template<
typename VT
205 template<
typename Arg >
206 inline void Rand< SparseSubvector<VT,AF,TF> >
::randomize( SparseSubvector<VT,AF,TF>& subvector,
207 size_t nonzeros,
const Arg& min,
const Arg& max )
const
211 const size_t size( subvector.size() );
213 if( nonzeros >
size )
214 throw std::invalid_argument(
"Invalid number of non-zero elements" );
216 if(
size == 0UL )
return;
219 subvector.reserve( nonzeros );
221 while( subvector.nonZeros() < nonzeros ) {
222 subvector[ rand<size_t>( 0UL,
size-1UL ) ] = rand<ElementType>( min, max );
Header file for all restructuring submatrix functions.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1043
Implementation of a random number generator.
Header file for all restructuring subvector functions.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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 SparseSubvector class template.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
SubvectorExprTrait< VT, unaligned >::Type subvector(Vector< VT, TF > &vector, size_t index, size_t size)
Creating a view on a specific subvector of the given vector.
Definition: Subvector.h:140
Header file for the DenseSubvector class template.
Header file for the SparseSubmatrix class template.