theplu::yat::utility::VectorView Class Reference

This is the yat interface to gsl_vector_view. More...

#include <yat/utility/VectorView.h>

Inheritance diagram for theplu::yat::utility::VectorView:

theplu::yat::utility::VectorMutable theplu::yat::utility::VectorBase

List of all members.

Classes

struct  proxy

Public Types

typedef double & reference
typedef StrideIterator< double * > iterator
 mutable iterator
typedef double value_type
typedef const double & const_reference
typedef StrideIterator< const
double * > 
const_iterator
 VectorBase::const_iterator.

Public Member Functions

 VectorView (void)
 Default constructor.
 VectorView (VectorView &other)
 The copy constructor.
 VectorView (VectorMutable &other)
 copy another VectorMutable
 VectorView (VectorMutable &v, size_t offset, size_t n, size_t stride=1)
 VectorView constructor.
 VectorView (Matrix &m, size_t i, bool row=true)
 ~VectorView (void)
bool isview (void) const
const VectorViewoperator= (const VectorView &)
 The assignment operator.
const VectorViewoperator= (const VectorBase &)
 The assignment operator.
 VectorView (proxy p)
 create VectorView from proxy class
 operator proxy ()
void all (double value)
iterator begin (void)
const_iterator begin (void) const
void div (const VectorBase &other)
 This function performs element-wise division, $ this_i = this_i / other_i \; \forall i $.
iterator end (void)
const_iterator end (void) const
gsl_vector * gsl_vector_p (void)
const gsl_vector * gsl_vector_p (void) const
void mul (const VectorBase &other)
 This function performs element-wise multiplication, $ this_i = this_i * other_i \; \forall i $.
void reverse (void)
 Reverse the order of elements in the VectorMutable.
void swap (size_t i, size_t j)
 Exchange elements i and j.
double & operator() (size_t i)
 Element access operator.
const double & operator() (size_t i) const
 Element access operator.
const VectorMutableoperator+= (const VectorBase &)
 Addition and assign operator. VectorBase addition, $ this_i = this_i + other_i \; \forall i $.
const VectorMutableoperator+= (double d)
 Add a constant to a VectorBase, $ this_i = this_i + d \; \forall i $.
const VectorMutableoperator-= (const VectorBase &)
 Subtract and assign operator. VectorBase subtraction, $ this_i = this_i - other_i \; \forall i $.
const VectorMutableoperator-= (double d)
 Subtract a constant to a VectorBase, $ this_i = this_i - d \; \forall i $.
const VectorMutableoperator*= (double d)
 Multiply with scalar and assign operator, $ this_i = this_i * d \; \forall i $.
bool equal (const VectorBase &, const double precision=0) const
 Check whether VectorBases are equal within a user defined precision, set by precision.
size_t size (void) const
bool operator== (const VectorBase &) const
 Comparison operator. Takes linear time.
bool operator!= (const VectorBase &) const
 Comparison operator. Takes linear time.
double operator* (const VectorBase &) const

Protected Attributes

gsl_vector * vec_
const gsl_vector * const_vec_
 pointer to underlying GSL vector

Related Functions

(Note that these are not member functions.)

Vector operator* (const VectorBase &, const Matrix &)
 Matrix Vector multiplication.
bool isnull (const VectorBase &)
 Check if all elements of the VectorBase are zero.
double max (const VectorBase &)
 Get the maximum value of the VectorBase.
size_t max_index (const VectorBase &)
 Locate the maximum value in the VectorBase.
double min (const VectorBase &)
 Get the minimum value of the VectorBase.
size_t min_index (const VectorBase &)
 Locate the minimum value in the VectorBase.
bool nan (const VectorBase &templat, Vector &flag)
 Create a VectorBase flag indicating NaN's in another VectorBase templat.
void sort_index (std::vector< size_t > &sort_index, const VectorBase &invec)
void sort_smallest_index (std::vector< size_t > &sort_index, size_t k, const VectorBase &invec)
void sort_largest_index (std::vector< size_t > &sort_index, size_t k, const VectorBase &invec)
double sum (const VectorBase &)
 Calculate the sum of all VectorBase elements.
