35 #ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_
36 #define _BLAZE_MATH_COMPRESSEDMATRIX_H_
67 template<
typename Type
69 class Rand< CompressedMatrix<Type,SO> >
75 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n )
const;
76 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros )
const;
78 template<
typename Arg >
79 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const;
81 template<
typename Arg >
82 inline const CompressedMatrix<Type,SO>
generate(
size_t m,
size_t n,
size_t nonzeros,
83 const Arg&
min,
const Arg&
max )
const;
90 inline void randomize( CompressedMatrix<Type,SO>& matrix )
const;
91 inline void randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros )
const;
93 template<
typename Arg >
94 inline void randomize( CompressedMatrix<Type,SO>& matrix,
const Arg&
min,
const Arg&
max )
const;
96 template<
typename Arg >
97 inline void randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros,
98 const Arg&
min,
const Arg&
max )
const;
114 template<
typename Type
116 inline const CompressedMatrix<Type,SO>
117 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n )
const
119 CompressedMatrix<Type,SO> matrix( m, n );
138 template<
typename Type
140 inline const CompressedMatrix<Type,SO>
141 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros )
const
144 throw std::invalid_argument(
"Invalid number of non-zero elements" );
146 CompressedMatrix<Type,SO> matrix( m, n );
165 template<
typename Type
167 template<
typename Arg >
168 inline const CompressedMatrix<Type,SO>
169 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const
171 CompressedMatrix<Type,SO> matrix( m, n );
192 template<
typename Type
194 template<
typename Arg >
195 inline const CompressedMatrix<Type,SO>
196 Rand< CompressedMatrix<Type,SO> >::generate(
size_t m,
size_t n,
size_t nonzeros,
197 const Arg&
min,
const Arg&
max )
const
200 throw std::invalid_argument(
"Invalid number of non-zero elements" );
202 CompressedMatrix<Type,SO> matrix( m, n );
218 template<
typename Type
220 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix )
const
222 const size_t m( matrix.rows() );
223 const size_t n( matrix.columns() );
225 if( m == 0UL || n == 0UL )
return;
227 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
230 matrix.reserve( nonzeros );
232 while( matrix.nonZeros() < nonzeros ) {
233 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>();
249 template<
typename Type
251 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
size_t nonzeros )
const
253 const size_t m( matrix.rows() );
254 const size_t n( matrix.columns() );
257 throw std::invalid_argument(
"Invalid number of non-zero elements" );
259 if( m == 0UL || n == 0UL )
return;
262 matrix.reserve( nonzeros );
264 while( matrix.nonZeros() < nonzeros ) {
265 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>();
281 template<
typename Type
283 template<
typename Arg >
284 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
285 const Arg& min,
const Arg& max )
const
287 const size_t m( matrix.rows() );
288 const size_t n( matrix.columns() );
290 if( m == 0UL || n == 0UL )
return;
292 const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
295 matrix.reserve( nonzeros );
297 while( matrix.nonZeros() < nonzeros ) {
298 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>(
min,
max );
316 template<
typename Type
318 template<
typename Arg >
319 inline void Rand< CompressedMatrix<Type,SO> >
::randomize( CompressedMatrix<Type,SO>& matrix,
320 size_t nonzeros,
const Arg& min,
const Arg& max )
const
322 const size_t m( matrix.rows() );
323 const size_t n( matrix.columns() );
326 throw std::invalid_argument(
"Invalid number of non-zero elements" );
328 if( m == 0UL || n == 0UL )
return;
331 matrix.reserve( nonzeros );
333 while( matrix.nonZeros() < nonzeros ) {
334 matrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<Type>(
min,
max );
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
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:369
Implementation of a compressed MxN matrix.
Implementation of a random number generator.
Header file for the floating point precision of the Blaze library.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for all basic SparseMatrix functionality.
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:1602
CompressedMatrix< float, false > CMatMxNf
MxN single precision matrix.
Definition: CompressedMatrix.h:353
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:361