KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
kjb::Gsl_Vector Class Reference

RAII wrapper for GSL vector objects. More...

#include <gsl_vector.h>

Public Member Functions

 Gsl_Vector (size_t dims)
 ctor to build an uninitialized vector of a given size More...
 
 Gsl_Vector (const kjb::Vector &kv)
 conversion ctor makes a copy of a KJB vector More...
 
 Gsl_Vector (const Gsl_Vector &src)
 copy ctor More...
 
 Gsl_Vector (const gsl_vector &vec_to_be_copied)
 ctor copies an unwrapped GSL vector, does NOT take ownership. More...
 
Gsl_Vectoroperator= (const Gsl_Vector &src)
 assignment operator More...
 
double * begin ()
 
const double * begin () const
 
double * end ()
 
const double * end () const
 
void swap (Gsl_Vector &v)
 swap the contents of two vectors More...
 
 ~Gsl_Vector ()
 dtor releases the resources in a vector More...
 
template<class Iterator >
 Gsl_Vector (Iterator begin, Iterator end)
 ctor constructs from a pair of input iterators More...
 
size_t size () const
 returns the size of the vector More...
 
double at (size_t index) const
 element access for the vector, returning an rvalue More...
 
double & at (size_t index)
 element access for the vector, returning an lvalue More...
 
double & front ()
 access the first element of the vector, returning an lvalue More...
 
double front () const
 access the first element of the vector, returning an rvalue More...
 
double & back ()
 access the last element of the vector, returning an lvalue More...
 
double back () const
 access the last element of the vector, returning an rvalue More...
 
Gsl_Vectorset_all (double val)
 set all vector members to a given value More...
 
Gsl_Vectorset_zero ()
 set all vector members to zero More...
 
Gsl_Vectorset_basis (size_t index)
 Init to the (j+1)th column of identity matrix, given argument j. More...
 
 operator gsl_vector * ()
 Automatically (danger!) convert a wrapped object into a pointer. More...
 
kjb::Vector vec () const
 Export contents in a KJB Vector (the C++ kind). More...
 
Gsl_Vector ew_multiply (const Gsl_Vector &that) const
 Perform element-wise multiplcation of two vectors, same size. More...
 
double sum () const
 Return the sum of the elements of the vector. More...
 
double dot (const Gsl_Vector &that) const
 Return the dot product of two vectors. More...
 
double l2_norm () const
 Return the L2 norm (the Euclidean norm) of the vector. More...
 
bool is_normal () const
 Test whether all vector entries are "normal" values. More...
 
Gsl_Vectoroperator+= (const Gsl_Vector &that)
 Add a vector of the same size to this vector, elementwise. More...
 
Gsl_Vector operator+ (const Gsl_Vector &that) const
 Return the sum of this vector and another vector of same size. More...
 
Gsl_Vectoroperator-= (const Gsl_Vector &that)
 Subtract a vector of the same size from this vector, elementwise. More...
 
Gsl_Vector operator- (const Gsl_Vector &that) const
 Return the difference of two vectors of the same size. More...
 
Gsl_Vectorow_multiply_vector_by_scalar (double scalar)
 Scale by a real value, like kjb_c::ow_multiply_vector_by_scalar. More...
 
Gsl_Vectoroperator*= (double scalar)
 Scale by a real value, like ow_multiply_vector_by_scalar. More...
 
Gsl_Vectorow_reverse ()
 Reverse the order of the elements of the vector, in place. More...
 
Gsl_Vector operator* (double scalar) const
 Scale by a real value and return the result. More...
 
Gsl_Vectoroperator+= (double scalar)
 add scalar to each elt. of this vector, in-place More...
 
Gsl_Vector operator+ (double scalar) const
 Return copy of this vector with a scalar added to each elt. More...
 
Gsl_Vectoroperator-= (double scalar)
 subtract scalar from each elt. of this vector, in-place More...
 
Gsl_Vector operator- (double scalar) const
 Return copy of this vector w/ a scalar subtracted from each elt. More...
 
Gsl_Vector operator- () const
 Return copy of this vector with every element negated. More...
 
double max () const
 return the maximum value in the vector More...
 
double min () const
 return the minimum value in the vector More...
 

Detailed Description

RAII wrapper for GSL vector objects.

Note the "operator gsl_vector*()" method, which makes it transparent. GSL is the Gnu Scientific Library. Ordinary GSL vectors are a resource with an API in C, so they must be allocated and freed. This C++ wrapper will automatically free the object when control flow leaves the object's scope. (That's just the basic RAII paradigm.)

Implementation invariant: pointer m_vec is never to be left equal to NULL.

Constructor & Destructor Documentation

kjb::Gsl_Vector::Gsl_Vector ( size_t  dims)
inline

ctor to build an uninitialized vector of a given size

kjb::Gsl_Vector::Gsl_Vector ( const kjb::Vector kv)
inlineexplicit

conversion ctor makes a copy of a KJB vector

kjb::Gsl_Vector::Gsl_Vector ( const Gsl_Vector src)
inline

copy ctor

kjb::Gsl_Vector::Gsl_Vector ( const gsl_vector vec_to_be_copied)
inline

ctor copies an unwrapped GSL vector, does NOT take ownership.

kjb::Gsl_Vector::~Gsl_Vector ( )
inline

dtor releases the resources in a vector

template<class Iterator >
kjb::Gsl_Vector::Gsl_Vector ( Iterator  begin,
Iterator  end 
)
inline

ctor constructs from a pair of input iterators

Member Function Documentation

double kjb::Gsl_Vector::at ( size_t  index) const
inline

element access for the vector, returning an rvalue

double& kjb::Gsl_Vector::at ( size_t  index)
inline

