IETL Documentation - vectorspace.h

IETL library: vectorspace.h

The header vectorspace.h contains two vector space classes that should be sufficient for most applications:

The vector space functions

The vector space header provides default implementations for the three functions required of a vector space, by forwarding to a member of the same name:
namespace ietl {

template <class VS>
typename ietl::vectorspace_traits<VS>::vector_type new_vector(const VS& vs)
{
return vs.new_vector();
}

template <class VS>
typename ietl::vectorspace_traits<VS>::size_type vec_dimension(const VS& vs)
{
return vs.vec_dimension();
}


template<class VS>
void project(typename ietl::vectorspace_traits<VS>::vector_type& v, const VS& vs)
{
vs.project(v);
}

}

The vectorspace class

The vectorspace class implements the required vector space functionality for any standard container.

namespace ietl {
template<class V>
class vectorspace {
public:
typedef V vector_type;
typedef typename V::value_type scalar_type;
typedef typename V::size_type size_type;

vectorspace(size_type n);

size_type vec_dimension() const;
vector_type new_vector() const;
void project(vector_type&) const {}
};
}

The vector_wrapper class

The vector_wrapper class is provided for standard containers that do not provide return value optimization. It stores a boost::shared_pointer smart pointer to the vector and forwards all the functions and operators necessary for the IETL to the actual vector. This speeds up returning eigenvectors from the IETL functions.
namespace ietl {

template <class V>
class vector_wrapper : public boost::shared_ptr<V> {
public:
vector_wrapper(V* p) : boost::shared_ptr<V>(p) {}
operator V& ();
operator const V& () const;

...
};
}

The wrapper_vectorspace class

is a vector space implementation using the vector_wrapper class:
namespace ietl {

template<class V> class wrapper_vectorspace {
public:
typedef vector_wrapper<V> vector_type;
typedef typename V::value_type scalar_type;
typedef typename V::size_type size_type;

wrapper_vectorspace(size_type n):n_(n){}

size_type vec_dimension() const;
vector_type new_vector() const;
void project(vector_type& src) const {}
};




copyright 2002-2004 by Matthias Troyer and Prakash Dayal