12 #ifndef MY_MULTIVECTOR_HPP
13 #define MY_MULTIVECTOR_HPP
32 template <
class ScalarType>
38 MyMultiVec (
const ptrdiff_t Length,
const int NumberVecs) :
44 data_.resize(NumberVecs);
49 data_[v] =
new ScalarType[Length];
58 MyMultiVec(
const ptrdiff_t Length,
const std::vector<ScalarType*>& rhs) :
93 for (
int i = 0 ; i <
Length_ ; ++i)
94 (*
this)(i, v) = rhs(i, v);
128 int size = index.size();
131 for (
size_t v = 0 ; v < index.size() ; ++v) {
132 for (
int i = 0 ; i <
Length_ ; ++i) {
133 (*tmp)(i, v) = (*
this)(i, index[v]);
143 int size = index.size();
144 std::vector<ScalarType*> values(size);
146 for (
size_t v = 0 ; v < index.size() ; ++v)
147 values[v] =
data_[index[v]];
155 int size = index.size();
156 std::vector<ScalarType*> values (size);
158 for (
size_t v = 0; v < index.size (); ++v) {
159 values[v] =
data_[index[v]];
178 const ScalarType beta)
187 if ((*
this)[0] == (*MyA)[0]) {
194 for (
int i = 0 ; i <
Length_ ; ++i) {
196 tmp[v] = (*MyA)(i, v);
199 for (
int v = 0 ; v < B.
numCols() ; ++v) {
200 (*this)(i, v) *= beta;
204 res += tmp[j] * B(j, v);
207 (*this)(i, v) += alpha * res;
212 for (
int i = 0 ; i <
Length_ ; ++i) {
213 for (
int v = 0 ; v < B.
numCols() ; ++v) {
214 (*this)(i, v) *= beta;
215 ScalarType res = 0.0;
217 res += (*MyA)(i, j) * B(j, v);
220 (*this)(i, v) += alpha * res;
243 for (
int i = 0 ; i <
Length_ ; ++i) {
244 (*this)(i, v) = alpha * (*MyA)(i, v) + beta * (*MyB)(i, v);
253 for (
int i = 0 ; i <
Length_ ; ++i) {
254 (*this)(i, v) *= alpha;
260 void MvScale (
const std::vector<ScalarType>& alpha)
264 for (
int i = 0 ; i <
Length_ ; ++i) {
265 (*this)(i, v) *= alpha[v];
284 ScalarType value = 0.0;
285 for (
int i = 0 ; i <
Length_ ; ++i) {
288 B(v, w) = alpha * value;
306 ScalarType value = 0.0;
307 for (
int i = 0 ; i <
Length_ ; ++i) {
324 for (
int i = 0 ; i <
Length_ ; ++i) {
337 const std::vector<int> &index)
346 for (
unsigned int v = 0 ; v < index.size() ; ++v) {
347 for (
int i = 0 ; i <
Length_ ; ++i) {
348 (*this)(i, index[v]) = (*MyA)(i, v);
357 Teuchos::randomSyncedMatrix( R );
359 for (
int i = 0 ; i <
Length_ ; ++i) {
360 (*this)(i, v) = R(i, v);
369 for (
int i = 0 ; i <
Length_ ; ++i) {
370 (*this)(i, v) = alpha;
377 os <<
"Object MyMultiVec" << std::endl;
378 os <<
"Number of rows = " <<
Length_ << std::endl;
379 os <<
"Number of vecs = " <<
NumberVecs_ << std::endl;
381 for (
int i = 0 ; i <
Length_ ; ++i)
384 os << (*
this)(i, v) <<
" ";
392 if (i < 0 || i >=
Length_)
throw(-2);
397 inline const ScalarType&
operator()(
const int i,
const int j)
const
400 if (i < 0 || i >=
Length_)
throw(-2);
420 throw(
"Length must be positive");
423 throw(
"Number of vectors must be positive");
438 #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.