std::ostream & operator<< (std::ostream &s, const VectorBase &v)
 The output operator for the VectorBase class.


Detailed Description

This is the yat interface to gsl_vector_view.

This class can be used to create a vector view into a Matrix or a VectorMutable. Modifying a view will also modify the underlying data, i.e., the Matrix or VectorMutable that is viewed into. For that reason all constructors are taking non-const references to disallow mutable views into a const objects.

The fact that there is no copy constructor with const argument, but only a so-called move constructor (copying a non-const reference), implies that temporary objects such as objects returned from functions can not be copied directly. Instead the copying is done via a proxy class. Also since we can not bind a temporary to a non-const reference, a VectorView returned from a function cannot be sent directly to a function. For example

     Matrix m(10,10);
     sum(m.row_view(0));
but you need to create a dummie object
     Matrix m(10,10);
     VectorView vv = m.row_view(0);
     sum(vv);
or since sum is a const function, you can use VectorConstView
     Matrix m(10,10);
     sum(m.row_const_view(0));

Note that VectorView does not own underlying data, and a VectorView is not valid if Vector/Matrix owning the data is deallocated.


Member Typedef Documentation

typedef const double& theplu::yat::utility::VectorBase::const_reference [inherited]

const_reference type is const double&

Since:
New in yat 0.5

reference type is double&

Since:
New in yat 0.5

value_type is double

Since:
New in yat 0.5


Constructor & Destructor Documentation

theplu::yat::utility::VectorView::VectorView ( void   ) 

Default constructor.

Creates a view into nothing and behaves like an empty Vector.

theplu::yat::utility::VectorView::VectorView ( VectorView other  ) 

The copy constructor.

Modifications to created VectorView will also modify other. Created VectorView is not dependent on other, but if underlying data (Vector or Matrix) is deallocated VectorView is invalid.

theplu::yat::utility::VectorView::VectorView ( VectorMutable other  )  [explicit]

copy another VectorMutable

Note:
If the object viewed by the view goes out of scope or is deleted, the view becomes invalid and the result of further use is undefined.

theplu::yat::utility::VectorView::VectorView ( VectorMutable v,
size_t  offset,
size_t  n,
size_t  stride = 1 
)

VectorView constructor.

Create a view of VectorMutable v, with starting index offset, size n, and an optional stride.

Note:
If the object viewed by the view goes out of scope or is deleted, the view becomes invalid and the result of further use is undefined.

theplu::yat::utility::VectorView::VectorView ( Matrix m,
size_t  i,
bool  row = true 
)

Matrix row/column view constructor.

Create a row/column VectorView view of matrix m, pointing at row/column i. The parameter row is used to set whether the view should be a row or column view. If row is set to true, the view will be a row view (default behaviour), and, naturally, a column view otherwise.

A VectorView view can be used as any VectorMutable with the difference that changes made to the view will also change the object that is viewed.

Note:
If the object viewed by the view goes out of scope or is deleted, the view becomes invalid and the result of further use is undefined.

theplu::yat::utility::VectorView::~VectorView ( void   ) 

The destructor.


Member Function Documentation

void theplu::yat::utility::VectorMutable::all ( double  value  )  [inherited]

Set all elements to value.

const_iterator theplu::yat::utility::VectorBase::begin ( void   )  const [inherited]

Returns:
read-only iterator to start of VectorBase

iterator theplu::yat::utility::VectorMutable::begin ( void   )  [inherited]

Returns:
mutable iterator to start of VectorMutable

void theplu::yat::utility::VectorMutable::div ( const VectorBase other  )  [inherited]

This function performs element-wise division, $ this_i = this_i / other_i \; \forall i $.

Exceptions:
GSL_error if dimensions mis-match.

const_iterator theplu::yat::utility::VectorBase::end ( void   )  const [inherited]

Returns:
read-only iterator to end of VectorBase

