35#ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_
36#define _BLAZE_MATH_COMPRESSEDMATRIX_H_
71template<
typename Type
74class Rand< CompressedMatrix<Type,SO,Tag> >
84 inline const CompressedMatrix<Type,SO,Tag>
generate(
size_t m,
size_t n )
const
86 CompressedMatrix<Type,SO,Tag> matrix( m, n );
102 inline const CompressedMatrix<Type,SO,Tag>
103 generate(
size_t m,
size_t n,
size_t nonzeros )
const
105 if( nonzeros > m*n ) {
109 CompressedMatrix<Type,SO,Tag> matrix( m, n );
125 template<
typename Arg >
126 inline const CompressedMatrix<Type,SO,Tag>
127 generate(
size_t m,
size_t n,
const Arg&
min,
const Arg&
max )
const
129 CompressedMatrix<Type,SO,Tag> matrix( m, n );
147 template<
typename Arg >
148 inline const CompressedMatrix<Type,SO,Tag>
149 generate(
size_t m,
size_t n,
size_t nonzeros,
150 const Arg&
min,
const Arg&
max )
const
152 if( nonzeros > m*n ) {
156 CompressedMatrix<Type,SO,Tag> matrix( m, n );
169 inline void randomize( CompressedMatrix<Type,SO,Tag>& matrix )
const
171 const size_t m( matrix.rows() );
172 const size_t n( matrix.columns() );
174 if( m == 0UL || n == 0UL )
return;
176 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*m*n ) ) );
190 inline void randomize( CompressedMatrix<Type,false,Tag>& matrix,
size_t nonzeros )
const
192 const size_t m( matrix.rows() );
193 const size_t n( matrix.columns() );
195 if( nonzeros > m*n ) {
199 if( m == 0UL || n == 0UL )
return;
202 matrix.reserve( nonzeros );
204 std::vector<size_t> dist( m );
206 for(
size_t nz=0UL; nz<nonzeros; ) {
207 const size_t index = rand<size_t>( 0UL, m-1UL );
208 if( dist[index] == n )
continue;
213 for(
size_t i=0UL; i<m; ++i ) {
214 const Indices<size_t> indices( 0UL, n-1UL, dist[i] );
215 for(
size_t j : indices ) {
216 matrix.append( i, j, rand<Type>() );
218 matrix.finalize( i );
231 inline void randomize( CompressedMatrix<Type,true,Tag>& matrix,
size_t nonzeros )
const
233 const size_t m( matrix.rows() );
234 const size_t n( matrix.columns() );
236 if( nonzeros > m*n ) {
240 if( m == 0UL || n == 0UL )
return;
243 matrix.reserve( nonzeros );
245 std::vector<size_t> dist( n );
247 for(
size_t nz=0UL; nz<nonzeros; ) {
248 const size_t index = rand<size_t>( 0UL, n-1UL );
249 if( dist[index] == m )
continue;
254 for(
size_t j=0UL; j<n; ++j ) {
255 const Indices<size_t> indices( 0UL, m-1UL, dist[j] );
256 for(
size_t i : indices ) {
257 matrix.append( i, j, rand<Type>() );
259 matrix.finalize( j );
272 template<
typename Arg >
273 inline void randomize( CompressedMatrix<Type,SO,Tag>& matrix,
274 const Arg&
min,
const Arg&
max )
const
276 const size_t m( matrix.rows() );
277 const size_t n( matrix.columns() );
279 if( m == 0UL || n == 0UL )
return;
281 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.5*m*n ) ) );
297 template<
typename Arg >
298 inline void randomize( CompressedMatrix<Type,false,Tag>& matrix,
299 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const
301 const size_t m( matrix.rows() );
302 const size_t n( matrix.columns() );
304 if( nonzeros > m*n ) {
308 if( m == 0UL || n == 0UL )
return;
311 matrix.reserve( nonzeros );
313 std::vector<size_t> dist( m );
315 for(
size_t nz=0UL; nz<nonzeros; ) {
316 const size_t index = rand<size_t>( 0UL, m-1UL );
317 if( dist[index] == n )
continue;
322 for(
size_t i=0UL; i<m; ++i ) {
323 const Indices<size_t> indices( 0UL, n-1UL, dist[i] );
324 for(
size_t j : indices ) {
325 matrix.append( i, j, rand<Type>(
min,
max ) );
327 matrix.finalize( i );
342 template<
typename Arg >
343 inline void randomize( CompressedMatrix<Type,true,Tag>& matrix,
344 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const
346 const size_t m( matrix.rows() );
347 const size_t n( matrix.columns() );
349 if( nonzeros > m*n ) {
353 if( m == 0UL || n == 0UL )
return;
356 matrix.reserve( nonzeros );
358 std::vector<size_t> dist( n );
360 for(
size_t nz=0UL; nz<nonzeros; ) {
361 const size_t index = rand<size_t>( 0UL, n-1UL );
362 if( dist[index] == m )
continue;
367 for(
size_t j=0UL; j<n; ++j ) {
368 const Indices<size_t> indices( 0UL, m-1UL, dist[j] );
369 for(
size_t i : indices ) {
370 matrix.append( i, j, rand<Type>(
min,
max ) );
372 matrix.finalize( j );
Header file for run time assertion macros.
Header file for the complete CompressedVector implementation.
Header file for the complete IdentityMatrix implementation.
Header file for the Indices class.
Header file for all basic SparseMatrix functionality.
Header file for the complete ZeroMatrix implementation.
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:1339
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:1375
decltype(auto) ceil(const DenseMatrix< MT, SO > &dm)
Applies the ceil() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1380
decltype(auto) generate(size_t m, size_t n, OP op)
Generates a new dense matrix filled via the given custom binary operation.
Definition: DMatGenExpr.h:675
void randomize(T &&value)
Randomization of a given variable.
Definition: Random.h:626
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
Header file for the exception macros of the math module.
Implementation of a compressed MxN matrix.
Implementation of a random number generator.