35 #ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_
36 #define _BLAZE_MATH_COMPRESSEDMATRIX_H_
65 template<
typename Type
67 class Rand< CompressedMatrix<Type,SO> >
73 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n )
const;
74 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros )
const;
76 template<
typename Arg >
77 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
const Arg& min,
const Arg& max )
const;
79 template<
typename Arg >
80 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros,
81 const Arg& min,
const Arg& max )
const;
88 inline void randomize( CompressedMatrix<Type,SO>& matrix )
const;
89 inline void randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros )
const;
91 template<
typename Arg >
92 inline void randomize( CompressedMatrix<Type,SO>& matrix,
const Arg& min,
const Arg& max )
const;
94 template<
typename Arg >
95 inline void randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros,
96 const Arg& min,
const Arg& max )
const;
112 template<
typename Type
114 inline const CompressedMatrix<Type,SO>
115 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n )
const
117 CompressedMatrix<Type,SO> matrix( m, n );
136 template<
typename Type
138 inline const CompressedMatrix<Type,SO>
139 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros )
const
142 throw std::invalid_argument(
"Invalid number of non-zero elements" );
144 CompressedMatrix<Type,SO> matrix( m, n );
163 template<
typename Type
165 template<
typename Arg >
166 inline const CompressedMatrix<Type,SO>
167 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
const Arg& min,
const Arg& max )
const
169 CompressedMatrix<Type,SO> matrix( m, n );
190 template<
typename Type
192 template<
typename Arg >
193 inline const CompressedMatrix<Type,SO>
194 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros,
195 const Arg& min,
const Arg& max )
const
198 throw std::invalid_argument(
"Invalid number of non-zero elements" );
200 CompressedMatrix<Type,SO> matrix( m, n );
216 template<
typename Type
218 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix )
const
220 const size_t m( matrix.rows() );
221 const size_t n( matrix.columns() );
223 if( m == 0UL || n == 0UL )
return;
225 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
228 matrix.reserve( nonzeros );
230 while( matrix.nonZeros() < nonzeros ) {
231 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>();
247 template<
typename Type
249 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros )
const
251 const size_t m( matrix.rows() );
252 const size_t n( matrix.columns() );
255 throw std::invalid_argument(
"Invalid number of non-zero elements" );
257 if( m == 0UL || n == 0UL )
return;
260 matrix.reserve( nonzeros );
262 while( matrix.nonZeros() < nonzeros ) {
263 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>();
279 template<
typename Type
281 template<
typename Arg >
282 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
283 const Arg& min,
const Arg& max )
const
285 const size_t m( matrix.rows() );
286 const size_t n( matrix.columns() );
288 if( m == 0UL || n == 0UL )
return;
290 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
293 matrix.reserve( nonzeros );
295 while( matrix.nonZeros() < nonzeros ) {
296 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>( min, max );
314 template<
typename Type
316 template<
typename Arg >
317 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
318 size_t nonzeros,
const Arg& min,
const Arg& max )
const
320 const size_t m( matrix.rows() );
321 const size_t n( matrix.columns() );
324 throw std::invalid_argument(
"Invalid number of non-zero elements" );
326 if( m == 0UL || n == 0UL )
return;
329 matrix.reserve( nonzeros );
331 while( matrix.nonZeros() < nonzeros ) {
332 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>( min, max );
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
void randomize(T &value)
Randomization of a given variable.
Definition: Random.h:1043
CompressedMatrix< real, false > CMatMxN
MxN matrix with system-specific precision.
Definition: CompressedMatrix.h:367
Implementation of a compressed MxN matrix.
Implementation of a random number generator.
Header file for the floating point precision of the Blaze library.
Header file for the SparseMatrix CRTP base class.
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:262
CompressedMatrix< float, false > CMatMxNf
MxN single precision matrix.
Definition: CompressedMatrix.h:351
Header file for the complete CompressedVector implementation.
T generate() const
Generation of a random value in the range .
Definition: Random.h:222
CompressedMatrix< double, false > CMatMxNd
MxN double precision matrix.
Definition: CompressedMatrix.h:359