iterator theplu::yat::utility::VectorMutable::end ( void   )  [inherited]

Returns:
mutable iterator to end of VectorMutable

bool theplu::yat::utility::VectorBase::equal ( const VectorBase ,
const double  precision = 0 
) const [inherited]

Check whether VectorBases are equal within a user defined precision, set by precision.

Returns:
True if each element deviates less or equal than d. If any VectorBase contain a NaN, false is always returned.
See also:
operator== and operator!=

const gsl_vector* theplu::yat::utility::VectorBase::gsl_vector_p ( void   )  const [inherited]

Returns:
A const pointer to the internal GSL vector,

gsl_vector* theplu::yat::utility::VectorMutable::gsl_vector_p ( void   )  [inherited]

Returns:
A pointer to the internal GSL vector,

bool theplu::yat::utility::VectorView::isview ( void   )  const [virtual]

Returns:
true

Implements theplu::yat::utility::VectorMutable.

void theplu::yat::utility::VectorMutable::mul ( const VectorBase other  )  [inherited]

This function performs element-wise multiplication, $ this_i = this_i * other_i \; \forall i $.

Exceptions:
GSL_error if dimensions mis-match.

theplu::yat::utility::VectorView::operator proxy (  ) 

conversion operator to private proxy class.

bool theplu::yat::utility::VectorBase::operator!= ( const VectorBase  )  const [inherited]

Comparison operator. Takes linear time.

Checks are performed with exact matching, i.e., rounding off effects may destroy comparison. Use the equal function for comparing elements within a user defined precision.

Returns:
False if all elements are equal otherwise true.
See also:
equal(const VectorBase&, const double precision=0)

const double& theplu::yat::utility::VectorBase::operator() ( size_t  i  )  const [inherited]

Element access operator.

Returns:
Const reference to element i.
Exceptions:
If GSL range checks are enabled in the underlying GSL library a GSL_error exception is thrown if either index is out of range.

double& theplu::yat::utility::VectorMutable::operator() ( size_t  i  )  [inherited]

Element access operator.

Returns:
Reference to element i.
Exceptions:
If GSL range checks are enabled in the underlying GSL library a GSL_error exception is thrown if either index is out of range.

double theplu::yat::utility::VectorBase::operator* ( const VectorBase  )  const [inherited]

Returns:
The dot product.

const VectorMutable& theplu::yat::utility::VectorMutable::operator*= ( double  d  )  [inherited]

Multiply with scalar and assign operator, $ this_i = this_i * d \; \forall i $.

Returns:
A const reference to the resulting VectorBase.

const VectorMutable& theplu::yat::utility::VectorMutable::operator+= ( double  d  )  [inherited]

Add a constant to a VectorBase, $ this_i = this_i + d \; \forall i $.

Returns:
A const reference to the resulting VectorBase.

const VectorMutable& theplu::yat::utility::VectorMutable::operator+= ( const VectorBase  )  [inherited]

Addition and assign operator. VectorBase addition, $ this_i = this_i + other_i \; \forall i $.

Returns:
A const reference to the resulting VectorBase.
Exceptions:
GSL_error if dimensions mis-match.

const VectorMutable& theplu::yat::utility::VectorMutable::operator-= ( double  d  )  [inherited]

Subtract a constant to a VectorBase, $ this_i = this_i - d \; \forall i $.

Returns:
A const reference to the resulting VectorBase.

const VectorMutable& theplu::yat::utility::VectorMutable::operator-= ( const VectorBase  )  [inherited]

Subtract and assign operator. VectorBase subtraction, $ this_i = this_i - other_i \; \forall i $.

Returns:
A const reference to the resulting VectorBase.
Exceptions:
GSL_error if dimensions mis-match.

const VectorView& theplu::yat::utility::VectorView::operator= ( const VectorBase  ) 

The assignment operator.

Returns:
A const reference to the resulting vector.
Note:
modifies underlying data.
Exceptions:
GSL_error if dimensions mis-match or if assignment fails

