22 #ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_
23 #define _BLAZE_MATH_COMPRESSEDMATRIX_H_
52 template<
typename Type
54 class Rand< CompressedMatrix<Type,SO> >
60 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n )
const;
61 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros )
const;
63 template<
typename Arg >
64 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const;
66 template<
typename Arg >
67 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros,
68 const Arg&
min,
const Arg&
max )
const;
75 inline void randomize( CompressedMatrix<Type,SO>& matrix )
const;
76 inline void randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros )
const;
78 template<
typename Arg >
79 inline void randomize( CompressedMatrix<Type,SO>& matrix,
const Arg&
min,
const Arg&
max )
const;
81 template<
typename Arg >
82 inline void randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros,
83 const Arg&
min,
const Arg&
max )
const;
99 template<
typename Type
101 inline const CompressedMatrix<Type,SO>
102 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n )
const
104 CompressedMatrix<Type,SO> matrix( m, n );
123 template<
typename Type
125 inline const CompressedMatrix<Type,SO>
126 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros )
const
129 throw std::invalid_argument(
"Invalid number of non-zero elements" );
131 CompressedMatrix<Type,SO> matrix( m, n );
150 template<
typename Type
152 template<
typename Arg >
153 inline const CompressedMatrix<Type,SO>
154 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const
156 CompressedMatrix<Type,SO> matrix( m, n );
177 template<
typename Type
179 template<
typename Arg >
180 inline const CompressedMatrix<Type,SO>
181 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros,
182 const Arg&
min,
const Arg&
max )
const
185 throw std::invalid_argument(
"Invalid number of non-zero elements" );
187 CompressedMatrix<Type,SO> matrix( m, n );
203 template<
typename Type
205 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix )
const
207 const size_t m( matrix.rows() );
208 const size_t n( matrix.columns() );
210 if( m == 0UL || n == 0UL )
return;
212 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
215 matrix.reserve( nonzeros );
217 while( matrix.nonZeros() < nonzeros ) {
218 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>();
234 template<
typename Type
236 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros )
const
238 const size_t m( matrix.rows() );
239 const size_t n( matrix.columns() );
242 throw std::invalid_argument(
"Invalid number of non-zero elements" );
244 if( m == 0UL || n == 0UL )
return;
247 matrix.reserve( nonzeros );
249 while( matrix.nonZeros() < nonzeros ) {
250 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>();
266 template<
typename Type
268 template<
typename Arg >
269 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
270 const Arg& min,
const Arg& max )
const
272 const size_t m( matrix.rows() );
273 const size_t n( matrix.columns() );
275 if( m == 0UL || n == 0UL )
return;
277 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
280 matrix.reserve( nonzeros );
282 while( matrix.nonZeros() < nonzeros ) {
283 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>(
min,
max );
301 template<
typename Type
303 template<
typename Arg >
304 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
305 size_t nonzeros,
const Arg& min,
const Arg& max )
const
307 const size_t m( matrix.rows() );
308 const size_t n( matrix.columns() );
311 throw std::invalid_argument(
"Invalid number of non-zero elements" );
313 if( m == 0UL || n == 0UL )
return;
316 matrix.reserve( nonzeros );
318 while( matrix.nonZeros() < nonzeros ) {
319 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>(
min,
max );