35 #ifndef _BLAZE_MATH_SPARSESUBMATRIX_H_
36 #define _BLAZE_MATH_SPARSESUBMATRIX_H_
70 class Rand< SparseSubmatrix<MT,AF,SO> >
79 template<
typename Arg >
82 template<
typename Arg >
84 const Arg&
min,
const Arg&
max )
const;
102 inline void Rand< SparseSubmatrix<MT,AF,SO> >
::randomize( SparseSubmatrix<MT,AF,SO>&
submatrix )
const
106 const size_t m( submatrix.rows() );
107 const size_t n( submatrix.columns() );
109 if( m == 0UL || n == 0UL )
return;
111 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
114 submatrix.reserve( nonzeros );
116 while( submatrix.nonZeros() < nonzeros ) {
117 submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>();
133 template<
typename MT
136 inline void Rand< SparseSubmatrix<MT,AF,SO> >
::randomize( SparseSubmatrix<MT,AF,SO>& submatrix,
size_t nonzeros )
const
140 const size_t m( submatrix.rows() );
141 const size_t n( submatrix.columns() );
144 throw std::invalid_argument(
"Invalid number of non-zero elements" );
146 if( m == 0UL || n == 0UL )
return;
149 submatrix.reserve( nonzeros );
151 while( submatrix.nonZeros() < nonzeros ) {
152 submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>();
168 template<
typename MT
171 template<
typename Arg >
172 inline void Rand< SparseSubmatrix<MT,AF,SO> >
::randomize( SparseSubmatrix<MT,AF,SO>& submatrix,
173 const Arg&
min,
const Arg&
max )
const
177 const size_t m( submatrix.rows() );
178 const size_t n( submatrix.columns() );
180 if( m == 0UL || n == 0UL )
return;
182 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
185 submatrix.reserve( nonzeros );
187 while( submatrix.nonZeros() < nonzeros ) {
188 submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>(
min,
max );
206 template<
typename MT
209 template<
typename Arg >
210 inline void Rand< SparseSubmatrix<MT,AF,SO> >
::randomize( SparseSubmatrix<MT,AF,SO>& submatrix,
211 size_t nonzeros,
const Arg& min,
const Arg& max )
const
215 const size_t m( submatrix.rows() );
216 const size_t n( submatrix.columns() );
219 throw std::invalid_argument(
"Invalid number of non-zero elements" );
221 if( m == 0UL || n == 0UL )
return;
224 submatrix.reserve( nonzeros );
226 while( submatrix.nonZeros() < nonzeros ) {
227 submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-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:994
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.
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 SparseSubvector class template.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Header file for the DenseSubvector class template.
SubmatrixExprTrait< MT, unaligned >::Type submatrix(Matrix< MT, SO > &matrix, size_t row, size_t column, size_t m, size_t n)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:137
Header file for the SparseSubmatrix class template.