1.5.0
CCC
 
Utilities.hpp File Reference
#include "gstlearn_export.hpp"
#include "geoslib_define.h"
#include "Basic/VectorNumT.hpp"
#include "Matrix/MatrixSquareGeneral.hpp"
#include "Enum/EOperator.hpp"
#include <map>
#include <cmath>
#include <math.h>

Classes

struct  StatResults
 

Macros

#define DOUBLE_NA   TEST
 
#define INT_NA   ITEST
 
#define STRING_NA   "NA"
 
#define FLOAT_NA   static_cast<float>(TEST)
 

Typedefs

typedef double(* operate_function) (double)
 

Functions

GSTLEARN_EXPORT bool isInteger (double value, double eps=EPSILON10)
 
GSTLEARN_EXPORT int getClosestInteger (double value)
 
GSTLEARN_EXPORT bool isMultiple (int nbig, int nsmall)
 
GSTLEARN_EXPORT bool isOdd (int number)
 
GSTLEARN_EXPORT bool isEven (int number)
 
GSTLEARN_EXPORT bool isZero (double value, double eps=EPSILON10)
 
GSTLEARN_EXPORT bool isOne (double value, double eps=EPSILON10)
 
GSTLEARN_EXPORT bool areEqual (double v1, double v2, double eps=EPSILON10)
 
GSTLEARN_EXPORT double getMin (double val1, double val2)
 
GSTLEARN_EXPORT double getMax (double val1, double val2)
 
GSTLEARN_EXPORT double ut_deg2rad (double angle)
 
GSTLEARN_EXPORT double ut_rad2deg (double angle)
 
GSTLEARN_EXPORT bool FFFF (double value)
 
GSTLEARN_EXPORT bool IFFFF (int value)
 
GSTLEARN_EXPORT double getTEST ()
 
GSTLEARN_EXPORT int getITEST ()
 
template<typename T >
T getNA ()
 
template<>
double getNA ()
 
template<typename T >
bool isNA (const T &v)
 
template<>
bool isNA (const double &v)
 
template<>
bool isNA (const int &v)
 
template<>
bool isNA (const String &v)
 
template<>
bool isNA (const float &v)
 
GSTLEARN_EXPORT void ut_sort_double (int safe, int nech, int *ind, double *value)
 
GSTLEARN_EXPORT StatResults ut_statistics (int nech, const double *tab, const double *sel=nullptr, const double *wgt=nullptr)
 
GSTLEARN_EXPORT void ut_stats_mima_print (const char *title, int nech, double *tab, double *sel)
 
GSTLEARN_EXPORT void ut_facies_statistics (int nech, double *tab, double *sel, int *nval, int *mini, int *maxi)
 
GSTLEARN_EXPORT void ut_classify (int nech, const double *tab, double *sel, int nclass, double start, double pas, int *nmask, int *ntest, int *nout, int *classe)
 
GSTLEARN_EXPORT double ut_median (double *tab, int ntab)
 
GSTLEARN_EXPORT double ut_cnp (int n, int k)
 
GSTLEARN_EXPORT MatrixSquareGeneral ut_pascal (int ndim)
 
GSTLEARN_EXPORT int * ut_combinations (int n, int maxk, int *ncomb)
 
GSTLEARN_EXPORT void ut_shuffle_array (int nrow, int ncol, double *tab)
 
GSTLEARN_EXPORT VectorInt getListActiveToAbsolute (const VectorDouble &sel)
 
GSTLEARN_EXPORT std::map< int, int > getMapAbsoluteToRelative (const VectorDouble &sel, bool verbose=false)
 
GSTLEARN_EXPORT int getRankMapAbsoluteToRelative (const std::map< int, int > &map, int iabs)
 
GSTLEARN_EXPORT int getRankMapRelativeToAbsolute (const std::map< int, int > &map, int irel)
 
GSTLEARN_EXPORT operate_function operate_Identify (int oper)
 
GSTLEARN_EXPORT double operate_Identity (double x)
 
GSTLEARN_EXPORT double operate_Inverse (double x)
 
