Dense vectors

Vectors are one-dimensional arrays in which all the coefficients are stored (even if they are zero). They provide classical arithmetic operations such as addition, substraction, multiplication by scalars . . . available in a vector space. An implementation is given by the class:

template<class C, class R=linalg::rep1d<C> > struct VectDse<C,R>;

The class depends on two parameters:

Notice that this vector type differs from the container type std:vector<C>, used for array storage.

Containers

Any container type which provides the following operations can be used for the parameter R:

typedef size_type; // type of the index. 
typedef value_type; // type of the coefficients. 
typedef iterator; // type of the iterator. 
R(size_type n); R(size_type n, value_type* t); 
R(iterator b,iterator e); 
R& R::operator=(const R &);
size_type R::size();
void R::resize(size_type); 
iterator       R::begin(); 
const_iterator R::begin() const; 
iterator       R::end(); 
const_iterator R::end() const; 
value_type & R::operator[] (size_type i); 
value_type   R::operator[] (size_type i) const;

For instance

Example

o+

#include <synaps/linalg/VectDse.h>
#include <synaps/arithm/gmp.h>

typedef double coeff_t;
typedef VectDse<double> vect_t;
// equivalently typedef VectDse<double,linalg::rep1d<double> >
// VectDse<double> definition based on array1d container, 
// with double coefficients.

using std::cout;
using std::endl;

int main (int argc, char **argv)
{

  VectDse<double> U(4,"0 1 2 3");
    VectDse<double >     V(4,"1 2 3 4");
  VectDse<double >     W(4,"0 1 2 3");
  VectDse<QQ, linalg::rep1d<QQ> > a(3, "1 2 3 4");
  a = 2 * U;
  W = (U*V)*V;
  W = W/3;
  W = (U+V-(U*V)*U/3);
  //  cout << " W = " << W << endl;
  W = -W;
  std::cout << W << std::endl;
  coeff_t tmp;
  let::assign(tmp,(U*V));
  std::cout << tmp << std::endl;
  
  cout << U<<", "<<V<<endl;
  //| U = [0, 2, 1, 3], V = [1, 2, 3, 4] 

  cout<<V*2<<", "<<V/4<<endl;

  //| ([1, 2, 3, 4]).(2), ([1, 2, 3, 4])/(4)
  //| The operations are performed only when the result is assigned to a
  //| variable.


  V /= 2; cout<<V<<endl;

  //| [ 0.5, 1, 1.5, 2 ]

  W=U;U[1]=-1; cout<<W<<", "<<V<<endl;

  //| [0, 2, 1, 3], [0.5, -1,  1.5, 2]

  W= U[Range(1,2)]; cout<<W<<endl;

  //| [-1, 1]

  U[Range(1,2)]= Eval(V[Range(2,3)]); cout<<U<<endl;

  //| [0, 1.5, 2, 3]

}

Implementation

See also:
synaps/linalg/VectDse.h

Generic tools for vectors

Generic implementations for vectors are available in the module VECTOR.

SYNAPS DOCUMENTATION
logo