GammaLib 2.1.0.dev
|
Vector class. More...
#include <GVector.hpp>
Public Member Functions | |
GVector (void) | |
Void vector constructor. | |
GVector (const int &num) | |
Vector constructor. | |
GVector (const double &a) | |
Single element vector constructor. | |
GVector (const double &a, const double &b) | |
Two elements vector constructor. | |
GVector (const double &a, const double &b, const double &c) | |
Three elements vector constructor. | |
GVector (const GVector &vector) | |
Copy constructor. | |
virtual | ~GVector (void) |
Destructor. | |
double & | operator[] (const int &index) |
Vector element access operator. | |
const double & | operator[] (const int &index) const |
Vector element access operator (const variant) | |
bool | operator== (const GVector &vector) const |
Equality operator. | |
bool | operator!= (const GVector &vector) const |
Non-equality operator. | |
GVector & | operator= (const GVector &vector) |
Assignment operator. | |
GVector & | operator+= (const GVector &vector) |
Unary addition operator. | |
GVector & | operator-= (const GVector &vector) |
Unary subtraction operator. | |
GVector & | operator*= (const GVector &vector) |
Unary multiplication operator. | |
GVector & | operator/= (const GVector &vector) |
Unary division operator. | |
GVector & | operator= (const double &scalar) |
Scalar assignment operator. | |
GVector & | operator+= (const double &scalar) |
Scalar unary addition operator. | |
GVector & | operator-= (const double &scalar) |
Scalar unary subtraction operator. | |
GVector & | operator*= (const double &scalar) |
Scalar unary multiplication operator. | |
GVector & | operator/= (const double &scalar) |
Scalar unary division operator. | |
GVector | operator- (void) const |
Unary minus operator. | |
void | clear (void) |
Clear vector. | |
GVector * | clone (void) const |
Clone vector. | |
std::string | classname (void) const |
Return class name. | |
const int & | size (void) const |
Return size of vector. | |
double & | at (const int &index) |
Vector element access with range checking. | |
const double & | at (const int &index) const |
Vector element access with range checking (const variant) | |
int | non_zeros (void) const |
Returns number of non-zero elements in vector. | |
int | first_nonzero (void) const |
Return the index of the first non-zero element in a vector. | |
int | last_nonzero (void) const |
Return the index of the last non-zero element in a vector. | |
GVector | slice (const int &start, const int &stop) const |
Vector slice operator. | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print vector information. | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. | |
Private Member Functions | |
void | init_members (void) |
Initialise class members. | |
void | alloc_members (void) |
Allocate vector. | |
void | copy_members (const GVector &vector) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
Private Attributes | |
int | m_num |
Number of elements in vector. | |
double * | m_data |
Vector array. | |
Friends | |
GVector | cross (const GVector &a, const GVector &b) |
Vector cross product. | |
double | operator* (const GVector &a, const GVector &b) |
Vector scalar product. | |
double | norm (const GVector &vector) |
Computes vector norm. | |
double | min (const GVector &vector) |
Computes minimum vector element. | |
double | max (const GVector &vector) |
Computes maximum vector element. | |
double | sum (const GVector &vector) |
Computes vector sum. | |
double | angle (const GVector &a, const GVector &b) |
Computes angle between vectors. | |
GVector | perm (const GVector &vector, const int *p) |
Computes vector permutation. | |
GVector | iperm (const GVector &vector, const int *p) |
Computes vector inverse permutation. | |
GVector | acos (const GVector &vector) |
Computes arccos of vector elements. | |
GVector | acosh (const GVector &vector) |
Computes acosh of vector elements. | |
GVector | asin (const GVector &vector) |
Computes arcsin of vector elements. | |
GVector | asinh (const GVector &vector) |
Computes asinh of vector elements. | |
GVector | atan (const GVector &vector) |
Computes arctan of vector elements. | |
GVector | atanh (const GVector &vector) |
Computes atanh of vector elements. | |
GVector | cos (const GVector &vector) |
Computes cosine of vector elements. | |
GVector | cosh (const GVector &vector) |
Computes cosh of vector elements. | |
GVector | exp (const GVector &vector) |
Computes exponential of vector elements. | |
GVector | abs (const GVector &vector) |
Computes absolute of vector elements. | |
GVector | log (const GVector &vector) |
Computes natural logarithm of vector elements. | |
GVector | log10 (const GVector &vector) |
Computes base10 logarithm of vector elements. | |
GVector | sin (const GVector &vector) |
Computes sine of vector elements. | |
GVector | sinh (const GVector &vector) |
Computes sinh of vector elements. | |
GVector | sqrt (const GVector &vector) |
Computes square root of vector elements. | |
GVector | tan (const GVector &vector) |
Computes tangens of vector elements. | |
GVector | tanh (const GVector &vector) |
Computes tanh of vector elements. | |
GVector | pow (const GVector &vector, const double &power) |
Computes tanh of vector elements. | |
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.
GVector::GVector | ( | void | ) |
Void vector constructor.
Definition at line 56 of file GVector.cpp.
References init_members().
Referenced by clone().
|
explicit |
Vector constructor.
[in] | num | Number of elements in vector [>=0]. |
GException::invalid_argument | Number of elements is negative. |
Initialises a vector with num
elements. All vector elements will be set to 0.
Definition at line 77 of file GVector.cpp.
References alloc_members(), G_CONSTRUCTOR, init_members(), m_num, and gammalib::str().
|
explicit |
Single element vector constructor.
[in] | a | Vector element. |
Initialises a vector with a single element.
Definition at line 111 of file GVector.cpp.
References alloc_members(), init_members(), m_data, and m_num.
|
explicit |
Two elements vector constructor.
[in] | a | First vector element. |
[in] | b | Second vector element. |
Initialises a vector with two elements.
Definition at line 138 of file GVector.cpp.
References alloc_members(), init_members(), m_data, and m_num.
|
explicit |
Three elements vector constructor.
[in] | a | First vector element. |
[in] | b | Second vector element. |
[in] | c | Third vector element. |
Initialises a vector with three elements.
Definition at line 167 of file GVector.cpp.
References alloc_members(), init_members(), m_data, and m_num.
GVector::GVector | ( | const GVector & | vector | ) |
Copy constructor.
[in] | vector | Vector. |
Definition at line 192 of file GVector.cpp.
References copy_members(), and init_members().
|
virtual |
|
private |
double & GVector::at | ( | const int & | index | ) |
Vector element access with range checking.
[in] | index | Element index [0,...,size()[. |
GException::out_of_range | Element index is out of range. |
Definition at line 590 of file GVector.cpp.
const double & GVector::at | ( | const int & | index | ) | const |
Vector element access with range checking (const variant)
[in] | index | Element index [0,...,size()[. |
GException::out_of_range | Element index is out of range. |
Definition at line 610 of file GVector.cpp.
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 138 of file GVector.hpp.
|
virtual |
Clear vector.
Implements GBase.
Definition at line 557 of file GVector.cpp.
References free_members(), and init_members().
Referenced by GCOMResponse::compute_faq(), GCOMBvc::init_members(), GCOMResponse::init_members(), and GIntegrals::init_members().
|
virtual |
Clone vector.
Implements GBase.
Definition at line 575 of file GVector.cpp.
References GVector().
|
private |
Copy class members.
[in] | vector | Vector from which members should be copied. |
Definition at line 803 of file GVector.cpp.
Referenced by GVector(), and operator=().
int GVector::first_nonzero | ( | void | ) | const |
Return the index of the first non-zero element in a vector.
Returns the index of the first non-zero element. If all elements are zero the method will return -1.
Definition at line 651 of file GVector.cpp.
|
private |
Delete class members.
Definition at line 829 of file GVector.cpp.
References m_data.
Referenced by clear(), operator=(), and ~GVector().
|
private |
int GVector::last_nonzero | ( | void | ) | const |
Return the index of the last non-zero element in a vector.
Returns the index of the last non-zero element. If all elements are zero the method will return -1.
Definition at line 677 of file GVector.cpp.
int GVector::non_zeros | ( | void | ) | const |
Returns number of non-zero elements in vector.
Definition at line 627 of file GVector.cpp.
References m_data, m_num, and non_zeros().
Referenced by GMatrixSparse::add_to_column(), GMatrixSparse::colfill_set_column(), GMatrixSparse::column(), GVectorSparse::GVectorSparse(), non_zeros(), and GResponseVectorCache::set().
bool GVector::operator!= | ( | const GVector & | vector | ) | const |
Non-equality operator.
[in] | vector | Vector. |
Definition at line 286 of file GVector.cpp.
References operator==().
GVector & GVector::operator*= | ( | const double & | scalar | ) |
Scalar unary multiplication operator.
[in] | scalar | Scalar. |
Multiply all vector elements by scalar.
Definition at line 494 of file GVector.cpp.
Unary multiplication operator.
[in] | vector | Vector. |
GException::vector_mismatch | Vectors have not the same size. |
Multiplies vector elements.
Definition at line 371 of file GVector.cpp.
References G_OP_MULT, m_data, m_num, and gammalib::str().
GVector & GVector::operator+= | ( | const double & | scalar | ) |
Scalar unary addition operator.
[in] | scalar | Scalar. |
Adds scalar to all vector elements.
Definition at line 454 of file GVector.cpp.
Unary addition operator.
[in] | vector | Vector. |
GException::invalid_argument | Vectors have not the same size. |
Adds vector elements.
Definition at line 307 of file GVector.cpp.
References G_OP_ADD, m_data, m_num, and gammalib::str().
GVector GVector::operator- | ( | void | ) | const |
Unary minus operator.
Negate all vector elements.
Definition at line 533 of file GVector.cpp.
GVector & GVector::operator-= | ( | const double & | scalar | ) |
Scalar unary subtraction operator.
[in] | scalar | Scalar. |
Subtract scalar to all vector elements.
Definition at line 474 of file GVector.cpp.
Unary subtraction operator.
[in] | vector | Vector. |
GException::vector_mismatch | Vectors have not the same size. |
Subtracts vector elements.
Definition at line 339 of file GVector.cpp.
References G_OP_SUB, m_data, m_num, and gammalib::str().
GVector & GVector::operator/= | ( | const double & | scalar | ) |
Scalar unary division operator.
[in] | scalar | Scalar. |
Divide all vector elements by scalar.
Definition at line 514 of file GVector.cpp.
Unary division operator.
[in] | vector | Vector. |
GException::vector_mismatch | Vectors have not the same size. |
Divide vector elements.
Definition at line 405 of file GVector.cpp.
References G_OP_DIV, m_data, m_num, and gammalib::str().
GVector & GVector::operator= | ( | const double & | scalar | ) |
Scalar assignment operator.
[in] | scalar | Scalar. |
Subtracts vector.
Definition at line 434 of file GVector.cpp.
Assignment operator.
[in] | vector | Vector. |
Definition at line 230 of file GVector.cpp.
References copy_members(), free_members(), and init_members().
bool GVector::operator== | ( | const GVector & | vector | ) | const |
Equality operator.
[in] | vector | Vector. |
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 260 of file GVector.cpp.
Referenced by operator!=().
|
inline |
Vector element access operator.
[in] | index | Element index [0,...,size()-1] |
Definition at line 151 of file GVector.hpp.
References m_data.
|
inline |
Vector element access operator (const variant)
[in] | index | Element index [0,...,size()-1] |
Definition at line 165 of file GVector.hpp.
References m_data.
Print vector information.
[in] | chatter | Chattiness. |
Implements GBase.
Definition at line 729 of file GVector.cpp.
References m_num, SILENT, and gammalib::str().
Referenced by GIntegrals::print(), GIntegrals::romberg(), and GIntegrals::trapzd().
|
inline |
Return size of vector.
Returns the number of elements in the vector.
Definition at line 180 of file GVector.hpp.
References m_num.
Referenced by GMatrix::add_to_column(), GMatrixSparse::add_to_column(), GMatrixSymmetric::add_to_column(), GMatrix::add_to_row(), GMatrixSymmetric::add_to_row(), at(), at(), GMatrixSparse::cholesky_solver(), GMatrixSymmetric::cholesky_solver(), GMatrixSparse::colfill_set_column(), GMatrix::column(), GMatrixSparse::column(), GMatrixSymmetric::column(), GMatrixSparse::column_to_vector(), GResponseVectorCache::contains(), GVectorSparse::GVectorSparse(), GMatrixSparse::insert_row(), GObservation::likelihood_gaussian_binned(), GObservation::likelihood_poisson_binned(), GObservation::likelihood_poisson_unbinned(), GObservation::model(), GMatrixSparse::multiply_column(), GNodeArray::nodes(), GCOMObservation::npred(), GObservation::npred(), GMatrix::operator*(), GMatrixSparse::operator*(), GMatrixSymmetric::operator*(), GIntegrals::polint(), GIntegrals::romberg(), GMatrix::row(), GResponseVectorCache::set(), com_elliptical_kerns_omega::size(), com_elliptical_kerns_rho::size(), com_radial_kerns_omega::size(), com_radial_kerns_rho::size(), spi_elliptical_kerns_omega::size(), spi_elliptical_kerns_rho::size(), spi_radial_kerns_omega::size(), spi_radial_kerns_rho::size(), GMatrixSparse::solve(), GMatrixSparse::stack_push_column(), and GIntegrals::trapzd().
GVector GVector::slice | ( | const int & | start, |
const int & | stop ) const |
Vector slice operator.
Definition at line 702 of file GVector.cpp.
References m_data.
Computes absolute of vector elements.
[in] | vector | Vector. |
Definition at line 1321 of file GVector.cpp.
Computes arccos of vector elements.
[in] | vector | Vector. |
Definition at line 1132 of file GVector.cpp.
Computes acosh of vector elements.
[in] | vector | Vector. |
Definition at line 1153 of file GVector.cpp.
Computes angle between vectors.
[in] | a | Vector. |
[in] | b | Vector. |
a
and b
in radians.GException::invalid_argument | Mismatch 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 1042 of file GVector.cpp.
Computes arcsin of vector elements.
[in] | vector | Vector. |
Definition at line 1174 of file GVector.cpp.
Computes asinh of vector elements.
[in] | vector | Vector. |
Definition at line 1195 of file GVector.cpp.
Computes arctan of vector elements.
[in] | vector | Vector. |
Definition at line 1216 of file GVector.cpp.
Computes atanh of vector elements.
[in] | vector | Vector. |
Definition at line 1237 of file GVector.cpp.
Computes cosine of vector elements.
[in] | vector | Vector. |
Definition at line 1258 of file GVector.cpp.
Computes cosh of vector elements.
[in] | vector | Vector. |
Definition at line 1279 of file GVector.cpp.
Vector cross product.
[in] | a | Vector. |
[in] | b | Vector. |
GException::invalid_argument | Mismatch 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 861 of file GVector.cpp.
Computes exponential of vector elements.
[in] | vector | Vector. |
Definition at line 1300 of file GVector.cpp.
Computes vector inverse permutation.
[in] | vector | Vector. |
[in] | p | Permutation array. |
Definition at line 1106 of file GVector.cpp.
Computes natural logarithm of vector elements.
[in] | vector | Vector. |
Definition at line 1342 of file GVector.cpp.
Computes base10 logarithm of vector elements.
[in] | vector | Vector. |
Definition at line 1363 of file GVector.cpp.
|
friend |
Computes maximum vector element.
[in] | vector | Vector. |
Definition at line 983 of file GVector.cpp.
|
friend |
Computes minimum vector element.
[in] | vector | Vector. |
Definition at line 954 of file GVector.cpp.
|
friend |
Computes vector norm.
[in] | vector | Vector. |
Definition at line 932 of file GVector.cpp.
Vector scalar product.
[in] | a | Vector. |
[in] | b | Vector. |
a
and b
.GException::invalid_argument | Mismatch between vector size. |
Returns the scalar product between vector a
and b
.
Definition at line 904 of file GVector.cpp.
Computes vector permutation.
[in] | vector | Vector. |
[in] | p | Permutation array. |
Definition at line 1079 of file GVector.cpp.
Computes tanh of vector elements.
[in] | vector | Vector. |
[in] | power | Power. |
Definition at line 1490 of file GVector.cpp.
Computes sine of vector elements.
[in] | vector | Vector. |
Definition at line 1384 of file GVector.cpp.
Computes sinh of vector elements.
[in] | vector | Vector. |
Definition at line 1405 of file GVector.cpp.
Computes square root of vector elements.
[in] | vector | Vector. |
Definition at line 1426 of file GVector.cpp.
|
friend |
Computes vector sum.
[in] | vector | Vector. |
Definition at line 1012 of file GVector.cpp.
Computes tangens of vector elements.
[in] | vector | Vector. |
Definition at line 1447 of file GVector.cpp.
Computes tanh of vector elements.
[in] | vector | Vector. |
Definition at line 1468 of file GVector.cpp.
|
private |
Vector array.
Definition at line 128 of file GVector.hpp.
Referenced by alloc_members(), at(), at(), copy_members(), first_nonzero(), free_members(), GVector(), GVector(), GVector(), init_members(), last_nonzero(), non_zeros(), operator*=(), operator*=(), operator+=(), operator+=(), operator-(), operator-=(), operator-=(), operator/=(), operator/=(), operator=(), operator==(), operator[](), operator[](), and slice().
|
private |
Number of elements in vector.
Definition at line 127 of file GVector.hpp.
Referenced by alloc_members(), copy_members(), first_nonzero(), GVector(), GVector(), GVector(), GVector(), init_members(), last_nonzero(), non_zeros(), operator*=(), operator*=(), operator+=(), operator+=(), operator-(), operator-=(), operator-=(), operator/=(), operator/=(), operator=(), operator==(), print(), and size().