GSTLEARN_EXPORT double operate_Square (double x)
 
GSTLEARN_EXPORT double operate_InverseSquare (double x)
 
GSTLEARN_EXPORT double operate_Sqrt (double x)
 
GSTLEARN_EXPORT double operate_InverseSqrt (double x)
 
GSTLEARN_EXPORT double modifyOperator (const EOperator &oper, double oldval, double value)
 
GSTLEARN_EXPORT double roundZero (double value, double eps=EPSILON6)
 
GSTLEARN_EXPORT double truncateDecimals (double value, int ndec=0)
 
GSTLEARN_EXPORT double truncateDigits (double value, int ndigits)
 
GSTLEARN_EXPORT void setInternalDebug (bool status)
 
GSTLEARN_EXPORT bool isInternalDebug ()
 
GSTLEARN_EXPORT void print_range (const char *title, int ntab, const double *tab, const double *sel)
 
GSTLEARN_EXPORT void convertIndptrToIndices (int ncumul, const int *cumul, int *tab)
 TODO: transfer this in swig_inc.i. More...
 

Macro Definition Documentation

◆ DOUBLE_NA

#define DOUBLE_NA   TEST

◆ FLOAT_NA

#define FLOAT_NA   static_cast<float>(TEST)

◆ INT_NA

#define INT_NA   ITEST

◆ STRING_NA

#define STRING_NA   "NA"

Typedef Documentation

◆ operate_function

typedef double(* operate_function) (double)

Function Documentation

◆ areEqual()

GSTLEARN_EXPORT bool areEqual ( double  v1,
double  v2,
double  eps = EPSILON10 
)

◆ convertIndptrToIndices()

GSTLEARN_EXPORT void convertIndptrToIndices ( int  ncumul,
const int *  cumul,
int *  tab 
)

TODO: transfer this in swig_inc.i.

◆ FFFF()

GSTLEARN_EXPORT bool FFFF ( double  value)

Checks if a double value is TEST

Returns
true if a TEST value is encountered; 0 otherwise
Parameters
[in]valueValue to be tested

◆ getClosestInteger()

GSTLEARN_EXPORT int getClosestInteger ( double  value)

◆ getITEST()

GSTLEARN_EXPORT int getITEST ( )

◆ getListActiveToAbsolute()

GSTLEARN_EXPORT VectorInt getListActiveToAbsolute ( const VectorDouble sel)

Returns the list of absolute indices for the only active samples A sample is active if its 'sel' value is equal to 1

Parameters
selVector giving the status of all samples (Dimension: absolute)
Returns

◆ getMapAbsoluteToRelative()

GSTLEARN_EXPORT std::map<int, int> getMapAbsoluteToRelative ( const VectorDouble sel,
bool  verbose 
)

Returns the map such that MAP[iabs] = iact. A sample is active if its 'sel' value is equal to 1

Parameters
selVector giving the status of all samples (Dimension: absolute)
verboseVerbose flag
Returns
The map (dimension: nrel)

◆ getMax()

GSTLEARN_EXPORT double getMax ( double  val1,
double  val2 
)

◆ getMin()

GSTLEARN_EXPORT double getMin ( double  val1,
double  val2 
)

◆ getNA() [1/2]

template<typename T >
T getNA ( )
inline

◆ getNA() [2/2]

template<>
float getNA ( )
inline

◆ getRankMapAbsoluteToRelative()

GSTLEARN_EXPORT int getRankMapAbsoluteToRelative ( const std::map< int, int > &  map,
int  iabs 
)

Returns the rank of the relative grid node from its absolute index using the Map

Parameters
mapThe <int,int> map
iabsAbsolute rank of the grid node
Returns
Rank of the corresponding active (relative) grid node (or -1 is not found)

◆ getRankMapRelativeToAbsolute()

GSTLEARN_EXPORT int getRankMapRelativeToAbsolute ( const std::map< int, int > &  map,
int  irel 
)

◆ getTEST()

GSTLEARN_EXPORT double getTEST ( )

