yat  0.20.3pre
Public Types | Public Member Functions | Protected Attributes | Related Functions | List of all members
theplu::yat::utility::Vector Class Reference

This is the yat interface to GSL vector. More...

#include <yat/utility/Vector.h>

Inheritance diagram for theplu::yat::utility::Vector:
theplu::yat::utility::VectorMutable theplu::yat::utility::VectorBase theplu::yat::utility::BasicVector< VectorBase >

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.
 
typedef VectorBase derived_type
 

Public Member Functions

 Vector (void)
 The default constructor.
 
 Vector (size_t n, double init_value=0)
 Allocates memory space for n elements, and sets all elements to init_value. More...
 
 Vector (const Vector &other)
 The copy constructor. More...
 
template<class T >
 Vector (const VectorExpression< T > &other)
 Constructor from a vector expression.
 
 Vector (Vector &&other) noexcept
 The move constructor. More...
 
template<class T >
 Vector (VectorExpression< T > &&other)
 Move constructor from Vector expression. More...
 
 Vector (const VectorBase &other)
 Copy a VectorBase. More...
 
 Vector (std::istream &, char sep='\0')
 The istream constructor. More...
 
 ~Vector (void)
 
bool isview (void) const
 
void resize (size_t, double init_value=0)
 Resize Vector. More...
 
const Vectoroperator= (const Vector &)
 The assignment operator. More...
 
template<class T >
Vectoroperator= (const VectorExpression< T > &rhs)
 assignment from vector expression More...
 
Vectoroperator= (Vector &&)
 The move assignment operator. More...
 
template<class T >
Vectoroperator= (VectorExpression< T > &&rhs)
 move assignment from vector expression More...
 
const Vectoroperator= (const VectorBase &)
 The assignment operator. More...
 
void all (double value)
 
iterator begin (void)
 
const_iterator begin (void) const
 
const_iterator begin (void) const
 
void div (const VectorBase &other)
 This function performs element-wise division, $ this_i = this_i / other_i \; \forall i $. More...
 
iterator end (void)
 
const_iterator end (void) const
 
const_iterator end (void) const
 
gsl_vector * gsl_vector_p (void)
 
const gsl_vector * gsl_vector_p (void) const
 
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 $. More...
 
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. More...
 
const double & operator() (size_t i) const
 Element access operator. More...
 
const VectorMutableoperator+= (const VectorBase &)
 Addition and assign operator. VectorBase addition, $ this_i = this_i + other_i \; \forall i $. More...
 
template<class T >
VectorMutableoperator+= (const VectorExpression< T > &rhs)
 Addition and assign operator. More...
 
const VectorMutableoperator+= (double d)
 Add a constant to a VectorBase, $ this_i = this_i + d \; \forall i $. More...
 
const VectorMutableoperator-= (const VectorBase &)
 Subtract and assign operator. VectorBase subtraction, $ this_i = this_i - other_i \; \forall i $. More...
 
template<class T >
VectorMutableoperator-= (const VectorExpression< T > &rhs)
 Subtraction and assign operator. More...
 
const VectorMutableoperator-= (double d)
 Subtract a constant to a VectorBase, $ this_i = this_i - d \; \forall i $. More...
 
const VectorMutableoperator*= (double d)
 Multiply with scalar and assign operator, $ this_i = this_i * d \; \forall i $. More...
 
bool equal (const VectorBase &, const double precision=0) const
 Check whether VectorBases are equal within a user defined precision, set by precision. More...
 
size_t size (void) const
 
bool operator== (const VectorBase &) const
 Comparison operator. Takes linear time. More...
 
bool operator!= (const VectorBase &) const
 Comparison operator. Takes linear time. More...
 
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.)

void swap (Vector &, Vector &)
 Swap Vector elements by copying. More...
 
template<class Derived1 , class Derived2 >
double operator* (const BasicVector< Derived1 > &lhs, const BasicVector< Derived2 > &rhs)
 
template<typename T >
expression::ScaledVector< T > operator* (double k, const BasicVector< T > &vec)
 scale a vector expression More...
 