Reimplemented from theplu::yat::utility::VectorBase.

const VectorView& theplu::yat::utility::VectorView::operator= ( const VectorView  ) 

The assignment operator.

Returns:
A const reference to the resulting vector.
Note:
modifies underlying data.
Exceptions:
GSL_error if dimensions mis-match or if assignment fails

bool theplu::yat::utility::VectorBase::operator== ( const VectorBase  )  const [inherited]

Comparison operator. Takes linear time.

Checks are performed with exact matching, i.e., rounding off effects may destroy comparison. Use the equal function for comparing elements within a user defined precision.

Returns:
True if all elements are equal otherwise false.
See also:
equal(const VectorBase&, const double precision=0)

size_t theplu::yat::utility::VectorBase::size ( void   )  const [inherited]

Returns:
number of elements in the VectorBase.


Friends And Related Function Documentation

bool isnull ( const VectorBase  )  [related, inherited]

Check if all elements of the VectorBase are zero.

Returns:
True if all elements in the VectorBase is zero, false othwerwise.

double max ( const VectorBase  )  [related, inherited]

Get the maximum value of the VectorBase.

Returns:
The maximum value of the VectorBase.

size_t max_index ( const VectorBase  )  [related, inherited]

Locate the maximum value in the VectorBase.

Returns:
The index to the maximum value of the VectorBase.
Note:
Lower index has precedence.

double min ( const VectorBase  )  [related, inherited]

Get the minimum value of the VectorBase.

Returns:
The minimum value of the VectorBase.

size_t min_index ( const VectorBase  )  [related, inherited]

Locate the minimum value in the VectorBase.

Returns:
The index to the minimum value of the VectorBase.
Note:
Lower index has precedence.

bool nan ( const VectorBase templat,
Vector flag 
) [related, inherited]

Create a VectorBase flag indicating NaN's in another VectorBase templat.

The flag VectorBase is changed to contain 1's and 0's only. A 1 means that the corresponding element in the templat VectorBase is valid and a zero means that the corresponding element is a NaN.

Note:
Space for vector flag is reallocated to fit the size of VectorBase templat if sizes mismatch.
Returns:
True if the templat VectorBase contains at least one NaN.

std::ostream & operator<< ( std::ostream &  s,
const VectorBase v 
) [related, inherited]

The output operator for the VectorBase class.

Elements in VectorBase v are sent to ostream s and separated with the fill character of stream s, s.fill(). If you, for example, want to print the VectorBase v with the elements separated by a ':', you do so by:

		 s << setfill(':') << v; 
		 

void sort_index ( std::vector< size_t > &  sort_index,
const VectorBase invec 
) [related, inherited]

Create a vector sort_index containing the indeces of elements in a another VectorBase invec. The elements of sort_index give the index of the VectorBase element which would have been stored in that position if the VectorBase had been sorted in place. The first element of sort_index gives the index of the least element in invec, and the last element of sort_index gives the index of the greatest element in invec . The VectorBase invec is not changed.

void sort_largest_index ( std::vector< size_t > &  sort_index,
size_t  k,
const VectorBase invec 
) [related, inherited]

Similar to sort_index but creates a VectorBase with indices to the k largest elements in invec.

void sort_smallest_index ( std::vector< size_t > &  sort_index,
size_t  k,
const VectorBase invec 
) [related, inherited]

Similar to sort_index but creates a VectorBase with indices to the k smallest elements in invec.

double sum ( const VectorBase  )  [related, inherited]

Calculate the sum of all VectorBase elements.

Returns:
The sum.


Member Data Documentation

gsl_vector* theplu::yat::utility::VectorMutable::vec_ [protected, inherited]

pointer to underlying GSL vector. Should always point to same gsl_vector as const_vec_ in base class does. This pointer should by used for mutable operations. Do not use this in const functions; use const_vec_ inherited from BaseVector.


The documentation for this class was generated from the following file:

Generated on Mon Nov 7 02:25:53 2011 for yat by  doxygen 1.5.9