24#ifndef _GEMA_VECTOR_UTILS_H_
25#define _GEMA_VECTOR_UTILS_H_
27#ifndef GM_VECTOR_DEFINED
30#define GM_VECTOR_DEFINED
41#if ARMA_VERSION_MAJOR != 14 || ARMA_VERSION_MINOR != 0
42#error Unexpected Armadillo version. Please check that our internal fiddling done below is still valid
54 inline double sqrDistance(const GmVector& a, const GmVector& b)
56 assert(a.n_elem == b.n_elem);
59 for(unsigned int i = 0; i<a.n_elem; i++)
61 double d = a[i] - b[i];
68 inline double distance(const GmVector& a, const GmVector& b)
70 return sqrt(sqrDistance(a, b));
74 inline double sqrNorm(const GmVector& v)
77 for(unsigned int i = 0; i<v.n_elem; i++)
83 inline double sqrNorm(
const double* v,
unsigned s)
86 for(
unsigned int i = 0; i < s; i++)
95 if(a.n_elem != b.n_elem)
97 for(
unsigned i = 0; i<a.n_elem; i++)
108 for(
unsigned i = 0; i<a.n_elem; i++)
129 assert(v.vec_state == 1);
130 assert(v.mem_state == 2 || (v.mem_state == 0 && v.n_elem == 0 && v.mem == NULL));
131 assert(v.n_alloc == 0);
132 arma::access::rw(v.mem) = data;
133 arma::access::rw(v.mem_state) = 2;
134 arma::access::rw(v.n_rows) = nlin;
135 arma::access::rw(v.n_cols) = 1;
136 arma::access::rw(v.n_elem) = nlin;
149 assert(v.vec_state == 1);
152 arma::access::rw(v.mem) = NULL;
153 arma::access::rw(v.mem_state) = 0;
154 arma::access::rw(v.n_rows) = 0;
155 arma::access::rw(v.n_cols) = 1;
156 arma::access::rw(v.n_elem) = 0;
158 else if(v.mem_state == 0)
161 arma::access::rw(v.mem) = NULL;
165 assert(v.n_alloc == 0);
182 assert(v.vec_state == 1);
183 assert(v.mem_state == 2);
184 assert(v.n_alloc == 0);
186 arma::access::rw(v.n_rows) = nlin;
187 arma::access::rw(v.n_cols) = 1;
188 arma::access::rw(v.n_elem) = nlin;
192 char format =
'g',
int precision = -1);
Class representing a category with multiple logging levels.
Definition gmLog.h:58
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Functions for comparing double values.
#define GM_DOUBLECMP_ABSTOL
Tolerância absoluta entre valores para comparar valores próximos de zero.
Definition gmDoubleCmp.h:64
#define GM_DOUBLECMP_RELTOL
Tolerância relativa entre valores = 0.000001%.
Definition gmDoubleCmp.h:61
Declaration of support functions and macros for information logging.
GmLogLevel
Available log levels list.
Definition gmLog.h:36
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
bool equal(double a, double b, double relTol=GM_DOUBLECMP_RELTOL, double absTol=GM_DOUBLECMP_ABSTOL)
Funcao para comparar se dois números reais são iguais usando uma tolerância recebida como parâmetro.
Definition gmDoubleCmp.h:71
bool isZero(double a, double absTol)
Funcao para comparar se o valor a é ou não igual a zero dada uma tolerância absoluta.
Definition gmDoubleCmp.h:93
Groups utilitary routines for working with vectors.
Definition gmVectorUtils.cpp:31
double isZero(const GmVector &a, double absTol)
Check to see if a vector is zero using GmDoubleCmp::isZero over each component.
Definition gmVectorUtils.h:106
void print(const GmVector &v, const GmLogCategory &logger, GmLogLevel level, int fieldWidth, char format, int precision)
Prints the vector using the specified logger, level and precision fields. Values are separated by spa...
Definition gmVectorUtils.cpp:34
QString toString(const GmVector &v, int fieldWidth, char format, int precision, bool noBraces)
Serializes the vector to a string using the specified precision fields. Coordinates are surrounded by...
Definition gmVectorUtils.cpp:48
void setVectorMemory(GmVector &v, double *data, int nlin)
Updates the memory area used internally by a vector. DANGEROUS. Should be used only by the bold ones ...
Definition gmVectorUtils.h:124
double equal(const GmVector &a, const GmVector &b, double relTol=GM_DOUBLECMP_RELTOL, double absTol=GM_DOUBLECMP_ABSTOL)
Check to see if two vectors are equal comparing values using GmDoubleCmp::equal.
Definition gmVectorUtils.h:93
double sqrNorm(const double *v, unsigned s)
Returns the squared norm of vector v, with size s.
Definition gmVectorUtils.h:83
bool hasSharedMemory(GmVector &v)
Is this vector operating over a shared memory (set by setVectorMemory())?
Definition gmVectorUtils.h:169
void fillFromLuaTable(GmVector &v, LuaTable &t)
Resizes and fills the vector v to receive the data stored in a lua table.
Definition gmVectorUtils.cpp:60
void resetVectorMemory(GmVector &v)
Updates a vector that was prepared with setVectorMemory() to a common empty column vector....
Definition gmVectorUtils.h:144
void setVectorSize(GmVector &v, int nlin)
Updates the logical vector size WITHOUT changin the used memory area. DANGEROUS. Should be used only ...
Definition gmVectorUtils.h:177