Type Multivector
A multi-vector is an abstraction that is very useful in Krylov subspace methods, esp. when they are implemented generically. It is a matrix that composed of column vectors. The simplest use case is to just store multiple vectors of the same length. Especially the matrix vector product including its transposed form allow for well-readable implementations of algorithms like GMRES and for straight-forward extension to distributed vectors.
To create a multi-vector, there are two ways:
mtl::multi_vector<Vector> A(2, 3);
mtl::multi_vector<Vector> A(Vector(3), 2);
In the 2nd method, you get a matrix with 2 rows and 3 columns. Remark: in older versions, before revision 6957, the arguments were reversed.
To find out the number of rows use
unsigned r= num_rows(A);
It returns an unsigned integer (more precisely the size_type of the vector type). Likewise the number of columns is given
unsigned c= num_cols(A);
To modify individual entries of the multi-vector, there are several possibilities. You can write a vector (same length) in the k-th column of the multi-vector, and vice versa.
mtl::multi_vector<Vector> A(2, 3); Vector v(2), w(2); A.vector(k)= v; v= A.vector(k);
You can also specify the row and column of the entry to be changed.
A[1][1]= 3.5;
On the one hand we can consider a multi-vector as a collection of vectors, on the other hand as a matrix. Thus, there are many multi-vector operations.
// File: multi_vector.cpp #include <iostream> #include <boost/numeric/mtl/mtl.hpp> int main(int, char**) { using namespace mtl; typedef dense_vector<double> Vector; Vector v(2, 3.4), w(3, 2.5); mtl::multi_vector<Vector> A(2, 3); dense2D<double> B(2,2), C(3,2), D(3,3); // Initialize matrices A= 3.0; B= 4.0; C= 5.0; D= 6.0; // vector= multi_vector * vector v= A * w; // vector= transposed multi_vector * vector w= trans(A) * v; // vector= matrix * vector v= B * A.vector(1); // vector= matrix * vector A.vector(0)= B * A.vector(1); // Orthogonalize multi_vector orth(A); return 0; }
The multi-vector is a matrix, therefore the following matrix operations are defined: trace(A), conj(A), trans(A), hermitian(A). The interface is nevertheless minimalistic and not the same functionality as for other matrix types is provided. More functions will be implemented when needed.
Return to Matrix Types Table of Content Proceed to Vector Insertion
Type Multivector -- MTL 4 -- Peter Gottschling and Andrew Lumsdaine
-- Gen. with
rev. 7542
on Sat Aug 11 2012 by doxygen 1.7.6.1 -- © 2010 by SimuNova UG.