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>
62 #include <blaze/util/Assert.h>
64 #include <blaze/util/mpl/If.h>
65 #include <blaze/util/Types.h>
66 
67 
68 namespace blaze {
69 
70 //=================================================================================================
71 //
72 // CLASS DMATINVEXPR
73 //
74 //=================================================================================================
75 
76 //*************************************************************************************************
82 template< typename MT // Type of the dense matrix
83  , bool SO > // Storage order
85  : public MatInvExpr< DenseMatrix< DMatInvExpr<MT,SO>, SO > >
86  , private Computation
87 {
88  private:
89  //**Type definitions****************************************************************************
90  using RT = ResultType_<MT>;
92  //**********************************************************************************************
93 
94  public:
95  //**Type definitions****************************************************************************
102 
104  using CompositeType = const ResultType;
105 
107  using Operand = If_< IsExpression<MT>, const MT, const MT& >;
108  //**********************************************************************************************
109 
110  //**Compilation flags***************************************************************************
112  enum : bool { simdEnabled = false };
113 
115  enum : 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 {
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 
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 
477 
478 
479 //=================================================================================================
480 //
481 // SIZE SPECIALIZATIONS
482 //
483 //=================================================================================================
484 
485 //*************************************************************************************************
487 template< typename MT, bool SO >
488 struct Size< DMatInvExpr<MT,SO>, 0UL >
489  : public Size<MT,0UL>
490 {};
491 
492 template< typename MT, bool SO >
493 struct Size< DMatInvExpr<MT,SO>, 1UL >
494  : public Size<MT,1UL>
495 {};
497 //*************************************************************************************************
498 
499 
500 
501 
502 //=================================================================================================
503 //
504 // ISSYMMETRIC SPECIALIZATIONS
505 //
506 //=================================================================================================
507 
508 //*************************************************************************************************
510 template< typename MT, bool SO >
511 struct IsSymmetric< DMatInvExpr<MT,SO> >
512  : public IsSymmetric<MT>
513 {};
515 //*************************************************************************************************
516 
517 
518 
519 
520 //=================================================================================================
521 //
522 // ISHERMITIAN SPECIALIZATIONS
523 //
524 //=================================================================================================
525 
526 //*************************************************************************************************
528 template< typename MT, bool SO >
529 struct IsHermitian< DMatInvExpr<MT,SO> >
530  : public IsHermitian<MT>
531 {};
533 //*************************************************************************************************
534 
535 
536 
537 
538 //=================================================================================================
539 //
540 // ISLOWER SPECIALIZATIONS
541 //
542 //=================================================================================================
543 
544 //*************************************************************************************************
546 template< typename MT, bool SO >
547 struct IsLower< DMatInvExpr<MT,SO> >
548  : public IsLower<MT>
549 {};
551 //*************************************************************************************************
552 
553 
554 
555 
556 //=================================================================================================
557 //
558 // ISUNILOWER SPECIALIZATIONS
559 //
560 //=================================================================================================
561 
562 //*************************************************************************************************
564 template< typename MT, bool SO >
565 struct IsUniLower< DMatInvExpr<MT,SO> >
566  : public IsUniLower<MT>
567 {};
569 //*************************************************************************************************
570 
571 
572 
573 
574 //=================================================================================================
575 //
576 // ISUPPER SPECIALIZATIONS
577 //
578 //=================================================================================================
579 
580 //*************************************************************************************************
582 template< typename MT, bool SO >
583 struct IsUpper< DMatInvExpr<MT,SO> >
584  : public IsUpper<MT>
585 {};
587 //*************************************************************************************************
588 
589 
590 
591 
592 //=================================================================================================
593 //
594 // ISUNIUPPER SPECIALIZATIONS
595 //
596 //=================================================================================================
597 
598 //*************************************************************************************************
600 template< typename MT, bool SO >
601 struct IsUniUpper< DMatInvExpr<MT,SO> >
602  : public IsUniUpper<MT>
603 {};
605 //*************************************************************************************************
606 
607 } // namespace blaze
608 
609 #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.
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
BLAZE_ALWAYS_INLINE 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:949
Header file for basic type definitions.
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
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
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
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:87
Header file for the Computation base class.
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:87
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
Header file for the IsUniLower type trait.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:343
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:129
typename IfTrue< Condition, T1, T2 >::Type IfTrue_
Auxiliary alias declaration for the IfTrue class template.The IfTrue_ alias declaration provides a co...
Definition: If.h:109
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatInvExpr.h:133
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
DMatInvExpr(const MT &dm) noexcept
Constructor for the DMatInvExpr class.
Definition: DMatInvExpr.h:123
Constraint on the data type.
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatInvExpr.h:177
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:86
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.
ReturnType_< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatInvExpr.h:101
OppositeType_< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatInvExpr.h:98
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
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Flag for the inversion of a Hermitian matrix (same as byLDLH).
Definition: InversionFlag.h:110
Header file for the IsLower type trait.
Compile time check for diagonal matrices.This type trait tests whether or not the given template para...
Definition: IsDiagonal.h:89
ResultType_< MT > ResultType
Result type for expression template evaluations.
Definition: DMatInvExpr.h:97
Constraints on the storage order of matrix types.
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
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.
TransposeType_< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatInvExpr.h:99
Compile time check for lower unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniLower.h:86
CompositeType_< MT > CT
Composite type of the dense matrix expression.
Definition: DMatInvExpr.h:91
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
Header file for run time assertion macros.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
ResultType_< MT > RT
Result type of the dense matrix expression.
Definition: DMatInvExpr.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
Compile time check for Hermitian matrices.This type trait tests whether or not the given template par...
Definition: IsHermitian.h:85
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:816
#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
typename T::OppositeType OppositeType_
Alias declaration for nested OppositeType type definitions.The OppositeType_ alias declaration provid...
Definition: Aliases.h:263
#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:84
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3080
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatInvExpr.h:104
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
ElementType_< MT > ElementType
Resulting element type.
Definition: DMatInvExpr.h:100
Compile time evaluation of the size of vectors and matrices.The Size type trait evaluates the size of...
Definition: Size.h:80
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
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.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:908
If_< IsExpression< MT >, const MT, const MT &> Operand
Composite data type of the dense matrix expression.
Definition: DMatInvExpr.h:107
Header file for the Size type trait.
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.