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 <iosfwd>
45 #include <blaze/math/Aliases.h>
46 #include <blaze/math/Exception.h>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // GLOBAL FUNCTIONS
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
63 template< typename MT, bool SO >
64 bool isSymmetric( const Matrix<MT,SO>& m );
65 
66 template< typename MT, bool SO >
67 bool isHermitian( const Matrix<MT,SO>& m );
68 
69 template< typename MT, bool SO >
70 bool isUniform( const Matrix<MT,SO>& m );
71 
72 template< typename MT, bool SO >
73 bool isLower( const Matrix<MT,SO>& m );
74 
75 template< typename MT, bool SO >
76 bool isUniLower( const Matrix<MT,SO>& m );
77 
78 template< typename MT, bool SO >
79 bool isStrictlyLower( const Matrix<MT,SO>& m );
80 
81 template< typename MT, bool SO >
82 bool isUpper( const Matrix<MT,SO>& m );
83 
84 template< typename MT, bool SO >
85 bool isUniUpper( const Matrix<MT,SO>& m );
86 
87 template< typename MT, bool SO >
88 bool isStrictlyUpper( const Matrix<MT,SO>& m );
89 
90 template< typename MT, bool SO >
91 bool isDiagonal( const Matrix<MT,SO>& m );
92 
93 template< typename MT, bool SO >
94 bool isIdentity( const Matrix<MT,SO>& m );
95 
96 template< typename MT, bool SO >
97 auto trace( const Matrix<MT,SO>& m );
98 
99 template< bool RF, typename MT, bool SO >
100 decltype(auto) reverse( const Matrix<MT,SO>& m );
102 //*************************************************************************************************
103 
104 
105 //*************************************************************************************************
138 template< typename MT // Type of the matrix
139  , bool SO > // Storage order
140 inline bool isSymmetric( const Matrix<MT,SO>& m )
141 {
142  return isSymmetric<relaxed>( ~m );
143 }
144 //*************************************************************************************************
145 
146 
147 //*************************************************************************************************
182 template< typename MT // Type of the matrix
183  , bool SO > // Storage order
184 inline bool isHermitian( const Matrix<MT,SO>& m )
185 {
186  return isHermitian<relaxed>( ~m );
187 }
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
224 template< typename MT // Type of the matrix
225  , bool SO > // Storage order
226 inline bool isUniform( const Matrix<MT,SO>& m )
227 {
228  return isUniform<relaxed>( ~m );
229 }
230 //*************************************************************************************************
231 
232 
233 //*************************************************************************************************
276 template< typename MT // Type of the matrix
277  , bool SO > // Storage order
278 inline bool isLower( const Matrix<MT,SO>& m )
279 {
280  return isLower<relaxed>( ~m );
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
327 template< typename MT // Type of the matrix
328  , bool SO > // Storage order
329 inline bool isUniLower( const Matrix<MT,SO>& m )
330 {
331  return isUniLower<relaxed>( ~m );
332 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
379 template< typename MT // Type of the matrix
380  , bool SO > // Storage order
381 inline bool isStrictlyLower( const Matrix<MT,SO>& m )
382 {
383  return isStrictlyLower<relaxed>( ~m );
384 }
385 //*************************************************************************************************
386 
387 
388 //*************************************************************************************************
431 template< typename MT // Type of the matrix
432  , bool SO > // Storage order
433 inline bool isUpper( const Matrix<MT,SO>& m )
434 {
435  return isUpper<relaxed>( ~m );
436 }
437 //*************************************************************************************************
438 
439 
440 //*************************************************************************************************
482 template< typename MT // Type of the matrix
483  , bool SO > // Storage order
484 inline bool isUniUpper( const Matrix<MT,SO>& m )
485 {
486  return isUniUpper<relaxed>( ~m );
487 }
488 //*************************************************************************************************
489 
490 
491 //*************************************************************************************************
534 template< typename MT // Type of the matrix
535  , bool SO > // Storage order
536 inline bool isStrictlyUpper( const Matrix<MT,SO>& m )
537 {
538  return isStrictlyUpper<relaxed>( ~m );
539 }
540 //*************************************************************************************************
541 
542 
543 //*************************************************************************************************
587 template< typename MT // Type of the matrix
588  , bool SO > // Storage order
589 inline bool isDiagonal( const Matrix<MT,SO>& m )
590 {
591  return isDiagonal<relaxed>( ~m );
592 }
593 //*************************************************************************************************
594 
595 
596 //*************************************************************************************************
639 template< typename MT // Type of the matrix
640  , bool SO > // Storage order
641 inline bool isIdentity( const Matrix<MT,SO>& m )
642 {
643  return isIdentity<relaxed>( ~m );
644 }
645 //*************************************************************************************************
646 
647 
648 
649 //*************************************************************************************************
664 template< typename MT // Type of the matrix
665  , bool SO > // Storage order
666 inline auto trace( const Matrix<MT,SO>& m )
667 {
668  if( !isSquare( ~m ) ) {
669  BLAZE_THROW_INVALID_ARGUMENT( "Invalid input matrix for trace computation" );
670  }
671 
672  return sum( diagonal( ~m ) );
673 }
674 //*************************************************************************************************
675 
676 
677 //*************************************************************************************************
685 template< bool RF
686  , typename MT
687  , bool SO
688  , EnableIf_t< RF == rowwise >* = nullptr >
689 inline decltype(auto) reverse_backend( const Matrix<MT,SO>& m )
690 {
691  return rows( ~m, [max=(~m).rows()-1UL]( size_t i ){ return max - i; }, (~m).rows() );
692 }
694 //*************************************************************************************************
695 
696 
697 //*************************************************************************************************
705 template< bool RF
706  , typename MT
707  , bool SO
708  , EnableIf_t< RF == columnwise >* = nullptr >
709 inline decltype(auto) reverse_backend( const Matrix<MT,SO>& m )
710 {
711  return columns( ~m, [max=(~m).columns()-1UL]( size_t i ){ return max - i; }, (~m).columns() );
712 }
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
752 template< bool RF // Reverse flag
753  , typename MT // Type of the matrix
754  , bool SO > // Storage order
755 inline decltype(auto) reverse( const Matrix<MT,SO>& m )
756 {
757  return reverse_backend<RF>( ~m );
758 }
759 //*************************************************************************************************
760 
761 
762 
763 
764 //=================================================================================================
765 //
766 // GLOBAL OPERATORS
767 //
768 //=================================================================================================
769 
770 //*************************************************************************************************
773 template< typename MT, bool SO >
774 std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m );
776 //*************************************************************************************************
777 
778 
779 //*************************************************************************************************
787 template< typename MT // Type of the matrix
788  , bool SO > // Storage order
789 inline std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m )
790 {
791  CompositeType_t<MT> tmp( ~m );
792 
793  for( size_t i=0UL; i<tmp.rows(); ++i ) {
794  os << "( ";
795  for( size_t j=0UL; j<tmp.columns(); ++j ) {
796  os << std::setw(12) << tmp(i,j) << " ";
797  }
798  os << ")\n";
799  }
800 
801  return os;
802 }
803 //*************************************************************************************************
804 
805 } // namespace blaze
806 
807 #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:1004
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1271
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1179
bool isUniLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower unitriangular matrix.
Definition: DenseMatrix.h:1092
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1539
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1644
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2146
decltype(auto) reverse(const Matrix< MT, SO > &m)
Reverse the rows or columns of a matrix.
Definition: Matrix.h:755
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
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:849
decltype(auto) diagonal(Matrix< MT, SO > &matrix, RDAs... args)
Creating a view on the diagonal of the given matrix.
Definition: Band.h:375
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:1446
Header file for the relaxation flag types.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:617
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:109
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:539
auto trace(const Matrix< MT, SO > &m)
Computes the trace of the given square matrix.
Definition: Matrix.h:666
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
Header file for the implementation of the Elements view.
bool isUniUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper unitriangular matrix.
Definition: DenseMatrix.h:1359
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:951