Blaze 3.9
DMatDVecSolveExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATDVECSOLVEEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATDVECSOLVEEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
58#include <blaze/util/Assert.h>
60#include <blaze/util/mpl/If.h>
61#include <blaze/util/Types.h>
62
63
64namespace blaze {
65
66//=================================================================================================
67//
68// CLASS DMATDVECSOLVEEXPR
69//
70//=================================================================================================
71
72//*************************************************************************************************
79template< typename MT // Type of the dense system matrix
80 , typename VT // Type of the dense right-hand side vector
81 , bool TF > // Transpose flag
83 : public MatVecSolveExpr< DenseVector< DMatDVecSolveExpr<MT,VT,TF>, TF > >
84 , private Computation
85{
86 private:
87 //**Type definitions****************************************************************************
90 //**********************************************************************************************
91
92 public:
93 //**Type definitions****************************************************************************
96
99
104
107
109 using LeftOperand = If_t< IsExpression_v<MT>, const MT, const MT& >;
110
112 using RightOperand = If_t< IsExpression_v<VT>, const VT, const VT& >;
113 //**********************************************************************************************
114
115 //**Compilation flags***************************************************************************
117 static constexpr bool simdEnabled = false;
118
120 static constexpr bool smpAssignable = false;
121 //**********************************************************************************************
122
123 //**Constructor*********************************************************************************
129 inline DMatDVecSolveExpr( const MT& mat, const VT& vec ) noexcept
130 : mat_( mat ) // Left-hand side dense matrix of the solver expression
131 , vec_( vec ) // Right-hand side dense vector of the solver expression
132 {}
133 //**********************************************************************************************
134
135 //**Size function*******************************************************************************
140 inline size_t size() const noexcept {
141 return mat_.rows();
142 }
143 //**********************************************************************************************
144
145 //**Left operand access*************************************************************************
150 inline LeftOperand leftOperand() const noexcept {
151 return mat_;
152 }
153 //**********************************************************************************************
154
155 //**Right operand access************************************************************************
160 inline RightOperand rightOperand() const noexcept {
161 return vec_;
162 }
163 //**********************************************************************************************
164
165 //**********************************************************************************************
171 template< typename T >
172 inline bool canAlias( const T* alias ) const noexcept {
173 return ( mat_.isAliased( alias ) || vec_.isAliased( alias ) );
174 }
175 //**********************************************************************************************
176
177 //**********************************************************************************************
183 template< typename T >
184 inline bool isAliased( const T* alias ) const noexcept {
185 return ( mat_.isAliased( alias ) || vec_.isAliased( alias ) );
186 }
187 //**********************************************************************************************
188
189 private:
190 //**Member variables****************************************************************************
193 //**********************************************************************************************
194
195 //**Assignment to dense vectors*****************************************************************
207 template< typename VT2 > // Type of the target dense vector
208 friend inline void assign( DenseVector<VT2,TF>& lhs, const DMatDVecSolveExpr& rhs )
209 {
211
212 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
213
214 solve( rhs.leftOperand(), *lhs, rhs.rightOperand() );
215 }
217 //**********************************************************************************************
218
219 //**Assignment to sparse vectors****************************************************************
231 template< typename VT2 > // Type of the target sparse vector
232 friend inline void assign( SparseVector<VT2,TF>& lhs, const DMatDVecSolveExpr& rhs )
233 {
235
239
240 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
241
242 const ResultType tmp( serial( rhs ) );
243 assign( *lhs, tmp );
244 }
246 //**********************************************************************************************
247
248 //**Addition assignment to dense vectors********************************************************
260 template< typename VT2 > // Type of the target dense vector
261 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DMatDVecSolveExpr& rhs )
262 {
264
268
269 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
270
271 const ResultType tmp( serial( rhs ) );
272 addAssign( *lhs, tmp );
273 }
275 //**********************************************************************************************
276
277 //**Addition assignment to sparse vectors*******************************************************
278 // No special implementation for the addition assignment to sparse vectors.
279 //**********************************************************************************************
280
281 //**Subtraction assignment to dense vectors*****************************************************
294 template< typename VT2 > // Type of the target dense vector
295 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DMatDVecSolveExpr& rhs )
296 {
298
302
303 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
304
305 const ResultType tmp( serial( rhs ) );
306 subAssign( *lhs, tmp );
307 }
309 //**********************************************************************************************
310
311 //**Subtraction assignment to sparse vectors****************************************************
312 // No special implementation for the subtraction assignment to sparse vectors.
313 //**********************************************************************************************
314
315 //**Multiplication assignment to dense vectors**************************************************
328 template< typename VT2 > // Type of the target dense vector
329 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DMatDVecSolveExpr& rhs )
330 {
332
336
337 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
338
339 const ResultType tmp( serial( rhs ) );
340 multAssign( *lhs, tmp );
341 }
343 //**********************************************************************************************
344
345 //**Multiplication assignment to sparse vectors*************************************************
346 // No special implementation for the multiplication assignment to sparse vectors.
347 //**********************************************************************************************
348
349 //**Division assignment to dense vectors********************************************************
361 template< typename VT2 > // Type of the target dense vector
362 friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DMatDVecSolveExpr& rhs )
363 {
365
369
370 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
371
372 const ResultType tmp( serial( rhs ) );
373 divAssign( *lhs, tmp );
374 }
376 //**********************************************************************************************
377
378 //**Division assignment to sparse vectors*******************************************************
379 // No special implementation for the division assignment to sparse vectors.
380 //**********************************************************************************************
381
382 //**Compile time checks*************************************************************************
389 //**********************************************************************************************
390};
391//*************************************************************************************************
392
393
394
395
396//=================================================================================================
397//
398// GLOBAL OPERATORS
399//
400//=================================================================================================
401
402//*************************************************************************************************
472template< typename MT // Type of the system matrix
473 , bool SO // Storage order of the system matrix
474 , typename VT // Type of the right-hand side vector
475 , bool TF > // Transpose flag of the right-hand side vector
476inline decltype(auto) solve( const DenseMatrix<MT,SO>& A, const DenseVector<VT,TF>& b )
477{
479
480 if( !isSquare( *A ) ) {
481 BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square system matrix provided" );
482 }
483 else if( (*A).rows() != (*b).size() ) {
484 BLAZE_THROW_INVALID_ARGUMENT( "Invalid right-hand side vector provided" );
485 }
486
487 using ReturnType = const DMatDVecSolveExpr<MT,VT,TF>;
488 return ReturnType( *A, *b );
489}
490//*************************************************************************************************
491
492} // namespace blaze
493
494#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::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.
Deactivation of problematic macros.
Header file for the Solver trait.
Expression object for dense matrix-dense vector solvers.
Definition: DMatDVecSolveExpr.h:85
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatDVecSolveExpr.h:101
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatDVecSolveExpr.h:117
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatDVecSolveExpr.h:106
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatDVecSolveExpr.h:120
If_t< IsExpression_v< MT >, const MT, const MT & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatDVecSolveExpr.h:109
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatDVecSolveExpr.h:172
ReturnType_t< ResultType > ReturnType
Return type for expression template evaluations.
Definition: DMatDVecSolveExpr.h:103
RightOperand rightOperand() const noexcept
Returns the right-hand side dense vector operand.
Definition: DMatDVecSolveExpr.h:160
If_t< IsExpression_v< VT >, const VT, const VT & > RightOperand
Composite type of the right-hand side dense vector expression.
Definition: DMatDVecSolveExpr.h:112
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatDVecSolveExpr.h:150
ResultType_t< MT > MRT
Result type of the left-hand side dense matrix expression.
Definition: DMatDVecSolveExpr.h:88
ResultType_t< VT > VRT
Result type of the right-hand side dense vector expression.
Definition: DMatDVecSolveExpr.h:89
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatDVecSolveExpr.h:184
SolveTrait_t< MRT, VRT > ResultType
Result type for expression template evaluations.
Definition: DMatDVecSolveExpr.h:100
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DMatDVecSolveExpr.h:140
LeftOperand mat_
Left-hand side dense matrix of the solver expression.
Definition: DMatDVecSolveExpr.h:191
DMatDVecSolveExpr(const MT &mat, const VT &vec) noexcept
Constructor for the DMatDVecSolveExpr class.
Definition: DMatDVecSolveExpr.h:129
RightOperand vec_
Right-hand side dense vector of the solver expression.
Definition: DMatDVecSolveExpr.h:192
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatDVecSolveExpr.h:102
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Constraint on the data type.
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 DenseVector base class.
Header file for the MatVecSolveExpr 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) solve(const DenseMatrix< MT, SO > &A, const DenseVector< VT, TF > &b)
Solving the given linear system of equations ( ).
Definition: DMatDVecSolveExpr.h:476
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATVECSOLVEEXPR(T1, T2)
Constraint on the data type.
Definition: MatVecSolveExpr.h:104
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.
Definition: TransposeFlag.h:63
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: DenseVector.h:61
typename SolveTrait< T1, T2 >::Type SolveTrait_t
Auxiliary alias declaration for the SolveTrait class template.
Definition: SolveTrait.h:138
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.
Constraint on the data type.
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 single LSE solver expression templates.
Definition: MatVecSolveExpr.h:69
Header file for basic type definitions.