10 #ifndef _TEUCHOS_SERIALQRDENSESOLVER_MP_VECTOR_HPP_
11 #define _TEUCHOS_SERIALQRDENSESOLVER_MP_VECTOR_HPP_
27 template<
typename OrdinalType,
typename Storage>
70 base_QR_.factorWithEquilibration(flag);
75 base_QR_.solveWithTranspose(flag);
80 base_QR_.solveWithTranspose(trans);
92 int factor() {
return base_QR_.factor(); }
98 int solve() {
return base_QR_.solve(); }
105 return base_QR_.computeEquilibrateScaling();
173 bool solved() {
return base_QR_.solved(); }
211 std::vector<ScalarType>
tau()
const {
return base_QR_.tau(); }
220 void Print(std::ostream& os)
const;
268 template <
typename Ordinal,
typename Value,
typename Device>
285 new (v_vec+i)
Vector(vector_size, v+i*vector_size,
false);
291 template <
typename Ordinal,
typename Value,
typename Device,
int Num>
298 return reinterpret_cast<Value*
>(v);
303 return reinterpret_cast<Vector*
>(v);
310 using namespace details;
314 template<
typename OrdinalType,
typename Storage>
315 SerialQRDenseSolver<OrdinalType,Sacado::MP::Vector<Storage> >::
316 SerialQRDenseSolver()
318 Object(
"Teuchos::SerialQRDenseSolver"),
327 template<
typename OrdinalType,
typename Storage>
336 template<
typename OrdinalType,
typename Storage>
346 template<
typename OrdinalType,
typename Storage>
354 mat->values(), mat->stride()*mat->numCols());
358 mat->stride()*SacadoSize_,
359 mat->numRows()*SacadoSize_,
365 template<
typename OrdinalType,
typename Storage>
373 base_mat->values(), base_mat->stride()*base_mat->numCols(), SacadoSize_);
377 base_mat->stride()/SacadoSize_,
378 base_mat->numRows()/SacadoSize_,
379 base_mat->numCols()));
384 template<
typename OrdinalType,
typename Storage>
389 A->numRows() <
A->numCols(), std::invalid_argument,
390 "SerialQRDenseSolver<T>::setMatrix: the matrix A must have A.numRows() >= A.numCols()!");
399 if (Storage::is_static)
400 SacadoSize_ = Storage::static_size;
401 else if (M_ > 0 && N_ > 0)
402 SacadoSize_ = (*A)(0,0).size();
406 return base_QR_.setMatrix( createBaseMatrix(
A) );
410 template<
typename OrdinalType,
typename Storage>
418 B->numCols() != X->numCols(), std::invalid_argument,
419 "SerialQRDenseSolver<T>::setVectors: X and B have different numbers of columns!");
421 B->values()==0, std::invalid_argument,
422 "SerialQRDenseSolver<T>::setVectors: B is an empty SerialDenseMatrix<T>!");
424 X->values()==0, std::invalid_argument,
425 "SerialQRDenseSolver<T>::setVectors: X is an empty SerialDenseMatrix<T>!");
427 B->stride()<1, std::invalid_argument,
428 "SerialQRDenseSolver<T>::setVectors: B has an invalid stride!");
430 X->stride()<1, std::invalid_argument,
431 "SerialQRDenseSolver<T>::setVectors: X has an invalid stride!");
437 return base_QR_.setVectors( createBaseMatrix(X), createBaseMatrix(
B) );
442 template<
typename OrdinalType,
typename Storage>
445 int ret = base_QR_.
formQ();
446 FactorQ_ = createMatrix( base_QR_.getQ() );
452 template<
typename OrdinalType,
typename Storage>
455 int ret = base_QR_.
formR();
456 FactorR_ = createMatrix( base_QR_.getR() );
457 Factor_ = createMatrix( base_QR_.getFactoredMatrix() );
463 template<
typename OrdinalType,
typename Storage>
467 return base_QR_.
multiplyQ(transq, createBaseMatrix(C));
472 template<
typename OrdinalType,
typename Storage>
476 return base_QR_.
solveR(transr, createBaseMatrix(C));
481 template<
typename OrdinalType,
typename Storage>
483 Print(std::ostream& os)
const {
485 if (Matrix_!=
Teuchos::null) os <<
"Solver Matrix" << std::endl << *Matrix_ << std::endl;
486 if (Factor_!=
Teuchos::null) os <<
"Solver Factored Matrix" << std::endl << *Factor_ << std::endl;
487 if (LHS_ !=
Teuchos::null) os <<
"Solver LHS" << std::endl << *LHS_ << std::endl;
488 if (RHS_ !=
Teuchos::null) os <<
"Solver RHS" << std::endl << *RHS_ << std::endl;
void factorWithEquilibration(bool flag)
Causes equilibration to be called just before the matrix factorization as part of the call to factor...
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getFactoredMatrix() const
Returns pointer to factored matrix (assuming factorization has been performed).
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > FactorR_
static Value * getValueArray(Vector *v, Ordinal len)
SerialDenseMatrix< OrdinalType, ScalarType > MatrixType
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getMatrix() const
Returns pointer to current matrix.
static Vector * getVectorArray(Value *v, Ordinal len, Ordinal vector_size)
OrdinalType numRows() const
Returns row dimension of system.
int equilibrateRHS()
Equilibrates the current RHS.
int setMatrix(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &A)
bool factored()
Returns true if matrix is factored (factor available via getFactoredMatrix()).
static Value * getValueArray(Vector *v, Ordinal len)
int multiplyQ(ETransp transq, SerialDenseMatrix< OrdinalType, ScalarType > &C)
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getRHS() const
Returns pointer to current RHS.
int solveR(ETransp transr, SerialDenseMatrix< OrdinalType, ScalarType > &C)
RCP< BaseMatrixType > Base_RHS_
Statically allocated storage class.
RCP< BaseMatrixType > Base_Matrix_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< BaseMatrixType > Base_Factor_
bool equilibratedB()
Returns true if RHS is equilibrated (RHS available via getRHS()).
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > LHS_
SerialQRDenseSolver & operator=(const SerialQRDenseSolver< OrdinalType, ScalarType > &Source)
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getLHS() const
Returns pointer to current LHS.
Stokhos::StaticFixedStorage< Ordinal, Value, Num, Device > Storage
bool shouldEquilibrate()
Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system...
void solveWithTranspose(bool flag)
If flag is true, causes all subsequent function calls to work with the adjoint of this matrix...
Templated class for solving dense linear problems.
virtual ~SerialQRDenseSolver()
SerialQRDenseSolver destructor.
Sacado::MP::Vector< Storage > Vector
RCP< MatrixType > FactorR_
OrdinalType numCols() const
Returns column dimension of system.
Specialization for Sacado::UQ::PCE< Storage<...> >
SerialDenseMatrix< OrdinalType, BaseScalarType > BaseMatrixType
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > Matrix_
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static Vector * getVectorArray(Value *v, Ordinal len, Ordinal vector_size)
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > FactorQ_
ScalarType::value_type BaseScalarType
MagnitudeType ANORM() const
Returns the absolute value of the largest element of this matrix (returns -1 if not yet computed)...
bool solved()
Returns true if the current set of vectors has been solved.
void Print(std::ostream &os) const
int unequilibrateLHS()
Unscales the solution vectors if equilibration was used to solve the system.
bool formedQ()
Returns true if Q has been formed explicitly.
bool equilibratedA()
Returns true if factor is equilibrated (factor available via getFactoredMatrix()).
RCP< MatrixType > Factor_
RCP< MatrixType > FactorQ_
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > Factor_
std::vector< ScalarType > tau() const
Returns pointer to pivot vector (if factorization has been computed), zero otherwise.
bool formedR()
Returns true if R has been formed explicitly.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > RHS_
SerialQRDenseSolver< OrdinalType, BaseScalarType > BaseQRType
ScalarTraits< ScalarType >::magnitudeType MagnitudeType
RCP< BaseMatrixType > Base_FactorR_
int computeEquilibrateScaling()
Determines if this matrix should be scaled.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getR() const
Returns pointer to R (assuming factorization has been performed).
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getQ() const
Returns pointer to Q (assuming factorization has been performed).
RCP< BaseMatrixType > Base_LHS_
int solve()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
RCP< BaseMatrixType > Base_FactorQ_
RCP< MatrixType > Matrix_
Sacado::MP::Vector< Storage > ScalarType
int factor()
Computes the in-place QR factorization of the matrix using the LAPACK routine _GETRF or the Eigen cla...
Stokhos::DynamicStorage< Ordinal, Value, Device > Storage
int equilibrateMatrix()
Equilibrates the this matrix.
void solveWithTransposeFlag(Teuchos::ETransp trans)
All subsequent function calls will work with the transpose-type set by this method (Teuchos::NO_TRANS...
Sacado::MP::Vector< Storage > Vector
int setVectors(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &B)
bool transpose()
Returns true if adjoint of this matrix has and will be used.