35 #ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_ 36 #define _BLAZE_MATH_COMPRESSEDMATRIX_H_ 70 template<
typename Type
72 class Rand< CompressedMatrix<Type,SO> >
78 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n )
const;
79 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros )
const;
81 template<
typename Arg >
82 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const;
84 template<
typename Arg >
85 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros,
86 const Arg&
min,
const Arg&
max )
const;
93 inline void randomize( CompressedMatrix<Type,SO>& matrix )
const;
94 inline void randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros )
const;
95 inline void randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros )
const;
97 template<
typename Arg >
98 inline void randomize( CompressedMatrix<Type,SO>& matrix,
const Arg&
min,
const Arg&
max )
const;
100 template<
typename Arg >
101 inline void randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros,
102 const Arg&
min,
const Arg&
max )
const;
103 template<
typename Arg >
104 inline void randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros,
105 const Arg&
min,
const Arg&
max )
const;
121 template<
typename Type
123 inline const CompressedMatrix<Type,SO>
124 Rand< CompressedMatrix<Type,SO> >
::generate(
size_t m,
size_t n )
const 126 CompressedMatrix<Type,SO> matrix( m, n );
145 template<
typename Type
147 inline const CompressedMatrix<Type,SO>
148 Rand< CompressedMatrix<Type,SO> >
::generate(
size_t m,
size_t n,
size_t nonzeros )
const 150 if( nonzeros > m*n ) {
154 CompressedMatrix<Type,SO> matrix( m, n );
173 template<
typename Type
175 template<
typename Arg >
176 inline const CompressedMatrix<Type,SO>
177 Rand< CompressedMatrix<Type,SO> >
::generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const 179 CompressedMatrix<Type,SO> matrix( m, n );
200 template<
typename Type
202 template<
typename Arg >
203 inline const CompressedMatrix<Type,SO>
204 Rand< CompressedMatrix<Type,SO> >
::generate(
size_t m,
size_t n,
size_t nonzeros,
205 const Arg&
min,
const Arg&
max )
const 207 if( nonzeros > m*n ) {
211 CompressedMatrix<Type,SO> matrix( m, n );
227 template<
typename Type
229 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix )
const 231 const size_t m( matrix.rows() );
232 const size_t n( matrix.columns() );
234 if( m == 0UL || n == 0UL )
return;
236 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*m*n ) ) );
253 template<
typename Type
255 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros )
const 257 const size_t m( matrix.rows() );
258 const size_t n( matrix.columns() );
260 if( nonzeros > m*n ) {
264 if( m == 0UL || n == 0UL )
return;
267 matrix.reserve( nonzeros );
269 std::vector<size_t> dist( m );
271 for(
size_t nz=0UL; nz<nonzeros; ) {
272 const size_t index = rand<size_t>( 0UL, m-1UL );
273 if( dist[index] == n )
continue;
278 for(
size_t i=0UL; i<m; ++i ) {
279 const Indices indices( 0UL, n-1UL, dist[i] );
280 for(
size_t j : indices ) {
281 matrix.append( i, j, rand<Type>() );
283 matrix.finalize( i );
299 template<
typename Type
301 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros )
const 303 const size_t m( matrix.rows() );
304 const size_t n( matrix.columns() );
306 if( nonzeros > m*n ) {
310 if( m == 0UL || n == 0UL )
return;
313 matrix.reserve( nonzeros );
315 std::vector<size_t> dist( n );
317 for(
size_t nz=0UL; nz<nonzeros; ) {
318 const size_t index = rand<size_t>( 0UL, n-1UL );
319 if( dist[index] == m )
continue;
324 for(
size_t j=0UL; j<n; ++j ) {
325 const Indices indices( 0UL, m-1UL, dist[j] );
326 for(
size_t i : indices ) {
327 matrix.append( i, j, rand<Type>() );
329 matrix.finalize( j );
345 template<
typename Type
347 template<
typename Arg >
348 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
349 const Arg& min,
const Arg& max )
const 351 const size_t m( matrix.rows() );
352 const size_t n( matrix.columns() );
354 if( m == 0UL || n == 0UL )
return;
356 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*m*n ) ) );
375 template<
typename Type
377 template<
typename Arg >
378 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,false>& matrix,
379 size_t nonzeros,
const Arg& min,
const Arg& max )
const 381 const size_t m( matrix.rows() );
382 const size_t n( matrix.columns() );
384 if( nonzeros > m*n ) {
388 if( m == 0UL || n == 0UL )
return;
391 matrix.reserve( nonzeros );
393 std::vector<size_t> dist( m );
395 for(
size_t nz=0UL; nz<nonzeros; ) {
396 const size_t index = rand<size_t>( 0UL, m-1UL );
397 if( dist[index] == n )
continue;
402 for(
size_t i=0UL; i<m; ++i ) {
403 const Indices indices( 0UL, n-1UL, dist[i] );
404 for(
size_t j : indices ) {
405 matrix.append( i, j, rand<Type>( min, max ) );
407 matrix.finalize( i );
425 template<
typename Type
427 template<
typename Arg >
428 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,true>& matrix,
429 size_t nonzeros,
const Arg& min,
const Arg& max )
const 431 const size_t m( matrix.rows() );
432 const size_t n( matrix.columns() );
434 if( nonzeros > m*n ) {
438 if( m == 0UL || n == 0UL )
return;
441 matrix.reserve( nonzeros );
443 std::vector<size_t> dist( n );
445 for(
size_t nz=0UL; nz<nonzeros; ) {
446 const size_t index = rand<size_t>( 0UL, n-1UL );
447 if( dist[index] == m )
continue;
452 for(
size_t j=0UL; j<n; ++j ) {
453 const Indices indices( 0UL, m-1UL, dist[j] );
454 for(
size_t i : indices ) {
455 matrix.append( i, j, rand<Type>( min, max ) );
457 matrix.finalize( j );
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
decltype(auto) ceil(const DenseMatrix< MT, SO > &dm)
Applies the ceil() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1234
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1762
Implementation of a compressed MxN matrix.
Implementation of a random number generator.
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1809
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:290
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for all basic SparseMatrix functionality.
Header file for the exception macros of the math module.
Header file for the complete CompressedVector implementation.
Header file for run time assertion macros.
Header file for the Indices class.
T generate() const
Generation of a random value in the range .
Definition: Random.h:250
Header file for the complete IdentityMatrix implementation.