template<typename T >
expression::ScaledVector< T > operator* (const BasicVector< T > &vec, double k)
 scale a vector expression More...
 
template<class MATRIX , class VECTOR >
expression::MatrixVector< MATRIX, VECTOR > operator* (const BasicMatrix< MATRIX > &lhs, const BasicVector< VECTOR > &rhs)
 
template<class MATRIX , class VECTOR >
expression::MatrixVector< MatrixExpression< expression::TransposedMatrix< MATRIX > >, VECTOR > operator* (const BasicVector< VECTOR > &lhs, const BasicMatrix< MATRIX > &rhs)
 
template<class Derived1 , class Derived2 >
expression::VectorBinary< Derived1, Derived2, expression::Plusoperator+ (const BasicVector< Derived1 > &lhs, const BasicVector< Derived2 > &rhs)
 
template<class Derived1 , class Derived2 >
expression::VectorBinary< Derived1, Derived2, expression::Minusoperator- (const BasicVector< Derived1 > &lhs, const BasicVector< Derived2 > &rhs)
 
template<typename T >
expression::ScaledVector< T > operator- (const BasicVector< T > &vec)
 negation operator More...
 
bool isnull (const VectorBase &)
 Check if all elements of the VectorBase are zero. More...
 
double max (const VectorBase &)
 Get the maximum value of the VectorBase. More...
 
size_t max_index (const VectorBase &)
 Locate the maximum value in the VectorBase. More...
 
double min (const VectorBase &)
 Get the minimum value of the VectorBase. More...
 
size_t min_index (const VectorBase &)
 Locate the minimum value in the VectorBase. More...
 
bool nan (const VectorBase &templat, Vector &flag)
 Create a VectorBase flag indicating NaN's in another VectorBase templat. More...
 
double norm2_squared (const VectorBase &v)
 
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. More...
 
std::ostream & operator<< (std::ostream &s, const VectorBase &v)
 The output operator for the VectorBase class. More...
 

Detailed Description

This is the yat interface to GSL vector.

File streams:
Reading and writing vectors to file streams are of course supported. These are implemented without using GSL functionality, and thus binary read and write to streams are not supported.
Vector views: GSL vector views are supported in classes
VectorView and VectorConstView

Member Typedef Documentation

◆ const_reference

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

const_reference type is const double&

Since
New in yat 0.5

◆ derived_type

Class that inherits from BasicVector

◆ reference

reference type is double&

Since
New in yat 0.5

◆ value_type

value_type is double

Since
New in yat 0.5

Constructor & Destructor Documentation

◆ Vector() [1/6]

theplu::yat::utility::Vector::Vector ( size_t  n,
double  init_value = 0 
)
explicit

Allocates memory space for n elements, and sets all elements to init_value.

Exceptions
GSL_errorif memory allocation fails.

◆ Vector() [2/6]

theplu::yat::utility::Vector::Vector ( const Vector other)

The copy constructor.

Exceptions
AGSL_error is indirectly thrown if memory allocation fails.

◆ Vector() [3/6]

theplu::yat::utility::Vector::Vector ( Vector &&  other)
noexcept

The move constructor.

Since
new in yat 0.15

◆ Vector() [4/6]

template<class T >
theplu::yat::utility::Vector::Vector ( VectorExpression< T > &&  other)
inline

Move constructor from Vector expression.

Since
new in yat 0.15

◆ Vector() [5/6]

theplu::yat::utility::Vector::Vector ( const VectorBase other)
explicit

Copy a VectorBase.

Exceptions
AGSL_error is indirectly thrown if memory allocation fails.

◆ Vector() [6/6]

theplu::yat::utility::Vector::Vector ( std::istream &  ,
char  sep = '\0' 
)
explicit

The istream constructor.

Either elements should be separated with white space characters (default), or elements should be separated by the delimiter sep. When delimiter sep is used empty elements are stored as NaN's (except that empty lines are ignored). The end of input to the Vector is at end of file marker.

Exceptions
GSL_errorif memory allocation fails, IO_error if unexpected input is found in the input stream.

◆ ~Vector()

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

The destructor.

Member Function Documentation

◆ all()

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

Set all elements to value.

