Blaze 3.9
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>
55#include <blaze/util/Assert.h>
57#include <blaze/util/mpl/If.h>
58#include <blaze/util/Types.h>
59
60
61namespace blaze {
62
63//=================================================================================================
64//
65// CLASS DMATINVEXPR
66//
67//=================================================================================================
68
69//*************************************************************************************************
75template< typename MT // Type of the dense matrix
76 , bool SO > // Storage order
78 : public MatInvExpr< DenseMatrix< DMatInvExpr<MT,SO>, SO > >
79 , private Computation
80{
81 private:
82 //**Type definitions****************************************************************************
85 //**********************************************************************************************
86
87 public:
88 //**Type definitions****************************************************************************
91
94
100
103
105 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
106 //**********************************************************************************************
107
108 //**Compilation flags***************************************************************************
110 static constexpr bool simdEnabled = false;
111
113 static constexpr bool smpAssignable = false;
114 //**********************************************************************************************
115
116 //**Constructor*********************************************************************************
121 explicit inline DMatInvExpr( const MT& dm ) noexcept
122 : dm_( dm ) // Dense matrix of the inversion expression
123 {
124 BLAZE_INTERNAL_ASSERT( isSquare( *dm ), "Non-square matrix detected" );
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 //**Assignment to dense matrices****************************************************************
199 template< typename MT2 // Type of the target dense matrix
200 , bool SO2 > // Storage order of the target dense matrix
201 friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
202 {
204
205 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
206 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
207
208 if( !isSame( *lhs, rhs.dm_ ) ) {
209 assign( *lhs, rhs.dm_ );
210 }
211
212 invert( *lhs );
213 }
215 //**********************************************************************************************
216
217 //**Assignment to sparse matrices***************************************************************
229 template< typename MT2 // Type of the target sparse matrix
230 , bool SO2 > // Storage order of the target sparse matrix
231 friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
232 {
234
236
243
244 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
245 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
246
247 const TmpType tmp( serial( rhs ) );
248 assign( *lhs, tmp );
249 }
251 //**********************************************************************************************
252
253 //**Addition assignment to dense matrices*******************************************************
265 template< typename MT2 // Type of the target dense matrix
266 , bool SO2 > // Storage order of the target dense matrix
267 friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
268 {
270
271 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
272 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
273
274 const ResultType tmp( serial( rhs ) );
275 addAssign( *lhs, tmp );
276 }
278 //**********************************************************************************************
279
280 //**Addition assignment to sparse matrices******************************************************
281 // No special implementation for the addition assignment to sparse matrices.
282 //**********************************************************************************************
283
284 //**Subtraction assignment to dense matrices****************************************************
296 template< typename MT2 // Type of the target dense matrix
297 , bool SO2 > // Storage order of the target dense matrix
298 friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
299 {
301
302 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
303 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
304
305 const ResultType tmp( serial( rhs ) );
306 subAssign( *lhs, tmp );
307 }
309 //**********************************************************************************************
310
311 //**Subtraction assignment to sparse matrices***************************************************
312 // No special implementation for the subtraction assignment to sparse matrices.
313 //**********************************************************************************************
314
315 //**Schur product assignment to dense matrices**************************************************
327 template< typename MT2 // Type of the target dense matrix
328 , bool SO2 > // Storage order of the target dense matrix
329 friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatInvExpr& rhs )
330 {
332
333 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
334 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
335
336 const ResultType tmp( serial( rhs ) );
337 schurAssign( *lhs, tmp );
338 }
340 //**********************************************************************************************
341
342 //**Schur product assignment to sparse matrices*************************************************
343 // No special implementation for the Schur product assignment to sparse matrices.
344 //**********************************************************************************************
345
346 //**Multiplication assignment to dense matrices*************************************************
347 // No special implementation for the multiplication assignment to dense matrices.
348 //**********************************************************************************************
349
350 //**Multiplication assignment to sparse matrices************************************************
351 // No special implementation for the multiplication assignment to sparse matrices.
352 //**********************************************************************************************
353
354 //**Compile time checks*************************************************************************
359 //**********************************************************************************************
360};
361//*************************************************************************************************
362
363
364
365
366//=================================================================================================
367//
368// GLOBAL OPERATORS
369//
370//=================================================================================================
371
372//*************************************************************************************************
403template< typename MT // Type of the dense matrix
404 , bool SO > // Storage order
405inline decltype(auto) inv( const DenseMatrix<MT,SO>& dm )
406{
408
409 if( !isSquare( *dm ) ) {
410 BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
411 }
412
413 using ReturnType = const DMatInvExpr<MT,SO>;
414 return ReturnType( *dm );
415}
416//*************************************************************************************************
417
418} // namespace blaze
419
420#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the invert shim.
Header file for the IsExpression type trait class.
Expression object for dense matrix inversions.
Definition: DMatInvExpr.h:80
DMatInvExpr(const MT &dm) noexcept
Constructor for the DMatInvExpr class.
Definition: DMatInvExpr.h:121
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatInvExpr.h:133
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatInvExpr.h:102
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatInvExpr.h:113
CompositeType_t< MT > CT
Composite type of the dense matrix expression.
Definition: DMatInvExpr.h:84
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatInvExpr.h:99
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatInvExpr.h:97
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatInvExpr.h:96
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the dense matrix expression.
Definition: DMatInvExpr.h:105
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatInvExpr.h:165
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatInvExpr.h:95
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatInvExpr.h:143
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatInvExpr.h:177
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatInvExpr.h:110
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatInvExpr.h:98
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatInvExpr.h:153
Operand dm_
Dense matrix of the inversion expression.
Definition: DMatInvExpr.h:184
ResultType_t< MT > RT
Result type of the dense matrix expression.
Definition: DMatInvExpr.h:83
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the MatInvExpr base class.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:405
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:693
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_SAME_STORAGE_ORDER(T1, T2)
Constraint on the data type.
Definition: StorageOrder.h:84
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
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:1424
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:1383
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for all forward declarations for expression class templates.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix inversion expression templates.
Definition: MatInvExpr.h:72
Header file for basic type definitions.