47 #ifndef ANASAZI_THYRA_ADAPTER_HPP
48 #define ANASAZI_THYRA_ADAPTER_HPP
54 #include <Thyra_DetachedMultiVectorView.hpp>
55 #include <Thyra_MultiVectorBase.hpp>
56 #include <Thyra_MultiVectorStdOps.hpp>
57 #include <Thyra_VectorStdOps.hpp>
59 #include <Teuchos_Ptr.hpp>
60 #include <Teuchos_ArrayRCP.hpp>
61 #include <Teuchos_ArrayView.hpp>
79 template<
class ScalarType>
83 typedef Thyra::MultiVectorBase<ScalarType> TMVB;
109 const int numvecs = mv.domain()->dim();
113 Thyra::assign (Teuchos::outArg (*cc), mv);
124 const int numvecs = index.size();
130 Thyra::assign (Teuchos::outArg (*cc), *view);
137 const int numVecs = index.
size();
143 Thyra::assign (Teuchos::outArg (*cc), *view);
154 int numvecs = index.size();
170 for (
int i=0; i<numvecs; i++) {
171 if (lb+i != index[i]) contig =
false;
176 const Thyra::Range1D rng(lb,lb+numvecs-1);
178 cc = mv.subView(rng);
182 cc = mv.subView( Teuchos::arrayViewFromVector( index ) );
195 return mv.subView (index);
205 int numvecs = index.size();
221 for (
int i=0; i<numvecs; i++) {
222 if (lb+i != index[i]) contig =
false;
227 const Thyra::Range1D rng(lb,lb+numvecs-1);
229 cc = mv.subView(rng);
233 cc = mv.subView(Teuchos::arrayViewFromVector( index ) );
246 return mv.subView (index);
256 {
return mv.range()->dim(); }
260 {
return mv.domain()->dim(); }
271 const ScalarType beta, TMVB & mv )
277 B_thyra = Thyra::createMembersView(
279 RTOpPack::ConstSubMultiVectorView<ScalarType>(
281 Teuchos::arcpFromArrayView(Teuchos::arrayView(&B(0,0), B.
stride()*B.
numCols())), B.
stride()
285 A.apply(Thyra::NOTRANS,*B_thyra,Teuchos::outArg (mv),alpha,beta);
290 static void MvAddMv(
const ScalarType alpha,
const TMVB & A,
291 const ScalarType beta,
const TMVB & B, TMVB & mv )
293 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::inoutArg;
295 Thyra::linear_combination<ScalarType>(
296 tuple(alpha, beta)(), tuple(ptrInArg(A), ptrInArg(B))(), ST::zero(), inoutArg(mv));
301 static void MvTransMv(
const ScalarType alpha,
const TMVB & A,
const TMVB & mv,
305 int m = A.domain()->dim();
306 int n = mv.domain()->dim();
309 B_thyra = Thyra::createMembersView(
311 RTOpPack::SubMultiVectorView<ScalarType>(
313 Teuchos::arcpFromArrayView(Teuchos::arrayView(&B(0,0), B.
stride()*B.
numCols())), B.
stride()
322 static void MvDot(
const TMVB & mv,
const TMVB & A, std::vector<ScalarType> &b )
323 { Thyra::dots(mv,A,Teuchos::arrayViewFromVector( b )); }
329 const ScalarType alpha)
331 Thyra::scale (alpha, Teuchos::inOutArg (mv));
338 const std::vector<ScalarType>& alpha)
340 for (
unsigned int i=0; i<alpha.size(); i++) {
341 Thyra::scale (alpha[i], mv.col(i).ptr());
354 { Thyra::norms_2(mv,Teuchos::arrayViewFromVector( normvec )); }
363 static void SetBlock(
const TMVB & A,
const std::vector<int>& index, TMVB & mv )
366 int numvecs = index.size();
367 std::vector<int> indexA(numvecs);
368 int numAcols = A.domain()->dim();
369 for (
int i=0; i<numvecs; i++) {
374 if ( numAcols < numvecs ) {
379 else if ( numAcols > numvecs ) {
381 indexA.resize( numAcols );
388 Thyra::assign (Teuchos::outArg (*reldest), *relsource);
394 const int numColsA = A.domain()->dim();
395 const int numColsMv = mv.domain()->dim();
397 const bool validIndex = index.
lbound() >= 0 && index.
ubound() < numColsMv;
399 const bool validSource = index.
size() <= numColsA;
401 if (! validIndex || ! validSource)
403 std::ostringstream os;
404 os <<
"Anasazi::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar> "
405 ">::SetBlock(A, [" << index.
lbound() <<
", " << index.
ubound()
408 os.str() <<
"Range lower bound must be nonnegative.");
410 os.str() <<
"Range upper bound must be less than "
411 "the number of columns " << numColsA <<
" in the "
412 "'mv' output argument.");
414 os.str() <<
"Range must have no more elements than"
415 " the number of columns " << numColsA <<
" in the "
416 "'A' input argument.");
424 if (index.
lbound() == 0 && index.
ubound()+1 == numColsMv)
425 mv_view = Teuchos::rcpFromRef (mv);
427 mv_view = mv.subView (index);
433 if (index.
size() == numColsA)
434 A_view = Teuchos::rcpFromRef (A);
439 Thyra::assign (Teuchos::outArg (*mv_view), *A_view);
443 Assign (
const TMVB& A, TMVB& mv)
449 const int numColsA = A.domain()->dim();
450 const int numColsMv = mv.domain()->dim();
451 if (numColsA > numColsMv) {
452 const std::string prefix (
"Anasazi::MultiVecTraits<Scalar, "
453 "Thyra::MultiVectorBase<Scalar>"
454 " >::Assign(A, mv): ");
456 prefix <<
"Input multivector 'A' has "
457 << numColsA <<
" columns, but output multivector "
458 "'mv' has only " << numColsMv <<
" columns.");
462 if (numColsA == numColsMv) {
463 Thyra::assign (outArg (mv), A);
467 Thyra::assign (outArg (*mv_view), A);
479 Teuchos::outArg (mv));
488 Thyra::assign (Teuchos::outArg (mv), alpha);
498 static void MvPrint(
const TMVB & mv, std::ostream& os )
501 out->setf(std::ios_base::scientific);
526 template <
class ScalarType>
527 class OperatorTraits < ScalarType, Thyra::MultiVectorBase<ScalarType>, Thyra::LinearOpBase<ScalarType> >
534 static void Apply (
const Thyra::LinearOpBase< ScalarType >& Op,
const Thyra::MultiVectorBase< ScalarType > & x, Thyra::MultiVectorBase< ScalarType > & y )
static void MvNorm(const TMVB &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 Teuchos::RCP< TMVB > CloneCopy(const TMVB &mv, const std::vector< int > &index)
Creates a new MultiVectorBase and copies the selected contents of mv into the new vector (deep copy)...
static void MvDot(const TMVB &mv, const TMVB &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 ...
Declaration of basic traits for the multivector type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Virtual base class which defines basic traits for the operator type.
static void MvTimesMatAddMv(const ScalarType alpha, const TMVB &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, TMVB &mv)
Update mv with .
static void Assign(const MV &A, MV &mv)
mv := A
static void MvPrint(const TMVB &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void MvTransMv(const ScalarType alpha, const TMVB &A, const TMVB &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
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).
Virtual base class which defines basic traits for the operator type.
static void MvAddMv(const ScalarType alpha, const TMVB &A, const ScalarType beta, const TMVB &B, TMVB &mv)
Replace mv with .
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
static void MvRandom(TMVB &mv)
Replace the vectors in mv with random vectors.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
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).
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
OrdinalType numCols() const
static int GetNumberVecs(const TMVB &mv)
Obtain the number of vectors in mv.
static void SetBlock(const TMVB &A, const std::vector< int > &index, TMVB &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
static Teuchos::RCP< TMVB > CloneViewNonConst(TMVB &mv, const std::vector< int > &index)
Creates a new MultiVectorBase that shares the selected contents of mv (shallow copy).
static void MvInit(TMVB &mv, ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
static Teuchos::RCP< TMVB > CloneCopy(const TMVB &mv)
Creates a new MultiVectorBase and copies contents of mv into the new vector (deep copy)...
static void MvScale(TMVB &mv, const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
static ptrdiff_t GetGlobalLength(const TMVB &mv)
Obtain the vector length of mv.
static void Apply(const Thyra::LinearOpBase< ScalarType > &Op, const Thyra::MultiVectorBase< ScalarType > &x, Thyra::MultiVectorBase< ScalarType > &y)
This method takes the MultiVectorBase x and applies the LinearOpBase Op to it resulting in the MultiV...
static Teuchos::RCP< const TMVB > CloneView(const TMVB &mv, const std::vector< int > &index)
Creates a new const MultiVectorBase that shares the selected contents of mv (shallow copy)...
static void MvScale(TMVB &mv, const ScalarType alpha)
Scale each element of the vectors in *this with alpha.
OrdinalType stride() const
OrdinalType numRows() const
static Teuchos::RCP< TMVB > Clone(const TMVB &mv, const int numvecs)
Creates a new empty MultiVectorBase containing numvecs columns.