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 
63 #include <blaze/util/Assert.h>
65 #include <blaze/util/Exception.h>
66 #include <blaze/util/InvalidType.h>
68 #include <blaze/util/SelectType.h>
69 #include <blaze/util/Types.h>
71 
72 
73 namespace blaze {
74 
75 //=================================================================================================
76 //
77 // CLASS DMATINVEXPR
78 //
79 //=================================================================================================
80 
81 //*************************************************************************************************
87 template< typename MT // Type of the dense matrix
88  , bool SO > // Storage order
89 class DMatInvExpr : public DenseMatrix< DMatInvExpr<MT,SO>, SO >
90  , private MatInvExpr
91  , private Computation
92 {
93  private:
94  //**Type definitions****************************************************************************
95  typedef typename MT::ResultType RT;
96  typedef typename MT::CompositeType CT;
97  //**********************************************************************************************
98 
99  public:
100  //**Type definitions****************************************************************************
102  typedef typename MT::ResultType ResultType;
103  typedef typename MT::OppositeType OppositeType;
104  typedef typename MT::TransposeType TransposeType;
105  typedef typename MT::ElementType ElementType;
106  typedef typename MT::ReturnType ReturnType;
107 
109  typedef const ResultType CompositeType;
110 
112  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
113  //**********************************************************************************************
114 
115  //**Compilation flags***************************************************************************
117  enum { vectorizable = 0 };
118 
120  enum { smpAssignable = 0 };
121  //**********************************************************************************************
122 
123  //**Constructor*********************************************************************************
128  explicit inline DMatInvExpr( const MT& dm )
129  : dm_( dm ) // Dense matrix of the inversion expression
130  {}
131  //**********************************************************************************************
132 
133  //**Rows function*******************************************************************************
138  inline size_t rows() const {
139  return dm_.columns();
140  }
141  //**********************************************************************************************
142 
143  //**Columns function****************************************************************************
148  inline size_t columns() const {
149  return dm_.rows();
150  }
151  //**********************************************************************************************
152 
153  //**Operand access******************************************************************************
158  inline Operand operand() const {
159  return dm_;
160  }
161  //**********************************************************************************************
162 
163  //**********************************************************************************************
169  template< typename T >
170  inline bool canAlias( const T* alias ) const {
171  return dm_.isAliased( alias );
172  }
173  //**********************************************************************************************
174 
175  //**********************************************************************************************
181  template< typename T >
182  inline bool isAliased( const T* alias ) const {
183  return dm_.isAliased( alias );
184  }
185  //**********************************************************************************************
186 
187  private:
188  //**Member variables****************************************************************************
189  Operand dm_;
190  //**********************************************************************************************
191 
192  //**Assignment to dense matrices****************************************************************
204  template< typename MT2 // Type of the target dense matrix
205  , bool SO2 > // Storage order of the target dense matrix
206  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
207  {
209 
210  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
211  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
212 
213  assign( ~lhs, rhs.dm_ );
214  invert( ~lhs );
215  }
217  //**********************************************************************************************
218 
219  //**Assignment to sparse matrices***************************************************************
231  template< typename MT2 // Type of the target sparse matrix
232  , bool SO2 > // Storage order of the target sparse matrix
233  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
234  {
236 
238 
245 
246  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
247  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
248 
249  const TmpType tmp( serial( rhs ) );
250  assign( ~lhs, tmp );
251  }
253  //**********************************************************************************************
254 
255  //**Addition assignment to dense matrices*******************************************************
267  template< typename MT2 // Type of the target dense matrix
268  , bool SO2 > // Storage order of the target dense matrix
269  friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
270  {
272 
273  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
274  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
275 
276  const ResultType tmp( serial( rhs ) );
277  addAssign( ~lhs, tmp );
278  }
280  //**********************************************************************************************
281 
282  //**Addition assignment to sparse matrices******************************************************
283  // No special implementation for the addition assignment to sparse matrices.
284  //**********************************************************************************************
285 
286  //**Subtraction assignment to dense matrices****************************************************
298  template< typename MT2 // Type of the target dense matrix
299  , bool SO2 > // Storage order of the target dense matrix
300  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
301  {
303 
304  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
305  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
306 
307  const ResultType tmp( serial( rhs ) );
308  subAssign( ~lhs, tmp );
309  }
311  //**********************************************************************************************
312 
313  //**Subtraction assignment to sparse matrices***************************************************
314  // No special implementation for the subtraction assignment to sparse matrices.
315  //**********************************************************************************************
316 
317  //**Multiplication assignment to dense matrices*************************************************
318  // No special implementation for the multiplication assignment to dense matrices.
319  //**********************************************************************************************
320 
321  //**Multiplication assignment to sparse matrices************************************************
322  // No special implementation for the multiplication assignment to sparse matrices.
323  //**********************************************************************************************
324 
325  //**Compile time checks*************************************************************************
330  //**********************************************************************************************
331 };
332 //*************************************************************************************************
333 
334 
335 
336 
337 //=================================================================================================
338 //
339 // GLOBAL OPERATORS
340 //
341 //=================================================================================================
342 
343 //*************************************************************************************************
373 template< typename MT // Type of the dense matrix
374  , bool SO > // Storage order
375 inline const DMatInvExpr<MT,SO> inv( const DenseMatrix<MT,SO>& dm )
376 {
378 
379  if( !isSquare( ~dm ) ) {
380  BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
381  }
382 
383  return DMatInvExpr<MT,SO>( ~dm );
384 }
385 //*************************************************************************************************
386 
387 
388 
389 
390 //=================================================================================================
391 //
392 // GLOBAL RESTRUCTURING FUNCTIONS
393 //
394 //=================================================================================================
395 
396 //*************************************************************************************************
416 template< typename MT // Type of the dense matrix
417  , bool SO > // Storage order
418 inline typename DMatInvExpr<MT,SO>::Operand inv( const DMatInvExpr<MT,SO>& dm )
419 {
421 
422  return dm.operand();
423 }
425 //*************************************************************************************************
426 
427 
428 
429 
430 //=================================================================================================
431 //
432 // ROWS SPECIALIZATIONS
433 //
434 //=================================================================================================
435 
436 //*************************************************************************************************
438 template< typename MT, bool SO >
439 struct Rows< DMatInvExpr<MT,SO> > : public Rows<MT>
440 {};
442 //*************************************************************************************************
443 
444 
445 
446 
447 //=================================================================================================
448 //
449 // COLUMNS SPECIALIZATIONS
450 //
451 //=================================================================================================
452 
453 //*************************************************************************************************
455 template< typename MT, bool SO >
456 struct Columns< DMatInvExpr<MT,SO> > : public Columns<MT>
457 {};
459 //*************************************************************************************************
460 
461 
462 
463 
464 //=================================================================================================
465 //
466 // ISSYMMETRIC SPECIALIZATIONS
467 //
468 //=================================================================================================
469 
470 //*************************************************************************************************
472 template< typename MT, bool SO >
473 struct IsSymmetric< DMatInvExpr<MT,SO> > : public IsTrue< IsSymmetric<MT>::value >
474 {};
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // ISHERMITIAN SPECIALIZATIONS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
489 template< typename MT, bool SO >
490 struct IsHermitian< DMatInvExpr<MT,SO> > : public IsTrue< IsHermitian<MT>::value >
491 {};
493 //*************************************************************************************************
494 
495 
496 
497 
498 //=================================================================================================
499 //
500 // ISLOWER SPECIALIZATIONS
501 //
502 //=================================================================================================
503 
504 //*************************************************************************************************
506 template< typename MT, bool SO >
507 struct IsLower< DMatInvExpr<MT,SO> > : public IsTrue< IsUpper<MT>::value >
508 {};
510 //*************************************************************************************************
511 
512 
513 
514 
515 //=================================================================================================
516 //
517 // ISUNILOWER SPECIALIZATIONS
518 //
519 //=================================================================================================
520 
521 //*************************************************************************************************
523 template< typename MT, bool SO >
524 struct IsUniLower< DMatInvExpr<MT,SO> > : public IsTrue< IsUniUpper<MT>::value >
525 {};
527 //*************************************************************************************************
528 
529 
530 
531 
532 //=================================================================================================
533 //
534 // ISUPPER SPECIALIZATIONS
535 //
536 //=================================================================================================
537 
538 //*************************************************************************************************
540 template< typename MT, bool SO >
541 struct IsUpper< DMatInvExpr<MT,SO> > : public IsTrue< IsLower<MT>::value >
542 {};
544 //*************************************************************************************************
545 
546 
547 
548 
549 //=================================================================================================
550 //
551 // ISUNIUPPER SPECIALIZATIONS
552 //
553 //=================================================================================================
554 
555 //*************************************************************************************************
557 template< typename MT, bool SO >
558 struct IsUniUpper< DMatInvExpr<MT,SO> > : public IsTrue< IsUniLower<MT>::value >
559 {};
561 //*************************************************************************************************
562 
563 
564 
565 
566 //=================================================================================================
567 //
568 // EXPRESSION TRAIT SPECIALIZATIONS
569 //
570 //=================================================================================================
571 
572 //*************************************************************************************************
574 template< typename MT >
575 struct DMatInvExprTrait< DMatInvExpr<MT,false> >
576 {
577  public:
578  //**********************************************************************************************
579  typedef typename SelectType< IsDenseMatrix<MT>::value && IsRowMajorMatrix<MT>::value
580  , typename DMatInvExpr<MT,false>::Operand
581  , INVALID_TYPE >::Type Type;
582  //**********************************************************************************************
583 };
585 //*************************************************************************************************
586 
587 
588 //*************************************************************************************************
590 template< typename MT >
591 struct TDMatInvExprTrait< DMatInvExpr<MT,true> >
592 {
593  public:
594  //**********************************************************************************************
595  typedef typename SelectType< IsDenseMatrix<MT>::value && IsColumnMajorMatrix<MT>::value
596  , typename DMatInvExpr<MT,true>::Operand
597  , INVALID_TYPE >::Type Type;
598  //**********************************************************************************************
599 };
601 //*************************************************************************************************
602 
603 } // namespace blaze
604 
605 #endif
MT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DMatInvExpr.h:104
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
Operand dm_
Dense matrix of the inversion expression.
Definition: DMatInvExpr.h:189
Header file for the Rows type trait.
Header file for the IsUniUpper type trait.
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix)
Checks if the given matrix is a square matrix.
Definition: Matrix.h:603
MT::CompositeType CT
Composite type of the dense matrix expression.
Definition: DMatInvExpr.h:96
#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:81
Header file for the TDMatInvExprTrait class template.
Operand operand() const
Returns the dense matrix operand.
Definition: DMatInvExpr.h:158
#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:79
Header file for the IsColumnMajorMatrix type trait.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DMatInvExpr.h:148
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
Header file for the Computation base class.
Header file for the MatInvExpr base class.
DMatInvExpr(const MT &dm)
Constructor for the DMatInvExpr class.
Definition: DMatInvExpr.h:128
Header file for the IsUniLower type trait.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2584
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:117
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DMatInvExpr.h:182
Constraint on the data type.
Constraint on the data type.
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:767
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the DenseMatrix base class.
Header file for the Columns type trait.
Header file for the IsLower type trait.
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:78
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2585
Constraints on the storage order of matrix types.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Header file for the serial shim.
Header file for the DMatInvExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for run time assertion macros.
Utility type for generic codes.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DMatInvExpr.h:106
MT::ResultType ResultType
Result type for expression template evaluations.
Definition: DMatInvExpr.h:102
Base class for all matrix inversion expression templates.The MatInvExpr class serves as a tag for all...
Definition: MatInvExpr.h:65
DMatInvExpr< MT, SO > This
Type of this DMatInvExpr instance.
Definition: DMatInvExpr.h:101
MT::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatInvExpr.h:103
#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:122
Expression object for dense matrix inversions.The DMatInvExpr class represents the compile time expre...
Definition: DMatInvExpr.h:89
MT::ResultType RT
Result type of the dense matrix expression.
Definition: DMatInvExpr.h:95
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DMatInvExpr.h:170
Header file for the IsRowMajorMatrix type trait.
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: DMatInvExpr.h:112
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatInvExpr.h:109
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
Header file for the IsTrue value trait.
Header file for the IsUpper type trait.
Header file for exception macros.
MT::ElementType ElementType
Resulting element type.
Definition: DMatInvExpr.h:105
Header file for the IsHermitian type trait.
const DMatInvExpr< MT, SO > inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:375
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DMatInvExpr.h:138
#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 FunctionTrace class.