Blaze 3.9
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 <utility>
46#include <blaze/math/Aliases.h>
56#include <blaze/util/EnableIf.h>
57
58
59namespace blaze {
60
61//=================================================================================================
62//
63// GLOBAL FUNCTIONS
64//
65//=================================================================================================
66
67//*************************************************************************************************
70template< typename MT, bool SO >
71bool isSymmetric( const Matrix<MT,SO>& m );
72
73template< typename MT, bool SO >
74bool isHermitian( const Matrix<MT,SO>& m );
75
76template< typename MT, bool SO >
77bool isUniform( const Matrix<MT,SO>& m );
78
79template< typename MT, bool SO >
80bool isLower( const Matrix<MT,SO>& m );
81
82template< typename MT, bool SO >
83bool isUniLower( const Matrix<MT,SO>& m );
84
85template< typename MT, bool SO >
86bool isStrictlyLower( const Matrix<MT,SO>& m );
87
88template< typename MT, bool SO >
89bool isUpper( const Matrix<MT,SO>& m );
90
91template< typename MT, bool SO >
92bool isUniUpper( const Matrix<MT,SO>& m );
93
94template< typename MT, bool SO >
95bool isStrictlyUpper( const Matrix<MT,SO>& m );
96
97template< typename MT, bool SO >
98bool isDiagonal( const Matrix<MT,SO>& m );
99
100template< typename MT, bool SO >
101bool isIdentity( const Matrix<MT,SO>& m );
102
103template< typename MT, bool SO >
104decltype(auto) pow2( const Matrix<MT,SO>& m );
105
106template< typename MT, bool SO >
107decltype(auto) pow3( const Matrix<MT,SO>& m );
108
109template< typename MT, bool SO >
110decltype(auto) pow4( const Matrix<MT,SO>& m );
111
112template< typename MT1, bool SO1, typename MT2, bool SO2 >
113decltype(auto) schur( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs );
114
115template< typename MT, bool SO >
116auto trace( const Matrix<MT,SO>& m );
117
118template< bool RF, typename MT >
119decltype(auto) reverse( MT&& m );
121//*************************************************************************************************
122
123
124//*************************************************************************************************
157template< typename MT // Type of the matrix
158 , bool SO > // Storage order
159inline bool isSymmetric( const Matrix<MT,SO>& m )
160{
161 return isSymmetric<relaxed>( *m );
162}
163//*************************************************************************************************
164
165
166//*************************************************************************************************
201template< typename MT // Type of the matrix
202 , bool SO > // Storage order
203inline bool isHermitian( const Matrix<MT,SO>& m )
204{
205 return isHermitian<relaxed>( *m );
206}
207//*************************************************************************************************
208
209
210//*************************************************************************************************
243template< typename MT // Type of the matrix
244 , bool SO > // Storage order
245inline bool isUniform( const Matrix<MT,SO>& m )
246{
247 return isUniform<relaxed>( *m );
248}
249//*************************************************************************************************
250
251
252//*************************************************************************************************
295template< typename MT // Type of the matrix
296 , bool SO > // Storage order
297inline bool isLower( const Matrix<MT,SO>& m )
298{
299 return isLower<relaxed>( *m );
300}
301//*************************************************************************************************
302
303
304//*************************************************************************************************
346template< typename MT // Type of the matrix
347 , bool SO > // Storage order
348inline bool isUniLower( const Matrix<MT,SO>& m )
349{
350 return isUniLower<relaxed>( *m );
351}
352//*************************************************************************************************
353
354
355//*************************************************************************************************
398template< typename MT // Type of the matrix
399 , bool SO > // Storage order
400inline bool isStrictlyLower( const Matrix<MT,SO>& m )
401{
402 return isStrictlyLower<relaxed>( *m );
403}
404//*************************************************************************************************
405
406
407//*************************************************************************************************
450template< typename MT // Type of the matrix
451 , bool SO > // Storage order
452inline bool isUpper( const Matrix<MT,SO>& m )
453{
454 return isUpper<relaxed>( *m );
455}
456//*************************************************************************************************
457
458
459//*************************************************************************************************
501template< typename MT // Type of the matrix
502 , bool SO > // Storage order
503inline bool isUniUpper( const Matrix<MT,SO>& m )
504{
505 return isUniUpper<relaxed>( *m );
506}
507//*************************************************************************************************
508
509
510//*************************************************************************************************
553template< typename MT // Type of the matrix
554 , bool SO > // Storage order
555inline bool isStrictlyUpper( const Matrix<MT,SO>& m )
556{
557 return isStrictlyUpper<relaxed>( *m );
558}
559//*************************************************************************************************
560
561
562//*************************************************************************************************
606template< typename MT // Type of the matrix
607 , bool SO > // Storage order
608inline bool isDiagonal( const Matrix<MT,SO>& m )
609{
610 return isDiagonal<relaxed>( *m );
611}
612//*************************************************************************************************
613
614
615//*************************************************************************************************
658template< typename MT // Type of the matrix
659 , bool SO > // Storage order
660inline bool isIdentity( const Matrix<MT,SO>& m )
661{
662 return isIdentity<relaxed>( *m );
663}
664//*************************************************************************************************
665
666
667//*************************************************************************************************
684template< typename MT // Type of the matrix
685 , bool SO > // Storage order
686inline decltype(auto) pow2( const Matrix<MT,SO>& m )
687{
688 return (*m) % (*m);
689}
690//*************************************************************************************************
691
692
693//*************************************************************************************************
710template< typename MT // Type of the matrix
711 , bool SO > // Storage order
712inline decltype(auto) pow3( const Matrix<MT,SO>& m )
713{
714 return (*m) % (*m) % (*m);
715}
716//*************************************************************************************************
717
718
719//*************************************************************************************************
736template< typename MT // Type of the matrix
737 , bool SO > // Storage order
738inline decltype(auto) pow4( const Matrix<MT,SO>& m )
739{
740 return pow2( pow2( *m ) );
741}
742//*************************************************************************************************
743
744
745//*************************************************************************************************
764template< typename MT1 // Type of the left-hand side matrix
765 , bool SO1 // Storage order of the left-hand side matrix
766 , typename MT2 // Type of the right-hand side matrix
767 , bool SO2 > // Storage order of the right-hand side matrix
768inline decltype(auto) schur( const Matrix<MT1,SO1>& lhs, const Matrix<MT2,SO2>& rhs )
769{
770 return (*lhs) % (*rhs);
771}
772//*************************************************************************************************
773
774
775//*************************************************************************************************
790template< typename MT // Type of the matrix
791 , bool SO > // Storage order
792inline auto trace( const Matrix<MT,SO>& m )
793{
794 if( !isSquare( *m ) ) {
795 BLAZE_THROW_INVALID_ARGUMENT( "Invalid input matrix for trace computation" );
796 }
797
798 return sum( diagonal( *m ) );
799}
800//*************************************************************************************************
801
802
803//*************************************************************************************************
811template< bool RF // Reverse flag
812 , typename MT // Type of the matrix
813 , EnableIf_t< RF == rowwise >* = nullptr >
814inline decltype(auto) reverse_backend( MT&& m )
815{
816 return rows( std::forward<MT>( m ), [max=m.rows()-1UL]( size_t i ){ return max - i; }, m.rows() );
817}
819//*************************************************************************************************
820
821
822//*************************************************************************************************
830template< bool RF // Reverse flag
831 , typename MT // Type of the matrix
832 , EnableIf_t< RF == columnwise >* = nullptr >
833inline decltype(auto) reverse_backend( MT&& m )
834{
835 return columns( std::forward<MT>( m ), [max=m.columns()-1UL]( size_t i ){ return max - i; }, m.columns() );
836}
838//*************************************************************************************************
839
840
841//*************************************************************************************************
876template< bool RF // Reverse flag
877 , typename MT > // Type of the matrix
878inline decltype(auto) reverse( MT&& m )
879{
880 return reverse_backend<RF>( std::forward<MT>( m ) );
881}
882//*************************************************************************************************
883
884
885
886
887//=================================================================================================
888//
889// GLOBAL OPERATORS
890//
891//=================================================================================================
892
893//*************************************************************************************************
896template< typename MT, bool SO >
897std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m );
899//*************************************************************************************************
900
901
902//*************************************************************************************************
910template< typename MT // Type of the matrix
911 , bool SO > // Storage order
912inline std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m )
913{
914 CompositeType_t<MT> tmp( *m );
915
916 for( size_t i=0UL; i<tmp.rows(); ++i ) {
917 os << "( ";
918 for( size_t j=0UL; j<tmp.columns(); ++j ) {
919 os << std::setw(12) << tmp(i,j) << " ";
920 }
921 os << ")\n";
922 }
923
924 return os;
925}
926//*************************************************************************************************
927
928} // namespace blaze
929
930#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
Header file for the EnableIf class template.
Header file for the reduction flags.
Base class for matrices.
Definition: Matrix.h:85
Header file for the Matrix base class.
decltype(auto) diagonal(Matrix< MT, SO > &matrix, RDAs... args)
Creating a view on the diagonal of the given matrix.
Definition: Band.h:380
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) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2156
bool isUniLower(const Matrix< MT, SO > &m)
Checks if the given matrix is a lower unitriangular matrix.
Definition: Matrix.h:348
bool isHermitian(const Matrix< MT, SO > &m)
Checks if the given matrix is Hermitian.
Definition: Matrix.h:203
BLAZE_ALWAYS_INLINE constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
bool isSymmetric(const Matrix< MT, SO > &m)
Checks if the given matrix is symmetric.
Definition: Matrix.h:159
bool isLower(const Matrix< MT, SO > &m)
Checks if the given matrix is a lower triangular matrix.
Definition: Matrix.h:297
bool isUniform(const Matrix< MT, SO > &m)
Checks if the given matrix is a uniform matrix.
Definition: Matrix.h:245
decltype(auto) schur(const Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Schur product of two matrices ( ).
Definition: Matrix.h:768
decltype(auto) pow2(const Matrix< MT, SO > &m)
Computes the square for each single element of the matrix m.
Definition: Matrix.h:686
bool isDiagonal(const Matrix< MT, SO > &m)
Checks if the give matrix is diagonal.
Definition: Matrix.h:608
BLAZE_ALWAYS_INLINE constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
bool isIdentity(const Matrix< MT, SO > &m)
Checks if the give matrix is an identity matrix.
Definition: Matrix.h:660
bool isStrictlyLower(const Matrix< MT, SO > &m)
Checks if the given matrix is a strictly lower triangular matrix.
Definition: Matrix.h:400
bool isUniUpper(const Matrix< MT, SO > &m)
Checks if the given matrix is an upper unitriangular matrix.
Definition: Matrix.h:503
std::ostream & operator<<(std::ostream &os, const Matrix< MT, SO > &m)
Global output operator for dense and sparse matrices.
Definition: Matrix.h:912
decltype(auto) pow3(const Matrix< MT, SO > &m)
Computes the cube for each single element of the matrix m.
Definition: Matrix.h:712
bool isStrictlyUpper(const Matrix< MT, SO > &m)
Checks if the given matrix is a strictly upper triangular matrix.
Definition: Matrix.h:555
decltype(auto) reverse(MT &&m)
Reverse the rows or columns of a matrix.
Definition: Matrix.h:878
auto trace(const Matrix< MT, SO > &m)
Computes the trace of the given square matrix.
Definition: Matrix.h:792
bool isUpper(const Matrix< MT, SO > &m)
Checks if the given matrix is an upper triangular matrix.
Definition: Matrix.h:452
decltype(auto) pow4(const Matrix< MT, SO > &m)
Computes the quadruple for each single element of the matrix m.
Definition: Matrix.h:738
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:1383
#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.
Header file for the add shim.
Header file for the div shim.
Header file for the mult shim.
Header file for the sub shim.
Header file for the implementation of the Band view.
Header file for the implementation of the Elements view.