35 #ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_ 36 #define _BLAZE_MATH_COMPRESSEDMATRIX_H_ 71 template<
typename Type
73 class Rand< CompressedMatrix<Type,SO> >
79 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n )
const;
80 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros )
const;
82 template<
typename Arg >
83 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const;
85 template<
typename Arg >
86 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros,
87 const Arg&
min,
const Arg&
max )
const;
94 inline void randomize( CompressedMatrix<Type,SO>& matrix )
const;
95 inline void randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros )
const;
96 inline void randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros )
const;
98 template<
typename Arg >
99 inline void randomize( CompressedMatrix<Type,SO>& matrix,
const Arg&
min,
const Arg&
max )
const;
101 template<
typename Arg >
102 inline void randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros,
103 const Arg&
min,
const Arg&
max )
const;
104 template<
typename Arg >
105 inline void randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros,
106 const Arg&
min,
const Arg&
max )
const;
122 template<
typename Type
124 inline const CompressedMatrix<Type,SO>
125 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n )
const 127 CompressedMatrix<Type,SO> matrix( m, n );
146 template<
typename Type
148 inline const CompressedMatrix<Type,SO>
149 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros )
const 151 if( nonzeros > m*n ) {
155 CompressedMatrix<Type,SO> matrix( m, n );
174 template<
typename Type
176 template<
typename Arg >
177 inline const CompressedMatrix<Type,SO>
178 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const 180 CompressedMatrix<Type,SO> matrix( m, n );
201 template<
typename Type
203 template<
typename Arg >
204 inline const CompressedMatrix<Type,SO>
205 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros,
206 const Arg&
min,
const Arg&
max )
const 208 if( nonzeros > m*n ) {
212 CompressedMatrix<Type,SO> matrix( m, n );
228 template<
typename Type
230 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix )
const 232 const size_t m( matrix.rows() );
233 const size_t n( matrix.columns() );
235 if( m == 0UL || n == 0UL )
return;
237 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*m*n ) ) );
254 template<
typename Type
256 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros )
const 258 const size_t m( matrix.rows() );
259 const size_t n( matrix.columns() );
261 if( nonzeros > m*n ) {
265 if( m == 0UL || n == 0UL )
return;
268 matrix.reserve( nonzeros );
270 std::vector<size_t> dist( m );
272 for(
size_t nz=0UL; nz<nonzeros; ) {
273 const size_t index = rand<size_t>( 0UL, m-1UL );
274 if( dist[index] == n )
continue;
279 for(
size_t i=0UL; i<m; ++i ) {
280 const Indices indices( 0UL, n-1UL, dist[i] );
281 for(
size_t j : indices ) {
282 matrix.append( i, j, rand<Type>() );
284 matrix.finalize( i );
300 template<
typename Type
302 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros )
const 304 const size_t m( matrix.rows() );
305 const size_t n( matrix.columns() );
307 if( nonzeros > m*n ) {
311 if( m == 0UL || n == 0UL )
return;
314 matrix.reserve( nonzeros );
316 std::vector<size_t> dist( n );
318 for(
size_t nz=0UL; nz<nonzeros; ) {
319 const size_t index = rand<size_t>( 0UL, n-1UL );
320 if( dist[index] == m )
continue;
325 for(
size_t j=0UL; j<n; ++j ) {
326 const Indices indices( 0UL, m-1UL, dist[j] );
327 for(
size_t i : indices ) {
328 matrix.append( i, j, rand<Type>() );
330 matrix.finalize( j );
346 template<
typename Type
348 template<
typename Arg >
349 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
350 const Arg&
min,
const Arg&
max )
const 352 const size_t m( matrix.rows() );
353 const size_t n( matrix.columns() );
355 if( m == 0UL || n == 0UL )
return;
357 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*m*n ) ) );
376 template<
typename Type
378 template<
typename Arg >
379 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,false>& matrix,
380 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const 382 const size_t m( matrix.rows() );
383 const size_t n( matrix.columns() );
385 if( nonzeros > m*n ) {
389 if( m == 0UL || n == 0UL )
return;
392 matrix.reserve( nonzeros );
394 std::vector<size_t> dist( m );
396 for(
size_t nz=0UL; nz<nonzeros; ) {
397 const size_t index = rand<size_t>( 0UL, m-1UL );
398 if( dist[index] == n )
continue;
403 for(
size_t i=0UL; i<m; ++i ) {
404 const Indices indices( 0UL, n-1UL, dist[i] );
405 for(
size_t j : indices ) {
406 matrix.append( i, j, rand<Type>(
min,
max ) );
408 matrix.finalize( i );
426 template<
typename Type
428 template<
typename Arg >
429 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,true>& matrix,
430 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const 432 const size_t m( matrix.rows() );
433 const size_t n( matrix.columns() );
435 if( nonzeros > m*n ) {
439 if( m == 0UL || n == 0UL )
return;
442 matrix.reserve( nonzeros );
444 std::vector<size_t> dist( n );
446 for(
size_t nz=0UL; nz<nonzeros; ) {
447 const size_t index = rand<size_t>( 0UL, n-1UL );
448 if( dist[index] == m )
continue;
453 for(
size_t j=0UL; j<n; ++j ) {
454 const Indices indices( 0UL, m-1UL, dist[j] );
455 for(
size_t i : indices ) {
456 matrix.append( i, j, rand<Type>(
min,
max ) );
458 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:1239
void randomize(T &&value)
Randomization of a given variable.
Definition: Random.h:929
Implementation of a compressed MxN matrix.
Implementation of a random number generator.
void randomize(T &value) const
Randomization of the given variable with a new value in the range .
Definition: Random.h:292
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for all basic SparseMatrix functionality.
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
Header file for the exception macros of the math module.
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1179
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:252
Header file for the complete IdentityMatrix implementation.
Header file for the complete ZeroMatrix implementation.