Matrix.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_MATRIX_H_
36 #define _BLAZE_MATH_MATRIX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iomanip>
44 #include <ostream>
45 #include <blaze/math/Aliases.h>
46 #include <blaze/math/Exception.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // GLOBAL FUNCTIONS
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
62 template< typename MT, bool SO >
63 inline bool isSymmetric( const Matrix<MT,SO>& m );
64 
65 template< typename MT, bool SO >
66 inline bool isHermitian( const Matrix<MT,SO>& m );
67 
68 template< typename MT, bool SO >
69 inline bool isUniform( const Matrix<MT,SO>& m );
70 
71 template< typename MT, bool SO >
72 inline bool isLower( const Matrix<MT,SO>& m );
73 
74 template< typename MT, bool SO >
75 inline bool isUniLower( const Matrix<MT,SO>& m );
76 
77 template< typename MT, bool SO >
78 inline bool isStrictlyLower( const Matrix<MT,SO>& m );
79 
80 template< typename MT, bool SO >
81 inline bool isUpper( const Matrix<MT,SO>& m );
82 
83 template< typename MT, bool SO >
84 inline bool isUniUpper( const Matrix<MT,SO>& m );
85 
86 template< typename MT, bool SO >
87 inline bool isStrictlyUpper( const Matrix<MT,SO>& m );
88 
89 template< typename MT, bool SO >
90 inline bool isDiagonal( const Matrix<MT,SO>& m );
91 
92 template< typename MT, bool SO >
93 inline bool isIdentity( const Matrix<MT,SO>& m );
94 
95 template< typename MT, bool SO >
96 inline auto trace( const Matrix<MT,SO>& m );
98 //*************************************************************************************************
99 
100 
101 //*************************************************************************************************
134 template< typename MT // Type of the matrix
135  , bool SO > // Storage order
136 inline bool isSymmetric( const Matrix<MT,SO>& m )
137 {
138  return isSymmetric<relaxed>( ~m );
139 }
140 //*************************************************************************************************
141 
142 
143 //*************************************************************************************************
178 template< typename MT // Type of the matrix
179  , bool SO > // Storage order
180 inline bool isHermitian( const Matrix<MT,SO>& m )
181 {
182  return isHermitian<relaxed>( ~m );
183 }
184 //*************************************************************************************************
185 
186 
187 //*************************************************************************************************
220 template< typename MT // Type of the matrix
221  , bool SO > // Storage order
222 inline bool isUniform( const Matrix<MT,SO>& m )
223 {
224  return isUniform<relaxed>( ~m );
225 }
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
272 template< typename MT // Type of the matrix
273  , bool SO > // Storage order
274 inline bool isLower( const Matrix<MT,SO>& m )
275 {
276  return isLower<relaxed>( ~m );
277 }
278 //*************************************************************************************************
279 
280 
281 //*************************************************************************************************
323 template< typename MT // Type of the matrix
324  , bool SO > // Storage order
325 inline bool isUniLower( const Matrix<MT,SO>& m )
326 {
327  return isUniLower<relaxed>( ~m );
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
375 template< typename MT // Type of the matrix
376  , bool SO > // Storage order
377 inline bool isStrictlyLower( const Matrix<MT,SO>& m )
378 {
379  return isStrictlyLower<relaxed>( ~m );
380 }
381 //*************************************************************************************************
382 
383 
384 //*************************************************************************************************
427 template< typename MT // Type of the matrix
428  , bool SO > // Storage order
429 inline bool isUpper( const Matrix<MT,SO>& m )
430 {
431  return isUpper<relaxed>( ~m );
432 }
433 //*************************************************************************************************
434 
435 
436 //*************************************************************************************************
478 template< typename MT // Type of the matrix
479  , bool SO > // Storage order
480 inline bool isUniUpper( const Matrix<MT,SO>& m )
481 {
482  return isUniUpper<relaxed>( ~m );
483 }
484 //*************************************************************************************************
485 
486 
487 //*************************************************************************************************
530 template< typename MT // Type of the matrix
531  , bool SO > // Storage order
532 inline bool isStrictlyUpper( const Matrix<MT,SO>& m )
533 {
534  return isStrictlyUpper<relaxed>( ~m );
535 }
536 //*************************************************************************************************
537 
538 
539 //*************************************************************************************************
583 template< typename MT // Type of the matrix
584  , bool SO > // Storage order
585 inline bool isDiagonal( const Matrix<MT,SO>& m )
586 {
587  return isDiagonal<relaxed>( ~m );
588 }
589 //*************************************************************************************************
590 
591 
592 //*************************************************************************************************
635 template< typename MT // Type of the matrix
636  , bool SO > // Storage order
637 inline bool isIdentity( const Matrix<MT,SO>& m )
638 {
639  return isIdentity<relaxed>( ~m );
640 }
641 //*************************************************************************************************
642 
643 
644 
645 //*************************************************************************************************
660 template< typename MT // Type of the matrix
661  , bool SO > // Storage order
662 inline auto trace( const Matrix<MT,SO>& m )
663 {
664  using ET = ElementType_<MT>;
665 
666  if( !isSquare( ~m ) ) {
667  BLAZE_THROW_INVALID_ARGUMENT( "Invalid input matrix for trace computation" );
668  }
669 
670  if( (~m).rows() == 0UL ) {
671  return ET();
672  }
673 
674  ET tmp( (~m)(0UL,0UL) );
675 
676  for( size_t i=1UL; i<(~m).rows(); ++i ) {
677  tmp += (~m)(i,i);
678  }
679 
680  return tmp;
681 }
682 //*************************************************************************************************
683 
684 
685 
686 
687 //=================================================================================================
688 //
689 // GLOBAL OPERATORS
690 //
691 //=================================================================================================
692 
693 //*************************************************************************************************
696 template< typename MT, bool SO >
697 inline std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m );
699 //*************************************************************************************************
700 
701 
702 //*************************************************************************************************
710 template< typename MT // Type of the matrix
711  , bool SO > // Storage order
712 inline std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m )
713 {
714  CompositeType_<MT> tmp( ~m );
715 
716  for( size_t i=0UL; i<tmp.rows(); ++i ) {
717  os << "( ";
718  for( size_t j=0UL; j<tmp.columns(); ++j ) {
719  os << std::setw(12) << tmp(i,j) << " ";
720  }
721  os << ")\n";
722  }
723 
724  return os;
725 }
726 //*************************************************************************************************
727 
728 } // namespace blaze
729 
730 #endif
#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
Header file for auxiliary alias declarations.
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:1073
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1328
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1245
bool isUniLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower unitriangular matrix.
Definition: DenseMatrix.h:1158
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1584
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1686
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Header file for the exception macros of the math module.
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:1010
Header file for the Matrix base class.
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1500
Header file for the relaxation flag types.
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:778
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:101
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:700
auto trace(const Matrix< MT, SO > &m)
Computes the trace of the given square matrix.
Definition: Matrix.h:662
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:324
bool isUniUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper unitriangular matrix.
Definition: DenseMatrix.h:1413
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:742