GammaLib  2.0.0
 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...
 
double angle (const GVector &a, const GVector &b)
 Computes angle between vectors. 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 54 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 [>=0].
Exceptions
GException::invalid_argumentNumber of elements is negative.

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

Definition at line 75 of file GVector.cpp.

References alloc_members(), G_CONSTRUCTOR, init_members(), m_num, and gammalib::str().

GVector::GVector ( const double &  a)
explicit

Single element vector constructor.

Parameters
[in]aVector element.

Initialises a vector with a single element.

Definition at line 109 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 136 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 165 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 190 of file GVector.cpp.

References copy_members(), and init_members().

GVector::~GVector ( void  )
virtual

Destructor.

Definition at line 206 of file GVector.cpp.

References free_members().

Member Function Documentation

void GVector::alloc_members ( void  )
private

Allocate vector.

Definition at line 710 of file GVector.cpp.

References m_data, and m_num.

Referenced by GVector().

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

Vector element access with range checking.

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

Definition at line 522 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()[.
Exceptions
GException::out_of_rangeElement index is out of range.

Definition at line 542 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 136 of file GVector.hpp.

void GVector::clear ( void  )
virtual

Clear vector.

Implements GBase.

Definition at line 489 of file GVector.cpp.

References free_members(), and init_members().

Referenced by GCOMBvc::init_members(), and GIntegrals::init_members().

GVector * GVector::clone ( void  ) const
virtual

Clone vector.

Returns
Pointer to deep copy of vector.

Implements GBase.

Definition at line 507 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 735 of file GVector.cpp.

References 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 583 of file GVector.cpp.

References m_data, and m_num.

void GVector::free_members ( void  )
private

Delete class members.

Definition at line 761 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 696 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 609 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 559 of file GVector.cpp.

References m_data, and m_num.

Referenced by GMatrixSparse::add_to_column(), and GResponseVectorCache::set().

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

Non-equality operator.

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

Definition at line 284 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 426 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::invalid_argumentVectors have not the same size.

Adds vector.

Definition at line 305 of file GVector.cpp.

References G_OP_ADD, m_data, m_num, and gammalib::str().

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

Scalar unary addition operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Adds scalar to all vector elements.

Definition at line 386 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 465 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 337 of file GVector.cpp.

References G_OP_SUB, m_data, m_num, and gammalib::str().

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

Scalar unary subtraction operator.

Parameters
[in]scalarScalar.
Returns
Vector.

Subtract scalar to all vector elements.

Definition at line 406 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 446 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 228 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 366 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 258 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 149 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 163 of file GVector.hpp.

References m_data.

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

Print vector information.

Parameters
[in]chatterChattiness.
Returns
String containing vector information.

Implements GBase.

Definition at line 661 of file GVector.cpp.

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

Referenced by GIntegrals::print(), GIntegrals::romberg(), and GIntegrals::trapzd().

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 634 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 1253 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 1064 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 1085 of file GVector.cpp.

double angle ( const GVector a,
const GVector b 
)
friend

Computes angle between vectors.

Parameters
[in]aVector.
[in]bVector.
Returns
Angle between vector a and b in radians.
Exceptions
GException::invalid_argumentMismatch between vector size.

Returns the angle \(\alpha\) between vector a and b in radians. The computation is done using

\[ \alpha = \arccos{\frac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|}} \]

Definition at line 974 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 1106 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 1127 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 1148 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 1169 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 1190 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 1211 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::invalid_argumentMismatch between vector size or vector not of size 3.

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

Definition at line 793 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 1232 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 1038 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 1274 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 1295 of file GVector.cpp.

double max ( const GVector vector)
friend

Computes maximum vector element.

Parameters
[in]vectorVector.
Returns
Maximum vector element.

Definition at line 915 of file GVector.cpp.

double min ( const GVector vector)
friend

Computes minimum vector element.

Parameters
[in]vectorVector.
Returns
Minimum vector element.

Definition at line 886 of file GVector.cpp.

double norm ( const GVector vector)
friend

Computes vector norm.

Parameters
[in]vectorVector.
Returns
Vector norm.

Definition at line 864 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::invalid_argumentMismatch between vector size.

Returns the scalar product between vector a and b.

Definition at line 836 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 1011 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 1422 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 1316 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 1337 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 1358 of file GVector.cpp.

double sum ( const GVector vector)
friend

Computes vector sum.

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

Definition at line 944 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 1379 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 1400 of file GVector.cpp.

Member Data Documentation


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