1.2.2
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 int FFFF (double value)
 
GSTLEARN_EXPORT int IFFFF (int value)
 
GSTLEARN_EXPORT double getTEST ()
 
GSTLEARN_EXPORT int getITEST ()
 
template<typename T >
T getNA ()
 
template<>
double getNA ()
 
template<>
int getNA ()
 
template<>
String getNA ()
 
template<>
float 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, 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 ()
 

Macro Definition Documentation

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

Typedef Documentation

typedef double(* operate_function) (double)

Function Documentation

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

Checks if a double value is TEST

Returns
1 if a TEST value is encountered; 0 otherwise
Parameters
[in]valueValue to be tested
GSTLEARN_EXPORT int getClosestInteger ( double  value)
GSTLEARN_EXPORT int getITEST ( )
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
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)
GSTLEARN_EXPORT double getMax ( double  val1,
double  val2 
)
GSTLEARN_EXPORT double getMin ( double  val1,
double  val2 
)
template<typename T >
T getNA ( )
inline
template<>
double getNA ( )
inline
template<>
int getNA ( )
inline
template<>
String getNA ( )
inline
template<>
float getNA ( )
inline
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)
GSTLEARN_EXPORT int getRankMapRelativeToAbsolute ( const std::map< int, int > &  map,
int  irel 
)
GSTLEARN_EXPORT double getTEST ( )
GSTLEARN_EXPORT int IFFFF ( int  value)

Checks if an integer value is TEST

Returns
1 if a ITEST value is encountered; 0 otherwise
Parameters
[in]valueValue to be tested
GSTLEARN_EXPORT bool isEven ( int  number)
GSTLEARN_EXPORT bool isInteger ( double  value,
double  eps = EPSILON10 
)
GSTLEARN_EXPORT bool isInternalDebug ( )
GSTLEARN_EXPORT bool isMultiple ( int  nbig,
int  nsmall 
)
template<typename T >
bool isNA ( const T v)
inline
template<>
bool isNA ( const double &  v)
inline
template<>
bool isNA ( const int &  v)
inline
template<>
bool isNA ( const String v)
inline
template<>
bool isNA ( const float &  v)
inline
GSTLEARN_EXPORT bool isOdd ( int  number)
GSTLEARN_EXPORT bool isOne ( double  value,
double  eps = EPSILON10 
)
GSTLEARN_EXPORT bool isZero ( double  value,
double  eps = EPSILON10 
)
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
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
GSTLEARN_EXPORT double operate_Identity ( double  x)
GSTLEARN_EXPORT double operate_Inverse ( double  x)
GSTLEARN_EXPORT double operate_InverseSqrt ( double  x)
GSTLEARN_EXPORT double operate_InverseSquare ( double  x)
GSTLEARN_EXPORT double operate_Sqrt ( double  x)
GSTLEARN_EXPORT double operate_Square ( double  x)
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.
GSTLEARN_EXPORT void setInternalDebug ( bool  status)
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
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
GSTLEARN_EXPORT void ut_classify ( int  nech,
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
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)
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.
GSTLEARN_EXPORT double ut_deg2rad ( double  angle)

Translates from degree to radian

Parameters
[in]angleAngle in degrees
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
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
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
GSTLEARN_EXPORT double ut_rad2deg ( double  angle)

Translates from radian to degree

Parameters
[in]angleAngle in radian
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
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
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
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