Jive reference manual
List of all members | Public Member Functions | Protected Member Functions
jive::algebra::StdVectorSpace Class Reference

Provides a straightforward implementation of the VectorSpace class. More...

Inheritance diagram for jive::algebra::StdVectorSpace:
Inheritance graph

Public Member Functions

 StdVectorSpace ()
 Constructs a vector space with zero size. More...
 
 StdVectorSpace (int size)
 Constructs a vector space with a given size. More...
 
void resize (int n)
 Sets the size of this vector space. More...
 
virtual double product (const Vector &x, const Vector &y) const
 Computes the scalar product of two vectors. More...
 
virtual void products (const Vector &a, const Matrix &x, const Matrix &y) const
 Computes the scalar product of several vectors. More...
 
virtual void project (const Vector &a, const Vector &x, const Matrix &y) const
 Computes the scalar product of a vector with several other vectors. More...
 
virtual int size () const
 Returns the size of this vector space. More...
 
virtual void print (const Vector &x) const
 Writes the constents of a vector to the standard output. More...
 
- Public Member Functions inherited from jem::Object
virtual ClassgetClass () const
 Returns the Class instance representing the runtime class of this object. More...
 
virtual String toString () const
 Returns a short textual description of this object. More...
 
virtual long hashValue () const
 Returns a hash value for this object. More...
 
virtual bool equals (const Ref< Object > &obj) const
 Tests whether two objects are equal. More...
 
Ref< Objectclone () const
 Returns a copy of this object. More...
 

Protected Member Functions

virtual ~StdVectorSpace ()
 
- Protected Member Functions inherited from jive::algebra::VectorSpace
virtual ~VectorSpace ()
 
- Protected Member Functions inherited from jem::Collectable
 Collectable ()
 Creates an empty Collectable. More...
 
 ~Collectable ()
 Frees resources. More...
 

Additional Inherited Members

- Public Types inherited from jive::algebra::VectorSpace
typedef util::Vector Vector
 A vector type. More...
 
typedef util::Matrix Matrix
 A matrix type. More...
 
- Static Public Member Functions inherited from jem::Object
static ClassgetType ()
 Returns the Class instance representing the Object class. More...
 
- Public Attributes inherited from jive::algebra::VectorSpace
jem::util::Event< int > resizeEvent
 Signals that the size of this vector space has changed. More...
 

Detailed Description

#include <jive/algebra/StdVectorSpace.h>

The StdVectorSpace class is a subclass of the VectorSpace class that provides a straightforward implementation of the scalar product of two vectors. If x and y denote two vectors of the same size, then the scalar product s of these two vectors is computed as:

s = 0.0;
for ( i = 0; i < x.size(); i++ ) {
s += x[i] * y[i];
}

Or, using an array expression:

s = sum( x * y );

Constructor & Destructor Documentation

jive::algebra::StdVectorSpace::StdVectorSpace ( )

Constructs a vector space with zero size.

Postcondition
this->size() == 0
jive::algebra::StdVectorSpace::StdVectorSpace ( int  size)
explicit

Constructs a vector space with size size.

Parameters
size- the size of this vector space.
Precondition
size >= 0
Postcondition
this->size() == size
virtual jive::algebra::StdVectorSpace::~StdVectorSpace ( )
protectedvirtual

Member Function Documentation

void jive::algebra::StdVectorSpace::resize ( int  n)

Sets the size of this vector space to n. This function emits the event resizeEvent if the new size is different from the current size.

Parameters
n- the new size of this vector space.
Precondition
n >= 0
Postcondition
this->size() == n
virtual double jive::algebra::StdVectorSpace::product ( const Vector x,
const Vector y 
) const
virtual

Returns the scalar product of the vectors x and y. The implementation provided by the StdVectorSpace class simply executes:

return sum ( x * y );
Returns
The scalar product of x and y.

Implements jive::algebra::VectorSpace.

virtual void jive::algebra::StdVectorSpace::products ( const Vector a,
const Matrix x,
const Matrix y 
) const
virtual

Fills the vector a with the scalar products of the columns of the matrices x and y. The implementation provided by the StdVectorClass is given by:

int i;
for ( i = 0; i < x.size(1); i++ ) {
a[i] = sum ( x( slice(ALL), i ) * y( slice(ALL), i ) );
}

Reimplemented from jive::algebra::VectorSpace.

virtual void jive::algebra::StdVectorSpace::project ( const Vector a,
const Vector x,
const Matrix y 
) const
virtual

Fills the vector a with the scalar products of the vector x with the columns of the matrix y. If the size of a is larger than n, with n equal to the number of columns in y, then a[n] is set to the scalar product of x with itself. The implementation of this function provided by the StdVectorSpace classes calls the function matmul to compute the scalar products.

Reimplemented from jive::algebra::VectorSpace.

virtual int jive::algebra::StdVectorSpace::size ( ) const
virtual

Returns the size of this vector space.

Returns
The size of this vector space.

Implements jive::algebra::VectorSpace.

virtual void jive::algebra::StdVectorSpace::print ( const Vector x) const
virtual

Writes the contents of the vector x to the standard output. The output format is unspecified. Use this function for debugging purposes.

Parameters
x- the vector to be printed.
Precondition
x.size() == this->size()

Implements jive::algebra::VectorSpace.