DMatInvExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATINVEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DMATINVEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
47 #include <blaze/math/Exception.h>
61 #include <blaze/util/Assert.h>
63 #include <blaze/util/mpl/If.h>
64 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS DMATINVEXPR
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
81 template< typename MT // Type of the dense matrix
82  , bool SO > // Storage order
84  : public MatInvExpr< DenseMatrix< DMatInvExpr<MT,SO>, SO > >
85  , private Computation
86 {
87  private:
88  //**Type definitions****************************************************************************
89  using RT = ResultType_t<MT>;
91  //**********************************************************************************************
92 
93  public:
94  //**Type definitions****************************************************************************
102 
104  using CompositeType = const ResultType;
105 
107  using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
108  //**********************************************************************************************
109 
110  //**Compilation flags***************************************************************************
112  static constexpr bool simdEnabled = false;
113 
115  static constexpr bool smpAssignable = false;
116  //**********************************************************************************************
117 
118  //**Constructor*********************************************************************************
123  explicit inline DMatInvExpr( const MT& dm ) noexcept
124  : dm_( dm ) // Dense matrix of the inversion expression
125  {}
126  //**********************************************************************************************
127 
128  //**Rows function*******************************************************************************
133  inline size_t rows() const noexcept {
134  return dm_.columns();
135  }
136  //**********************************************************************************************
137 
138  //**Columns function****************************************************************************
143  inline size_t columns() const noexcept {
144  return dm_.rows();
145  }
146  //**********************************************************************************************
147 
148  //**Operand access******************************************************************************
153  inline Operand operand() const noexcept {
154  return dm_;
155  }
156  //**********************************************************************************************
157 
158  //**********************************************************************************************
164  template< typename T >
165  inline bool canAlias( const T* alias ) const noexcept {
166  return dm_.isAliased( alias );
167  }
168  //**********************************************************************************************
169 
170  //**********************************************************************************************
176  template< typename T >
177  inline bool isAliased( const T* alias ) const noexcept {
178  return dm_.isAliased( alias );
179  }
180  //**********************************************************************************************
181 
182  private:
183  //**Member variables****************************************************************************
185  //**********************************************************************************************
186 
187  //**********************************************************************************************
193  static constexpr InversionFlag getInversionFlag() noexcept {
194  return ( IsDiagonal_v<MT> ? asDiagonal
195  : IsUniUpper_v<MT> ? asUniUpper
196  : IsUpper_v<MT> ? asUpper
197  : IsUniLower_v<MT> ? asUniLower
198  : IsLower_v<MT> ? asLower
199  : IsHermitian_v<MT> ? asHermitian
200  : IsSymmetric_v<MT> ? asSymmetric
201  : asGeneral );
202  }
204  //**********************************************************************************************
205 
206  //**Assignment to dense matrices****************************************************************
218  template< typename MT2 // Type of the target dense matrix
219  , bool SO2 > // Storage order of the target dense matrix
220  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
221  {
223 
224  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
225  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
226 
227  if( !isSame( ~lhs, rhs.dm_ ) ) {
228  assign( ~lhs, rhs.dm_ );
229  }
230 
231  invert< DMatInvExpr::getInversionFlag() >( ~lhs );
232  }
234  //**********************************************************************************************
235 
236  //**Assignment to sparse matrices***************************************************************
248  template< typename MT2 // Type of the target sparse matrix
249  , bool SO2 > // Storage order of the target sparse matrix
250  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
251  {
253 
254  using TmpType = If_t< SO == SO2, ResultType, OppositeType >;
255 
262 
263  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
264  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
265 
266  const TmpType tmp( serial( rhs ) );
267  assign( ~lhs, tmp );
268  }
270  //**********************************************************************************************
271 
272  //**Addition assignment to dense matrices*******************************************************
284  template< typename MT2 // Type of the target dense matrix
285  , bool SO2 > // Storage order of the target dense matrix
286  friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
287  {
289 
290  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
291  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
292 
293  const ResultType tmp( serial( rhs ) );
294  addAssign( ~lhs, tmp );
295  }
297  //**********************************************************************************************
298 
299  //**Addition assignment to sparse matrices******************************************************
300  // No special implementation for the addition assignment to sparse matrices.
301  //**********************************************************************************************
302 
303  //**Subtraction assignment to dense matrices****************************************************
315  template< typename MT2 // Type of the target dense matrix
316  , bool SO2 > // Storage order of the target dense matrix
317  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
318  {
320 
321  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
322  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
323 
324  const ResultType tmp( serial( rhs ) );
325  subAssign( ~lhs, tmp );
326  }
328  //**********************************************************************************************
329 
330  //**Subtraction assignment to sparse matrices***************************************************
331  // No special implementation for the subtraction assignment to sparse matrices.
332  //**********************************************************************************************
333 
334  //**Schur product assignment to dense matrices**************************************************
346  template< typename MT2 // Type of the target dense matrix
347  , bool SO2 > // Storage order of the target dense matrix
348  friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
349  {
351 
352  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
353  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
354 
355  const ResultType tmp( serial( rhs ) );
356  schurAssign( ~lhs, tmp );
357  }
359  //**********************************************************************************************
360 
361  //**Schur product assignment to sparse matrices*************************************************
362  // No special implementation for the Schur product assignment to sparse matrices.
363  //**********************************************************************************************
364 
365  //**Multiplication assignment to dense matrices*************************************************
366  // No special implementation for the multiplication assignment to dense matrices.
367  //**********************************************************************************************
368 
369  //**Multiplication assignment to sparse matrices************************************************
370  // No special implementation for the multiplication assignment to sparse matrices.
371  //**********************************************************************************************
372 
373  //**Compile time checks*************************************************************************
378  //**********************************************************************************************
379 };
380 //*************************************************************************************************
381 
382 
383 
384 
385 //=================================================================================================
386 //
387 // GLOBAL OPERATORS
388 //
389 //=================================================================================================
390 
391 //*************************************************************************************************
421 template< typename MT // Type of the dense matrix
422  , bool SO > // Storage order
423 inline decltype(auto) inv( const DenseMatrix<MT,SO>& dm )
424 {
426 
427  if( !isSquare( ~dm ) ) {
428  BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
429  }
430 
431  using ReturnType = const DMatInvExpr<MT,SO>;
432  return ReturnType( ~dm );
433 }
434 //*************************************************************************************************
435 
436 
437 
438 
439 //=================================================================================================
440 //
441 // GLOBAL RESTRUCTURING FUNCTIONS
442 //
443 //=================================================================================================
444 
445 //*************************************************************************************************
465 template< typename MT // Type of the dense matrix
466  , bool SO > // Storage order
467 inline decltype(auto) inv( const DMatInvExpr<MT,SO>& dm )
468 {
470 
471  return dm.operand();
472 }
474 //*************************************************************************************************
475 
476 } // namespace blaze
477 
478 #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
CompositeType_t< MT > CT
Composite type of the dense matrix expression.
Definition: DMatInvExpr.h:90
Header file for auxiliary alias declarations.
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatInvExpr.h:101
Operand dm_
Dense matrix of the inversion expression.
Definition: DMatInvExpr.h:184
Header file for the IsUniUpper type trait.
Flag for the inversion of a diagonal matrix.
Definition: InversionFlag.h:115
bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:992
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
Flag for the inversion of a general matrix (same as byLU).
Definition: InversionFlag.h:108
Flag for the inversion of a upper unitriangular matrix.
Definition: InversionFlag.h:114
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Flag for the inversion of a lower unitriangular matrix.
Definition: InversionFlag.h:112
Header file for the serial shim.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:63
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatInvExpr.h:112
Header file for the IsDiagonal type trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:61
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatInvExpr.h:100
Header file for the Computation base class.
Header file for the MatInvExpr base class.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatInvExpr.h:165
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the IsUniLower type trait.
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatInvExpr.h:133
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatInvExpr.h:98
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatInvExpr.h:97
DMatInvExpr(const MT &dm) noexcept
Constructor for the DMatInvExpr class.
Definition: DMatInvExpr.h:123
Constraint on the data type.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatInvExpr.h:177
Flag for the inversion of a upper triangular matrix.
Definition: InversionFlag.h:113
Flag for the inversion of a lower triangular matrix.
Definition: InversionFlag.h:111
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatInvExpr.h:115
Header file for the DenseMatrix base class.
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:423
Flag for the inversion of a Hermitian matrix (same as byLDLH).
Definition: InversionFlag.h:110
Header file for the IsLower type trait.
Constraints on the storage order of matrix types.
Header file for the exception macros of the math module.
Constraint on the data type.
Header file for all forward declarations for expression class templates.
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
Flag for the inversion of a symmetric matrix (same as byLDLT).
Definition: InversionFlag.h:109
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatInvExpr.h:153
If_t< IsExpression_v< MT >, const MT, const MT &> Operand
Composite data type of the dense matrix expression.
Definition: DMatInvExpr.h:107
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Base class for all matrix inversion expression templates.The MatInvExpr class serves as a tag for all...
Definition: MatInvExpr.h:66
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_SAME_STORAGE_ORDER(T1, T2)
Constraint on the data type.In case either of the two given data types T1 or T2 is not a matrix type ...
Definition: StorageOrder.h:84
Expression object for dense matrix inversions.The DMatInvExpr class represents the compile time expre...
Definition: DMatInvExpr.h:83
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatInvExpr.h:104
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatInvExpr.h:99
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
ResultType_t< MT > RT
Result type of the dense matrix expression.
Definition: DMatInvExpr.h:89
Header file for the IsUpper type trait.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatInvExpr.h:143
Header file for the IsHermitian type trait.
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:951
InversionFlag
Inversion flag.The InversionFlag type enumeration represents the different types of matrix inversion ...
Definition: InversionFlag.h:101
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the IsExpression type trait class.
Header file for the function trace functionality.