◆ begin() [1/3]

const_iterator theplu::yat::utility::VectorBase::begin ( void  ) const
inherited
Returns
read-only iterator to start of VectorBase

◆ begin() [2/3]

iterator theplu::yat::utility::VectorMutable::begin ( void  )
inherited
Returns
mutable iterator to start of VectorMutable

◆ begin() [3/3]

const_iterator theplu::yat::utility::VectorBase::begin
inherited
Returns
read-only iterator to start of VectorBase

◆ div()

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_errorif dimensions mis-match.

◆ end() [1/3]

const_iterator theplu::yat::utility::VectorBase::end ( void  ) const
inherited
Returns
read-only iterator to end of VectorBase

◆ end() [2/3]

iterator theplu::yat::utility::VectorMutable::end ( void  )
inherited
Returns
mutable iterator to end of VectorMutable

◆ end() [3/3]

const_iterator theplu::yat::utility::VectorBase::end
inherited
Returns
read-only iterator to end of VectorBase

◆ equal()

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!=

◆ gsl_vector_p() [1/3]

const gsl_vector* theplu::yat::utility::VectorBase::gsl_vector_p ( void  ) const
inherited
Returns
A const pointer to the internal GSL vector,

◆ gsl_vector_p() [2/3]

gsl_vector* theplu::yat::utility::VectorMutable::gsl_vector_p ( void  )
inherited
Returns
A pointer to the internal GSL vector,

◆ gsl_vector_p() [3/3]

const gsl_vector* theplu::yat::utility::VectorBase::gsl_vector_p
inherited
Returns
A const pointer to the internal GSL vector,

◆ isview()

bool theplu::yat::utility::Vector::isview ( void  ) const
virtual
Returns
false

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

◆ mul()

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_errorif dimensions mis-match.

◆ operator!=()

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)

◆ operator()() [1/2]

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

Element access operator.

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

◆ operator()() [2/2]

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

Element access operator.

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

◆ operator*()

double theplu::yat::utility::VectorBase::operator* ( const VectorBase ) const
inherited
Returns
The dot product.

◆ operator*=()

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.

◆ operator+=() [1/3]

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 VectorMutable.
Exceptions
GSL_errorif dimensions mis-match.

◆ operator+=() [2/3]

template<class T >
VectorMutable& theplu::yat::utility::VectorMutable::operator+= ( const VectorExpression< T > &  rhs)
inlineinherited

Addition and assign operator.

Returns
A reference to the resulting VectorMutable.

◆ operator+=() [3/3]

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.

◆ operator-=() [1/3]

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_errorif dimensions mis-match.

◆ operator-=() [2/3]

template<class T >
VectorMutable& theplu::yat::utility::VectorMutable::operator-= ( const VectorExpression< T > &  rhs)
inlineinherited

Subtraction and assign operator.

Returns
A reference to the resulting VectorMutable.

◆ operator-=() [3/3]

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.

◆ operator=() [1/5]

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

The assignment operator.

Note
Invalidates views and iterators of Vector.
Returns
A const reference to the resulting Vector.
Exceptions
GSL_errorif assignment fails.

◆ operator=() [2/5]

template<class T >
Vector& theplu::yat::utility::Vector::operator= ( const VectorExpression< T > &  rhs)
inline

assignment from vector expression

Since
new in yat 0.15

◆ operator=() [3/5]

Vector& theplu::yat::utility::Vector::operator= ( Vector &&  )

The move assignment operator.

Note
Invalidates views and iterators of Vector.
Returns
A reference to the resulting Vector.
Since
new in yat 0.15

◆ operator=() [4/5]

template<class T >
Vector& theplu::yat::utility::Vector::operator= ( VectorExpression< T > &&  rhs)
inline

move assignment from vector expression

Since
new in yat 0.15

◆ operator=() [5/5]

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

The assignment operator.

Note
Invalidates views and iterators of Vector.
Returns
A const reference to the resulting Vector.
Exceptions
GSL_errorif assignment fails.

◆ operator==()

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)

◆ resize()

void theplu::yat::utility::Vector::resize ( size_t  ,
double  init_value = 0 
)

