GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GVector Class Reference

Vector class. More...

#include <GVector.hpp>

Inheritance diagram for GVector:
GBase

Public Member Functions

 GVector (void)
 Void vector constructor. More...
 
 GVector (const int &num)
 Vector constructor. More...
 
 GVector (const double &a)
 Single element vector constructor. More...
 
 GVector (const double &a, const double &b)
 Two elements vector constructor. More...
 
 GVector (const double &a, const double &b, const double &c)
 Three elements vector constructor. More...
 
 GVector (const GVector &vector)
 Copy constructor. More...
 
virtual ~GVector (void)
 Destructor. More...
 
double & operator[] (const int &index)
 Vector element access operator. More...
 
const double & operator[] (const int &index) const
 Vector element access operator (const variant) More...
 
bool operator== (const GVector &vector) const
 Equality operator. More...
 
bool operator!= (const GVector &vector) const
 Non-equality operator. More...
 
GVectoroperator= (const GVector &vector)
 Assignment operator. More...
 
GVectoroperator+= (const GVector &vector)
 Unary addition operator. More...
 
GVectoroperator-= (const GVector &vector)
 Unary subtraction operator. More...
 
GVectoroperator= (const double &scalar)
 Scalar assignment operator. More...
 
GVectoroperator+= (const double &scalar)
 Scalar unary addition operator. More...
 
GVectoroperator-= (const double &scalar)
 Scalar unary subtraction operator. More...
 
GVectoroperator*= (const double &scalar)
 Scalar unary multiplication operator. More...
 
GVectoroperator/= (const double &scalar)
 Scalar unary division operator. More...
 
GVector operator- (void) const
 Unary minus operator. More...
 
void clear (void)
 Clear vector. More...
 
GVectorclone (void) const
 Clone vector. More...
 
std::string classname (void) const
 Return class name. More...
 
const int & size (void) const
 Return size of vector. More...
 
double & at (const int &index)
 Vector element access with range checking. More...
 
const double & at (const int &index) const
 Vector element access with range checking (const variant) More...
 
int non_zeros (void) const
 Returns number of non-zero elements in vector. More...
 
int first_nonzero (void) const
 Return the index of the first non-zero element in a vector. More...
 
int last_nonzero (void) const
 Return the index of the last non-zero element in a vector. More...
 
GVector slice (const int &start, const int &stop) const
 Vector slice operator. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print vector information. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Private Member Functions

void init_members (void)
 Initialise class members. More...
 
void alloc_members (void)
 Allocate vector. More...
 
void copy_members (const GVector &vector)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Private Attributes

int m_num
 Number of elements in vector. More...
 
double * m_data
 Vector array. More...
 

Friends

GVector cross (const GVector &a, const GVector &b)
 Vector cross product. More...
 
double operator* (const GVector &a, const GVector &b)
 Vector scalar product. More...
 
double norm (const GVector &vector)
 Computes vector norm. More...
 
double min (const GVector &vector)
 Computes minimum vector element. More...
 
double max (const GVector &vector)
 Computes maximum vector element. More...
 
double sum (const GVector &vector)
 Computes vector sum. More...
 
GVector perm (const GVector &vector, const int *p)
 Computes vector permutation. More...
 
GVector iperm (const GVector &vector, const int *p)
 Computes vector inverse permutation. More...
 
GVector acos (const GVector &vector)
 Computes arccos of vector elements. More...
 
GVector acosh (const GVector &vector)
 Computes acosh of vector elements. More...
 
GVector asin (const GVector &vector)
 Computes arcsin of vector elements. More...
 
GVector asinh (const GVector &vector)
 Computes asinh of vector elements. More...
 
GVector atan (const GVector &vector)
 Computes arctan of vector elements. More...
 
GVector atanh (const GVector &vector)
 Computes atanh of vector elements. More...
 
GVector cos (const GVector &vector)
 Computes cosine of vector elements. More...
 
GVector cosh (const GVector &vector)
 Computes cosh of vector elements. More...
 
GVector exp (const GVector &vector)
 Computes exponential of vector elements. More...
 
GVector abs (const GVector &vector)
 Computes absolute of vector elements. More...
 
GVector log (const GVector &vector)
 Computes natural logarithm of vector elements. More...
 
GVector log10 (const GVector &vector)
 Computes base10 logarithm of vector elements. More...
 
GVector sin (const GVector &vector)
 Computes sine of vector elements. More...
 
