42#ifndef ANASAZI_MULTI_VEC_HPP
43#define ANASAZI_MULTI_VEC_HPP
89template <
class ScalarType>
106 virtual MultiVec<ScalarType> *
Clone (
const int numvecs )
const = 0;
118 virtual MultiVec<ScalarType> *
CloneCopy (
const std::vector<int>& index )
const = 0;
134 virtual const MultiVec<ScalarType> *
CloneView (
const std::vector<int>& index )
const = 0;
153 const MultiVec<ScalarType>& A,
154 const Teuchos::SerialDenseMatrix<int,ScalarType>& B, ScalarType beta) = 0;
157 virtual void MvAddMv ( ScalarType alpha,
const MultiVec<ScalarType>& A, ScalarType beta,
const MultiVec<ScalarType>& B ) = 0;
160 virtual void MvScale ( ScalarType alpha ) = 0;
163 virtual void MvScale (
const std::vector<ScalarType>& alpha ) = 0;
168 virtual void MvTransMv ( ScalarType alpha,
const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B
169#ifdef HAVE_ANASAZI_EXPERIMENTAL
179 virtual void MvDot (
const MultiVec<ScalarType>& A, std::vector<ScalarType> & b
180#ifdef HAVE_ANASAZI_EXPERIMENTAL
193 virtual void MvNorm ( std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec )
const = 0;
203 virtual void SetBlock (
const MultiVec<ScalarType>& A,
const std::vector<int>& index ) = 0;
209 virtual void MvInit ( ScalarType alpha ) = 0;
216 virtual void MvPrint ( std::ostream& os )
const = 0;
219#ifdef HAVE_ANASAZI_TSQR
246 factorExplicit (MultiVec<ScalarType>& Q,
247 Teuchos::SerialDenseMatrix<int, ScalarType>& R,
248 const bool forceNonnegativeDiagonal=
false)
250 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"The Anasazi::MultiVec<"
251 << Teuchos::TypeNameTraits<ScalarType>::name() <<
"> subclass which you "
252 "are using does not implement the TSQR-related method factorExplicit().");
290 revealRank (Teuchos::SerialDenseMatrix<int, ScalarType>& R,
291 const typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& tol)
293 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"The Anasazi::MultiVec<"
294 << Teuchos::TypeNameTraits<ScalarType>::name() <<
"> subclass which you "
295 "are using does not implement the TSQR-related method revealRank().");
320template<
class ScalarType>
323 typedef MultiVec<ScalarType> MV;
324 typedef ScalarType scalar_type;
325 typedef int ordinal_type;
326 typedef int node_type;
327 typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type;
328 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
334 dense_matrix_type& R,
335 const bool forceNonnegativeDiagonal=
false)
337 A.factorExplicit (Q, R, forceNonnegativeDiagonal);
343 dense_matrix_type& R,
344 const magnitude_type& tol)
346 return Q.revealRank (R, tol);
360 template<
class ScalarType>
368 static Teuchos::RCP<MultiVec<ScalarType> >
369 Clone (
const MultiVec<ScalarType>& mv,
const int numvecs) {
370 return Teuchos::rcp (
const_cast<MultiVec<ScalarType>&
> (mv).
Clone (numvecs));
377 static Teuchos::RCP<MultiVec<ScalarType> >
CloneCopy(
const MultiVec<ScalarType>& mv )
378 {
return Teuchos::rcp(
const_cast<MultiVec<ScalarType>&
>(mv).
CloneCopy() ); }
385 static Teuchos::RCP<MultiVec<ScalarType> >
CloneCopy(
const MultiVec<ScalarType>& mv,
const std::vector<int>& index )
386 {
return Teuchos::rcp(
const_cast<MultiVec<ScalarType>&
>(mv).
CloneCopy(index) ); }
393 static Teuchos::RCP<MultiVec<ScalarType> >
CloneViewNonConst( MultiVec<ScalarType>& mv,
const std::vector<int>& index )
394 {
return Teuchos::rcp( mv.CloneViewNonConst(index) ); }
401 static Teuchos::RCP<const MultiVec<ScalarType> >
CloneView(
const MultiVec<ScalarType>& mv,
const std::vector<int>& index )
402 {
return Teuchos::rcp(
const_cast<MultiVec<ScalarType>&
>(mv).
CloneView(index) ); }
411 {
return mv.GetGlobalLength(); }
415 {
return mv.GetNumberVecs(); }
425 const Teuchos::SerialDenseMatrix<int,ScalarType>& B,
426 ScalarType beta, MultiVec<ScalarType>& mv )
427 { mv.MvTimesMatAddMv(alpha, A, B, beta); }
431 static void MvAddMv( ScalarType alpha,
const MultiVec<ScalarType>& A, ScalarType beta,
const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv )
432 { mv.MvAddMv(alpha, A, beta, B); }
436 static void MvTransMv( ScalarType alpha,
const MultiVec<ScalarType>& A,
const MultiVec<ScalarType>& mv, Teuchos::SerialDenseMatrix<int,ScalarType>& B
437#ifdef HAVE_ANASAZI_EXPERIMENTAL
441 { mv.MvTransMv(alpha, A, B
442#ifdef HAVE_ANASAZI_EXPERIMENTAL
449 static void MvDot(
const MultiVec<ScalarType>& mv,
const MultiVec<ScalarType>& A, std::vector<ScalarType> & b
450#ifdef HAVE_ANASAZI_EXPERIMENTAL
455#ifdef HAVE_ANASAZI_EXPERIMENTAL
461 static void MvScale ( MultiVec<ScalarType>& mv, ScalarType alpha )
462 { mv.MvScale( alpha ); }
465 static void MvScale ( MultiVec<ScalarType>& mv,
const std::vector<ScalarType>& alpha )
466 { mv.MvScale( alpha ); }
475 static void MvNorm(
const MultiVec<ScalarType>& mv, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec )
476 { mv.MvNorm(normvec); }
486 static void SetBlock(
const MultiVec<ScalarType>& A,
const std::vector<int>& index, MultiVec<ScalarType>& mv )
487 { mv.SetBlock(A, index); }
496 static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() )
497 { mv.MvInit(alpha); }
504 static void MvPrint(
const MultiVec<ScalarType>& mv, std::ostream& os )
509#ifdef HAVE_ANASAZI_TSQR
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Declaration of basic traits for the multivector type.
static Teuchos::RCP< MultiVec< ScalarType > > CloneViewNonConst(MultiVec< ScalarType > &mv, const std::vector< int > &index)
Creates a new Anasazi::MultiVec that shares the selected contents of mv (shallow copy).
static int GetNumberVecs(const MultiVec< ScalarType > &mv)
Obtain the number of vectors in mv.
static Teuchos::RCP< const MultiVec< ScalarType > > CloneView(const MultiVec< ScalarType > &mv, const std::vector< int > &index)
Creates a new const Anasazi::MultiVec that shares the selected contents of mv (shallow copy).
static void MvScale(MultiVec< ScalarType > &mv, const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
static void MvTimesMatAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, ScalarType beta, MultiVec< ScalarType > &mv)
Update mv with .
static void MvTransMv(ScalarType alpha, const MultiVec< ScalarType > &A, const MultiVec< ScalarType > &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
static void MvRandom(MultiVec< ScalarType > &mv)
Replace the vectors in mv with random vectors.
static void MvInit(MultiVec< ScalarType > &mv, ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
static void SetBlock(const MultiVec< ScalarType > &A, const std::vector< int > &index, MultiVec< ScalarType > &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index.
static Teuchos::RCP< MultiVec< ScalarType > > CloneCopy(const MultiVec< ScalarType > &mv, const std::vector< int > &index)
Creates a new Anasazi::MultiVec and copies the selected contents of mv into the new vector (deep copy...
static Teuchos::RCP< MultiVec< ScalarType > > CloneCopy(const MultiVec< ScalarType > &mv)
Creates a new Anasazi::MultiVec and copies contents of mv into the new vector (deep copy).
static Teuchos::RCP< MultiVec< ScalarType > > Clone(const MultiVec< ScalarType > &mv, const int numvecs)
Create a new empty MultiVec containing numvecs columns.
static ptrdiff_t GetGlobalLength(const MultiVec< ScalarType > &mv)
Obtain the vector length of mv.
static void MvPrint(const MultiVec< ScalarType > &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
static void MvNorm(const MultiVec< ScalarType > &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec)
Compute the 2-norm of each individual vector of mv. Upon return, normvec[i] holds the value of ,...
static void MvAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, ScalarType beta, const MultiVec< ScalarType > &B, MultiVec< ScalarType > &mv)
Replace mv with .
static void MvScale(MultiVec< ScalarType > &mv, ScalarType alpha)
Scale each element of the vectors in *this with alpha.
static void MvDot(const MultiVec< ScalarType > &mv, const MultiVec< ScalarType > &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
Interface for multivectors used by Anasazi's linear solvers.
virtual int GetNumberVecs() const =0
The number of vectors (i.e., columns) in the multivector.
virtual void MvDot(const MultiVec< ScalarType > &A, std::vector< ScalarType > &b) const =0
Compute the dot product of each column of *this with the corresponding column of A.
virtual void MvAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, ScalarType beta, const MultiVec< ScalarType > &B)=0
Replace *this with alpha * A + beta * B.
virtual void MvTimesMatAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, ScalarType beta)=0
Update *this with alpha * A * B + beta * (*this).
virtual void MvScale(const std::vector< ScalarType > &alpha)=0
Scale each element of the i-th vector in *this with alpha[i].
virtual const MultiVec< ScalarType > * CloneView(const std::vector< int > &index) const =0
Creates a new Anasazi::MultiVec that shares the selected contents of *this. The index of the numvecs ...
virtual MultiVec< ScalarType > * CloneCopy(const std::vector< int > &index) const =0
Creates a new Anasazi::MultiVec and copies the selected contents of *this into the new vector (deep c...
virtual ptrdiff_t GetGlobalLength() const =0
The number of rows in the multivector.
virtual void MvNorm(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const =0
Compute the 2-norm of each vector in *this.
virtual void MvScale(ScalarType alpha)=0
Scale each element of the vectors in *this with alpha.
virtual MultiVec< ScalarType > * CloneViewNonConst(const std::vector< int > &index)=0
Creates a new Anasazi::MultiVec that shares the selected contents of *this. The index of the numvecs ...
virtual void MvTransMv(ScalarType alpha, const MultiVec< ScalarType > &A, Teuchos::SerialDenseMatrix< int, ScalarType > &B) const =0
Compute a dense matrix B through the matrix-matrix multiply alpha * A^T * (*this).
virtual void MvRandom()=0
Fill all the vectors in *this with random numbers.
virtual void SetBlock(const MultiVec< ScalarType > &A, const std::vector< int > &index)=0
Copy the vectors in A to a set of vectors in *this.
virtual MultiVec< ScalarType > * Clone(const int numvecs) const =0
Create a new MultiVec with numvecs columns.
MultiVec()
Default constructor.
virtual MultiVec< ScalarType > * CloneCopy() const =0
Create a new MultiVec and copy contents of *this into it (deep copy).
virtual void MvPrint(std::ostream &os) const =0
Print *this multivector to the os output stream.
virtual void MvInit(ScalarType alpha)=0
Replace each element of the vectors in *this with alpha.
virtual ~MultiVec()
Destructor (virtual for memory safety of derived classes).
TSQR adapter for MultiVec.
void factorExplicit(MV &A, MV &Q, dense_matrix_type &R, const bool forceNonnegativeDiagonal=false)
Compute QR factorization A = QR, using TSQR.
int revealRank(MV &Q, dense_matrix_type &R, const magnitude_type &tol)
Compute rank-revealing decomposition using results of factorExplicit().
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
ConjType
Enumerated types used to specify conjugation arguments.