◆ IFFFF()

GSTLEARN_EXPORT bool IFFFF ( int  value)

Checks if an integer value is TEST

Returns
true if a ITEST value is encountered; 0 otherwise
Parameters
[in]valueValue to be tested

◆ isEven()

GSTLEARN_EXPORT bool isEven ( int  number)

◆ isInteger()

GSTLEARN_EXPORT bool isInteger ( double  value,
double  eps = EPSILON10 
)

◆ isInternalDebug()

GSTLEARN_EXPORT bool isInternalDebug ( )

◆ isMultiple()

GSTLEARN_EXPORT bool isMultiple ( int  nbig,
int  nsmall 
)

◆ isNA() [1/5]

template<>
bool isNA ( const double &  v)
inline

◆ isNA() [2/5]

template<>
bool isNA ( const float &  v)
inline

◆ isNA() [3/5]

template<>
bool isNA ( const int &  v)
inline

◆ isNA() [4/5]

template<>
bool isNA ( const String v)
inline

◆ isNA() [5/5]

template<typename T >
bool isNA ( const T v)
inline

◆ isOdd()

GSTLEARN_EXPORT bool isOdd ( int  number)

◆ isOne()

GSTLEARN_EXPORT bool isOne ( double  value,
double  eps = EPSILON10 
)

◆ isZero()

GSTLEARN_EXPORT bool isZero ( double  value,
double  eps = EPSILON10 
)

◆ modifyOperator()

GSTLEARN_EXPORT double modifyOperator ( const EOperator &  oper,
double  oldval,
double  value 
)

Update an Old by a New value according to 'oper'

Parameters
operA keywork of EOperator enum
oldvalOld value
valueNew value

◆ operate_Identify()

GSTLEARN_EXPORT operate_function operate_Identify ( int  oper)

Identify the pointer to a function with following functionality: y = f(x)

Parameters
operGives the type of operation to be performed 1: returns the value itslef (no change) -1: returns its inverse 2: returns the squared value -2: returns the inverse of the squared value 3: returns its square root -3: returns the inverse of the square root
Returns
Pointer to the specified function

◆ operate_Identity()

GSTLEARN_EXPORT double operate_Identity ( double  x)

◆ operate_Inverse()

GSTLEARN_EXPORT double operate_Inverse ( double  x)

◆ operate_InverseSqrt()

GSTLEARN_EXPORT double operate_InverseSqrt ( double  x)

◆ operate_InverseSquare()

GSTLEARN_EXPORT double operate_InverseSquare ( double  x)

◆ operate_Sqrt()

GSTLEARN_EXPORT double operate_Sqrt ( double  x)

◆ operate_Square()

GSTLEARN_EXPORT double operate_Square ( double  x)

◆ print_range()

GSTLEARN_EXPORT void print_range ( const char *  title,
int  ntab,
const double *  tab,
const double *  sel 
)

Print the range of values in an array

Parameters
[in]titleoptional title (NULL if not defined)
[in]ntabnumber of values
[in]tabarray of values
[in]sel(optional) selection

◆ roundZero()

GSTLEARN_EXPORT double roundZero ( double  value,
double  eps 
)

Round off the value if close enough to zero. This ensures that the printout of a very small value does not come out with a non-significant negative sign This trick should only serve to make printouts similar on different platforms.

Parameters
valueInput value
epsTolerance to check that the value is considered as small
Returns
The value itself or a very small positive value if the input value is too small.

◆ setInternalDebug()

GSTLEARN_EXPORT void setInternalDebug ( bool  status)

◆ truncateDecimals()

GSTLEARN_EXPORT double truncateDecimals ( double  value,
int  ndec 
)