GVector sinh (const GVector &vector)
 Computes sinh of vector elements. More...
 
GVector sqrt (const GVector &vector)
 Computes square root of vector elements. More...
 
GVector tan (const GVector &vector)
 Computes tangens of vector elements. More...
 
GVector tanh (const GVector &vector)
 Computes tanh of vector elements. More...
 
GVector pow (const GVector &vector, const double &power)
 Computes tanh of vector elements. More...
 

Detailed Description

Vector class.

This class implement a double precision floating point vector class that is intended to be used for numerical computation (it is not meant to replace the std::vector template class).

Definition at line 46 of file GVector.hpp.

Constructor & Destructor Documentation

GVector::GVector ( void  )

Void vector constructor.

Definition at line 52 of file GVector.cpp.

References init_members().

Referenced by clone().

GVector::GVector ( const int &  num)
explicit

Vector constructor.

Parameters
[in]numNumber of elements in vector.

Initialises a vector with num elements. All vector elements will be set to 0.

Definition at line 70 of file GVector.cpp.

References alloc_members(), init_members(), and m_num.

GVector::GVector ( const double &  a)
explicit

Single element vector constructor.

Parameters
[in]aVector element.

Initialises a vector with a single element.

Definition at line 93 of file GVector.cpp.

References alloc_members(), init_members(), m_data, and m_num.

GVector::GVector ( const double &  a,
const double &  b 
)
explicit

Two elements vector constructor.

Parameters
[in]aFirst vector element.
[in]bSecond vector element.

Initialises a vector with two elements.

Definition at line 120 of file GVector.cpp.

References alloc_members(), init_members(), m_data, and m_num.

GVector::GVector ( const double &  a,
const double &  b,
const double &  c 
)
explicit

Three elements vector constructor.

Parameters
[in]aFirst vector element.
[in]bSecond vector element.
[in]cThird vector element.

Initialises a vector with three elements.

Definition at line 149 of file GVector.cpp.

References alloc_members(), init_members(), m_data, and m_num.

GVector::GVector ( const GVector vector)

Copy constructor.

Parameters
[in]vectorVector.

Definition at line 174 of file GVector.cpp.

References copy_members(), and init_members().

GVector::~GVector ( void  )
virtual

Destructor.

Definition at line 190 of file GVector.cpp.

References free_members().

Member Function Documentation

void GVector::alloc_members ( void  )
private

Allocate vector.

Definition at line 686 of file GVector.cpp.

References m_data, and m_num.

Referenced by copy_members(), and GVector().

double & GVector::at ( const int &  index)

Vector element access with range checking.

Parameters
[in]indexElement index [0,...,size()-1].
Exceptions
GException::out_of_rangeElement index is out of range.

Definition at line 498 of file GVector.cpp.

References G_AT, m_data, and size().

const double & GVector::at ( const int &  index) const

Vector element access with range checking (const variant)

Parameters
[in]indexElement index [0,...,size()-1].
Exceptions
GException::out_of_rangeElement index is out of range.

Definition at line 518 of file GVector.cpp.

References G_AT, m_data, and size().

std::string GVector::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GVector").

Implements GBase.

Definition at line 138 of file GVector.hpp.

void GVector::clear ( void  )
virtual

Clear vector.

Implements GBase.

Definition at line 465 of file GVector.cpp.

References free_members(), and init_members().

GVector * GVector::clone ( void  ) const
virtual

Clone vector.

Returns
Pointer to deep copy of vector.

Implements GBase.

Definition at line 483 of file GVector.cpp.

References GVector().

void GVector::copy_members ( const GVector vector)
private

Copy class members.

Parameters
[in]vectorVector from which members should be copied.

Definition at line 709 of file GVector.cpp.

References alloc_members(), m_data, and m_num.

Referenced by GVector(), and operator=().

int GVector::first_nonzero ( void  ) const

Return the index of the first non-zero element in a vector.

Returns
Index of first non-zero element in vector.

Returns the index of the first non-zero element. If all elements are zero the method will return -1.

Definition at line 559 of file GVector.cpp.

References m_data, and m_num.

void GVector::free_members ( void  )
private

Delete class members.

Definition at line 730 of file GVector.cpp.

References m_data.

Referenced by clear(), operator=(), and ~GVector().

void GVector::init_members ( void  )
private

Initialise class members.

Definition at line 672 of file GVector.cpp.

References m_data, and m_num.

Referenced by clear(), GVector(), and operator=().