Resize Vector.

All elements are set to init_value.

Note
Underlying GSL vector is destroyed and a view or an iterator into this Vector becomes invalid.
Exceptions
GSL_errorif memory allocation fails.

◆ size()

size_t theplu::yat::utility::VectorBase::size ( void  ) const
inherited
Returns
number of elements in the VectorBase.

Friends And Related Function Documentation

◆ isnull()

bool isnull ( const VectorBase )
related

Check if all elements of the VectorBase are zero.

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

◆ max()

double max ( const VectorBase )
related

Get the maximum value of the VectorBase.

Returns
The maximum value of the VectorBase.

◆ max_index()

size_t max_index ( const VectorBase )
related

Locate the maximum value in the VectorBase.

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

◆ min()

double min ( const VectorBase )
related

Get the minimum value of the VectorBase.

Returns
The minimum value of the VectorBase.

◆ min_index()

size_t min_index ( const VectorBase )
related

Locate the minimum value in the VectorBase.

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

◆ nan()

bool nan ( const VectorBase templat,
Vector flag 
)
related

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.

◆ norm2_squared()

double norm2_squared ( const VectorBase v)
related
Returns
L2 norm squared, or the dot product of v with itself
Since
New in yat 0.18

◆ operator*() [1/5]

template<class MATRIX , class VECTOR >
expression::MatrixVector< MATRIX, VECTOR > operator* ( const BasicMatrix< MATRIX > &  lhs,
const BasicVector< VECTOR > &  rhs 
)
related

Calculate product of Matrix expression and Vector expression

Since
new in yat 0.15

◆ operator*() [2/5]

template<class MATRIX , class VECTOR >
expression::MatrixVector< MatrixExpression< expression::TransposedMatrix< MATRIX > >, VECTOR > operator* ( const BasicVector< VECTOR > &  lhs,
const BasicMatrix< MATRIX > &  rhs 
)
related

Calculate product of Vector expression and Matrix expression

Since
new in yat 0.15

◆ operator*() [3/5]

template<class Derived1 , class Derived2 >
double operator* ( const BasicVector< Derived1 > &  lhs,
const BasicVector< Derived2 > &  rhs 
)
related
Since
New in yat 0.15

◆ operator*() [4/5]

template<typename T >
expression::ScaledVector< T > operator* ( double  k,
const BasicVector< T > &  vec 
)
related

scale a vector expression

Since
new in yat 0.15

◆ operator*() [5/5]

template<typename T >
expression::ScaledVector< T > operator* ( const BasicVector< T > &  vec,
double  k 
)
related

scale a vector expression

Since
new in yat 0.15

◆ operator+()

template<class Derived1 , class Derived2 >
expression::VectorBinary< Derived1, Derived2, expression::Plus > operator+ ( const BasicVector< Derived1 > &  lhs,
const BasicVector< Derived2 > &  rhs 
)
related

Element-wise addition of vectors

Since
new in yat 0.15

◆ operator-() [1/2]

template<class Derived1 , class Derived2 >
expression::VectorBinary< Derived1, Derived2, expression::Minus > operator- ( const BasicVector< Derived1 > &  lhs,
const BasicVector< Derived2 > &  rhs 
)
related

Element-wise subtraction of vectors

Since
new in yat 0.15

◆ operator-() [2/2]

template<typename T >
expression::ScaledVector< T > operator- ( const BasicVector< T > &  vec)
related

negation operator

Since
new in yat 0.15

◆ operator<<()

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

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;

◆ sort_index()

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

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.

◆ sort_largest_index()

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

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

◆ sort_smallest_index()

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

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

◆ sum()

double sum ( const VectorBase )
related

Calculate the sum of all VectorBase elements.

Returns
The sum.

◆ swap()

void swap ( Vector ,
Vector  
)
related

Swap Vector elements by copying.

The two Vectors must have the same length.

Exceptions
GSL_errorif Vector lengths differs.

Member Data Documentation

◆ vec_

gsl_vector* theplu::yat::utility::VectorMutable::vec_
protectedinherited

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 Sat Feb 18 2023 03:31:45 for yat by  doxygen 1.8.14