44 #ifndef MY_MULTIVECTOR_HPP
45 #define MY_MULTIVECTOR_HPP
64 template <
class ScalarType>
70 MyMultiVec (
const ptrdiff_t Length,
const int NumberVecs) :
76 data_.resize(NumberVecs);
81 data_[v] =
new ScalarType[Length];
90 MyMultiVec(
const ptrdiff_t Length,
const std::vector<ScalarType*>& rhs) :
125 for (
int i = 0 ; i <
Length_ ; ++i)
126 (*
this)(i, v) = rhs(i, v);
160 int size = index.size();
163 for (
size_t v = 0 ; v < index.size() ; ++v) {
164 for (
int i = 0 ; i <
Length_ ; ++i) {
165 (*tmp)(i, v) = (*
this)(i, index[v]);
175 int size = index.size();
176 std::vector<ScalarType*> values(size);
178 for (
size_t v = 0 ; v < index.size() ; ++v)
179 values[v] =
data_[index[v]];
187 int size = index.size();
188 std::vector<ScalarType*> values (size);
190 for (
size_t v = 0; v < index.size (); ++v) {
191 values[v] =
data_[index[v]];
210 const ScalarType beta)
219 if ((*
this)[0] == (*MyA)[0]) {
226 for (
int i = 0 ; i <
Length_ ; ++i) {
228 tmp[v] = (*MyA)(i, v);
231 for (
int v = 0 ; v < B.
numCols() ; ++v) {
232 (*this)(i, v) *= beta;
236 res += tmp[j] * B(j, v);
239 (*this)(i, v) += alpha * res;
244 for (
int i = 0 ; i <
Length_ ; ++i) {
245 for (
int v = 0 ; v < B.
numCols() ; ++v) {
246 (*this)(i, v) *= beta;
247 ScalarType res = 0.0;
249 res += (*MyA)(i, j) * B(j, v);
252 (*this)(i, v) += alpha * res;
275 for (
int i = 0 ; i <
Length_ ; ++i) {
276 (*this)(i, v) = alpha * (*MyA)(i, v) + beta * (*MyB)(i, v);
285 for (
int i = 0 ; i <
Length_ ; ++i) {
286 (*this)(i, v) *= alpha;
292 void MvScale (
const std::vector<ScalarType>& alpha)
296 for (
int i = 0 ; i <
Length_ ; ++i) {
297 (*this)(i, v) *= alpha[v];
316 ScalarType value = 0.0;
317 for (
int i = 0 ; i <
Length_ ; ++i) {
320 B(v, w) = alpha * value;
338 ScalarType value = 0.0;
339 for (
int i = 0 ; i <
Length_ ; ++i) {
356 for (
int i = 0 ; i <
Length_ ; ++i) {
369 const std::vector<int> &index)
378 for (
unsigned int v = 0 ; v < index.size() ; ++v) {
379 for (
int i = 0 ; i <
Length_ ; ++i) {
380 (*this)(i, index[v]) = (*MyA)(i, v);
389 Teuchos::randomSyncedMatrix( R );
391 for (
int i = 0 ; i <
Length_ ; ++i) {
392 (*this)(i, v) = R(i, v);
401 for (
int i = 0 ; i <
Length_ ; ++i) {
402 (*this)(i, v) = alpha;
409 os <<
"Object MyMultiVec" << std::endl;
410 os <<
"Number of rows = " <<
Length_ << std::endl;
411 os <<
"Number of vecs = " <<
NumberVecs_ << std::endl;
413 for (
int i = 0 ; i <
Length_ ; ++i)
416 os << (*
this)(i, v) <<
" ";
424 if (i < 0 || i >=
Length_)
throw(-2);
429 inline const ScalarType&
operator()(
const int i,
const int j)
const
432 if (i < 0 || i >=
Length_)
throw(-2);
452 throw(
"Length must be positive");
455 throw(
"Number of vectors must be positive");
470 #endif // MY_MULTIVECTOR_HPP
void MvTransMv(const ScalarType alpha, const Belos::MultiVec< ScalarType > &A, Teuchos::SerialDenseMatrix< int, ScalarType > &B) const
Compute a dense matrix B through the matrix-matrix multiply alpha * A^T * (*this).
MyMultiVec(const MyMultiVec &rhs)
Copy constructor, performs a deep copy.
std::vector< ScalarType * > data_
Pointers to the storage of the vectors.
virtual int GetNumberVecs() const =0
The number of vectors (i.e., columns) in the multivector.
ScalarType & operator()(const int i, const int j)
ScalarType * operator[](int v) const
void MvPrint(std::ostream &os) const
Print *this multivector to the os output stream.
void MvScale(const ScalarType alpha)
Scale each element of the vectors in *this with alpha.
MyMultiVec * CloneViewNonConst(const std::vector< int > &index)
Returns a view of current std::vector (shallow copy)
MyMultiVec(const ptrdiff_t Length, const std::vector< ScalarType * > &rhs)
Constructor with already allocated memory.
virtual ptrdiff_t GetGlobalLength() const =0
The number of rows in the multivector.
void MvTimesMatAddMv(const ScalarType alpha, const Belos::MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta)
Update *this with alpha * A * B + beta * (*this).
MyMultiVec * Clone(const int NumberVecs) const
Returns a clone of the current std::vector.
MyMultiVec * CloneCopy() const
Create a new MultiVec and copy contents of *this into it (deep copy).
Simple example of a user's defined Belos::MultiVec class.
const MyMultiVec * CloneView(const std::vector< int > &index) const
Returns a view of current std::vector (shallow copy), const version.
ScalarType * operator[](int v)
static magnitudeType magnitude(T a)
OrdinalType numCols() const
NormType
The type of vector norm to compute.
void MvRandom()
Fill all the vectors in *this with random numbers.
const int NumberVecs_
Number of multi-vectors.
void MvDot(const Belos::MultiVec< ScalarType > &A, std::vector< ScalarType > &b) const
Compute the dot product of each column of *this with the corresponding column of A.
void MvNorm(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, Belos::NormType type=Belos::TwoNorm) const
Compute the norm of each vector in *this.
Interface for multivectors used by Belos' linear solvers.
int GetNumberVecs() const
The number of vectors (i.e., columns) in the multivector.
MyMultiVec * CloneCopy(const std::vector< int > &index) const
Returns a clone copy of specified vectors.
#define TEUCHOS_ASSERT(assertion_test)
void MvScale(const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
const ptrdiff_t Length_
Length of the vectors.
Belos header file which uses auto-configuration information to include necessary C++ headers...
const ScalarType & operator()(const int i, const int j) const
void SetBlock(const Belos::MultiVec< ScalarType > &A, const std::vector< int > &index)
Copy the vectors in A to a set of vectors in *this.
std::vector< bool > ownership_
If true, then this object owns the vectors and must free them in dtor.
MyMultiVec(const ptrdiff_t Length, const int NumberVecs)
Constructor for a NumberVecs vectors of length Length.
void MvAddMv(const ScalarType alpha, const Belos::MultiVec< ScalarType > &A, const ScalarType beta, const Belos::MultiVec< ScalarType > &B)
Replace *this with alpha * A + beta * B.
OrdinalType numRows() const
void MvInit(const ScalarType alpha)
Replace each element of the vectors in *this with alpha.
Interface for multivectors used by Belos' linear solvers.
ptrdiff_t GetGlobalLength() const
The number of rows in the multivector.