int GVector::last_nonzero ( void  ) const

Return the index of the last non-zero element in a vector.

Returns
Index of last non-zero element in vector.

Returns the index of the last non-zero element. If all elements are zero the method will return -1.

Definition at line 585 of file GVector.cpp.

References m_data, and m_num.

int GVector::non_zeros ( void  ) const

Returns number of non-zero elements in vector.

Returns
Number of non-zero elements in vector.

Definition at line 535 of file GVector.cpp.

References m_data, and m_num.

Referenced by GMatrixSparse::add_to_column().

bool GVector::operator!= ( const GVector vector) const

Non-equality operator.

Parameters
[in]vectorVector.
Returns
True if both vectors are different.

Definition at line 268 of file GVector.cpp.

References operator==().

GVector & GVector::operator*= ( const double &  scalar)

Scalar unary multiplication operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Multiply all vector elements by scalar.

Definition at line 402 of file GVector.cpp.

References m_data, and m_num.

GVector & GVector::operator+= ( const GVector vector)

Unary addition operator.

Parameters
[in]vectorVector.
Returns
Vector.
Exceptions
GException::vector_mismatchVectors have not the same size.

Adds vector.

Definition at line 289 of file GVector.cpp.

References G_OP_ADD, m_data, and m_num.

GVector & GVector::operator+= ( const double &  scalar)

Scalar unary addition operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Adds scalar to all vector elements.

Definition at line 362 of file GVector.cpp.

References m_data, and m_num.

GVector GVector::operator- ( void  ) const

Unary minus operator.

Returns
Vector.

Negate all vector elements.

Definition at line 441 of file GVector.cpp.

References m_data, and m_num.

GVector & GVector::operator-= ( const GVector vector)

Unary subtraction operator.

Parameters
[in]vectorVector.
Returns
Vector.
Exceptions
GException::vector_mismatchVectors have not the same size.

Subtracts vector.

Definition at line 317 of file GVector.cpp.

References G_OP_SUB, m_data, and m_num.

GVector & GVector::operator-= ( const double &  scalar)

Scalar unary subtraction operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Subtract scalar to all vector elements.

Definition at line 382 of file GVector.cpp.

References m_data, and m_num.

GVector & GVector::operator/= ( const double &  scalar)

Scalar unary division operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Divide all vector elements by scalar.

Definition at line 422 of file GVector.cpp.

References m_data, and m_num.

GVector & GVector::operator= ( const GVector vector)

Assignment operator.

Parameters
[in]vectorVector.
Returns
Vector.

Definition at line 212 of file GVector.cpp.

References copy_members(), free_members(), and init_members().

GVector & GVector::operator= ( const double &  scalar)

Scalar assignment operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Subtracts vector.

Definition at line 342 of file GVector.cpp.

References m_data, and m_num.

bool GVector::operator== ( const GVector vector) const

Equality operator.

Parameters
[in]vectorVector.
Returns
True if vectors are identical.

Returns true if vectors are identical. Vectors are considered identical if they have the same size and if all their elements are identical.

Definition at line 242 of file GVector.cpp.

References m_data, and m_num.

Referenced by operator!=().

double & GVector::operator[] ( const int &  index)
inline

Vector element access operator.

Parameters
[in]indexElement index [0,...,size()-1]
Returns
Reference to vector element.

Definition at line 151 of file GVector.hpp.

References m_data.

const double & GVector::operator[] ( const int &  index) const
inline

Vector element access operator (const variant)

Parameters
[in]indexElement index [0,...,size()-1]
Returns
Reference to vector element.

Definition at line 165 of file GVector.hpp.

References m_data.

std::string GVector::print ( const GChatter chatter = NORMAL) const
virtual

Print vector information.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing vector information.

Implements GBase.

Definition at line 637 of file GVector.cpp.

References m_num, SILENT, and gammalib::str().

GVector GVector::slice ( const int &  start,
const int &  stop 
) const

Vector slice operator.

Parameters
[in]startStart index [0,...,size()-1]
[in]stopStop index [0,...,size()-1]
Returns
Vector made of elements [start,...,stop].

Definition at line 610 of file GVector.cpp.

References m_data.

Friends And Related Function Documentation

GVector abs ( const GVector vector)
friend

Computes absolute of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the absolute of every element.

Definition at line 1163 of file GVector.cpp.

GVector acos ( const GVector vector)
friend

Computes arccos of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the arccos of every element.