element access for the vector, returning an lvalue

double& kjb::Gsl_Vector::back ( )
inline

access the last element of the vector, returning an lvalue

double kjb::Gsl_Vector::back ( ) const
inline

access the last element of the vector, returning an rvalue

double* kjb::Gsl_Vector::begin ( )
inline
const double* kjb::Gsl_Vector::begin ( ) const
inline
double kjb::Gsl_Vector::dot ( const Gsl_Vector that) const
inline

Return the dot product of two vectors.

double* kjb::Gsl_Vector::end ( )
inline
const double* kjb::Gsl_Vector::end ( ) const
inline
Gsl_Vector kjb::Gsl_Vector::ew_multiply ( const Gsl_Vector that) const
inline

Perform element-wise multiplcation of two vectors, same size.

This method is similar to kjb_c::multiply_vectors(), and basically a wrapped up version of gsl_vector_mul().

This is not overloaded star because multiplication between two vectors is not self explanatory (inner, outer, scalar, elementwise)? Thus the name needs to be descriptive. The name "ew_multiply" is not my favorite, but lib/m_cpp uses something similar. There are two differences between this and that function:

  • That ew_multiply permits two vectors of different sizes to be arguments, but GSL does not; this follows GSL.
  • That ew_multiply overwrites one of the original KJB vectors; this is const.
double& kjb::Gsl_Vector::front ( )
inline

access the first element of the vector, returning an lvalue

double kjb::Gsl_Vector::front ( ) const
inline

access the first element of the vector, returning an rvalue

bool kjb::Gsl_Vector::is_normal ( ) const
inline

Test whether all vector entries are "normal" values.

Infinity (plus or minus) is abnormal; Not-a-Number (NaN) is abnormal; and rational numbers with exponents too extreme to normalize are abnormal. To me, all other values (including zero) that can be represented by a double are normal.

This method is similar to isnormal(3), but there is one significant difference: isnormal(3) does not define zero as a normal value. This method does regard zero as a normal value.

double kjb::Gsl_Vector::l2_norm ( ) const
inline

Return the L2 norm (the Euclidean norm) of the vector.

double kjb::Gsl_Vector::max ( ) const
inline

return the maximum value in the vector

double kjb::Gsl_Vector::min ( ) const
inline

return the minimum value in the vector

kjb::Gsl_Vector::operator gsl_vector * ( )
inline

Automatically (danger!) convert a wrapped object into a pointer.

Warning
Do not free the object explicitly using this method.

With great power comes great responsibility. This method gives you great power, and you the client are responsible for avoiding the inherent pitfalls. For example, don't gsl_vector_free().

Gsl_Vector kjb::Gsl_Vector::operator* ( double  scalar) const
inline

Scale by a real value and return the result.

Gsl_Vector& kjb::Gsl_Vector::operator*= ( double  scalar)
inline

Scale by a real value, like ow_multiply_vector_by_scalar.

Gsl_Vector kjb::Gsl_Vector::operator+ ( const Gsl_Vector that) const
inline

Return the sum of this vector and another vector of same size.

Gsl_Vector kjb::Gsl_Vector::operator+ ( double  scalar) const
inline

Return copy of this vector with a scalar added to each elt.

Gsl_Vector& kjb::Gsl_Vector::operator+= ( const Gsl_Vector that)
inline

Add a vector of the same size to this vector, elementwise.

Gsl_Vector& kjb::Gsl_Vector::operator+= ( double  scalar)
inline

add scalar to each elt. of this vector, in-place

Gsl_Vector kjb::Gsl_Vector::operator- ( const Gsl_Vector that) const
inline

Return the difference of two vectors of the same size.

Gsl_Vector kjb::Gsl_Vector::operator- ( double  scalar) const
inline

Return copy of this vector w/ a scalar subtracted from each elt.

Gsl_Vector kjb::Gsl_Vector::operator- ( ) const
inline

Return copy of this vector with every element negated.

Gsl_Vector& kjb::Gsl_Vector::operator-= ( const Gsl_Vector that)
inline

Subtract a vector of the same size from this vector, elementwise.

Gsl_Vector& kjb::Gsl_Vector::operator-= ( double  scalar)
inline

subtract scalar from each elt. of this vector, in-place

Gsl_Vector& kjb::Gsl_Vector::operator= ( const Gsl_Vector src)
inline

assignment operator

Gsl_Vector& kjb::Gsl_Vector::ow_multiply_vector_by_scalar ( double  scalar)
inline

Scale by a real value, like kjb_c::ow_multiply_vector_by_scalar.

For brevity, you might prefer to use operator*= instead of this method.

Gsl_Vector& kjb::Gsl_Vector::ow_reverse ( )
inline

Reverse the order of the elements of the vector, in place.

Gsl_Vector& kjb::Gsl_Vector::set_all ( double  val)
inline

set all vector members to a given value

Gsl_Vector& kjb::Gsl_Vector::set_basis ( size_t  index)
inline

Init to the (j+1)th column of identity matrix, given argument j.

For example, a call to v.set_basis(0) will set vector v to equal column 1 of the n x n identity matrix, assuming n is the number of elts in the vector v.

Gsl_Vector& kjb::Gsl_Vector::set_zero ( )
inline

set all vector members to zero

size_t kjb::Gsl_Vector::size ( ) const
inline

returns the size of the vector

double kjb::Gsl_Vector::sum ( ) const
inline

Return the sum of the elements of the vector.

void kjb::Gsl_Vector::swap ( Gsl_Vector v)
inline

swap the contents of two vectors

kjb::Vector kjb::Gsl_Vector::vec ( ) const
inline

Export contents in a KJB Vector (the C++ kind).


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