35#ifndef _BLAZE_MATH_UPPERMATRIX_H_
36#define _BLAZE_MATH_UPPERMATRIX_H_
82class Rand< UpperMatrix<MT,SO,DF> >
90 inline const UpperMatrix<MT,SO,DF>
generate()
const
94 UpperMatrix<MT,SO,DF> matrix;
106 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n )
const
110 UpperMatrix<MT,SO,DF> matrix( n );
124 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
size_t nonzeros )
const
129 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
133 UpperMatrix<MT,SO,DF> matrix( n );
147 template<
typename Arg >
148 inline const UpperMatrix<MT,SO,DF>
generate(
const Arg&
min,
const Arg&
max )
const
152 UpperMatrix<MT,SO,DF> matrix;
166 template<
typename Arg >
167 inline const UpperMatrix<MT,SO,DF>
generate(
size_t n,
const Arg&
min,
const Arg&
max )
const
171 UpperMatrix<MT,SO,DF> matrix( n );
187 template<
typename Arg >
188 inline const UpperMatrix<MT,SO,DF>
189 generate(
size_t n,
size_t nonzeros,
const Arg&
min,
const Arg&
max )
const
194 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
198 UpperMatrix<MT,SO,DF> matrix( n );
211 inline void randomize( UpperMatrix<MT,SO,DF>& matrix )
const
213 randomize( matrix,
typename IsDenseMatrix<MT>::Type() );
225 inline void randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros )
const
229 using ET = ElementType_t<MT>;
231 const size_t n( matrix.rows() );
233 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
237 if( n == 0UL )
return;
240 matrix.reserve( nonzeros );
242 std::vector<size_t> dist( n );
244 for(
size_t nz=0UL; nz<nonzeros; ) {
245 const size_t index = rand<size_t>( 0UL, n-1UL );
246 if( dist[index] == n - index )
continue;
251 for(
size_t i=0UL; i<n; ++i ) {
252 const Indices<size_t> indices( i, n-1UL, dist[i] );
253 for(
size_t j : indices ) {
254 matrix.append( i, j, rand<ET>() );
256 matrix.finalize( i );
269 inline void randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros )
const
273 using ET = ElementType_t<MT>;
275 const size_t n( matrix.rows() );
277 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
281 if( n == 0UL )
return;
284 matrix.reserve( nonzeros );
286 std::vector<size_t> dist( n );
288 for(
size_t nz=0UL; nz<nonzeros; ) {
289 const size_t index = rand<size_t>( 0UL, n-1UL );
290 if( dist[index] == index+1UL )
continue;
295 for(
size_t j=0UL; j<n; ++j ) {
296 const Indices<size_t> indices( 0UL, j, dist[j] );
297 for(
size_t i : indices ) {
298 matrix.append( i, j, rand<ET>() );
300 matrix.finalize( j );
313 template<
typename Arg >
314 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
const
330 template<
typename Arg >
331 inline void randomize( UpperMatrix<MT,false,DF>& matrix,
332 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const
336 using ET = ElementType_t<MT>;
338 const size_t n( matrix.rows() );
340 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
344 if( n == 0UL )
return;
347 matrix.reserve( nonzeros );
349 std::vector<size_t> dist( n );
351 for(
size_t nz=0UL; nz<nonzeros; ) {
352 const size_t index = rand<size_t>( 0UL, n-1UL );
353 if( dist[index] == n - index )
continue;
358 for(
size_t i=0UL; i<n; ++i ) {
359 const Indices<size_t> indices( i, n-1UL, dist[i] );
360 for(
size_t j : indices ) {
361 matrix.append( i, j, rand<ET>(
min,
max ) );
363 matrix.finalize( i );
378 template<
typename Arg >
379 inline void randomize( UpperMatrix<MT,true,DF>& matrix,
380 size_t nonzeros,
const Arg&
min,
const Arg&
max )
const
384 using ET = ElementType_t<MT>;
386 const size_t n( matrix.rows() );
388 if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
392 if( n == 0UL )
return;
395 matrix.reserve( nonzeros );
397 std::vector<size_t> dist( n );
399 for(
size_t nz=0UL; nz<nonzeros; ) {
400 const size_t index = rand<size_t>( 0UL, n-1UL );
401 if( dist[index] == index+1UL )
continue;
406 for(
size_t j=0UL; j<n; ++j ) {
407 const Indices<size_t> indices( 0UL, j, dist[j] );
408 for(
size_t i : indices ) {
409 matrix.append( i, j, rand<ET>(
min,
max ) );
411 matrix.finalize( j );
427 using ET = ElementType_t<MT>;
429 const size_t n( matrix.rows() );
431 for(
size_t i=0UL; i<n; ++i ) {
432 for(
size_t j=i; j<n; ++j ) {
433 matrix(i,j) = rand<ET>();
449 const size_t n( matrix.rows() );
451 if( n == 0UL )
return;
453 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.3*n*n ) ) );
467 template<
typename Arg >
468 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
473 using ET = ElementType_t<MT>;
475 const size_t n( matrix.rows() );
477 for(
size_t i=0UL; i<n; ++i ) {
478 for(
size_t j=i; j<n; ++j ) {
479 matrix(i,j) = rand<ET>(
min,
max );
493 template<
typename Arg >
494 inline void randomize( UpperMatrix<MT,SO,DF>& matrix,
499 const size_t n( matrix.rows() );
501 if( n == 0UL )
return;
503 const size_t nonzeros( rand<size_t>( 1UL,
std::ceil( 0.3*n*n ) ) );
531void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix )
533 const size_t n( matrix.rows() );
537 for(
size_t i=0UL; i<n; ++i ) {
538 matrix(i,i) = rand< ElementType_t<MT> >();
560void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
562 using Type = ElementType_t<MT>;
564 const size_t n( matrix.rows() );
568 for(
size_t i=0UL; i<n; ++i ) {
569 matrix(i,i) = rand<Type>(
min,
max );
588void makeHermitian( UpperMatrix<MT,SO,DF>& matrix )
590 using Type = UnderlyingBuiltin_t< ElementType_t<MT> >;
594 const size_t n( matrix.rows() );
598 for(
size_t i=0UL; i<n; ++i ) {
599 matrix(i,i) = rand<Type>();
621void makeHermitian( UpperMatrix<MT,SO,DF>& matrix,
const Arg&
min,
const Arg&
max )
623 using Type = UnderlyingBuiltin_t< ElementType_t<MT> >;
627 const size_t n( matrix.rows() );
631 for(
size_t i=0UL; i<n; ++i ) {
632 matrix(i,i) = rand<Type>(
min,
max );
651void makePositiveDefinite( UpperMatrix<MT,SO,DF>& matrix )
653 makeHermitian( matrix );
Header file for auxiliary alias declarations.
Header file for all basic DenseMatrix functionality.
Header file for the Indices class.
Header file for the IntegralConstant class template.
Header file for the IsDenseMatrix type trait.
Header file for the complete LowerMatrix implementation.
Constraint on the data type.
Constraint on the data type.
Header file for all basic SparseMatrix functionality.
Header file for the UnderlyingBuiltin type trait.
Header file for the implementation of a diagonal matrix adaptor.
Header file for the implementation of an upper matrix adaptor.
Constraint on the data type.
Constraint on the data type.
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
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:1534
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:1456
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
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE_TYPE(T)
Constraint on the data type.
Definition: Resizable.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE(T)
Constraint on the data type.
Definition: Resizable.h:61
#define BLAZE_CONSTRAINT_MUST_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:61
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
void randomize(T &&value)
Randomization of a given variable.
Definition: Random.h:626
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
BoolConstant< false > FalseType
Type/value traits base class.
Definition: IntegralConstant.h:121
#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 random number generator.
Header file for basic type definitions.