Definition at line 974 of file GVector.cpp.

GVector acosh ( const GVector vector)
friend

Computes acosh of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the acosh of every element.

Definition at line 995 of file GVector.cpp.

GVector asin ( const GVector vector)
friend

Computes arcsin of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the arcsin of every element.

Definition at line 1016 of file GVector.cpp.

GVector asinh ( const GVector vector)
friend

Computes asinh of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the asinh of every element.

Definition at line 1037 of file GVector.cpp.

GVector atan ( const GVector vector)
friend

Computes arctan of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the arctan of every element.

Definition at line 1058 of file GVector.cpp.

GVector atanh ( const GVector vector)
friend

Computes atanh of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the atanh of every element.

Definition at line 1079 of file GVector.cpp.

GVector cos ( const GVector vector)
friend

Computes cosine of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the cosine of every element.

Definition at line 1100 of file GVector.cpp.

GVector cosh ( const GVector vector)
friend

Computes cosh of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the cosh of every element.

Definition at line 1121 of file GVector.cpp.

GVector cross ( const GVector a,
const GVector b 
)
friend

Vector cross product.

Parameters
[in]aVector.
[in]bVector.
Returns
Vector cross product.
Exceptions
GException::vector_mismatchMismatch between vector size.

Computes the cross product between two 3-element vectors (note that the cross product is only defined for 3-element vectors).

Definition at line 762 of file GVector.cpp.

GVector exp ( const GVector vector)
friend

Computes exponential of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the exponential of every element.

Definition at line 1142 of file GVector.cpp.

GVector iperm ( const GVector vector,
const int *  p 
)
friend

Computes vector inverse permutation.

Parameters
[in]vectorVector.
[in]pPermutation array.
Returns
Inversely permuted vector.

Definition at line 948 of file GVector.cpp.

GVector log ( const GVector vector)
friend

Computes natural logarithm of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the natural logarithm of every element.

Definition at line 1184 of file GVector.cpp.

GVector log10 ( const GVector vector)
friend

Computes base10 logarithm of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the base10 logarithm of every element.

Definition at line 1205 of file GVector.cpp.

double max ( const GVector vector)
friend

Computes maximum vector element.

Parameters
[in]vectorVector.
Returns
Maximum vector element.

Definition at line 872 of file GVector.cpp.

double min ( const GVector vector)
friend

Computes minimum vector element.

Parameters
[in]vectorVector.
Returns
Minimum vector element.

Definition at line 843 of file GVector.cpp.

double norm ( const GVector vector)
friend

Computes vector norm.

Parameters
[in]vectorVector.
Returns
Vector norm.

Definition at line 821 of file GVector.cpp.

double operator* ( const GVector a,
const GVector b 
)
friend

Vector scalar product.

Parameters
[in]aVector.
[in]bVector.
Returns
Product between vector a and b.
Exceptions
GException::vector_mismatchMismatch between vector size.

Returns the scalar product between vector a and b.

Definition at line 797 of file GVector.cpp.

GVector perm ( const GVector vector,
const int *  p 
)
friend

Computes vector permutation.

Parameters
[in]vectorVector.
[in]pPermutation array.
Returns
Permuted vector.

Definition at line 921 of file GVector.cpp.

GVector pow ( const GVector vector,
const double &  power 
)
friend

Computes tanh of vector elements.

Parameters
[in]vectorVector.
[in]powerPower.
Returns
Vector containing the power of every element.

Definition at line 1332 of file GVector.cpp.

GVector sin ( const GVector vector)
friend

Computes sine of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the sine of every element.

Definition at line 1226 of file GVector.cpp.

GVector sinh ( const GVector vector)
friend

Computes sinh of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the sinh of every element.

Definition at line 1247 of file GVector.cpp.

GVector sqrt ( const GVector vector)
friend

Computes square root of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the square root of every element.

Definition at line 1268 of file GVector.cpp.

double sum ( const GVector vector)
friend

Computes vector sum.

Parameters
[in]vectorVector.
Returns
Sum of vector elements.

Definition at line 901 of file GVector.cpp.

GVector tan ( const GVector vector)
friend

Computes tangens of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the tangens of every element.

Definition at line 1289 of file GVector.cpp.

GVector tanh ( const GVector vector)
friend

Computes tanh of vector elements.

Parameters
[in]vectorVector.
Returns
Vector containing the tanh of every element.

Definition at line 1310 of file GVector.cpp.

Member Data Documentation


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