Rounding a double to a given number of decimals (from: https://stackoverflow.com/questions/304011/truncate-a-decimal-value-in-c/304013#304013)

Parameters
valueValue to be rounded up
ndecNumber of significant decimals

◆ truncateDigits()

GSTLEARN_EXPORT double truncateDigits ( double  value,
int  ndigits 
)

Rounding a double to a given number of decimals

Parameters
valueValue to be rounded up
ndigitsNumber of significant digits

◆ ut_classify()

GSTLEARN_EXPORT void ut_classify ( int  nech,
const double *  tab,
double *  sel,
int  nclass,
double  start,
double  pas,
int *  nmask,
int *  ntest,
int *  nout,
int *  classe 
)

Classify the samples into integer sieves

Parameters
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL
[in]nclassNumber of sieve classes
[in]startStarting sieve value
[in]pasWidth of the sieve
[out]nmaskNumber of masked values
[out]ntestNumber of undefined values
[out]noutNumber of values outside the classes
[out]classeArray for number of samples per sieve

◆ ut_cnp()

GSTLEARN_EXPORT double ut_cnp ( int  n,
int  k 
)

Compute combinations(n,k)

Returns
Return the number of combinations of 'k' objects amongst 'n'
Parameters
[in]nTotal number of objects (>= 1)
[in]kSelected number of objects (>= 1)

◆ ut_combinations()

GSTLEARN_EXPORT int* ut_combinations ( int  n,
int  maxk,
int *  ncomb 
)

Return all the combinations of k within n

Returns
Return all the combinations of 'k' objects amongst 'n'
Parameters
[in]nTotal number of objects (>1)
[in]maxkSelected number of objects (1<=maxk<n)
[out]ncombNumber of combinations
Remarks
The calling function must free the returned array.

◆ ut_deg2rad()

GSTLEARN_EXPORT double ut_deg2rad ( double  angle)

Translates from degree to radian

Parameters
[in]angleAngle in degrees

◆ ut_facies_statistics()

GSTLEARN_EXPORT void ut_facies_statistics ( int  nech,
double *  tab,
double *  sel,
int *  nval,
int *  mini,
int *  maxi 
)

Returns the statistics of an array containing the facies

Parameters
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL
[out]nvalNumber of active values
[out]miniMinimum value
[out]maxiMaximum value

◆ ut_median()

GSTLEARN_EXPORT double ut_median ( double *  tab,
int  ntab 
)

Calculate the median from a table of values

Returns
The median value
Parameters
[in]tabArray of values
[in]ntabNumber of samples

◆ ut_pascal()

GSTLEARN_EXPORT MatrixSquareGeneral ut_pascal ( int  ndim)

Create the matrix containing the Pascal Triangle coefficients

Returns
A matrix (Dimension: ndim * ndim) containing the coefficients
or NULL if core allocation problem has been encountered
Parameters
[in]ndimSize of the matrix
Remarks
The calling function must free the returned matrix

◆ ut_rad2deg()

GSTLEARN_EXPORT double ut_rad2deg ( double  angle)

Translates from radian to degree

Parameters
[in]angleAngle in radian

◆ ut_shuffle_array()

GSTLEARN_EXPORT void ut_shuffle_array ( int  nrow,
int  ncol,
double *  tab 
)

Shuffle an array (by line)

Parameters
[in]nrowNumber of rows
[in]ncolNumber of columns
[in,out]tabArray to be suffled

◆ ut_sort_double()

GSTLEARN_EXPORT void ut_sort_double ( int  safe,
int  nech,
int *  ind,
double *  value 
)

Sorts the (double) array value() and the array ind() in the ascending order of value

Parameters
[in]safe1 if the value array if preserved 0 if the value array is also sorted
[in]nechnumber of samples
[out]indoutput int array
[out]valueinput and output array
Remarks
If ind = NULL, ind is ignored

◆ ut_statistics()

GSTLEARN_EXPORT StatResults ut_statistics ( int  nech,
const double *  tab,
const double *  sel,
const double *  wgt 
)

Returns the statistics of an array in a StatResults structure

Parameters
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL
[in]wgtArray containing the Weights or NULL

◆ ut_stats_mima_print()

GSTLEARN_EXPORT void ut_stats_mima_print ( const char *  title,
int  nech,
double *  tab,
double *  sel 
)

Print minimum and maximum of an array

Parameters
[in]titleTitle
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL