Blaze 3.9
DMatDMatSolveExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATDMATSOLVEEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATDMATSOLVEEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
56#include <blaze/util/Assert.h>
58#include <blaze/util/mpl/If.h>
59#include <blaze/util/Types.h>
60
61
62namespace blaze {
63
64//=================================================================================================
65//
66// CLASS DMATDMATSOLVEEXPR
67//
68//=================================================================================================
69
70//*************************************************************************************************
77template< typename MT1 // Type of the dense system matrix
78 , typename MT2 // Type of the dense right-hand side matrix
79 , bool SO > // Storage order
81 : public MatMatSolveExpr< DenseMatrix< DMatDMatSolveExpr<MT1,MT2,SO>, SO > >
82 , private Computation
83{
84 private:
85 //**Type definitions****************************************************************************
88 //**********************************************************************************************
89
90 public:
91 //**Type definitions****************************************************************************
94
97
103
106
108 using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
109
111 using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
112 //**********************************************************************************************
113
114 //**Compilation flags***************************************************************************
116 static constexpr bool simdEnabled = false;
117
119 static constexpr bool smpAssignable = false;
120 //**********************************************************************************************
121
122 //**Constructor*********************************************************************************
128 inline DMatDMatSolveExpr( const MT1& lhs, const MT2& rhs ) noexcept
129 : lhs_( lhs ) // Left-hand side dense matrix of the solver expression
130 , rhs_( rhs ) // Right-hand side dense matrix of the solver expression
131 {}
132 //**********************************************************************************************
133
134 //**Rows function*******************************************************************************
139 inline size_t rows() const noexcept {
140 return rhs_.rows();
141 }
142 //**********************************************************************************************
143
144 //**Columns function****************************************************************************
149 inline size_t columns() const noexcept {
150 return rhs_.columns();
151 }
152 //**********************************************************************************************
153
154 //**Left operand access*************************************************************************
159 inline LeftOperand leftOperand() const noexcept {
160 return lhs_;
161 }
162 //**********************************************************************************************
163
164 //**Right operand access************************************************************************
169 inline RightOperand rightOperand() const noexcept {
170 return rhs_;
171 }
172 //**********************************************************************************************
173
174 //**********************************************************************************************
180 template< typename T >
181 inline bool canAlias( const T* alias ) const noexcept {
182 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
183 }
184 //**********************************************************************************************
185
186 //**********************************************************************************************
192 template< typename T >
193 inline bool isAliased( const T* alias ) const noexcept {
194 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
195 }
196 //**********************************************************************************************
197
198 private:
199 //**Member variables****************************************************************************
202 //**********************************************************************************************
203
204 //**Assignment to dense matrices****************************************************************
216 template< typename MT // Type of the target dense matrix
217 , bool SO2 > // Storage order of the target dense matrix
218 friend inline void assign( DenseMatrix<MT,SO2>& lhs, const DMatDMatSolveExpr& rhs )
219 {
221
222 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
223 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
224
225 solve( rhs.leftOperand(), *lhs, rhs.rightOperand() );
226 }
228 //**********************************************************************************************
229
230 //**Assignment to sparse matrices***************************************************************
242 template< typename MT // Type of the target sparse matrix
243 , bool SO2 > // Storage order of the target sparse matrix
244 friend inline void assign( SparseMatrix<MT,SO2>& lhs, const DMatDMatSolveExpr& rhs )
245 {
247
249
256
257 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
258 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
259
260 const TmpType tmp( serial( rhs ) );
261 assign( *lhs, tmp );
262 }
264 //**********************************************************************************************
265
266 //**Addition assignment to dense matrices*******************************************************
278 template< typename MT // Type of the target dense matrix
279 , bool SO2 > // Storage order of the target dense matrix
280 friend inline void addAssign( DenseMatrix<MT,SO2>& lhs, const DMatDMatSolveExpr& rhs )
281 {
283
287
288 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
289 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
290
291 const ResultType tmp( serial( rhs ) );
292 addAssign( *lhs, tmp );
293 }
295 //**********************************************************************************************
296
297 //**Addition assignment to sparse matrices******************************************************
298 // No special implementation for the addition assignment to sparse matrices.
299 //**********************************************************************************************
300
301 //**Subtraction assignment to dense matrices****************************************************
314 template< typename MT // Type of the target dense matrix
315 , bool SO2 > // Storage order of the target dense matrix
316 friend inline void subAssign( DenseMatrix<MT,SO2>& lhs, const DMatDMatSolveExpr& rhs )
317 {
319
323
324 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
325 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
326
327 const ResultType tmp( serial( rhs ) );
328 subAssign( *lhs, tmp );
329 }
331 //**********************************************************************************************
332
333 //**Subtraction assignment to sparse matrices***************************************************
334 // No special implementation for the subtraction assignment to sparse matrices.
335 //**********************************************************************************************
336
337 //**Schur product assignment to dense matrices**************************************************
350 template< typename MT // Type of the target dense matrix
351 , bool SO2 > // Storage order of the target dense matrix
352 friend inline void schurAssign( DenseMatrix<MT,SO2>& lhs, const DMatDMatSolveExpr& rhs )
353 {
355
359
360 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
361 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
362
363 const ResultType tmp( serial( rhs ) );
364 schurAssign( *lhs, tmp );
365 }
367 //**********************************************************************************************
368
369 //**Schur product assignment to sparse matrices*************************************************
370 // No special implementation for the Schur product assignment to sparse matrices.
371 //**********************************************************************************************
372
373 //**Multiplication assignment to dense matrices*************************************************
374 // No special implementation for the multiplication assignment to dense matrices.
375 //**********************************************************************************************
376
377 //**Multiplication assignment to sparse matrices************************************************
378 // No special implementation for the multiplication assignment to sparse matrices.
379 //**********************************************************************************************
380
381 //**Compile time checks*************************************************************************
388 //**********************************************************************************************
389};
390//*************************************************************************************************
391
392
393
394
395//=================================================================================================
396//
397// GLOBAL OPERATORS
398//
399//=================================================================================================
400
401//*************************************************************************************************
471template< typename MT1 // Type of the system matrix
472 , bool SO1 // Storage order of the system matrix
473 , typename MT2 // Type of the right-hand side matrix
474 , bool SO2 > // Storage order of the right-hand side matrix
475inline decltype(auto) solve( const DenseMatrix<MT1,SO1>& A, const DenseMatrix<MT2,SO2>& B )
476{
478
479 if( !isSquare( *A ) ) {
480 BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square system matrix provided" );
481 }
482 else if( (*A).rows() != (*B).rows() ) {
483 BLAZE_THROW_INVALID_ARGUMENT( "Invalid right-hand side matrix provided" );
484 }
485
486 using ReturnType = const DMatDMatSolveExpr<MT1,MT2,SO2>;
487 return ReturnType( *A, *B );
488}
489//*************************************************************************************************
490
491
492
493
494//=================================================================================================
495//
496// GLOBAL RESTRUCTURING FUNCTIONS
497//
498//=================================================================================================
499
500//*************************************************************************************************
517template< typename MT1 // Type of the dense system matrix
518 , typename MT2 // Type of the dense right-hand side matrix
519 , bool SO > // Storage order
520inline decltype(auto) det( const DMatDMatSolveExpr<MT1,MT2,SO>& dm )
521{
523
524 return det( evaluate( *dm ) );
525}
527//*************************************************************************************************
528
529} // namespace blaze
530
531#endif
Header file for auxiliary alias declarations.
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 IsExpression type trait class.
Header file for the Solver trait.
Expression object for dense matrix-dense matrix solvers.
Definition: DMatDMatSolveExpr.h:83
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatDMatSolveExpr.h:86
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatDMatSolveExpr.h:149
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: DMatDMatSolveExpr.h:87
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatDMatSolveExpr.h:105
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatDMatSolveExpr.h:139
LeftOperand lhs_
Left-hand side dense matrix of the solver expression.
Definition: DMatDMatSolveExpr.h:200
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatDMatSolveExpr.h:119
DMatDMatSolveExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the DMatDMatSolveExpr class.
Definition: DMatDMatSolveExpr.h:128
RightOperand rhs_
Right-hand side dense matrix of the solver expression.
Definition: DMatDMatSolveExpr.h:201
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: DMatDMatSolveExpr.h:169
SolveTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DMatDMatSolveExpr.h:98
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: DMatDMatSolveExpr.h:111
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatDMatSolveExpr.h:99
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatDMatSolveExpr.h:100
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatDMatSolveExpr.h:159
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatDMatSolveExpr.h:181
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatDMatSolveExpr.h:101
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatDMatSolveExpr.h:116
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatDMatSolveExpr.h:193
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatDMatSolveExpr.h:108
ReturnType_t< ResultType > ReturnType
Return type for expression template evaluations.
Definition: DMatDMatSolveExpr.h:102
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.
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the MatMatSolveExpr 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
ElementType_t< MT > det(const DenseMatrix< MT, SO > &dm)
Computation of the determinant of the given dense square matrix.
Definition: DMatDetExpr.h:384
decltype(auto) solve(const DenseMatrix< MT1, SO1 > &A, const DenseMatrix< MT2, SO2 > &B)
Solving the given linear system of equations ( ).
Definition: DMatDMatSolveExpr.h:475
#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_FORM_VALID_MATMATSOLVEEXPR(T1, T2)
Constraint on the data type.
Definition: MatMatSolveExpr.h:103
#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
typename SolveTrait< T1, T2 >::Type SolveTrait_t
Auxiliary alias declaration for the SolveTrait class template.
Definition: SolveTrait.h:138
MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:1282
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 multi LSE solver expression templates.
Definition: MatMatSolveExpr.h:69
Header file for basic type definitions.