Fulgurance

Table Of Contents




INTRODUCTION:

Stylished documentation is available here

In current development.

This framework provides functions for statistical analysis, machine learning, parsing and data manipulation with its own implementation of matrices and dataframes. Other tools can be found at fulgurance_tools part.

The framework is developped with C++ 14 but should work properly with 11 and 17 and furthers.

Philosophy

Dataframes implementation is a class. All functions that will transform 'voidly' (internaly) the relative data are built in the class. All functions that copy and transform the relative data are extern to classes.

Matrices are built with the Matrix class.



Commun functions

On elements

Standard operations

mod

#Usage

template <typename T> double mod(T &dividend, T &divider)

#Description

Returns the mod of 2 number (int, float or double)

#Arguments

NameDefinition
a is an the dividend (int, float, double)
b is the divider (int, float, double)

#Example(s)

float a = 45.216;
float b = 3.2164;
mod(a, b)
0.186401


int_lngth

#Usage

int int_lngth(const int &x)

#Description

Returns the length of an int.

#Arguments

NameDefinition
x is an int

#Example(s)

int a = 896;
int_lngth(a);
3


roundout

#Usage

template <typename T> T roundout(T x, int n)

#Description

Returns a rounded value with decimal precision.

#Arguments

NameDefinition
x is an int, float, double
n is an int indicating the decimal precision

#Example(s)

float x = 34.476;
int n = 2;
float out = roundout(x, n);
34.48
n = 0;
out = roundout(x, n);
34
n = -1;
out = roundout(x, n)
30


roundin

#Usage

template <typename T> void roundin(T &x, int n)

#Description

Transforms the input value to a rounded value with decimal precision.

#Arguments

NameDefinition
x is an int, float, double
n is an int indicating the decimal precision

#Example(s)

float x = 34.476
int n = 2;
roundin(x, n);
34.48
n = 0;
x = 67.754;
roundin(x, n);
68
n = -1;
roundin(x, n);
70


randint

#Usage

auto randint(const int &min, const int max, int seed = -1)

#Description

Returns a pseudo-random number between min and max.

#Arguments

NameDefinition
min is an int
max is a max
seed is an int that determines the pseudo-random output, defaults to -1, so the seed will be randomly picked up by default, if you want to determine the output, choose a seed between 0 and 9.

#Example(s)

int min = -300;
int max = 100;
randint(min, max);
-14
randint(min, max);
-231
// If you want to generate a float just do:
double x = randint(min, max);
min = 0;
max = 900;
x += randint(min, max) / 1000;
-13.257


logn

#Usage

template <typename T, typename T2> double logn(T &val, T2 &base)

#Description

Returns the logarithm of any positive number to any base. This generalizes the log(value) / log(base) method.

#Arguments

NameDefinition
val is the value of the logarith base n (must be positive)
base is the base of the logarithm

#Example(s)

double val = 2.63;
int base = 10;
logn(val, base);
0.419956
base = 2;
1.39506


Facto

#Usage

unsigned int Facto(unsigned int x)

#Description

Returns the factorial of a positive integer.

#Arguments

NameDefinition
x is a unsigned integer

#Example(s)

Facto(7);
5040
Facto(0);
1


Comb

#Usage

double Comb(double r, double n)

#Description

Returns the result of the combination formula for given parameters.

#Arguments

NameDefinition
r is the number of objects choosen among the set
n is the number of objects in the set

#Example(s)

Comb(2, 5);
10
Comb(5, 12);
792


String to int, float, double

si

#Usage

int si(const std::string &x)

#Description

Returns a std::string that can be converted to an int, to an int.

#Arguments

NameDefinition
x is a stl string that can be converted to an int

#Example(s)

std::string a = "341";
int out = si(a);
341


sf

#Usage

float sf(const std::string &x)

#Description

Returns a converted std::string that can be converted to a float, to a float. Produces the same results than stof.

#Arguments

NameDefinition
x is a stl string that can be converted to a float

#Example(s)

std::string a = "44.23";
float out = sf(a);
44.23


sf2

#Usage

float sf2(const std::string &x)

#Description

Returns a converted std::string that can be converted to a float, to a float. Uses another algorithm than edm1_sf.

#Arguments

NameDefinition
x is a stl string that can be converted to a float

#Example(s)

std::string a = "44.23";
float out = sf2(a);
44.23


stod

#Usage

double stod(const std::string &x)

#Description

Returns a converted std::string, that can be converted to a double, to a double.

#Arguments

NameDefinition
x is a stl string

#Example(s)

std::string a = "4566.132214";
double out = stod(a);
4566.132214


Int, double, to string

itos

#Usage

std::string itos(unsigned int x)

#Description

Returns the input integer as a std string.

#Arguments

NameDefinition
is an unsigned int

#Example(s)

itos(45897);
"45897"


Can be num ?

can_be_nb

#Usage

bool can_be_nb(std::string &x)

#Description

Returns a boolean, 1 if the input std::string can be converted to a number (int, float...), 0 if not.

#Arguments

NameDefinition
x is the input stdstring

#Example(s)

std::string inpt_str = "15.69596";
bool rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

1

inpt_str = "1569596";
rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

1

inpt_str = "1569T596";
rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

0

inpt_str = "15.69.596";
rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

0


can_be_flt_dbl

#Usage

bool can_be_flt_dbl(std::string &x)

#Description

Returns a boolean, 1 if the input std::string can be converted to a float or double, 0 if not.

#Arguments

NameDefinition
x is the input stdstring

#Example(s)

std::string inpt_str = "15.69596";
bool rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

1

inpt_str = "1569596";
rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

0

inpt_str = "1569T596";
rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

0

inpt_str = "15.69.596";
rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

0


On std::vector<Type>

Statistical functions

sum

#Usage

template <typename T> T sum(const std::vector<T> &x)

#Description

Returns the sum of all elements in a vector (int, float, double, bool).

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<double> vec = {1.434, 22.3322, 32423.097};
double out = sum(vec);
32446.8632


Mean

#Usage

template <typename T> T Mean(const std::vector<T> &x)

#Description

Returns the mean of all elements in a vector (int, float, double, bool).

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 4, 2};
double out = Mean(vec);
2.333333


quantile

#Usage

template <typename T, typename T2> double quantile(std::vector<T> &x, T2 &prob, double precision = 0.001)

#Description

Returns the quantile value for a given probability between 0 and 1 for an input stl vector (int, float, double, bool). If you just want to calculate median, the med() function is more straight forward.

#Arguments

NameDefinition
x stl vector (int, float, double, bool), must be ascendly sorted
prob is the probability(float, double)
precision is a double value representing the accuracy of the result. The lower the value is, higher the accuracy will be.

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<int> vec2 = {1, 2, 3, 4};
double prob = 0.89;
quantile(vec2, prob);
3.67188
prob = 0.65;
quantile(vec, prob);
6.84375


med

#Usage

template <typename T> double med(std::vector<T> &x)

#Description

Returns the median of a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool), must be ascendly sorted

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
double out = med(vec);
2.5


cor

#Usage

template <typename T, typename T2> double cor(const std::vector<T> &x, const std::vector<T2> &x2)

#Description

Returns the correlation between two variables / two stl vectors (int, float, double, bool)

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool)
x2 is an stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec1 = {1, 2, 3, 4, 5, 6};
std::vector<int> vec2 = {-6, -5, -4, -3, -2, -1};
double out = cor(vec1, vec2);
1


Sd

#Usage

template <typename T> double Sd(std::vector<T> &x)

#Description

Returns the standard deviation of a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 2, 2, 3, 3, 3, 4, 4, 5};
double out = Sd(vec);
1.224745


Uniform distribution

dunif

#Usage

template <typename T> std::vector<double> dunif(std::vector<T> &x, double &min, double &max)

#Description

Returns the probability distribution of the uniform distribution.

#Arguments

NameDefinition
x is a vector containing all the values you want the probability from
min is the minimum of the uniform distribution
max is the maximum of the uniform distribution

#Example(s)

double min = -2;
double max = 10;
std::vector<double> vec = {-7, -2, 3.5, 8, 12, 56};
std::vector<double> out = dunif(vec, min, max);
print_nvec(out);
:0: 0 0.0833333 0.0833333 0.0833333 0 0


punif

#Usage

template <typename T> std::vector<double> punif(std::vector<T> &x, double &min, double &max, double step = 0.01)

#Description

Returns the cumulative probablity distribution of the uniform distribution.

#Arguments

NameDefinition
x is a vector containing the values you want the cumulative probability from, must be ascendly sorted
min is the minimum of the probability distribution
max is the maximum of the probability distribution
step the lower it is, the more accurate the result gets

#Example(s)

double min = -2;
double max = 10;
std::vector<double> vec = {-7, -2, 3.5, 8, 12, 56};
std::vector<double> out = punif(vec, min, max);
print_nvec(out);
:0: 0 0.000833333 0.459167 0.834167 1 1


qunif

#Usage

std::vector<double> qunif(std::vector<double> &x, double &min, double &max)

#Description

Returns the quantile of the uniform distribution.

#Arguments

NameDefinition
x is the probability vector
min is the minimum of the uniform distribution
max is the maximum of the uniform distribution

#Example(s)

double min = -2;
double max = 10;
std::vector<double> vec = {-7, -2, 3.5, 8, 12, 56};
std::vector<double> vec2 = {0.2, 0.4, 0.5, 0.6, 0.75};
std::vector<double> out = qunif(vec2, min, max);
print_nvec(out);
:0: 3.6 5.2 6 6.8 8


runif

#Usage

std::vector<double> unif(unsigned int &n, double &min, double &max, double noise = 0.1, int seed = -1)

#Description

Returns a stl double vector containing pseudo-random uniform distribution between a min and max.

#Arguments

NameDefinition
n is the number of elements of the output stl vector
min is the minimum of the uniform distribution
max is the maximum of the uniform distribution
noise is the noise in the returnde uniform distribution
seed is an int, controlling the output values, defaults to -1, so by default the function returns pseudo-random uniform distribution. If you want to manually control the output, enter a positive int for this parameter.

#Example(s)

unsigned int n = 1500;
double min = 1;
double max = 55;
std::vector<double> out = unif(n, min, max);
print_nvec(out);
:0: 1 1.03701 1.07557 1.10951 1.14757 1.18151 1.21957 1.25351 1.29157 1.32551 1.36357 1.39751 1.43557 1.46951 1.50757 1.54151 1.57957 1.61351 1.65157 1.68551 1.72357 1.75751 1.79557 1.82951
...
:1475: 54.1015 54.1396 54.1735 54.2116 54.2455 54.2836 54.3175 54.3556 54.3895 54.4276 54.4615 54.4996 54.5335 54.5716 54.6055 54.6436 54.6775 54.7156 54.7495 54.7876 54.8215 54.8596 54.8935 54.9316
:1500: 55


Normal distribution

rnorm

#Usage

std::vector<double> rnorm(unsigned int &n, double &mean, double &sd, double noise = 0.05, int seed = -1)

#Description

Returns a pseudo-random normal distribution as a double stl vector. Note, if you can it is preferable to choose the smallest standard deviation possible to increase speed. Example: N(14, 10) -> N(1.4, 1).

#Arguments

NameDefinition
n is the number of elements in the output stl vector
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
noise is the noise, defaults to 0.05
seed is an int that dictates the result, defaults to -1, so by default the output is pseudo-random

#Example(s)

unsigned int n = 10000;
double sd = 250;
double mean = 155;
std::vector<double> out;
double result;
out = rnorm(n, mean, sd);
Sd(out);
250.6228
Mean(out);
154.9945



rnorm2

#Usage

std::vector<double> rnorm2(unsigned int &n, double &mean, double &sd, double noise = 0.05, int seed = -1)

#Description

Same as norm(), but faster and less accurate.

#Arguments

NameDefinition
n is the number of elements in the output stl vector
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
noise is the noise, defaults to 0.05
seed is an int that dictates the result, defaults to -1, so by default the output is pseudo-random

#Example(s)

unsigned int n = 10000;
double sd = 50;
double mean = 155;
std::vector<double> out;
double result;
out = rnorm2(n, mean, sd);
Sd(out);
42.06729
Mean(out);
155.0009



qnorm1

#Usage

template <typename T, typename T2> double qnorm1(T &mean, T2 &sd, double &val, double offset_prob = 0.05)

#Description

Returns the quantile value for a given theoretical normal distribution. There is an offset probability input that tells the most offset probability the function has to takein count in order to return the quantile value.

#Arguments

NameDefinition
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
val is the quantile percentage (between 0 and 1)
offset_prob is the probability from which is no longer not taken in count by the function in order to return a coherent value

#Example(s)

double mean = 12;
double sd = 2;
std::vector<double> vec = {0.33, 0.40, 0.45, 0.5, 0.55};
std::vector<double> out = qnorm1(vec, mean, sd);
print_nvec(out);
:0: 10.8688 11.3346 11.6673 12 12.3327


qnorm2

#Usage

template <typename T, typename T2> double qnorm1(T &mean, T2 &sd, double &val, double offset_prob = 0.05)

#Description

Returns the quantile value for a given theoretical normal distribution. This algorithm may be more precise than qnorm1 but takes slightly longer times to compute.

#Arguments

NameDefinition
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
x are the quantile percentage (between 0 and 1), must be ascendly sorted
step is the accuracy, the lower it is, the more precise it gets

#Example(s)

double mean = 12;
double sd = 2;
std::vector<double> vec = {0.33, 0.40, 0.45, 0.5, 0.55};
std::vector<double> out = qnorm2(vec, mean, sd);
print_nvec(out);
:0: 9.92 10.85 11.48 12.11 12.74


dnorm

#Usage

template <typename T> std::vector<double> dnorm(std::vector<T> &x, double &mean, double &sd, double step = 1)

#Description

Returns the density function of a given normal distribution as an stl double vector.

#Arguments

NameDefinition
x is an stl vector of values you want the probability from
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
step the step of each element you want the probability from, see examples. Defaults to 1, so it ouputs the same result as the dnorm() function in R by default.

#Example(s)

double mean = 12;
double sd = 2;
std::vector<double> vec = {1, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14};
std::vector<double> vec2 = {9, 10, 11, 12, 13, 14};
std::vector<double> out = dnorm(vec, mean, sd, 0.5);
print_nvec(out);
:0: 0.0323794 0.0456623 0.0604927 0.0752844 0.0880163 0.096667 0.0997356 0.096667 0.0880163 0.0752844 0.0604927
out = dnorm(vec2, mean, sd, 1);
:0: 0.0647588 0.120985 0.176033 0.199471 0.176033 0.120985


pnorm

#Usage

template <typename T> std::vector<double> pnorm(std::vector<T> &x, double &mean, double &sd, double step = 0.01)

#Description

Returns the cumulative distribution function of a given normal distribution.

#Arguments

NameDefinition
x is an stl vector containing all the elements you want the function distribution to be calculated with, must be ascendly sorted
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
step the lower it is the higher the accuracy is

#Example(s)

double mean = 15;
double sd = 2;
std::vector<double> vec = {13, 13.5, 14, 14.5, 15, 15.5, 16, 18};
std::vector<double> out = pnorm(vec, mean, sd);
print_nvec(out);
:0: 0.00120985 0.0693298 0.151367 0.24421 0.342947 0.441622 0.534291 0.774818


Binomial

dbinom

#Usage

std::vector<double> dbinom(std::vector<unsigned int> &k, unsigned int &n, double &p)

#Description

Returns the probability function of a binomial distribution as an stl double vector.

#Arguments

NameDefinition
x is an stl unsigned int vector containing all the x's
n is the size of the set
p is the probability of success

#Example(s)

std::vector<unsigned int> vec = {39, 40, 41, 42, 43, 44, 45, 46, 47, 48};
unsigned int n = 100;
double p = 0.45;
std::vector<double> out = dbinom(vec, n, p);
print_nvec(out);
:0: 0.03875 0.0483929 0.0580423 0.066859 0.0739653 0.0785867 0.0801904 0.0785867 0.0739653 0.066859 0.0580423 0.0483929


pbinom

#Usage

std::vector<double> pbinom(std::vector<unsigned int> &k, unsigned int &n, double &p)

#Description

Returns the cumulative distribution function of range P(X = {x1,x2...}) as an stl double vector.

#Arguments

NameDefinition
k is an stl unsigned int vector containing all the k's, must be ascendly sorted
n is the size of the set
p is the probability of success

#Example(s)

unsigned int n = 10;
double p = 0.5;
std::vector<unsigned int> vec = {3, 5, 7};
std::vector<double> out = pbinom(vec, n, p);
print_nvec(out);
:0: 0.117188 0.568359 0.890625


qbinom

#Usage

std::vector<unsigned int> qbinom(std::vector<double> &pvec, unsigned int &n, double &p)

#Description

Returns the quantiles of a binomial distribution.

#Arguments

NameDefinition
pvec is an stl vector of probabilities, must be ascendly sorted
n is size of the set, as an unsigned int
p is the probability of success, as a double

#Example(s)

std::vector<double> vec3 = {0.3, 0.4, 0.5, 0.6, 0.7};
unsigned int n = 100;
double prob = 0.55;
std::vector<unsigned int> out = qbinom(vec3, n, prob);
print_nvec(out);
:0: 47 48 50 51 52 54


rbinom

#Usage

std::vector<unsigned int> rbinom(unsigned int &n, unsigned int size, double p)

#Description

Returns pseudo-random values of binomial distribution.

#Arguments

NameDefinition
n is the number of observations
size is the size of the individuals
p is the probability of success

#Example(s)

unsigned int size = 100;
double p = 0.5;
unsigned int n = 60;
std::vector<unsigned int> out = rbinom(n, size, p);
print_nvec(out);
:25: 50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
:50: 50 50 50 50 50 50 50 50 50 50
Mean(out);
49
Sd(out);
5.90141
std::sqrt(size * p * (1 - p));
5


Poisson

dpois

#Usage

std::vector<double> dpois(std::vector<int> &k, int &lambda)

#Description

Returns the poisson probability distribution.

#Arguments

NameDefinition
k is the vector containing the k values
lambda is the mean

#Example(s)

int lambda = 500;
std::vector<int> vec2 = {492, 500, 520};
std::vector<double> out = dpois(vec2, lambda);
print_nvec(out);
:0: 0.0167352 0.0178412 0.0119593


ppois

#Usage

std::vector<double> ppois(std::vector<int> &k, int &lambda)

#Description

Returns the poisson cumulative probability distribution.

#Arguments

NameDefinition
k is the vector containing the k values
lambda is the mean

#Example(s)

int lambda = 500;
std::vector<int> vec2 = {492, 500, 520};
std::vector<double> out = ppois(vec2, lambda);
print_nvec(out);
:0: 0.0167352 0.157008 0.468481


qpois

#Usage

std::vector<unsigned int> qpois(std::vector<double> &p, int &lambda)

#Description

Returns the quantile of the poisson distribution

#Arguments

NameDefinition
p is the vector of probabilities
lambda is the mean

#Example(s)

std::vector<double> vec = {0.22, 0.5, 0.7};
int lambda = 500;
std::vector<unsigned int> out = qpois(vec, lambda);
:0: 483 500 512


rpois

#Usage

std::vector<unsigned int> rpois(unsigned int &n, unsigned int lambda)

#Description

#Arguments

NameDefinition
n is the number of observations
lambda is the mean

#Example(s)

unsigned int lambda = 100;
unsigned int n = 60;
std::vector<unsigned int> out = rpois(n, lambda);
print_nvec(out);
:0: 114 86 86 86 115 115 85
85 85 116 116 84 84 119 119
83 83 120 120 79 79 133 133 67
:25: 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
:50: 101 101 101 101 101 101 101 101
101 101
Mean(out);
99
Sd(out);
13.0799
std::sqrt(lambda);
10


Exponential distribution

dexp

#Usage

std::vector<double> dexp(std::vector<double> &x, double &rate)

#Description

Returns the probability distribution of the exponential distribution

#Arguments

NameDefinition
x is the vector containing the values you want the probability from
rate is the rate value for the exponential distribution, given by 1 / mean

#Example(s)

double rate = 0.2;
std::vector<double> vec = {1, 2, 3, 4, 5, 6};
std::vector<double> out = dexp(vec, rate);
print_nvec(out);
:0: 0.163746 0.134064 0.109762 0.0898658 0.0735759 0.0602388


pexp

#Usage

std::vector<double> pexp(std::vector<double> &x, double &rate, double step = 0.01)

#Description

Returns the cumulative probability distribution for the exponential distribution.

#Arguments

NameDefinition
x is the vector of the values you want the cumulative probability distribution from, must be ascendly sorted
rate is the rate for the exponential distribution
step the lower it is the more accurate the result will be

#Example(s)

:0: 0.00163746 0.148559 0.271287 0.37067 0.452038 0.518657


qexp

#Usage

std::vector<double> qexp(std::vector<double> &p, double &rate)

#Description

Returns the quantile of the exponential probability distribution

#Arguments

NameDefinition
p is the vector of probabilities
rate is the rate of the exponential distribution

#Example(s)

double rate = 0.2;
std::vector<double> vec2 = {0.1, 0.2, 0.3, 0.4, 0.5, 0.75};
std::vector<double> out = qexp(vec2, rate);
print_nvec(out);
:0: 0.526803 1.11572 1.78337 2.55413 3.46574 6.93147


rexp

#Usage

std::vector<double> rexp(unsigned int &n, double rate)

#Description

Returns a pseudo-random distribution of the exponential distribution

#Arguments

NameDefinition
n is the number of observations
rate is the rate of the exponential distribution

#Example(s)

double rate = 0.2;
unsigned int n = 100;
std::vector<double> out = rexp(n, rate);
print_nvec(out);
:0: 13.2 13.2 2.79385 2.79385 2.79385
13.6804 13.6804 4.10504 4.10504 15.9378
15.9378 5.60406 5.60406 21.5331 21.5331
10.4864 10.4864 5.20657 5.20657 5.20657
5.20657 5.20657 5.20657 5.20657
:25: 5.20657 5.20657 5.20657 5.20657 5.20657
4.80913 4.80913 4.80913 4.80913 4.80913 4.80913
4.80913 4.80913 4.80913 4.80913 4.80913 4.80913
4.80913 4.80913 5.3978 5.3978 5.3978 5.3978 5.3978
:50: 5.3978 5.3978 5.3978 5.3978 5.3978 4.57492
4.57492 4.57492 4.57492 4.57492 4.57492 4.57492
4.57492 4.57492 4.57492 4.57492 4.57492 5.58841
5.63733 5.63733 5.63733 5.63733 5.63733 5.63733
:75: 5.63733 5.63733 4.35393 4.35393 4.35393 4.35393
4.35393 4.35393 4.35393 4.35393 4.35393 4.35393
4.35393 5.82063 5.82063 5.82063 5.82063 5.82063
5.82063 5.82063 5.82063 4.19025 4.19025 4.19025
:100: 4.19025
Mean(out);
5.94307
Sd(out);
4.29426


Cauchy

dcauchy

#Usage

std::vector<double> dcauchy(std::vector<double> &x, double location = 0, double scale = 1)

#Description

Returns the probability distribution of the cauchy distribution.

#Arguments

NameDefinition
x is the vector of values you want the probability from
location is the x coordinate
scale is the t coordinate

#Example(s)

double location = 0;
double scale = 1;
std::vector<double> vec = {-2, -1, 0, 1, 2, 4};
std::vector<double> out = dcauchy(vec, location, scale);
print_nvec(out);
:0: 0.063662 0.159155 0.31831 0.159155 0.063662 0.0187241


pcauchy

#Usage

std::vector<double> pcauchy(std::vector<double> &x, double location = 0, double scale = 1)

#Description

Returns the cumulative probability distribution of the cauchy distribution (starts from first value).

#Arguments

NameDefinition
x is the vector of values you want the cumulative probability from
location is the x coordinate
scale is the t coordinate
step the lowest it is the more accurate the result gets

#Example(s)

double location = 0;
double scale = 1;
std::vector<double> vec = {-2, -1, 0, 1, 2, 4};
std::vector<double> out = pcauchy(vec, location, scale);
print_nvec(out);
:0: 0.000634083 0.10305 0.35305 0.60305 0.705467 0.775071


qcauchy

#Usage

std::vector<double> qcauchy(std::vector<double> &p, double location = 0, double scale = 1)

#Description

Returns the quantile of the cauchy probability distribution

#Arguments

NameDefinition
p is the vector containing the probabilities
location is the x coordiante
scale is the y coordinate

#Example(s)

double location = 0;
double scale = 1;
std::vector<double> vec = {0.1, 0.25, 0.4, 0.5, 0.63, 0.78};
std::vector<double> out = qcauchy(vec, location, scale);
print_nvec(out);
:0: -3.07768 -1 -0.32492 0 0.432739 1.20879


rcauchy

#Usage

std::vector<double> rcauchy(unsigned int n, double x = 0, double y = 1)

#Description

Returns a pseudo-random generation of numbers following a cauchy distribution.

#Arguments

NameDefinition
n is the number of numbers to generate
x is the x coordinate
y is the y coordinate

#Example(s)

int ref_min = -2;
double location = -4;
double scale = 8;
unsigned int n = 100;
std::vector<double> out = rcauchy(n, location, scale);
std::vector<bool> out2 = supcmp(out, ref_min);
sum(out2);
42


Gamma distribution

dgamma

#Usage

std::vector<double> dgamma(std::vector<double> &x, double &shape, double &rate)

#Description

Returns the gamma density probability distribution. Uses a normal law of mean = 1/rate * shape and sd = 1/rate * sqrt(shape) to approximate for shape value greater than 171

#Arguments

NameDefinition
x is the input vector composed of the x values
shape is the alpha value
rate is the rate value (lambda or 1/theta)

#Example(s)

std::vector<double> vec = {6444, 6666, 6888};
double shape = 3333;
double rate = 0.5;
std::vector<double> out = dgamma(vec, shape, rate);
print_nvec(out);
:0: 0.000544178 0.00345511 0.000544178


pgamma

#Usage

std::vector<double> pgamma(std::vector<double> &x, double &shape, double &rate, double step)

#Description

Returns the gamma cmulative probability distribution between an interval (first x value to last x value)

#Arguments

NameDefinition
x is the input x values, must be ascendly sorted
shape is the alpha value
rate is the lambda value, 1/theta
step the lower it is, the more accurate the result will be at a computational cost

#Example(s)

std::vector<double> vec = {6444, 6555, 6666, 6888};
double shape = 3333;
double rate = 0.5;
double step = 0.1;
std::vector<double> out = pgamma(vec, shape, rate, step);
print_nvec(out);
:0: 5.44178e-05 0.141121 0.473211 0.946151


qgamma

#Usage

std::vector<double> qgamma(std::vector<double> &x, double &shape, double &rate, double step)

#Description

Returns the quantile value of the gamma probability distribution

#Arguments

NameDefinition
x is the input vector of probabilities, must be ascendly sorted
shape is the alpha value
rate is the lambda value (1 / theta)
step the lower it is, the more accurate the result will be at a cmputational cost

#Example(s)

std::vector<double> vec = {0.26, 0.45, 0.5, 0.6, 0.88};
double shape = 3333;
double rate = 0.5;
double step = 0.1;
std::vector<double> out = qgamma(vec, shape, rate, step);
print_nvec(out);
:0: 6591.86 6651.56 6666.06 6695.36 6801.76


rgamma

#Usage

std::vector<double> rgamma(unsigned int &n, double &shape, double &rate, double step)

#Description

Generates pseudo-random variables that follow a gamma probability distribution

#Arguments

NameDefinition
n is the number of observations, more than 1
shape is the alpha value
rate is the lambda (1 / theta)
step the lower it is, the more the result will be accurate, at a computational cost

#Example(s)

unsigned int n = 100;
double shape = 3333;
double rate = 0.25;
double step = 0.01;
std::vector out = rgamma(n, shape, rate, step);
print_nvec(out);
:0: 12794.8 12857.7 12897.7 12927.7 12952.2 12973 12991.2
13007.5 13022.4 13036.1 13048.8 13060.7 13071.9 13082.5 13092.7
13102.4 13111.7 13120.6 13129.3 13137.7 13145.8 13153.7 13161.4
13168.9
:25: 13183.4 13190.5 13197.4 13204.2 13210.9 13217.5 13224 13230.4
13236.8 13243 13249.2 13255.4 13261.5 13267.5 13273.5 13279.5
13285.4 13291.3 13297.1 13303 13308.8 13314.6 13320.4 13326.2
:50: 13337.8 13343.6 13349.4 13355.2 13361 13366.9 13372.7 13378.6
13384.6 13390.5 13396.5 13402.6 13408.6 13414.8 13421 13427.3
13433.6 13440 13446.5 13453.1 13459.8 13466.6 13473.5 13480.6
:75: 13495.1 13502.6 13510.3 13518.2 13526.4 13534.7 13543.4
13552.4 13561.7 13571.3 13581.5 13592.1 13603.3 13615.3 13628
13641.6 13656.5 13672.8 13691 13711.9 13736.3 13766.3 13806.3
13869.2
:100: 13276.2


Beta distribution

dbeta

#Usage

std::vector<double> dbeta(std::vector<double> &x, double &a, double &b, double normalisation_step = 1)

#Description

Returns the beta density probability distribution

#Arguments

NameDefinition
x is the vector of the probabilities
a is alpha, number of successes
b is beta, the number of failures
normalisation_step is the probability unit of the x vector

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1};
double step = 0.005;
std::vector<double> out = dbeta(vec, a, b, step);
print_nvec(out);
:0: 0 1.24746e-15 1.1697e-06 0.00428754 0.0410157
0.00547615 1.23346e-05 1.87358e-10 1.06384e-18 0


pbeta

#Usage

std::vector<double> pbeta(std::vector<double> &x, double &a, double &b, double step = 0.01)

#Description

Returns the beta cumulative probability distribution, of an interval of the first input value to the last input value (from the input vector of probabilities)

#Arguments

NameDefinition
x is the vector of the probabilities, must be ascendly sorted
a is alpha, the number of successes
b is beta, the number of failures
step the lower this value is, the more accurate the result will be at a computational cost

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1};
double step = 0.005;
std::vector<double> out = pbeta(vec, a, b, step);
print_nvec(out);
:0: 0 2.65054e-16 1.23119e-06 0.0129867 0.468685 0.974149
0.999966 1 1 1


qbeta

#Usage

std::vector<double> qbeta(std::vector<double> &x, double &a, double &b, double step = 0.01)

#Description

Returns the quantile of given probabilities according to the beta probability distribution

#Arguments

NameDefinition
x is the vector of probabilities you want the probabilities from
a is alpha, the number of successes
b is beta, the number of failures
step the lower this value is, the more accurate the result will be at a computational cost

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0.3, 0.55, 0.9, 0.99};
double step = 0.005;
std::vector<double> out = qbeta(vec2, a, b, step);
print_nvec(out);


rbeta

#Usage

std::vector<double> rbeta(unsigned int &n, double &a, double &b, double step = 0.01)

#Description

Returns pseudo-ranomly value that follow a beta probability distribution

#Arguments

NameDefinition
n is the number of observations, values to generate
a is alpha, the number of successes
b is beta, the number of failures
step the lower this value is, the more accurate the result will be. Have to be lowered if the output starts having clone values, it can happen when n is very high

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0.3, 0.55, 0.9, 0.99};
double step = 0.005;
unsigned int n = 100;
std::vector<double> out = rbeta(n, a, b, step);
print_nvec(out);
:0: 0.29716 0.31027 0.31901 0.32338 0.32775 0.33212
0.33649 0.34086 0.34086 0.34523 0.34523 0.3496 0.35397
0.35397 0.35397 0.35834 0.35834 0.36271 0.36271 0.36708
0.36708 0.36708 0.37145 0.37145
:25: 0.37582 0.37582 0.37582 0.38019 0.38019 0.38019
0.38456 0.38456 0.38456 0.38893 0.38893 0.38893 0.38893
0.3933 0.3933 0.3933 0.39767 0.39767 0.39767 0.39767
0.40204 0.40204 0.40204 0.40641
:50: 0.40641 0.40641 0.41078 0.41078 0.41078 0.41515
0.41515 0.41515 0.41515 0.41952 0.41952 0.41952 0.42389
0.42389 0.42389 0.42389 0.42826 0.42826 0.42826 0.43263
0.43263 0.43263 0.437 0.437
:75: 0.44137 0.44137 0.44574 0.44574 0.44574 0.45011 0.45011
0.45448 0.45448 0.45448 0.45885 0.46322 0.46322 0.46759
0.46759 0.47196 0.47633 0.47633 0.4807 0.48507 0.49381 0.49818
0.50692 0.52003
:100: 0.3933


Chi Square distribution

dchisq

#Usage

std::vector<double> dchisq(std::vector<double> &x, double °f)

#Description

Returns the chi square density probability function

#Arguments

NameDefinition
x is the input vector of quantiles
degf is the degree of freedom

#Example(s)

std::vector<double> vec = {180, 200, 210, 250, 290, 310};
double degf = 240;
std::vector<double> out = dchisq(vec, degf);
print_nvec(out);
:0: 0.000263702 0.00333664 0.00747074 0.0157848
0.00152353 0.000193457


pchisq

#Usage

std::vector<double> pchisq(std::vector<double> &x, double °f, double step = 0.05)

#Description

Returns the chi square cumulative probability function

#Arguments

NameDefinition
x is the input vector of quantiles, must be ascendly sorted
degf is the degree of freedom
step the lower this value is the more accurate the result will be at a computational cost

#Example(s)

std::vector<double> vec = {180, 200, 210, 250, 290, 310};
double degf = 240;
std::vector<double> out = pchisq(vec, degf);
print_nvec(out);
:0: 1.31851e-05 0.0266942 0.0790938 0.682744
0.983524 0.996995


qchisq

#Usage

std::vector<double> qchisq(std::vector<double> &x, double °f, double step = 0.05)

#Description

Returns the probability of the input quantile values

#Arguments

NameDefinition
x is the input vector of probabilities, must be ascendly sorted
degf is the degree of freedom
step th lower this value is the more accurate the result will be at a computational cost

#Example(s)

std::vector<double> vec2 = {0.2, 0.45, 0.56, 0.69, 0.88};
double degf = 240;
std::vector<double> out = qchisq(vec2, degf);
print_nvec(out);
:0: 221.45 236.65 242.7 250.4 266


rchisq

#Usage

std::vector<double> rchisq(unsigned int &n, double °f, double step = 0.05)

#Description

Returns pseudo-random values that follow a chi square probability distribution

#Arguments

NameDefinition
n is the number of observations
degf is the degree of freedom
step the lower it is the more accurate the result is. Have to be lowered if the output begins to have clone values. It can happen if n is very high

#Example(s)

unsigned int n = 100;
double degf = 240;
std::vector out = rchisq(n, degf);
print_nvec(out);
:0: 192.049 197.248 200.571 203.09 205.181 206.95
208.558 209.951 211.238 212.417 213.542 214.614 215.579
216.544 217.402 218.313 219.117 219.921 220.671 221.422
222.172 222.869 223.566 224.262
:25: 225.602 226.246 226.889 227.478 228.122 228.711
229.301 229.89 230.48 231.07 231.606 232.195 232.785
233.321 233.91 234.446 234.982 235.572 236.108 236.644
237.18 237.77 238.306 238.842
:50: 239.914 240.503 241.039 241.575 242.165 242.701
243.29 243.826 244.416 244.952 245.542 246.131 246.721
247.31 247.9 248.543 249.133 249.776 250.419 251.062 251.706
252.349 253.046 253.742
:75: 255.19 255.94 256.69 257.441 258.245 259.102 259.96 260.871
261.782 262.801 263.819 264.891 266.017 267.25 268.536 269.93
271.43 273.146 275.022 277.166 279.738 282.901 287.189 293.942
:100: 223.914


test_chisq_fit

#Usage

bool test_chisq_fit(std::vector<double> theoretical, std::vector<double> observed, double a_value = 0.05, double step = 0.05)

#Description

Performs a chi square goodness of fit test. Returns 1 if the observed values fit the observed values at a given p_value, 0 else

#Arguments

NameDefinition
theoretical is the vector containing all the theoretical data
observed is the vector containing all the observed data
a_value is the significance level
step the lower this value is the more accurate the result wil be at a computational cost

#Example(s)

std::vector theoretical = {20, 20, 30, 40, 60, 30};
std::vector observed = {30, 14, 34, 45, 57, 20};
double a_value = 0.05;
bool out = test_chisq_fit(theoretical, observed, a_value);
0 // the observed data does not fit the theoretical data


test_chisq_independance

#Usage

bool test_chisq_independance(std::vector<std::vector<double>> &matr, double a_value = 0.05, double step = 0.05)

#Description

Performs a chi square independance test. Returns 0 if the variables are independant, 1 else

#Arguments

NameDefinition
matr is the input matrice (observed values)
a_value is the significance level (the greater it is the more likely the 2 variables will be percieved as independant)
step the lower this value is the more accurate the result will be at a computational cost

#Example(s)

std::vector<std::vector<double>> matr = {{8, 16, 11, 10},
{9, 27, 22, 16},
{7, 13, 8, 12},
{9, 13, 12, 7}};
print_matr(matr);
double step = 0.05;
double a_value = 0.05;
bool out = test_chisq_independance(matr, a_value, step);
0 // the variables are independant


Geometric distributions

dgeom

#Usage

std::vector<double> dgeom(std::vector<unsigned int> &x, double &p)

#Description

Returns the geometric density probability distribution

#Arguments

NameDefinition
x is the input vector of quantiles, representing the number of failures before success
p is the probability of success

#Example(s)

std::vector<unsigned int> vec = {2, 3, 4, 5};
double p = (double)1 / 6;
std::vector<double> out = dgeom(vec, p);
print_nvec(out);
:0: 0.115741 0.0964506 0.0803755 0.0669796


pgeom

#Usage

std::vector<double> pgeom(std::vector<unsigned int> &x, double &p)

#Description

Returns the geometric cumulative probability distribution (interval between firts value in vector and last, see example)

#Arguments

NameDefinition
x is the input vector of quantiles, representing the number of failures before success, must be ascendly sorted
p is the probability of success

#Example(s)

std::vector<unsigned int> vec = {2, 3, 4, 5};
double p = (double)1 / 6;
std::vector<double> out = pgeom(vec, p);
print_nvec(out);
:0: 0.115741 0.212191 0.292567 0.359546


qgeom

#Usage

std::vector<unsigned int> qgeom(std::vector<double> &x, double &p)

#Description

Returns the quantiles of the input probabilities according to a geometric probability distribution

#Arguments

NameDefinition
x is the input vector of probabilities, must be ascendly sorted
p is the probability of success

#Example(s)

std::vector<double> vec2 = {0.2, 0.3, 0.5, 0.52, 0.6, 0.85};
double p = (double)1 / 6;
std::vector<unsigned int> out = qgeom(vec2, p);
print_nvec(out);
:0: 1 1 3 4 5 10


rgeom

#Usage

std::vector<unsigned int> rgeom(unsigned int &n, double &p)

#Description

Returns pseudo-randomly generated values that follow a geometric distribution

#Arguments

NameDefinition
n is the number of observations
p is the probability of success

#Example(s)

double p = (double)2 / 9;
unsigned int n = 100;
std::vector<unsigned int> out = rgeom(n, p);
print_nvec(out);
:0: 8 13 3 0 4 2 0 4 2 11 4 1 12 3 9
5 2 10 15 7 0 5 7 2
:25: 8 4 3 9 17 2 10 5 2 1 4 8 12 6 1
5 6 9 4 2 0 5 2 1
:50: 8 2 6 1 13 6 0 4 7 1 4 7 1 5 1
4 3 9 4 2 10 5 2 10
:75: 1 12 3 8 17 2 9 4 2 11 6 8 3 6 0
5 7 10 5 2 2 3 1 13
:100: 6


Hypergeometric distribution

dhyper

#Usage

std::vector<double> dhyper(std::vector<int> &x, unsigned int &n_ones, unsigned int &n_others, int &n_trials)

#Description

Returns the hypergeometric probability distribution

#Arguments

NameDefinition
x is the vector of quantiles
n_ones is the number of desired elements in the set
n_others is the number of undesired elements in the set
n_trials is the number of drawns

#Example(s)

unsigned int n_others = 1300;
unsigned int n_ones = 415;
std::vector<int> x = {150, 190, 400};
int n_trials = 555;
std::vector<double> out = dhyper(x, n_ones, n_others, n_trials);
print_nvec(out);
:0: 0.00807227 1.69452e-11 4.42674e-236


phyper

#Usage

std::vector<double> phyper(std::vector<int> &x, unsigned int &n_ones, unsigned int &n_others, int &n_trials)

#Description

Returns the cumulative hypergeometric distribution (interval between the first value of the input quantiles and last value)

#Arguments

NameDefinition
x is the vector of qualtiles
n_ones is the number of desired elements in the set
n_others is the number of undesired elements in the set
n_trials is the number of drawns

#Example(s)

unsigned int n_others = 1300;
unsigned int n_ones = 415;
std::vector<int> x = {0, 150};

int n_trials = 555;

std::vector<double> out_v = phyper(x, n_ones, n_others, n_trials);

print_nvec(out_v);

:0: 2.59543e-84 0.973988


qhyper

#Usage

std::vector<unsigned int> qhyper(std::vector<double> &x, unsigned int &n_ones, unsigned int &n_others, int &n_trials)

#Description

Returns the quantiles of the input probabilities according to the hypergeometric probability distribution.

#Arguments

NameDefinition
x is the vector of the input probabilities, must be ascendly sorted
n_ones is the number of desired elements in the set
n_others is the number of undesired elements in the set
n_trials is the number of drawns

#Example(s)

unsigned int n_others = 1300;
unsigned int n_ones = 415;
std::vector<double> x = {0.05, 0.12, 0.35, 0.36, 0.36, 0.56, 0.78};

int n_trials = 555;

std::vector<unsigned int> out_v = qhyper(x, n_ones, n_others, n_trials);

print_nvec(out_v);

:0: 121 124 131 131 131 135 139


rhyper

#Usage

std::vector<unsigned int> rhyper(unsigned int &n_obs, unsigned int &n_ones, unsigned int n_others, int &n_trials)

#Description

Returns pseudo-randomly generated values that follow a hypergeometric distribution

#Arguments

NameDefinition
n_obs is the number of observations
n_ones is the number of desired elements in the set
n_others is the number of undesired elements in the set
n_trials is the number of drawns

#Example(s)

unsigned int n_others = 1300;
unsigned int n_ones = 415;

int n_trials = 555;
unsigned int n_obs = 12;

std::vector<unsigned int> out_v = rhyper(n_obs, n_ones, n_others, n_trials);

print_nvec(out_v);

:0: 129 133 136 139 143 149 124 129 133 136 139 143


Operations between vectors

add_vout

#Usage

template <typename T, typename T2> std::vector<T> add_vout(std::vector<T> x, T2 &to_add)

#Description

Adds a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_add is the value to add

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = add_vout(inv, val);
print_nvec(outv);
:0: 6.3 9.3 5.3 8.3


subs_vout

#Usage

template <typename T, typename T2> std::vector<T> subs_vout(std::vector<T> x, T2 &to_subs)

#Description

Substracts a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_substract is the value to substract

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = subs_vout(inv, val);
print_nvec(outv);
:0: -2.3 0.7 -3.3 -0.3


mult_vout

#Usage

template <typename T, typename T2> std::vector<T> mult_vout(std::vector<T> x, T2 &to_mult)

#Description

Multiplicates a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_multiplicate is the value to multiplicate

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = mult_vout(inv, val);
print_nvec(outv);
:0: 8.6 21.5 4.3 17.2


divide_vout

#Usage

template <typename T, typename T2> std::vector<T> divide_vout(std::vector<T> x, T2 &to_divide)

#Description

Divides a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_divide is the value to divide

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = divide_vout(inv, val);
print_nvec(outv);
:0: 0.465116 1.16279 0.232558 0.930233


add_vin

#Usage

template <typename T, typename T2> void add_vin(std::vector<T> &x, T2 &to_add)

#Description

Adds a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_add is the value to add

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
add_vin(inv, val);
print_nvec(inv);
:0: 6.3 9.3 5.3 8.3


subs_vin

#Usage

template <typename T, typename T2> void subs_vin(std::vector<T> &x, T2 &to_subs)

#Description

Substracts a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_subs is the value to substract

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
subs_vin(inv, val);
print_nvec(inv);
:0: -2.3 0.7 -3.3 -0.3


mult_vin

#Usage

template <typename T, typename T2> void mult_vin(std::vector<T> &x, T2 &to_mult)

#Description

Multiplicates a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_mult is the value to multiplicate

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
mult_vin(inv, val);
print_nvec(inv);
:0: 8.6 21.5 4.3 17.2


divide_vin

#Usage

template <typename T, typename T2> void divide_vin(std::vector<T> &x, T2 &to_divide)

#Description

Divides a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_divide is the value to divide

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
divide_vin(inv, val);
print_nvec(inv);
:0: 0.465116 1.16279 0.232558 0.930233


add_v2out

#Usage

template <typename T, typename T2> std::vector<T>
add_v2out(std::vector<T> x,
std::vector<T2> &x2)

#Description

Add corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = add_v2out(inv, inv2);

print_nvec(outv);
:0: 4 10 3 9


subs_v2out

#Usage

template <typename T, typename T2> std::vector<T>
subs_v2out(std::vector<T> x,
std::vector<T2> &x2)

#Description

Substracts corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = subs_v2out(inv, inv2);

print_nvec(outv);
:0: 0 0 -1 -1


mult_v2out

#Usage

template <typename T, typename T2> std::vector<T>
mult_v2out(std::vector<T> x,
std::vector<T2> &x2)

#Description

Multiplies corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = mult_v2out(inv, inv2);

print_nvec(outv);
:0: 4 25 2 20


divide_v2out

#Usage

template <typename T, typename T2> std::vector<T>
divide_v2out(std::vector<T> x,
std::vector<T2> &x2)

#Description

Divides corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = divide_v2out(inv, inv2);

print_nvec(outv);
:0: 1 1 0.5 0.8


add_v2in

#Usage

template <typename T, typename T2> void add_v2in(std::vector<T> &x,
std::vector<T2> &x2)

#Description

Adds corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

add_v2in(inv, inv2);

print_nvec(inv);
:0: 4 10 3 9


subs_v2in

#Usage

template <typename T, typename T2> void subs_v2in(std::vector<T> &x,
std::vector<T2> &x2)

#Description

Substract corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

subs_v2in(inv, inv2);

print_nvec(inv);
:0: 0 0 -1 -1


mult_v2in

#Usage

template <typename T, typename T2> void mult_v2in(std::vector<T> &x,
std::vector<T2> &x2)

#Description

Multiplies corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

mult_v2in(inv, inv2);

print_nvec(inv);
:0: 4 25 2 20


divide_v2in

#Usage

template <typename T, typename T2> void divide_v2in(std::vector<T> &x,
std::vector<T2> &x2)

#Description

Adds corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

divide_v2in(inv, inv2);

print_nvec(inv);

:0: 1 1 0.5 0.8


Min - Max

min

#Usage

template <typename T> T min(const std::vector<T> &x)

#Description

Returns the min element from a vector (int, float, double, bool)

For finding the index of the min element refer here

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {4, 1, -7};
int out = min(vec);
-7


max

#Usage

template <typename T> T max(const std::vector<T> &x)

#Description

Returns the max element from a vector (int, float, double, bool)

For finding the index of the min element refer here

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {4, 1, -7};
int out = max(vec);
4


Mixing

Heuristic (slightly slower)

mixout

#Usage

template <typename T> void mixout(std::vector<T> &x)

#Description

Returns a stl vector with its elements at different indexes pseudo-randomly chosen.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
std::vector<int> out = mixout(vec);
print_nvec(out);
:0: 66 10 51 47 46 57 13 6 85 40 28 55 42 91 61 34 63 12 23 19 79 62 35 84
:25: 43 5 54 17 93 90 0 73 9 18 49 71 20 89 70 41 4 56 22 45 2 29 88 31
:50: 65 3 75 25 94 77 52 78 39 87 83 27 1 15 24 44 76 99 58 95 92 68 97 26
:75: 64 74 11 80 81 69 59 38 8 7 50 14 98 36 82 60 72 32 96 33 37 30 53 67
:100: 48


mixin

#Usage

template <typename T> void mixin(std::vector<T> &x)

#Description

Transforms a stl vector with its elements at different indexes pseudo-randomly chosen.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
mixin(vec);
print_nvec(vec);
:0: 66 10 51 47 46 57 13 6 85 40 28 55 42 91 61 34 63 12 23 19 79 62 35 84
:25: 43 5 54 17 93 90 0 73 9 18 49 71 20 89 70 41 4 56 22 45 2 29 88 31
:50: 65 3 75 25 94 77 52 78 39 87 83 27 1 15 24 44 76 99 58 95 92 68 97 26
:75: 64 74 11 80 81 69 59 38 8 7 50 14 98 36 82 60 72 32 96 33 37 30 53 67
:100: 48


Deterministic (slightly faster)

mixoutd

#Usage

template <typename T> std::vector<T> mixoutd(std::vector<T> x)

#Description

Returns a stl vector with its elements at different indexes. The function is determinitic based on the size of the input stl vector.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
std::vector<int> out = mixoutd(vec);
print_nvec(out);
:0: 93 65 90 45 1 41 51 79 28 13 18 84 68 37 77 22 15 29 44 9 6 47 36 57
:25: 14 24 26 46 56 96 33 61 54 59 5 73 34 76 75 71 11 78 92 31 48 50 55 49
:50: 52 17 89 21 0 81 64 82 39 67 53 40 63 66 83 97 99 42 2 86 85 80 60 72
:75: 20 87 27 4 35 19 10 88 43 98 38 8 30 69 58 23 16 95 32 94 91 70 74 62
:100: 25


mixind

#Usage

template <typename T> std::vector<T> mixind(std::vector<T> &x)

#Description

Transforms a stl vector with its elements at different indexes. The function is determinitic based on the size of the input stl vector.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
mixind(vec);
print_nvec(vec);
:0: 93 65 90 45 1 41 51 79 28 13 18 84 68 37 77 22 15 29 44 9 6 47 36 57
:25: 14 24 26 46 56 96 33 61 54 59 5 73 34 76 75 71 11 78 92 31 48 50 55 49
:50: 52 17 89 21 0 81 64 82 39 67 53 40 63 66 83 97 99 42 2 86 85 80 60 72
:75: 20 87 27 4 35 19 10 88 43 98 38 8 30 69 58 23 16 95 32 94 91 70 74 62
:100: 25


Print

#Usage

template <typename T> void print_nvec(const std::vector<T> &x, int untl = -1)

#Description

Print a stl vector (int, float, double, bool)

#Arguments

NameDefinition
x stl vector (int, float, double, bool)
untl is an int idicating how many elements must be printed, defaults to -1, so by default all elements will be printed

#Example(s)

std::vector<int> vec = {12, 2, 4534, 7, -78, 12122};
for (int i = 0; i < 50; ++i) { vec.push_back(i); }
print_nvec(vec);
:0: 12 2 4534 7 -78 12122 0 1 2 3
:10: 4 5 6 7 8 9 10 11 12 13
:20: 14 15 16 17 18 19 20 21 22 23
:30: 24 25 26 27 28 29 30 31 32 33
:40: 34 35 36 37 38 39 40 41 42 43
:50: 44 45 46 47 48 49



#Usage

template <typename T> void print_nvec(const std::vector<T> &x, int untl = -1)

#Description

Print a stl vector (int, float, double, bool)

#Arguments

NameDefinition
x stl vector (int, float, double, bool)
untl is an int idicating how many elements must be printed, defaults to -1, so by default all elements will be printed

#Example(s)

std::vector<std::string> vec2 = {"peugeot", "wolkswagen", "honda", "renault", "stellantis"};
for (int i = 0; i < 20; ++i) { vec2.push_back("yesss"); }
print_svec(vec2);
:0: peugeot wolkswagen honda renault stellantis yesss yesss yesss
:8: yesss yesss yesss yesss yesss yesss yesss yesss
:16: yesss yesss yesss yesss yesss yesss yesss yesss
:24: yesss



Absolute values

abs_vin

#Usage

template <typename T> void abs_vin(std::vector<T> &x)

#Description

Converts the elements of a vector to absolute values.

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, -5, -7, 3};
abs_vin(vec);
{1, 5, 7, 3}


abs_vout

#Usage

template <typename T> void abs_vout(std::vector<T> &x)

#Description

Returns the input vector with all of its elements converted to absolute values.

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, -5, -7, 3};
std::vector<unsigned int> out = abs_vout(vec);
{1, 5, 7, 3}


abs_voutb

#Usage

template <typename T> std::vector<T> abs_voutb(const std::vector<T> &x)

#Description

Returns the input vector with all of its elements converted to absolute values.

uses another algorithm than abs_vout, with indices instead of iterators.

#Arguments

NameDefinition
x is a stl vector (int, float, double)

#Example(s)

std::vector<int> vec = {-45, 23, 21, -6, 45};
std::vector<unsigned int> out = abs_voutb(vec);
{45, 23, 21, 6, 45}


Match

matchl

#Usage

template <typename T, typename T2> bool matchl(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns 1 if the pattern is found in the stl vector, 0 if not. (returns bool)

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
bool out = matchl(vec, ptrn);
1


match

#Usage

template <typename T, typename T2> unsigned int match(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns the index of the pattern in the vector, -1 if not found.

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
unsigned int out = matchl(vec, ptrn);
2


match_max

#Usage

template <typename T> unsigned int match_max(const std::vector<T> &x)

#Description

Returns the index of the maximum value in a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double)

#Example(s)

std::vector<int> vec = {3, 1, -7, 23, 21};
unsigned int out = match_max(vec);
3


match_min

#Usage

template <typename T> unsigned int match_min(const std::vector<T> &x)

#Description

Returns the index of the minimum value in a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double)

#Example(s)

std::vector<int> vec = {3, 1, -7, 23, 21};
unsigned int out = match_min(vec);
2


match_n

#Usage

template typename <T>
std::vector<unsigned int >
match_n(const std::vector<T>& x, const std::vector<T>& ptrn)

#Description

Returns all the first index of occurence of all input elements in a set.

#Arguments

NameDefinition
x is the input set (where are the elements to be found)
ptrn is the vector containing all the elements to match

#Example(s)



std::vector<std::string> vec1 = {"az", "pp", "mm", "ff", "ff", "uv"};

std::vector<std::string> vec2 = {"ff", "ff", "mm"};

std::vector<unsigned int> vecout = match_n(vec1, vec2);
:0: 3 3 2


Grep

grep

#Usage

template <typename T, typename T2> std::vector<unsigned int> grep(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns the indices of a pattern inside a stl vector.

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
std::vector<unsigned int> out = grep(vec, ptrn);
{3 4}


grepl

#Usage

template <typename T, typename T2> std::vector<bool> grepl(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns a boolean vector where O corresponds to a non match with the pattern andthe corresponding elements of the stl vector. 1 represents a match.

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
std::vector<bool> out = grep(vec, ptrn);
{0 0 1 0 1}


Unique

unique

#Usage

template <typename T> std::vector<T> unique(const std::vector<T> &x)

#Description

Returns a stl vector with unique elements from an input stl vector.

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 4, 5, 6, 6};
std::vector<int> out = unique(vec);
{1, 2, 3, 4, 5, 6}


Reverse

reverse_out

#Usage

template <typename T> std::vector<T> reverse_out(const std::vector<T> &x)

#Description

Returns a reverse stl vector from an input stl vector.

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<std::string> vec = {"he", "ll", "o"};
std::vector<std::string> out = reverse_out(vec);
{"ll", "o", "he"}


reverse_in

#Usage

template <typename T> std::vector<T> reverse_in(const std::vector<T> &x)

#Description

Reverses a stl vector..

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<std::string> vec = {"he", "ll", "o"};
reverse_out(vec);
{"ll", "o", "he"}


reverse_out_standard

#Usage

template <typename T> std::vector<T> reverse_out(const std::vector<T> &x)

#Description

Returns a reverse stl vector from an input stl vector. Uses another algorithm than reverse_out.

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<std::string> vec = {"he", "ll", "o"};
std::vector<std::string> out = reverse_out(vec);
{"ll", "o", "he"}


Repetition of elements

rep

#Usage

template <typename T> std::vector<T> rep(const std::vector<T> &x, const std::vector<int> &hmn)

#Description

Returns a stl vector of elements repeted multiple times relatively to an int stl vector.

#Arguments

NameDefinition
x is a stl vector containing all the elements that will be repeated
hmn is a stl int vector containing all the times each element will be repeated

#Example(s)

std::vector<std::string> vec;
std::vector<int> hmn = {4, 2, 7};
std::vector<std::string> elmnts = {"ok", "ko", "ok2"};
vec = rep(elmnts, hmn);
print_svec(vec);
:0: ok ok ok ok ko ko ok2 ok2 ok2 ok2 ok2 ok2 ok2


rep

#Usage

template <typename T> std::vector<T> rep(T val, int n)

#Description

Returns a vector of the input element repeated n times

#Arguments

NameDefinition
val is your input value
n is the n

#Example(s)

int val = 14;
int n = 4;
std::vector<int> = rep(val, n);
{14, 14, 14, 14}


repeat_untl

#Usage

template <typename T> void repeat_untl(std::vector<T> &vec, int n)

#Description

Repeat the sequence of the input vector elements until it matches the target length

#Arguments

NameDefinition
vec is your input vector
n is the target len

#Example(s)

std::vector<int> vec = {1, 2, 3};
int n = 8;
repeat_untl(vec, n);
{1, 2, 3, 1, 2, 3, 1, 2}


Sequence/Range of elements

seq

#Usage

template <typename T, typename T2, typename T3> std::vector<T> seq(T from, T2 const &to, T3 const &by)

#Description

Returns a stl range vector(int, float, double).

#Arguments

NameDefinition
from is the starting value
to is the end value
by is the step value

#Example(s)

float from = 1.25;
float to = 3;
float by = 0.25;
std::vector<float> = seq(from, to, by);
{1.25, 1.5, 1.75, 2, 1.25, 2.5, 2.75, 3}


Comparisons to booleans

comp2

#Usage

template <typename T, typename T2> std::vector<bool> comp2(const std::vector<T> &x, const std::vector<T2> &x2)

#Description

Returns a boolean vector of 2 stl vectors that will be compared elements by elements. The vectors should not necessarily be the same size. The output boolean vector will be the same size as the first stl vector argument. This is the prefered way when there are only 2 vectors to compare, compared to using Compv class.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<unsigned int> vec = {1, 5, 2};
std::vector<unsigned int> vecb = {1, 5, 22};
std::vector<bool> out = comp2(vec, vecb);
1 1 0
vec = {1, 5, 2, 1, 5, 2};
out = comp2(vec, vecb);
1 1 0 1 1 0


Variadic / Indefinite number of arguments - Compv Class

Compv.to_comp()

#Usage

Compv comp1(std::vector<Type> vec1);
comp1.to_comp(std::vector<Type> vec2, std::vector<Type> vec3);
comp1.result();
comp1.reinitiate(std::vector<OtherType> vec4);
...

#Description

Returns a boolean vector of multiple stl vectors that will be compared elements by elements. The vectors do not have necessarily to be the same size. The output boolean vector will be the size of the initiation vector.

#Arguments

NameDefinition
... undefinite number of stl vectors

#Example(s)

std::vector<unsigned int> vec = {1, 5, 2};
std::vector<unsigned int> vecb = {1, 5, 2};
std::vector<unsigned int> vecc = {1, 5, 22};
std::vector<unsigned int> vec2 = {1, 5};
std::vector<unsigned int> vec2b = {1, 5};
std::vector<unsigned int> vec2c = {1, 5};
Compv obj1(vec);
obj1.to_comp(vecb, vecc);
std::vector<bool> out = obj1.result();
1 1 0
obj1.reinitiate(vec2);
out = obj1.result();
1 1
vec = {1, 5, 22, 1, 5, 2};
obj1.reinitiate(vec);
obj1.to_comp(vec, vecb, vecc);
out = obj1.result();
1 1 0 1 1 0


Bool and indices conversions

bool_to_idx

#Usage

std::vector<unsigned int> bool_to_idx(std::vector<bool> &x)

#Description

Converts a boolean vector to an indices vector.

#Arguments

NameDefinition
x is the input boolean vector

#Example(s)

std::vector<bool> xbool = {0, 0, 1, 1, 0, 1, 0};
std::vector<unsigned int> xidx = bool_to_idx(xbool);
print_nvec(xidx);
2 3 5


idx_to_bool

#Usage

std::vector<bool> idx_to_bool(std::vector<unsigned int> &x, int target_size = -1)

#Description

Converts a indice vector to a boolean vector

#Arguments

NameDefinition
x is the input indices vector
target_size is the size of the wanted output boolean vector

#Example(s)

std::vector<unsigned int> xidx = {2, 3, 5};
std::vector<bool> xbool = idx_to_bool(xidx, 7);
print_nvec(xbool);
:0: 0 0 1 1 0 1 0


Lower

lowercomp2

#Usage

template <typename T, typename T2> std::vector<bool> lowercomp2(std::vector<T> &x, std::vector<T2> &x2)

#Description

Returns a boolean vector, 1 if the corresponding values from the first vector is lower than the corresponding values from the second vecotr. The output vector is the size of the first vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> vec = {1, 2.5, -6, 7.8, 2};
std::vector<double> vec = {2, 2};
lowercomp2(vec, vec2);
1 0 1 0 0


Greater

greatercomp2

#Usage

template <typename T, typename T2> std::vector<bool> greatercomp2(std::vector<T> x, T2 x2)

#Description

Returns a boolean vector, 1 if the corresponding values from the first vector is greater than the corresponding values from the second vecotr. The output vector is the size of the first vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> vec = {1, 2.5, -6, 7.8, 2};
std::vector<double> vec = {2, 2, 2, 2, 2};
greatercomp2(vec, vec2);
0 1 0 1 0


Any - All

any

#Usage

bool any(const std::vector<bool> &x)

#Description

Returns 1 if a boolean vector has at least 1 as value of one of its elements, 0 if not.

#Arguments

NameDefinition
x is a stl boolean vector

#Example(s)

std::vector<bool> vec = {0, 0, 1, 0};
bool out = any(vec);
1
std::vector<bool> vec = {0, 0, 0, 0};
out = any(vec);
0


all

#Usage

all any(const std::vector<bool> &x)

#Description

Returns 1 if all the elements of a stl boolean vector equals to 1, 0 if not.

#Arguments

NameDefinition
x is a stl boolean vector

#Example(s)

std::vector<bool> vec = {0, 0, 1, 0};
bool out = all(vec);
0
std::vector<bool> vec = {1, 1, 1, 1};
out = all(vec);
1


Infamous Gnome Sorting Algorithm

sort_desc

#Usage

template <typename T> void sort_desc(std::vector<T> &x)

#Description

Transforms a stl vector (int, float, double, bool) to a sorted decreasing stl vector.

#Arguments

NameDefinition
x stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 5, 2, 1, 5, 22};
sort_desc(vec);
{22, 5, 5, 2, 1, 1}


sort_asc

#Usage

template <typename T> void sort_asc(std::vector<T> &x)

#Description

Transforms a stl vector (int, float, double, bool) to a sorted increasing stl vector.

#Arguments

NameDefinition
x stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 5, 2, 1, 5, 22};
sort_asc(vec);
{1, 1, 2, 5, 5, 22}


str_sort_descend

#Usage

std::vector<std::string> str_sort_descend(std::vector<std::string> x,
std::vector order_v = {
' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '[', '\\',
']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '{', '|', '}',
'~'
})

#Description

Returns a descendly sorted vector of std::string (according to ascii table order by default)

#Arguments

NameDefinition
x is the input vector
order_v is the order of each character (ascii table by default)

#Example(s)

std::vector<std::string> inv = {"b", "c", "a", "b", "a", "aa", "ab"};
std::vector<std::string> outv = str_sort_descend(inv);
print_svec(outv);
:0: c b b ab aa a a


str_sort_ascend

#Usage

std::vector<std::string> str_sort_ascend(std::vector<std::string> x, std::vector order_v = {
' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '[', '\\',
']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '{', '|', '}',
'~'

})

#Description

Returns a ascendly sorted vector of std::string. (according to ascii table order by default)

#Arguments

NameDefinition
x is the input vector
order_v is the order of each character (ascii table by default)

#Example(s)

std::vector<std::string> inv = {"b", "c", "a", "b", "a", "aa", "ab"};
std::vector<std::string> outv = str_sort_ascend(inv);
print_svec(outv);
:0: a a aa ab b b c


Remove range of elements

rm_ordered

#Usage

template <typename T> void rm_ordered(std::vector<T> &x, std::vector<int> ids)

#Description

Remove elements from a stl vector. Keeps the vector sorted at a certain computational cost compared to rm_unordered. The stl int vector provided for the indices of the element to be removed must be decreasingly sorted. The capacity of the vector is kept unchanged, so if you want to shrink it, consider doing shrink_to_fit() method.

#Arguments

NameDefinition
x is an stl vector
ids is an stl int vector decreasingly sorted

#Example(s)

std::vector<int> vec = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<int> ids = {8, 5, 3, 2};
rm_ordered(vec, ids);
print_nvec(vec);
:0: 0 1 4 6 7 9


rm_unordered

#Usage

template <typename T> void rm_unordered(std::vector<T> &x, std::vector<int> ids)

#Description

Remove elements from a stl vector. Does not keep the vector sorted for computational speed compared to rm_ordered. The stl int vector provided for the indices of the element to be removed must be decreasingly sorted. The capacity of the vector is kept unchanged, so if you want to shrink it, consider doing shrink_to_fit() method.

#Arguments

NameDefinition
x is an stl vector
ids is an stl int vector decreasingly sorted

#Example(s)

std::vector<int> vec = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<int> ids = {8, 5, 3, 2};
rm_unordered(vec, ids);
print_nvec(vec);
:0: 0 1 6 7 4 9


Sets (Union - Diff - Removing shared elements)

union2

#Usage

template <typename T> std::vector<T> union2(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the union of two stl vectors. Does not returns a stl vector with unique elements, so if you want it to return unique elements, make sure to enter unique stl vectors as input.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> out = union2(vec1, vec2);
print_nvec(out);
:0: 3 4 4 5 7 8 2 4 0 1 2 3 9 11


Variadic / Indefinite number of arguments - Unionv Class

Unionv.to_union()

#Usage

Unionv union1(std::vector<Type> vec1);
union1.to_union(std::vector<Type> vec2, std::vector<Type> vec3);
union1.result();
union1.reinitiate(std::vector<Type2> vec4);
...

#Arguments

NameDefinition
... undefinite number of stl vector of the same type

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> vec3 = {0, 1, 2, 3, 11, 9};
Unionv union1(vec1);
union1.to_union(vec2, vec3, vec3);
std::vector<int> out = union1.result();
print_nvec(out);
:0: 3 4 4 5 7 8 2 4 11 0 1 2 3 9 11 4 0 1 2 3 11 9 0 1
:25: 2 3 11 9
union1.reinitiate(vec2);
union1.to_union(vec1);
out = union1.result();
print_nvec(out);
:0: 0 1 2 3 9 11 4 3 4 4 5 7 8 2 4 11


intersect2

#Usage

template <typename T> std::vector<T> union2(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the commun elements of two stl vectors of the same type. Does not returns a stl vector with unique elements, so if you want it to return unique elements, make sure to enter unique stl vectors as input.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> out = intersect2(vec1, vec2);
print_nvec(out);
:0: 2 3


Variadic / Indefinite number of arguments - Intersectv Class

Intersectv.to_intersect()

#Usage

Intersectv intersect1(std::vector<Type> vec1);
intersect1.to_intersect(std::vector<Type> vec2, std::vector<Type> vec3);
intersect1.reinitiate(std::vector<Type2>);
...

#Description

Returns the commun elements of undefinite number of stl vectors of the same type. The returned vector can have extra capacity non initiated, to get rid of that consider applying it the shrink_to_fit() method. The returned vector does not return unique elements, so if you want unique elements, consider enter unique stl vectors as input.

#Arguments

NameDefinition
... undefinite number of stl vectors

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> vec3 = {0, 1, 2, 3, 11, 9};
Intersectv intersect1(vec1);
intersect1.to_intersect(vec2, vec3);
std::vector<int> out = intersect1.result();
print_nvec(out);
:0: 3 2 11
intersect1.reinitiate(vec1);
intersect1.to_intersect(vec2);
out = intersect1.result();
print_nvec(out);
:0: 3 4 4 2 4 11


diff2

#Usage

template <typename T> std::vector<T> diff2(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the elements that are in one of the stl vector but not in the intersection of all stl vectors. Does not returns a stl vector with unique elements, so if you want it to return unique elements, make sure to enter unique stl vectors as input.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> out = diff2(vec1, vec2);
print_nvec(out);
:0: 9 4 4 5 7 8 11 4 0 1


Variadic / Indefinite number of arguments - Diffv Class

Diffv.to_diff()

#Usage

Diffv diff1(std::vector<Type> vec1)
diff1.to_diff(std::vector<Type> vec2, std::vector<Type> vec2);
diff1.result();
diff1.reinitiate(std::vector<Type2> vec4);
...

#Description

Returs a stl vector of all the elements that are in one of the undefinite number of input stl vectors (of the same type) or more, but not in the intersection of all these stl vectors. Does not return a stl vector with unique elements, if you want it to return a stl vector with unique elements make sure that your input vectors contain unique elements. The returned vector can have more capacity than its size, to get rid of this unusable memory, you can apply the shrink_to_fit() method on it.

#Arguments

NameDefinition
... undefinite number of stl vectors of the same type

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> vec3 = {0, 1, 2, 3, 11, 9};
Diffv diff1(vec1);
diff1.to_diff(vec2, vec3);
std::vector<int> out = diff1.result();
print_nvec(out);
:0: 9 4 4 5 7 8 9 4 4 0 1 0 1
diff1.reinitiate(vec3);
diff1.to_diff(vec2, vec1);
out = diff1.result();
print_nvec(out);
:0: 0 1 4 4 4 9 0 1 5 7 9 8 4 //same elements, different orders because the initializer vector is not the same


rm_shared_in

#Usage

template <typename T> void rm_shared_in(std::vector<T> &x, std::vector<T> &x2)

#Description

Transforms the first stl vector input removing its commun elements with the second stl vector of the same type. The returned vector has its capacity unchanged, so consider applying the shrink_to_fit() method to it if you want to free some memory.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
rm_shared_in(vec1, vec2);
print_nvec(vec1);
:0: 5 7 8


rm_shared_out

#Usage

template <typename T> std::vector<T> rm_shared_out(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the first stl vector input minus the its commun elements with the second stl vector of the same type. The returned vector has its capacity unchanged, so consider applying the shrink_to_fit() method to it if you want to free some memory.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> out = rm_shared_out(vec1, vec2);
print_nvec(out);
:0: 5 7 8


Variadic / Indefinite number of arguments - Rm_sharedv Class

Rm_sharedv.to_rm()

#Usage

Rm_sharedv rm1(std::vector<Type> vec1);
rm1.to_comp(std::vector<Type> vec2, std::vector<Type> vec3);
rm1.result();
rm1.reinitiate(std::vector<OtherType> vec4);
...

#Description

Returns the initializer vector with the shared elements between this vector and an undefinite number of stl vectors, removed. This method is faster than finding commun elements between undefinite number of stl vectors and the initializer vector, and then removing the commun elements.

#Arguments

NameDefinition
... undefinite number of stl vectors

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> vec3 = {0, 1, 2, 3, 9, 11, 8};
Rm_sharedv obj1(vec1);
obj1.to_rm(vec2, vec3);
std::vector<int> out = obj1.result();
print_nvec(out);
:0: 4 4 4 5 7
obj1.reinitiate(vec1);
out = obj1.result();
print_nvec(out);
:0: 3 4 4 5 7 8 2 4


sub

#Usage

template <typename Iter> std::vector<typename std::iterator_traits<Iter>::value_type> sub(Iter first, Iter last)

#Description

Extract a contiguous subset from a vector.

#Arguments

NameDefinition
X No args

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5};
sub(vec.begin() + 1, vec.begin() + 3);
{2, 3}


Finding closest elements in stl vector

closest_idx

#Usage

template <typename T> unsigned int closest_idx(std::vector<T> &x, T &val)

#Description

Returns the closest elements from a stl vector (int, float, double, bool) and a given value as the index of the closet element of the stl vector. This is equivalent to finding the index of the minimum difference between the value and the elements in the stl vector, but more efficiently since the function assumes the stl vector is already sorted ascendly or descendly as you see in examples.

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool), must be ascendly or descendly sorted
val is an int, float, double, bool

#Example(s)

std::vector<double> vec = {0.1, 0.89, 1.2, 1.66, 1.78, 2.25, 4.56};
double val = 1.97;
closest_idx(vec, val);
4
val = 0.99;
closest_idx(vec, val);
1
std::vector<double> vec2 = sort_descout(vec);
closest_idx(vec, val);
5
val = 5.33;
closest_val(vec2, val);
0


String and vectors conversions

Collapse (vector to string)

ncollapse

#Usage

template <typename T, typename T2> std::string ncollapse(const std::vector<T> &x, const T2 &sep)

#Description

Collapses all elements from an stl vector (int, float, double, bool) to a string with a given separator.

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool)
sep is a char or string that will be the separator between the elements of x

#Example(s)

std::vector<int> vec = {5, 7, 22, 879};
char sep = "-";
std::string out = ncollapse(vec, sep);
"5-7-22-879"

std::string sep2 = "--";
out = ncollapse(vec, sep2);
"5--7--22--879"


scollapse

#Usage

template <typename T> std::string scollapse(const std::vector<std::string> &x, const T &sep)

#Description

Collapses all elements from an stl string vector to a string with a given separator.

#Arguments

NameDefinition
x is an stl vector (stl string)
sep is a char or string that will be the separator between the elements of x

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe"};
char sep = "-";
std::string out = ncollapse(vec, sep);
"yess-no-maybe"

std::string sep2 = "--";
out = ncollapse(vec, sep2);
"yess--no--maybe"


Split (string to vector)

split

#Usage

std::vector<std::string> split(const std::string &x, const char &sep)

#Description

Returns a stl vector of stl strings that are part of the input stl string. The input string must have a separator to differenciate elements for the output stl vector.

#Arguments

NameDefinition
x is a stl string
sep is a char

#Example(s)

std::string test = "y-e-ss";
char sep = '-';
std::vector<std::string> out = split(test, sep);
{"y", "e", "ss"}


Merge strings of 2 vectors

merge_strv

#Usage

std::vector<std::string> merge_strv(std::vector<std::string> &x1, std::vector<std::string> &x2, std::string sep = "-")

#Description

Returns a vector of merged strings of the input vectors

#Arguments

NameDefinition
x1 is the first vector
x2 is the second vector

#Example(s)


std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};

std::vector<std::string> vec2 = {"lm", "lm", "O"};

std::vector<std::string> outv = merge_strv(vec, vec2);
print_svec(outv);

:0: lm-lm lm-lm mm-O lm-lm po-lm rr-O rr-lm po-lm


Occurence of elements in vectors

occu

#Usage

template <typename T> std::map<std::vector<T>, std::vector<unsigned int>> occu(std::vector<T> &x)

#Description

Returns a map containing: the input vector of elements with unique elements, and their associated occurence in another vector (second in map)

#Arguments

NameDefinition
x is the input vector

#Example(s)

std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};
std::map<std::vector<std::string>, std::vector<unsigned int>> rtn_mp = occu(vec);
std::map<std::vector<std::string>, std::vector<unsigned int>>::iterator rtn_it = rtn_mp.begin();
int i;
std::vector<std::string> uvec = rtn_it->first;
std::vector<unsigned int> freqv = rtn_it->second;
for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};
lm 3
mm 1
po 2
rr 2


desc_occu

#Usage

template <typename T> std::map<std::vector<T>, std::vector<unsigned int>> desc_occu(std::vector<T> vec, std::vector<unsigned int> freqv)

#Description

Returns a descendly sorted occu() output.

#Arguments

NameDefinition
vec is the vector of unique elements
freqv is the associated occurence of the elements

#Example(s)

std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};
std::map<std::vector<std::string>, std::vector<unsigned int>> rtn_mp = occu(vec);
std::map<std::vector<std::string>, std::vector<unsigned int>>::iterator rtn_it = rtn_mp.begin();
int i;
std::vector<std::string> uvec = rtn_it->first;
std::vector<unsigned int> freqv = rtn_it->second;

std::cout << "######\n";

rtn_mp = desc_occu(uvec, freqv);
rtn_it = rtn_mp.begin();
uvec = rtn_it->first;
freqv = rtn_it->second;

for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};
lm 3
po 2
rr 2
mm 1


asc_occu

#Usage

template <typename T> std::map<std::vector<T>, std::vector<unsigned int>> asc_occu(std::vector<T> vec, std::vector<unsigned int> freqv)

#Description

Returns a ascendly sorted out put of the occu() output.

#Arguments

NameDefinition
vec is the vector of unique elements
freqv is the associated occurence of the elements

#Example(s)


std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};
std::map<std::vector<std::string>, std::vector<unsigned int>> rtn_mp = occu(vec);
std::map<std::vector<std::string>, std::vector<unsigned int>>::iterator rtn_it = rtn_mp.begin();
int i;
std::vector<std::string> uvec = rtn_it->first;
std::vector<unsigned int> freqv = rtn_it->second;
for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};

rtn_mp = asc_occu(uvec, freqv);
rtn_it = rtn_mp.begin();
uvec = rtn_it->first;
freqv = rtn_it->second;

for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};
mm 1
po 2
rr 2
lm 3


Others

pct_to_idx

#Usage

unsigned int percentage_to_idx(double &val, unsigned int &sizen)

#Description

Returns an idx of a stl vector from a percentage between 0 and 1.

#Arguments

NameDefinition
val is the percentage value, between 0 and 1
sizen is the size of the vector you want to have the index.

#Example(s)

std::<int> vec = {1, 2, 3, 4};
unsigned int sizen = vec.size();
double pct = 0.6;
unsigned int out = pct_to_idx(pct, sizen);
2


diff_mean

#Usage

template <typename T> double diff_mean(std::vector<T> &x)

#Description

Returns the mean of all the differences in value between the contiguous elementsof a stl vector.

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<double> vec = {10, 10.5, 11, 11.5};
diff_mean(vec);
0.5


The Dataframe Object

Dataframe

#Usage

Dataframe my_dataframe

#Description

Dataframe objects supporting writing / reading csv, storing columns in differents vectors type (automatically or not), specifying the rows and columns to copy or get by reference, perform all types of joins, groupby... See examples.

#Arguments

NameDefinition
See_below See below

#Example(s)

See below


Dataframe.readf

#Usage

template
void readf(std::string &file_name, char delim = ',', bool header_name = 1, char str_context_begin = '\'', char str_context_end = '\'')

#Description

Import a csv as a Dataframe object.

#Arguments

NameDefinition
file_name is the file_name of the csv to read
delim is the column delimiter
header_name is if the first row is in fact the column names
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context
strt_row is the first row to read, defaults to 0
end_row is the last row to read, defaults to max (value of 0)

#Example(s)

Dataframe obj1;
std::string file_name = "teste_dataframe.csv";
obj1.readf<3, 8>(file_name); reads from the 3thrd to the 8nth row


Dataframe.readf_trim

#Usage

template
void readf_trim(std::string &file_name, char delim = ',', bool header_name = 1, char str_context_begin = '\'', char str_context_end = '\'')

#Description

Import a csv as a Dataframe object. Automatically trim the value (removes extra spaces before and after)

#Arguments

NameDefinition
file_name is the file_name of the csv to read
delim is the column delimiter
header_name is if the first row is in fact the column names
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context
strt_row is the first row to read, defaults to 0
end_row is the last row to read, defaults to max (value of 0)

#Example(s)

Dataframe obj1;
std::string file_name = "teste_dataframe2.csv";
obj1.readf_trim<0, 8>(file_name); // reads until the 8nth row


Dataframe.readf_lambda

#Usage

template
void readf_lambda(std::string &file_name, void (&f)(std::string&), char delim = ',', bool header_name = 1, char str_context_begin = '\'', char str_context_end = '\'')

#Description

Import a csv as a Dataframe object. Applies a custom function to all values from the csv before parsing it as appropriate data types.

#Arguments

NameDefinition
file_name is the file_name of the csv to read
f is your custom function (void, must take a stdstring as argument)
delim is the column delimiter
header_name is if the first row is in fact the column names
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context
strt_row is the first row to read, defaults to 0
end_row is the last row to read, defaults to max (value of 0)

#Example(s)

void myfunc (std::string &x) {
x.push_back('L');
};
Dataframe obj1;
std::string file_name = "teste_dataframe2.csv";
obj1.readf_lambda<3, 0>(file_name, myfunc); // reads from the thirs row


Dataframe.readf_alrd

#Usage

template
void readf_alrd(std::string &file_name, std::vector<string>& dtype, char delim = ',', bool header_name = 1, char str_context_begin = '\'', char str_context_end = '\'')

#Description

Import a csv as a Dataframe object. This function only makes sense if you know in advance the column data types (faster than semantical analysis). The column data types are contiguously described in dtype argument. The values are 's' (string), 'c' (char), 'b' (bool), 'i' (int), 'u' (unsigned int) and 'd' (double)

#Arguments

NameDefinition
file_name is the file_name of the csv to read
dtype is the string vector containing all column data types
f is your custom function (void, must take a stdstring as argument)
delim is the column delimiter
header_name is if the first row is in fact the column names
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context
strt_row is the first row to read, defaults to 0
end_row is the last row to read, defaults to max (value of 0)

#Example(s)

std::string dvec = "dsusic";
Dataframe obj1;
std::string file_name = "teste_dataframe2.csv";
obj1.readf_lambda(file_name, dvec); //reads the entire file


Dataframe.writef

#Usage

void writef(std::string &file_name, char delim = ',', bool header_name = 1, char str_context_bgn = '\'', char str_context_end = '\'')

#Description

Write a dataframe object into a csv file.

#Arguments

NameDefinition
file_name is the file name to write data into
delim is the column delimiter
header_name 1 to write the column names, 0 else
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context

#Example(s)

// after reading teste_dataframe.csv as obj1
std::string out_file = "out.csv";
obj1.writef(out_file);


Dataframe.display

#Usage

void display();

#Description

Print the current dataframe.

#Arguments

NameDefinition
no no

#Example(s)

// after reading teste_dataframe.csv as obj1
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 1 2 3 aa 5 z
:1: 6 7 8 bb 10 e
:2: 1 2 3 cc 5 h
:3: 6 7 8 uu 10 a
:4: 1 2 3 s4 -5 q
:5: 6 7 8 s9 10 p
:6: 1 2 3 a4 5 j
:7: 6 7 8 m9 10 i
:8: 6 7 8 s9 10 p
:9: 1 2 3 a4 5 j
:10: 6 7 8 m9 10 i
:11: 6 7 8 m9 10 i
:12: 6 7 8 s9 10 p
:13: 1 2 3 a4 5 j
:14: 6 7 8 m9 10 i



Dataframe.display_filter

#Usage

void display_filter(std::vector<bool> &x, std::vector<int> &colv)

#Description

Print the current dataframe. Works seemlessly with Dataframe.view_colnb() to efficiently create boolean vector to filter rows, see example.

#Arguments

NameDefinition
x is the boolean vector filtering the rows to display
colv is the int vector representing the column index of the column to keep, {-1} to keep all columns

#Example(s)

// after reading teste_dataframe.csv as obj1

unsigned int n = 1;

std::vector<int> cols = {-1};

auto col = obj1.view_colnb(n);

std::vector<bool> mask;

std::visit([&mask](auto&& span) {
mask.resize(span.size());
for (size_t i = 0; i < span.size(); ++i)
mask[i] = span[i] > 3;
}, col);

obj1.display_filter(mask, cols);

<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:1: 6 7 8 bb 10 e
:3: 6 7 8 uu 10 a
:5: 6 7 8 s9 10 p
:7: 6 7 8 m9 10 i
:8: 6 7 8 s9 10 p
:10: 6 7 8 m9 10 i
:11: 6 7 8 m9 10 i
:12: 6 7 8 s9 10 p
:14: 6 7 8 m9 10 i


Dataframe.display_filter_idx

#Usage

void display_filter_idx(std::vector<int> &x, std::vector<int> &colv)

#Description

Print the current dataframe. Works seemlessly with Dataframe.view_colnb() to efficiently create an int vector to filter rows, see example.

#Arguments

NameDefinition
x is the int vector filtering the rows to display, the vector length is not forced to match the dataframe row number. {-1} to keep all rows in default order
colv is the int vector representing the column index of the column to keep, {-1} to keep all columns

#Example(s)


Dataframe obj1;
std::string fname = "csv_test/outb.csv";
obj1.readf<3, 0>(fname);
obj1.display();
<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id4 6 7 8 uu
:1: id5 1 2 3 s4
:2: id6 6 7 8 s9
:3: id7 1 2 3 a4
:4: id8 6 7 8 m9
:5: id9 6 7 8 s9
:6: id10 1 2 3 a4
:7: id11 6 7 8 m9
:8: id12 6 7 8 m9
:9: id13 6 7 8 s9
:10: id14 1 2 3 NA
:11: id15 16 7 8 m9
std::vector<int> rvec = {3, 2, 5, 3, 6, 7, 6, 5, 8, 9, 11, 10};
std::vector<int> cvec = {-1};
obj1.display_filter_idx(rvec, cvec);

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id7 1 2 3 a4
:1: id6 6 7 8 s9
:2: id9 6 7 8 s9
:3: id7 1 2 3 a4
:4: id10 1 2 3 a4
:5: id11 6 7 8 m9
:6: id10 1 2 3 a4
:7: id9 6 7 8 s9
:8: id12 6 7 8 m9
:9: id13 6 7 8 s9
:10: id15 16 7 8 m9
:11: id14 1 2 3 NA


Dataframe.get_dataframe

#Usage

void get_dataframe(std::vector<int> &cols, Dataframe &cur_obj)

#Description

Allow to copy a dataframe choosing columns (by index) of the copied dataframe.

#Arguments

NameDefinition
cols is the vector of the index of the columns to copy ({-1}) for all
cur_obj is the dataframe that will contain all the rows and columns of the copied dataframe

#Example(s)

// after reading teste_dataframe.csv as obj1
Dataframe obj2;
std::vector<int> idx_cols2 = {1, 2, 3};
obj2.get_dataframe(idx_cols2, obj1);

obj2.display();
col1 col2 col3
:0: 2 3 aa
:1: 7 8 bb
:2: 2 3 cc
:3: 7 8 uu
:4: 2 3 s4
:5: 7 8 s9
:6: 2 3 a4
:7: 7 8 m9
:8: 7 8 s9
:9: 2 3 a4
:10: 7 8 m9
:11: 7 8 m9
:12: 7 8 s9
:13: 2 3 a4
:14: 7 8 m9


Dataframe.get_dataframe_filter

#Usage

void get_dataframe_filter(std::vector<int> &cols, Dataframe &cur_obj, std::vector<bool> &mask)

#Description

Allow to copy a dataframe choosing columns (by index) of the copied dataframe, while applying a mask on the desired rows.

#Arguments

NameDefinition
cols is the vector of the index of the columns to copy ({-1}) for all
cur_obj is the dataframe that will contain all the rows and columns of the copied dataframe
mask is the boolean mask vector

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 3;
auto vec = obj1.view_colnb(n);
std::vector<bool> vmask = {};
std::visit([&vmask](auto&& span) {
vmask.resize(span.size());
for (size_t i = 0; i < span.size(); ++i)
vmask[i] = span[i] > 4;
}, vec);
Dataframe obj2;
std::vector<int> idx_cols2 = {1, 2, 3};
obj2.get_dataframe_filter(idx_cols2, obj1, vmask);

obj2.display();
col1 col2 col3
:1: 7 8 bb
:3: 7 8 uu
:5: 7 8 s9
:7: 7 8 m9
:8: 7 8 s9
:10: 7 8 m9
:11: 7 8 m9
:12: 7 8 s9
:14: 7 8 m9


Dataframe.get_dataframe_filter_idx

#Usage

void get_dataframe_filter_idx(std::vector<int> &cols, Dataframe &cur_obj, std::vector<int> &mask)

#Description

Allow to copy a dataframe choosing columns (by index) of the copied dataframe, while applying an index mask on the desired rows.

#Arguments

NameDefinition
cols is the vector of the index of the columns to copy ({-1}) for all
cur_obj is the dataframe that will contain all the rows and columns of the copied dataframe
mask is the index mask vector, {-1} to keep all rows

#Example(s)


Dataframe obj1, obj2, obj3;
std::string fname = "csv_test/outb.csv";
obj1.readf<3, 0>(fname);
obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id4 6 7 8 uu
:1: id5 1 2 3 s4
:2: id6 6 7 8 s9
:3: id7 1 2 3 a4
:4: id8 6 7 8 m9
:5: id9 6 7 8 s9
:6: id10 1 2 3 a4
:7: id11 6 7 8 m9
:8: id12 6 7 8 m9
:9: id13 6 7 8 s9
:10: id14 1 2 3 NA
:11: id15 16 7 8 m9

std::vector<int> rvec = {3, 2, 5, 3, 6, 7, 6, 5, 8, 9, 11, 10};
std::vector<int> cvec = {-1};
obj2.get_dataframe_filter_idx(cvec, obj1, rvec);
obj2.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id7 1 2 3 a4
:1: id6 6 7 8 s9
:2: id9 6 7 8 s9
:3: id7 1 2 3 a4
:4: id10 1 2 3 a4
:5: id11 6 7 8 m9
:6: id10 1 2 3 a4
:7: id9 6 7 8 s9
:8: id12 6 7 8 m9
:9: id13 6 7 8 s9
:10: id15 16 7 8 m9
:11: id14 1 2 3 NA


Dataframe.view_colnb

#Usage

using ColumnView = std::variant<
std::span<const int>,
std::span<const unsigned int>,
std::span<const double>
>;

ColumnView view_colnb(unsigned int &x) const

#Description

Allow to get the reference of a int, unsigned int or double column as a span<T>, by column index (>= C++ 20).

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all. Intended to be used for creating boolean vecotr by your own functions, to maybe filter data later with Dataframe.display_filter(), Dataframe.get_dataframe_filter(), Dataframe.get_col_filter, ...
x is the index of the column to get the ref from

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 1;

auto col = obj1.view_colnb(n);


Dataframe.view_colstr

#Usage

std::span<const std::string> view_colstr(unsigned int &x) const

#Description

Allow to get the reference of a std::string column by column index.

#Arguments

NameDefinition
x is the index of the column to get the ref from

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 3;

auto col = obj1.view_colstr(n);


Dataframe.view_colchr

#Usage

std::span<const std::string> view_colchr(unsigned int &x) const

#Description

Allow to get the reference of a char column by column index.

#Arguments

NameDefinition
x is the index of the column to get the ref from

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 5;

auto col = obj1.view_colchr(n);


Dataframe.view_colint

#Usage

std::span<const std::string> view_colint(unsigned int &x) const

#Description

Allow to get the reference of an int column by column index.

#Arguments

NameDefinition
x is the index of the column to get the ref from

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 4;

auto col = obj1.view_colstr(n);


Dataframe.view_coluint

#Usage

std::span<const std::string> view_coluint(unsigned int &x) const

#Description

Allow to get the reference of an uint column by column index.

#Arguments

NameDefinition
x is the index of the column to get the ref from

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 0;

auto col = obj1.view_colchr(n);


Dataframe.view_coldbl

#Usage

std::span<const std::string> view_coldbl(unsigned int &x) const

#Description

Allow to get the reference of a double column by column index.

#Arguments

NameDefinition
x is the index of the column to get the ref from

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int n = 1;

auto col = obj1.view_coldbl(n);


Dataframe.get_col

#Usage

template <typename T>
void get_col(unsigned int x, std::vector<T> &rtn_v)

#Description

Allow to copy a column as a vector, by column index.

#Arguments

NameDefinition
x is the index of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> outv2 = {};
obj1.get_col(3, outv2);


Dataframe.get_col_filter

#Usage

template <typename T>
void get_col_filter(unsigned int x, std::vector<T> &rtn_v, std::vector<bool> &mask)

#Description

Allow to copy a column as a vector, by column index with a boolean vector mask to keep the desired lines.

#Arguments

NameDefinition
x is the index of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> outv2 = {};
unsigned int n = 0;
std::vector<bool> mask;
unsigned int nrow = obj1.get_nrow();
mask.reserve(nrow);
auto vec = obj1.view_coluint(n);
std::visit([&mask](auto&& span) {
mask.resize(span.size());
for (size_t i = 0; i < span.size(); ++i)
mask[i] = span[i] > 3;
}, vec);
obj1.get_col(3, outv2, mask);


Dataframe.fapply

#Usage

template <typename T>
void fapply(void (&f)(T&), unsigned int &n)

#Description

Apply whatever function to all elements of a column. See example

#Arguments

NameDefinition
f is the function to apply
n is the column index

#Example(s)


obj1.display();

<str> <uint>
col1 col2
:0: id1 1
:1: id2 6
:2: id4 6
:3: id5 1
:4: id6 6
:5: id7 1
:6: id8 6
:7: id9 6
:8: id11 6
:9: id12 6
:10: id14 1
:11: id15 16

unsigned int n = 1;
obj1.fapply(mfunc, n);

obj1.display();

<str> <uint>
col1 col2
:0: id1 2
:1: id2 7
:2: id4 7
:3: id5 2
:4: id6 7
:5: id7 2
:6: id8 7
:7: id9 7
:8: id11 7
:9: id12 7
:10: id14 2
:11: id15 17


Dataframe.get_nrow

#Usage

unsigned int get_nrow();

#Description

Returns the number of rows for the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int nrow = obj1.get_nrow();
15


Dataframe.get_ncol

#Usage

unsigned int get_ncol();

Returns the number of columns for the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int ncol = obj1.get_ncol();
6


Dataframe.get_rowname

#Usage

std::vector<std::string> get_rowname();

Returns the rowname of the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> row_names = obj1.get_rowname();
nothing becuase obj1 has no rownames


Dataframe.get_colname

#Usage

std::vector<std::string> get_colname();

Returns the colname of the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> col_names = obj1.get_colname();
col1 col2 col3 col4 col5 col6


Dataframe.set_rowname

#Usage

void set_rowname(std::vector<std::string> &x);

Set rowname to the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> row_names = {"n1", "n2", "n3"..."n15"};
obj1.set_rowname(row_names);


Dataframe.set_colname

#Usage

void set_colname(std::vector<std::string> &x);

Set colname to the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> col_names = {"col1", "col2", "col3", "col4",
"col5", "col6"};
obj1.set_colname();


Dataframe.replace_col

#Usage

template <typename T> void replace_col(std::vector<T> &x, unsigned int &colnb)

Replace a column of the associated dataframe.

#Arguments

NameDefinition
x is the column (as vector) that will replace the dataframe column
colnb is the index of the column to replace

#Example(s)

// after reading teste_dataframe.csv as obj1

std::vector<unsigned int> rpl_col = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14};
unsigned int col = 0;
obj1.replace_col(rpl_col, col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 0 2 3 aa 5 z
:1: 1 7 8 bb 10 e
:2: 2 2 3 cc 5 h
:3: 3 7 8 uu 10 a
:4: 4 2 3 s4 -5 q
:5: 5 7 8 s9 10 p
:6: 6 2 3 a4 5 j
:7: 7 7 8 m9 10 i
:8: 8 7 8 s9 10 p
:9: 9 2 3 a4 5 j
:10: 10 7 8 m9 10 i
:11: 11 7 8 m9 10 i
:12: 12 7 8 s9 10 p
:13: 13 2 3 NA 5 j
:14: 14 7 8 m9 10 i


Dataframe.add_col

#Usage

template <typename T> void add_col(std::vector<T> &x, std::string name = "NA")

#Description

Add a column int, unsigned int, bool, double, char or string type to the associated dataframe

#Arguments

NameDefinition
x is the column to add
name is the column to add name

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<unsigned int> rpl_col = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14};
obj1.add_col(rpl_col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char> <uint>
col1 col2 col3 col4 col5 col6 NA
:0: 1 2 3 aa 5 z 0
:1: 6 7 8 bb 10 e 1
:2: 1 2 3 cc 5 h 2
:3: 6 7 8 uu 10 a 3
:4: 1 2 3 s4 -5 q 4
:5: 6 7 8 s9 10 p 5
:6: 1 2 3 a4 5 j 6
:7: 6 7 8 m9 10 i 7
:8: 6 7 8 s9 10 p 8
:9: 1 2 3 a4 5 j 9
:10: 6 7 8 m9 10 i 10
:11: 6 7 8 m9 10 i 11
:12: 6 7 8 s9 10 p 12
:13: 1 2 3 NA 5 j 13
:14: 6 7 8 m9 10 i 14


Dataframe.rm_col

#Usage

void rm_col(std::vector<unsigned int> &nbcolv)

#Description

Removes columns from associated dataframe.

#Arguments

NameDefinition
nbcolv is a vector containing all the indices of the columns to erase from the associated dataframe. The indices must be sorted descendly.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<unsigned int> colv = {4, 1};
obj1.rm_col(colv);
obj1.display();
<uint> <uint> <str> <char>
col1 col3 col4 col6
:0: 1 3 aa z
:1: 6 8 bb e
:2: 1 3 cc h
:3: 6 8 uu a
:4: 1 3 s4 q
:5: 6 8 s9 p
:6: 1 3 a4 j
:7: 6 8 m9 i
:8: 6 8 s9 p
:9: 1 3 a4 j
:10: 6 8 m9 i
:11: 6 8 m9 i
:12: 6 8 s9 p
:13: 1 3 NA j
:14: 6 8 m9 i


Dataframe.rm_row

#Usage

void rm_col(std::vector<unsigned int> &nbcolv)

#Description

Removes rows from associated dataframe.

#Arguments

NameDefinition
nbcolv is a vector containing all the indices of the rows to erase from the associated dataframe. The indices must be sorted descendly.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<unsigned int> rowv = {4, 1};
obj1.rm_row(rowv);
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 1 2 3 aa 5 z
:1: 1 2 3 cc 5 h
:2: 6 7 8 uu 10 a
:3: 6 7 8 s9 10 p
:4: 1 2 3 a4 5 j
:5: 6 7 8 m9 10 i
:6: 6 7 8 s9 10 p
:7: 1 2 3 a4 5 j
:8: 6 7 8 m9 10 i
:9: 6 7 8 m9 10 i
:10: 6 7 8 s9 10 p
:11: 1 2 3 NA 5 j
:12: 6 7 8 m9 10 i


Dataframe.transform_inner

#Usage

void transform_inner(Dataframe &cur_obj, unsigned int &in_col, unsigned int &ext_col)

#Description

Applies a inner join on the associated dataframe.

#Arguments

NameDefinition
cur_obj is the other dataframe used for inner join
in_col is the index of the column representing the key (primary) of the associated dataframe
ext_col is the index of the column representing the key (foreign) of the other dataframe used for the inner join

#Example(s)


Dataframe obj1, obj2;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj1.transform_inner(obj2, col1, col2);
obj1.display();
<str> <uint>
col1 col2
:0: id1 1
:1: id2 6
:2: id4 6
:3: id5 1
:4: id6 6
:5: id7 1
:6: id8 6
:7: id9 6
:8: id11 6
:9: id12 6
:10: id14 1
:11: id15 6


Dataframe.transform_inner_clean

#Usage

void transform_inner_clean(Dataframe &cur_obj, unsigned int &in_col, unsigned int &ext_col)

#Description

Applies a inner join on the associated dataframe. Is basically the same as transform_inner but uses another algorithm that takes more time but frees memory after having kept the common elements.

#Arguments

NameDefinition
cur_obj is the other dataframe used for inner join
in_col is the index of the column representing the key (primary) of the associated dataframe
ext_col is the index of the column representing the key (foreign) of the other dataframe used for the inner join

#Example(s)


Dataframe obj1, obj2;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj1.transform_inner_clean(obj2, col1, col2);
obj1.display();
<str> <uint>
col1 col2
:0: id1 1
:1: id2 6
:2: id4 6
:3: id5 1
:4: id6 6
:5: id7 1
:6: id8 6
:7: id9 6
:8: id11 6
:9: id12 6
:10: id14 1
:11: id15 6


Dataframe.transform_excluding

#Usage

void transform_excluding(Dataframe &cur_obj, unsigned int &in_col, unsigned int &ext_col)

#Description

Applies an excluding join on the associated dataframe.

#Arguments

NameDefinition
cur_obj is the other dataframe used for inner join
in_col is the index of the column representing the key (primary) of the associated dataframe
ext_col is the index of the column representing the key (foreign) of the other dataframe used for the inner join

#Example(s)


Dataframe obj1, obj2;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj1.transform_excluding(obj2, col1, col2);
obj1.display();
<str> <uint>
col1 col2
col1 col2 col3 col4 col5
:0: id3 1 2 3 cc
:1: id10 1 2 3 a4
:2: id13 6 7 8 s9


Dataframe.transform_excluding_clean

#Usage

void transform_excluding_clean(Dataframe &cur_obj, unsigned int &in_col, unsigned int &ext_col)

#Description

Applies an excluding join on the associated dataframe. Is basically the same as transform_excluding but uses another algorithm that takes more time but frees memory after having kept the common elements.

#Arguments

NameDefinition
cur_obj is the other dataframe used for inner join
in_col is the index of the column representing the key (primary) of the associated dataframe
ext_col is the index of the column representing the key (foreign) of the other dataframe used for the inner join

#Example(s)


Dataframe obj1, obj2;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj1.transform_excluding_clean(obj2, col1, col2);
obj1.display();
<str> <uint>
col1 col2
col1 col2 col3 col4 col5
:0: id3 1 2 3 cc
:1: id10 1 2 3 a4
:2: id13 6 7 8 s9


Dataframe.merge_inner

#Usage

void merge_inner(Dataframe &obj1, Dataframe &obj2, bool colname, unsigned int &key1, unsigned int &key2)

#Description

Performs a inner join on a newly created dataframe. May creates dupplicates if multiple occurences of the key is found in the second dataframes, use Dataframe.merge_inner2 if you do not want to create dupplicates.

#Arguments

NameDefinition
obj1 is the first dataframe
obj2 is the second dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the first dataframe column as primary key
key1 is the index of the first dataframe column as foreign key

#Example(s)


Dataframe obj1, obj2, obj3;
std::string filename = "csv_test/outb.csv";
obj1.readf(filename);

std::string f2 = "csv_test/outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_inner(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
[0] [1] [2] [3] [4] [5] [6] [7]
:0: id1 1 2 3 aa id1 2 3
:1: id1 1 2 3 aa id1 2 3
:2: id2 6 7 8 bb id2 7 8
:3: id4 6 7 8 uu id4 7 8
:4: id5 1 2 3 s4 id5 2 3
:5: id6 6 7 8 s9 id6 7 8
:6: id7 1 2 3 a4 id7 2 3
:7: id8 6 7 8 m9 id8 2 3
:8: id9 6 7 8 s9 id9 7 8
:9: id11 6 7 8 m9 id11 7 8
:10: id11 6 7 8 m9 id11 7 8
:11: id12 6 7 8 m9 id12 7 8
:12: id14 1 2 3 NA id14 7 8
:13: id15 16 7 8 m9 id15 2 3


Dataframe.merge_inner2

#Usage

void merge_inner2(Dataframe &obj1, Dataframe &obj2, bool colname, unsigned int &key1, unsigned int &key2)

#Description

Performs a inner join on a newly created dataframe.

#Arguments

NameDefinition
obj1 is the first dataframe
obj2 is the second dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the first dataframe column as primary key
key1 is the index of the first dataframe column as foreign key

#Example(s)


Dataframe obj1, obj2, obj3;
std::string filename = "csv_test/outb.csv";
obj1.readf(filename);

std::string f2 = "csv_test/outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_inner2(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
[0] [1] [2] [3] [4] [5] [6] [7]
:0: id1 1 2 3 aa id1 2 3
:1: id2 6 7 8 bb id2 7 8
:2: id4 6 7 8 uu id4 7 8
:3: id5 1 2 3 s4 id5 2 3
:4: id6 6 7 8 s9 id6 7 8
:5: id7 1 2 3 a4 id7 2 3
:6: id8 6 7 8 m9 id8 2 3
:7: id9 6 7 8 s9 id9 7 8
:8: id11 6 7 8 m9 id11 7 8
:9: id12 6 7 8 m9 id12 7 8
:10: id14 1 2 3 NA id14 7 8
:11: id15 16 7 8 m9 id15 2 3


Dataframe.merge_excluding

#Usage

void merge_excluding(Dataframe &obj1,
Dataframe &obj2,
bool colname,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
std::string default_chr = " ",
std::string default_bool = "0",
std::string default_int = "0",
std::string default_uint = "0",
std::string default_dbl = "0")

#Description

Performs a left excluding join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "csv_test/outb.csv";
obj1.readf(filename);

std::string f2 = "csv_test/outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_excluding(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
[0] [1] [2] [3] [4] [5] [6] [7]
:0: id3 1 2 3 cc NA 0 0
:1: id10 1 2 3 a4 NA 0 0
:2: id13 6 7 8 s9 NA 0 0


Dataframe.merge_excluding_both

#Usage

void merge_excluding_both(Dataframe &obj1,
Dataframe &obj2,
bool colname,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
std::string default_chr = " ",
std::string default_bool = "0",
std::string default_int = "0",
std::string default_uint = "0",
std::string default_dbl = "0")

#Description

Performs a full excluding join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "csv_test/outb.csv";
obj1.readf(filename);

std::string f2 = "csv_test/outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_excluding_both(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
[0] [1] [2] [3] [4] [5] [6] [7]
:0: id3 1 2 3 cc NA 0 0
:1: id10 1 2 3 a4 NA 0 0
:2: id13 6 7 8 s9 NA 0 0
:3: NA 0 0 0 NA id119 7 8


Dataframe.merge_all

#Usage

void merge_all(Dataframe &obj1,
Dataframe &obj2,
bool colname,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
std::string default_chr = " ",
std::string default_bool = "0",
std::string default_int = "0",
std::string default_uint = "0",
std::string default_dbl = "0")

#Description

Performs a full join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one. May producesdupplicates if several occurences of the same key appears in the second dataframe, use Dataframe.merge_all2 if you do not want to create dupplicates.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "csv_test/outb.csv";
obj1.readf(filename);

std::string f2 = "csv_test/outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_all(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
[0] [1] [2] [3] [4] [5] [6] [7]
:0: id1 1 2 3 aa id1 2 3
:1: id1 1 2 3 aa id1 22 3
:2: id2 6 7 8 bb id2 7 8
:3: id3 1 2 3 cc NA 0 0
:4: id4 6 7 8 uu id4 7 8
:5: id5 1 2 3 s4 id5 2 3
:6: id6 6 7 8 s9 id6 7 8
:7: id7 1 2 3 a4 id7 2 3
:8: id8 6 7 8 m9 id8 2 3
:9: id9 6 7 8 s9 id9 7 8
:10: id10 1 2 3 a4 NA 0 0
:11: id11 6 7 8 m9 id11 7 8
:12: id11 6 7 8 m9 id11 17 8
:13: id12 6 7 8 m9 id12 7 8
:14: id13 6 7 8 s9 NA 0 0
:15: id14 1 2 3 NA id14 7 8
:16: id15 6 7 8 m9 id15 2 3
:17: NA NA NA NA NA id119 7 8


Dataframe.merge_all2

#Usage

void merge_all2(Dataframe &obj1,
Dataframe &obj2,
bool colname,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
std::string default_chr = " ",
std::string default_bool = "0",
std::string default_int = "0",
std::string default_uint = "0",
std::string default_dbl = "0")

#Description

Performs a full join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "csv_test/outb.csv";
obj1.readf(filename);

std::string f2 = "csv_test/outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_all2(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
[0] [1] [2] [3] [4] [5] [6] [7]
:0: id1 1 2 3 aa id1 2 3
:1: id2 6 7 8 bb id2 7 8
:2: id3 1 2 3 cc NA 0 0
:3: id4 6 7 8 uu id4 7 8
:4: id5 1 2 3 s4 id5 2 3
:5: id6 6 7 8 s9 id6 7 8
:6: id7 1 2 3 a4 id7 2 3
:7: id8 6 7 8 m9 id8 2 3
:8: id9 6 7 8 s9 id9 7 8
:9: id10 1 2 3 a4 NA 0 0
:10: id11 6 7 8 m9 id11 7 8
:11: id12 6 7 8 m9 id12 7 8
:12: id13 6 7 8 s9 NA 0 0
:13: id14 1 2 3 NA id14 7 8
:14: id15 16 7 8 m9 id15 2 3
:15: NA 0 0 0 NA id119 7 8


Dataframe.transform_merge_inner2

#Usage

void transform_merge_inner2(Dataframe &obj1, Dataframe &obj2, unsigned int &key1, unsigned int &key2)

#Description

Performs a inner join on a the current dataframe with another one.

#Arguments

NameDefinition
obj1 is the second dataframe
key1 is the index of the first dataframe column as primary key
key1 is the index of the first dataframe column as foreign key

#Example(s)


Dataframe obj1, obj2;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);

std::cout << "\n";

fname = "csv_test/outb2.csv";
obj2.readf(fname);

unsigned int n = 0;
std::cout << "\n";

obj1.transform_merge_inner2(obj2, n, n);
obj1.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id1 1 2 3 aa id1 2 3
:1: id2 6 7 8 bb id2 7 8
:2: id4 6 7 8 uu id4 7 8
:3: id5 1 2 3 s4 id5 2 3
:4: id6 6 7 8 s9 id6 7 8
:5: id7 1 2 3 a4 id7 2 3
:6: id8 6 7 8 m9 id8 2 3
:7: id9 6 7 8 s9 id9 7 8
:8: id11 6 7 8 m9 id11 7 8
:9: id12 6 7 8 m9 id12 7 8
:10: id14 1 2 3 NA id14 7 8
:11: id15 16 7 8 m9 id15 2 3


Dataframe.transform_merge_inner2_clean

#Usage

void transform_merge_inner2_clean(Dataframe &obj1, Dataframe &obj2, unsigned int &key1, unsigned int &key2)

#Description

Performs a inner join on a the current dataframe with another one. Potentially significantly slower than transform_merge_inner2 because it frees unnused memory.

#Arguments

NameDefinition
obj1 is the second dataframe
key1 is the index of the first dataframe column as primary key
key1 is the index of the first dataframe column as foreign key

#Example(s)


Dataframe obj1, obj2;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);

std::cout << "\n";

fname = "csv_test/outb2.csv";
obj2.readf(fname);

unsigned int n = 0;
std::cout << "\n";

obj1.transform_merge_inner2_clean(obj2, n, n);
obj1.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id1 1 2 3 aa id1 2 3
:1: id2 6 7 8 bb id2 7 8
:2: id4 6 7 8 uu id4 7 8
:3: id5 1 2 3 s4 id5 2 3
:4: id6 6 7 8 s9 id6 7 8
:5: id7 1 2 3 a4 id7 2 3
:6: id8 6 7 8 m9 id8 2 3
:7: id9 6 7 8 s9 id9 7 8
:8: id11 6 7 8 m9 id11 7 8
:9: id12 6 7 8 m9 id12 7 8
:10: id14 1 2 3 NA id14 7 8
:11: id15 16 7 8 m9 id15 2 3


Dataframe.transform_left_join

#Usage

void transform_left_join(Dataframe &obj,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
char default_chr = ' ',
bool default_bool = 0,
int default_int = 0,
unsigned int default_uint = 0,
double default_dbl = 0)

#Description

Transforms the dataframe performing a left join.

#Arguments

NameDefinition
obj is the second dataframe
key1 is the column index of the primary key
key2 is the foreign key
default_str is the default value for NA string values
default_chr is the default value for NA char values
default_bool is the default value for NA boolean values
default_int is the default value for NA int values
default_uint is the default value for NA unsigned int values
default_dbl is the default value for NA double values

#Example(s)

Dataframe obj1, obj2;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);
fname = "csv_test/outb2.csv";
obj2.readf(fname);

unsigned int n = 0;
obj1.transform_left_join(obj2, n, n);

obj1.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id1 1 2 3 aa id1 2 3
:1: id2 6 7 8 bb id2 7 8
:2: id3 1 2 3 cc NA 0 0
:3: id4 6 7 8 uu id4 7 8
:4: id5 1 2 3 s4 id5 2 3
:5: id6 6 7 8 s9 id6 7 8
:6: id7 1 2 3 a4 id7 2 3
:7: id8 6 7 8 m9 id8 2 3
:8: id9 6 7 8 s9 id9 7 8
:9: id10 1 2 3 a4 NA 0 0
:10: id11 6 7 8 m9 id11 7 8
:11: id12 6 7 8 m9 id12 7 8
:12: id13 6 7 8 s9 NA 0 0
:13: id14 1 2 3 NA id14 7 8
:14: id15 16 7 8 m9 id15 2 3


Dataframe.transform_filter

#Usage

void transform_filter(std::vector<bool>& mask)

#Description

Keeps the desired row from a boolean mask.

#Arguments

NameDefinition
mask is the boolean mask

#Example(s)

Dataframe obj1, obj2;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);
fname = "csv_test/outb2.csv";
obj2.readf(fname);

std::vector mask = {0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1};

obj1.transform_filter(mask);

obj1.display();
<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id2 6 7 8 bb
:1: id4 6 7 8 uu
:2: id5 1 2 3 s4
:3: id6 6 7 8 s9
:4: id8 6 7 8 m9
:5: id10 1 2 3 a4
:6: id11 6 7 8 m9
:7: id12 6 7 8 m9
:8: id14 1 2 3 NA


Dataframe.pivot_dbl

#Usage

void pivot_dbl(Dataframe &obj, unsigned int &n1, unsigned int& n2, unsigned int& n3)

#Description

Performs a pivot to a newly created dataframe.

#Arguments

NameDefinition
obj is the dataframe from which the pivot is performed
n1 is the column index of the columns created for the pivot
n2 is the column index of the rows created for the pivot
n3 is the column index of the column from which the pivot is performed

#Example(s)


// after some random manipulation for obj1 dataframe
Dataframe obj3;
obj1.display();

<str> <uint> <uint> <uint> <str> <str> <uint> <double>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id1 1 2 3 A D 2 3
:1: id2 6 7 8 A D 7 8
:2: id3 1 2 3 A C 0 0
:3: id4 6 7 8 B C 7 8
:4: id5 1 2 3 B C 2 3
:5: id6 6 7 8 A D 7 8
:6: id7 1 2 3 B C 2 3
:7: id8 6 7 8 B D 2 3
:8: id9 6 7 8 B D 7 8
:9: id10 1 2 3 A C 0 0
:10: id11 6 7 8 A D 7 8
:11: id12 6 7 8 B C 7 8
:12: id13 6 7 8 B D 0 0
:13: id14 1 2 3 B C 7 8
:14: id15 16 7 8 B D 2 3

unsigned int n1 = 4;
unsigned int n2 = 5;
unsigned int n3 = 7;

obj3.pivot_uint(obj1, n, n2, n3);

obj3.display();

<double> <double>
A B
D : 27 14
C : 0 30


Dataframe.pivot_int

#Usage

void pivot_int(Dataframe &obj, unsigned int &n1, unsigned int& n2, unsigned int& n3)

#Description

Performs a pivot to a newly created dataframe.

#Arguments

NameDefinition
obj is the dataframe from which the pivot is performed
n1 is the column index of the columns created for the pivot
n2 is the column index of the rows created for the pivot
n3 is the column index of the column from which the pivot is performed

#Example(s)


// after some random manipulation for obj1 dataframe
Dataframe obj3;
obj1.display();

<str> <uint> <uint> <uint> <str> <str> <uint> <int>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id1 1 2 3 A D 2 3
:1: id2 6 7 8 A D 7 8
:2: id3 1 2 3 A C 0 0
:3: id4 6 7 8 B C 7 8
:4: id5 1 2 3 B C 2 3
:5: id6 6 7 8 A D 7 8
:6: id7 1 2 3 B C 2 3
:7: id8 6 7 8 B D 2 3
:8: id9 6 7 8 B D 7 8
:9: id10 1 2 3 A C 0 0
:10: id11 6 7 8 A D 7 8
:11: id12 6 7 8 B C 7 8
:12: id13 6 7 8 B D 0 0
:13: id14 1 2 3 B C 7 8
:14: id15 16 7 8 B D 2 3

unsigned int n1 = 4;
unsigned int n2 = 5;
unsigned int n3 = 7;

obj3.pivot_uint(obj1, n, n2, n3);

obj3.display();

<int> <int>
A B
D : 27 14
C : 0 30


Dataframe.pivot_uint

#Usage

void pivot_uint(Dataframe &obj, unsigned int &n1, unsigned int& n2, unsigned int& n3)

#Description

Performs a pivot to a newly created dataframe.

#Arguments

NameDefinition
obj is the dataframe from which the pivot is performed
n1 is the column index of the columns created for the pivot
n2 is the column index of the rows created for the pivot
n3 is the column index of the column from which the pivot is performed

#Example(s)


// after some random manipulation for obj1 dataframe
Dataframe obj3;
obj1.display();

<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id1 1 2 3 A D 2 3
:1: id2 6 7 8 A D 7 8
:2: id3 1 2 3 A C 0 0
:3: id4 6 7 8 B C 7 8
:4: id5 1 2 3 B C 2 3
:5: id6 6 7 8 A D 7 8
:6: id7 1 2 3 B C 2 3
:7: id8 6 7 8 B D 2 3
:8: id9 6 7 8 B D 7 8
:9: id10 1 2 3 A C 0 0
:10: id11 6 7 8 A D 7 8
:11: id12 6 7 8 B C 7 8
:12: id13 6 7 8 B D 0 0
:13: id14 1 2 3 B C 7 8
:14: id15 16 7 8 B D 2 3

unsigned int n1 = 4;
unsigned int n2 = 5;
unsigned int n3 = 7;

obj3.pivot_uint(obj1, n, n2, n3);

obj3.display();

<uint> <uint>
A B
D : 27 14
C : 0 30


Dataframe.get_typecol

#Usage

const std::vector<char>& get_typecol() const

#Description

Returns the column type of the dataframe, 'i' (int), 'u', (unsigned int), 'd', double, 's' (string), 'c' (char)

#Arguments

NameDefinition
X NO ARGS

#Example(s)

const std::vector& dtype = obj1.get_typecol();
'c' 'b' 'd' 'i'


Dataframe.transform_unique

#Usage

void transform_unique(unsigned int& n)

#Description

Trnasforms your current dataframe to keep the unique values from a chosen column.

#Arguments

NameDefinition
n is the column index

#Example(s)

std::string fname = "csv_test/outb.csv";
obj1.readf<3, 0>(fname);
obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id4 6 7 8 uu
:1: id5 1 2 3 s4
:2: id6 6 7 8 s9
:3: id7 1 2 3 a4
:4: id8 6 7 8 m9
:5: id9 6 7 8 s9
:6: id10 1 2 3 a4
:7: id11 6 7 8 m9
:8: id12 6 7 8 m9
:9: id13 6 7 8 s9
:10: id14 1 2 3 NA
:11: id15 16 7 8 m9

unsigned int n = 4;
obj1.transform_unique(n);
obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id4 6 7 8 uu
:1: id5 1 2 3 s4
:2: id6 6 7 8 s9
:3: id7 1 2 3 a4
:4: id8 6 7 8 m9
:5: id14 1 2 3 NA


Dataframe.transform_unique_clean

#Usage

void transform_unique_clean(unsigned int& n)

#Description

Trnasforms your current dataframe to keep the unique values from a chosen column. Basically the same as transfrm_unique, but frees memory, which can be slower.

#Arguments

NameDefinition
n is the column index

#Example(s)

std::string fname = "csv_test/outb.csv";
obj1.readf<3, 0>(fname);
obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id4 6 7 8 uu
:1: id5 1 2 3 s4
:2: id6 6 7 8 s9
:3: id7 1 2 3 a4
:4: id8 6 7 8 m9
:5: id9 6 7 8 s9
:6: id10 1 2 3 a4
:7: id11 6 7 8 m9
:8: id12 6 7 8 m9
:9: id13 6 7 8 s9
:10: id14 1 2 3 NA
:11: id15 16 7 8 m9

unsigned int n = 4;
obj1.transform_unique_clean(n);
obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id4 6 7 8 uu
:1: id5 1 2 3 s4
:2: id6 6 7 8 s9
:3: id7 1 2 3 a4
:4: id8 6 7 8 m9
:5: id14 1 2 3 NA


Dataframe.transform_merge_excluding

#Usage

void transform_merge_excluding(Dataframe &obj,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
char default_chr = ' ',
bool default_bool = 0,
int default_int = 0,
unsigned int default_uint = 0,
double default_dbl = 0)

#Description

Performs a left excluding join to the associated dataframe (already created). The dataframe as argument is considered as the right one.

#Arguments

NameDefinition
obj is the left dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)


Dataframe obj1, obj2, obj3;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);

fname = "csv_test/outb2.csv";
obj2.readf(fname);

unsigned int n = 0;

obj1.transform_merge_excluding(obj2, n, n);
obj1.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id3 1 2 3 cc NA 0 0
:1: id10 1 2 3 a4 NA 0 0
:2: id13 6 7 8 s9 NA 0 0


Dataframe.transform_merge_excluding_clean

#Usage

void transform_merge_excluding_clean(Dataframe &obj,
unsigned int &key1,
unsigned int &key2,
std::string default_str = "NA",
char default_chr = ' ',
bool default_bool = 0,
int default_int = 0,
unsigned int default_uint = 0,
double default_dbl = 0)

#Description

Performs a left excluding join to the associated dataframe (already created). The dataframe as argument is considered as the right one. May be significantly slower than transform_merge_excluding because this version frees unnused memory after doing the left excluding join.

#Arguments

NameDefinition
obj is the left dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)


Dataframe obj1, obj2, obj3;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);

fname = "csv_test/outb2.csv";
obj2.readf(fname);

unsigned int n = 0;

obj1.transform_merge_excluding_clean(obj2, n, n);
obj1.display();
<str> <uint> <uint> <uint> <str> <str> <uint> <uint>
col1 col2 col3 col4 col5 col1 col2 col3
:0: id3 1 2 3 cc NA 0 0
:1: id10 1 2 3 a4 NA 0 0
:2: id13 6 7 8 s9 NA 0 0


Dataframe.sort_by

#Usage

template <bool asc = 1>
void sort_by(unsigned int& n)

#Description

Transforms the dataframe by reordering the rows by the value of a column.

#Arguments

NameDefinition
n is the column index of the column value to reorder from

#Example(s)


Dataframe obj1;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);
obj1.display();

obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id1 1 2 3 aa
:1: id2 6 7 8 bb
:2: id3 1 2 3 cc
:3: id4 6 7 8 uu
:4: id5 1 2 3 s4
:5: id6 6 7 8 s9
:6: id7 1 2 3 a4
:7: id8 6 7 8 m9
:8: id9 6 7 8 s9
:9: id10 1 2 3 a4
:10: id11 6 7 8 m9
:11: id12 6 7 8 m9
:12: id13 6 7 8 s9
:13: id14 1 2 3 NA
:14: id15 16 7 8 m9

n = 2;
obj1.sort_by(n);

obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id1 1 2 3 aa
:1: id3 1 2 3 cc
:2: id5 1 2 3 s4
:3: id7 1 2 3 a4
:4: id10 1 2 3 a4
:5: id14 1 2 3 NA
:6: id2 6 7 8 bb
:7: id4 6 7 8 uu
:8: id6 6 7 8 s9
:9: id8 6 7 8 m9
:10: id9 6 7 8 s9
:11: id11 6 7 8 m9
:12: id12 6 7 8 m9
:13: id13 6 7 8 s9
:14: id15 16 7 8 m9

obj1.sort_by<0>(n);

obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id2 6 7 8 bb
:1: id4 6 7 8 uu
:2: id6 6 7 8 s9
:3: id8 6 7 8 m9
:4: id9 6 7 8 s9
:5: id11 6 7 8 m9
:6: id12 6 7 8 m9
:7: id13 6 7 8 s9
:8: id15 16 7 8 m9
:9: id1 1 2 3 aa
:10: id3 1 2 3 cc
:11: id5 1 2 3 s4
:12: id7 1 2 3 a4
:13: id10 1 2 3 a4
:14: id14 1 2 3 NA


Dataframe.concat

#Usage

void concat(Dataframe& obj)

#Description

Concaenates the row of the dataframes. See example.

#Arguments

NameDefinition
obj is the input datarame (from which the rows will be appended)

#Example(s)


Dataframe obj1, obj2, obj3;
std::string fname = "csv_test/outb.csv";
obj1.readf(fname);
obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id1 1 2 3 aa
:1: id2 6 7 8 bb
:2: id3 1 2 3 cc
:3: id4 6 7 8 uu
:4: id5 1 2 3 s4
:5: id6 6 7 8 s9
:6: id7 1 2 3 a4
:7: id8 6 7 8 m9
:8: id9 6 7 8 s9
:9: id10 1 2 3 a4
:10: id11 6 7 8 m9
:11: id12 6 7 8 m9
:12: id13 6 7 8 s9
:13: id14 1 2 3 NA
:14: id15 16 7 8 m9

fname = "csv_test/outb.csv";
obj2.readf(fname);

obj1.concat(obj2);

obj1.display();

<str> <uint> <uint> <uint> <str>
col1 col2 col3 col4 col5
:0: id1 1 2 3 aa
:1: id2 6 7 8 bb
:2: id3 1 2 3 cc
:3: id4 6 7 8 uu
:4: id5 1 2 3 s4
:5: id6 6 7 8 s9
:6: id7 1 2 3 a4
:7: id8 6 7 8 m9
:8: id9 6 7 8 s9
:9: id10 1 2 3 a4
:10: id11 6 7 8 m9
:11: id12 6 7 8 m9
:12: id13 6 7 8 s9
:13: id14 1 2 3 NA
:14: id15 16 7 8 m9
:15: id1 1 2 3 aa
:16: id2 6 7 8 bb
:17: id3 1 2 3 cc
:18: id4 6 7 8 uu
:19: id5 1 2 3 s4
:20: id6 6 7 8 s9
:21: id7 1 2 3 a4
:22: id8 6 7 8 m9
:23: id9 6 7 8 s9
:24: id10 1 2 3 a4
:25: id11 6 7 8 m9
:26: id12 6 7 8 m9
:27: id13 6 7 8 s9
:28: id14 1 2 3 NA
:29: id15 16 7 8 m9


Apply any function on indefinite numbers of same type vectors

Fapply object

#Usage

Fapply

#Description

Allows to perform any function on a set of same type vectors, simplified

#Arguments

NameDefinition
... all the vectors

#Example(s)

// declare a custom function

int add(std::vector<int> x) {
int rtn_v = x[0];
for (int i = 1; i < x.size(); ++i) {
rtn_v += x[i];
};
return rtn_v;
};

std::vector<int> inpt_v1 = {1, 2, 3, 4, 5, 6, 7};
std::vector<int> inpt_v2 = {7, 6, 5, 4, 3, 2, 1};

Fapply obj1(inpt_v1); //initialise object with a vector argument
obj1.set_args(inpt_v1, inpt_v2, inpt_v2); //ingest args

//performs the chosen function
std::vector<int> outv = obj1.fapply(add);

print_nvec(outv);

:0: 15 14 13 12 11 10 9


Fapply2d object

#Usage

Fapply(std::vector<TB> &x)

#Description

Apllies any function onto a variadic numbers of vectors of any type

#Arguments

NameDefinition
x is an empty vector of the type choosen for the operations between vectors

#Example(s)

std::vector<int> xint = {0, 1, 2};
std::vector<int> xint2 = {0, 1, 2};

std::vector<int> iinv = {};

Fapply2d obj1(iinv);


Fapply2d.set_args

#Usage

template <typename T, typename ...T2> void set_args(std::vector<T> &x, std::vector<T2>&... x2)

#Description

Is a variadic function allowing to put in the class an indefinite number of vectors of the same type that will be used by your custom function later, see Fapply2d.fapply2d()

#Arguments

NameDefinition
... is some same types vectors

#Example(s)


std::vector<int> xint = {0, 1, 2};
std::vector<int> xint2 = {0, 1, 2};

obj1.set_args(xint, xint, xint2);


Fapply2d.fapply2d

#Usage

template <typename T> std::vector<T> fapply2d(std::vector<T> (&f)(std::vector<std::vector<T>>))

#Description

Performs your custom function on the std::vector> created by Fapply2d.set_args().

#Arguments

NameDefinition
f is the reference to the custom function

#Example(s)


std::vector<int> addv(std::vector<std::vector<int>> x) {
std::vector<int> rtn_v = {};
int cur_val;
unsigned int i2;
const unsigned int n = x[0].size();
const unsigned int n2 = x.size();
for (int i = 0; i < n; ++i) {
cur_val = 0;
for (i2 = 0; i2 < n2; ++i2) {
cur_val += x[i2][i];
};
rtn_v.push_back(cur_val);
};
return rtn_v;
};

std::vector<int> xint = {0, 1, 2};
std::vector<int> xint2 = {0, 1, 2};

std::vector<int> iinv = {};

Fapply2d obj1(iinv);
obj1.set_args(xint, xint, xint2);
iinv = obj1.fapply2d(addv);
print_nvec(outv);
:0: 0 3 6


Fapply2d.reinitiate

#Usage

void reinitiate();

#Description

Empties the 2d T internal vector. Necessary to reset args (vectors input of the internal 2d vector) of same type before applying the function (or another) to new vectors.

#Arguments

NameDefinition
no no

#Example(s)

Fapply2d.reinitiate();


Geographical coordinates manipulation

geo_min

#Usage

double geo_min(double &lat1, double &longit1, double &lat2, double &longit2, const double sphere_ray = 6378)

#Description

Returns the shortest distance between 2 geographical points.

#Arguments

NameDefinition
lat1 is the lattitude of the first point
longit1 is the longitude of the second point
lat2 is the lattitude of the second point
longit2 is the longitude of the second point
sphere_ray is the rayon of the sphere in km (defaults to Earth)

#Example(s)

double lat1 = 23;
double longit1 = -45;

double lat2 = -23;
double longit2 = 45;

double delta = geo_min(lat1, longit1, lat2, longit2);

std::cout << delta << "\n";

lat1 = 60;
longit1 = 30;

lat2 = 60;
longit2 = -150;

delta = geo_min(lat1, longit1, lat2, longit2);

std::cout << delta << "\n";
6679.1


Date manipulation (Gregorian)

Format convertions

fr_to_eng_datefmt

#Usage

std::string fr_to_eng_datefmt(std::string &x, char sep = '-')

#Description

Converts a french date format to an english one.

#Arguments

NameDefinition
x is the input date
sep is the date separator

#Example(s)

std::string fr_date = "02-07-2022";
std::string eng_date = fr_to_eng_datefmt(fr_date);
std::cout << eng_date<< "\n";
07-02-2022


eng_to_fr_datefmt

#Usage

std::string eng_to_fr_datefmt(std::string &x, char sep = '-')

#Description

Converts a english date format to an french one.

#Arguments

NameDefinition
x is the input date
sep is the date separator

#Example(s)

std::string eng_date = "07-02-2022";
std::string fr_date = eng_to_fr_datefmt(eng_date);
std::cout << fr_date << "\n";
02-07-2022


fmt_converter_date

#Usage

std::string fmt_converter_date(std::string &x, std::string &in_fmt, std::string &out_fmt, char delim = '-')

#Description

Cpnverts a date to another date format.

#Arguments

NameDefinition
x is the input date
in_fmt is the input date format
out_fmt is the output date format

#Example(s)

std::string in_fmt = "dmy";
std::string out_fmt = "mdy";
std::string inpt_date = "02-07-2003";
std::string outfmtdate = fmt_converter_date(inpt_date, in_fmt, out_fmt);
std::cout << outfmtdate << "\n";
07-02-2003


Sort dates

ascend_sort_date

#Usage

std::vector<std::string> ascend_sort_date(std::vector<std::string> &x,
std::string &fmt, char delim = '-')

#Description

Returns a vector of date ascendly sorted. The format meaning is 'y' for year, 'm' for month, 'd' for day, 'h' for hour, 'n' for minute and 's' for second.

#Arguments

NameDefinition
x is the input vector of dates
fmt is the date format
delim is the date delimiter

#Example(s)

std::vector<std::string> vec = {
"02-04-2026",
"02-11-2023",
"07-02-2026",
"22-04-2016",
"02-12-2006",
"17-9-2015",
"03-04-2017",
"02-05-2017",
"15-01-2026"
};

std::string fmt = "dmy";

std::vector<std::string> outv = ascend_sort_date(vec, fmt);
print_svec(outv);
:0: 02-12-2006 17-9-2015 22-04-2016 03-04-2017 02-05-2017 02-11-2023 15-01-2026 07-02-2026
:8: 02-04-2026


descend_sort_date

#Usage

std::vector<std::string> descend_sort_date(std::vector<std::string> &x,
std::string &fmt, char delim = '-')

#Description

Returns a vector of date descendly sorted. The format meaning is 'y' for year, 'm' for month, 'd' for day, 'h' for hour, 'n' for minute and 's' for second.

#Arguments

NameDefinition
x is the input vector of dates
fmt is the date format
delim is the date delimiter

#Example(s)

std::vector<std::string> vec = {
"02-04-2026",
"02-11-2023",
"07-02-2026",
"22-04-2016",
"02-12-2006",
"17-9-2015",
"03-04-2017",
"02-05-2017",
"15-01-2026"
};

std::string fmt = "dmy";

std::vector<std::string> outv = descend_sort_date(vec, fmt);
print_svec(outv);
:0: 02-04-2026 07-02-2026 15-01-2026 02-11-2023 02-05-2017 03-04-2017 22-04-2016 17-9-2015
:8: 02-12-2006


is_leap

#Usage

template <typename T> bool is_leap(unsigned T &x)

#Description

Returns if the input year is leap.

#Arguments

NameDefinition
x is the input year

#Example(s)

int year = 2024;
bool bsx = is_leap(year);
std::cout << bsx << "\n";
1


delta_second

#Usage

double delta_second(std::string &bgn_date, std::string &end_date, int ref_year = 0, char delim = '-')

#Description

Returns the number of second elapsed between 2 dates.

#Arguments

NameDefinition
bgn_date is the first date, must be lower than the second date
end_date is the second date
ref_year is a reference year from which the time elapsed wil be calculated. This value must be lower than the year of the first date
delim is the date delimiter

#Example(s)

std::string bgn_date = "2003-07-02-2-23-46";
std::string end_date = "2025-04-01-12-13-26";
double delta = delta_second(bgn_date, end_date);
std::cout << delta << "\n";
6.86311e+08


is_greater_date

#Usage

bool is_greater_date(std::string &x, std::string &x2, char delim = '-')

#Description

Returns if the first date is greater than the second one. The dates must have the same format, which is the highest time unit at the beginning and so on.

#Arguments

NameDefinition
x is the first date
x2 is the second date
delim is the date delimiter

#Example(s)

std::string bgn_date = "2003-07-02-2-23-46";
std::string end_date = "2025-04-01-12-13-26";
bool outbool = is_greater_date(end_date, bgn_date);
std::cout << outbool << "\n";
1


Fulgurance Tools

Parser_tokenizer_full

#Usage

std::vector<std::vector<unsigned int>> Parser_tokenizer_full(std::string &x, char frst_chr = '(', char scd_chr = ')')

#Description

Returns a 2d stl vectors. First vector is the pair of each parenthesis. Second stl vector is the index of each parenthesis. Takes a stl string as input.

#Arguments

NameDefinition
x is a stl string

#Example(s)

std::string teste = "(o((ldjf)de)po(m()()m)po)()()";
std::vector<std::vector<unsigned int>> out = Parser_tokenizer_full(teste);
{5 1 0 0 1 4 2 2 3 3 4 5 6 6 7 7}
{0 2 3 8 11 14 16 17 18 19 21 24 25 26 27 28}


is_intricated

#Usage

bool is_intricated (unsigned int &idx, std::vector<unsigned int> &tkn_v)

#Description

Returns a boolean, 1 if the parenthesis refered is intricated in others parenthesis, 0 if not. See examples.

#Arguments

NameDefinition
tkn_v is a std vector containing all the parenthesis pairs. The one outputed by Parser_tokennizer_full function.
idx is an unsigned int that indicates the parenthesis refered in tkn_v vector

#Example(s)

std::string inpt_str = "(ldkhf(f)ek(()))dkjf(gf())()()";
std::vector<std::vector<unsigned int>> out_matr = Parser_tokenizer_full(inpt_str);
std::vector<unsigned int> tkn_v = out_matr[0];
std::vector<unsigned int> idx_v = out_matr[1];
unsigned int i;
for (i = 0; i < tkn_v.size(); ++i) {
std::cout << tkn_v[i] << " ";
};
std::cout << "\n";
for (i = 0; i < tkn_v.size(); ++i) {
std::cout << idx_v[i] << " ";
};
3 0 0 2 1 1 2 3 5 4 4 5 6 6 7 7
0 6 8 11 12 13 14 15 20 23 24 25 26 27 28 29
std::cout << "\n";
unsigned int cur_idx = 15;
bool is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
0
cur_idx = 3;
is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
1
cur_idx = 7;
is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
0
cur_idx = 6;
is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
1


is_symetric

#Usage

template <typename T> bool is_symetric(std::vector<T> &x)

#Description

Returns 1 if the vector is symetric, 0 if not. See examples.

#Arguments

NameDefinition
x is the input vector of any type

#Example(s)

std::vector<int> vec = {0, 1, 2, 43, 2, 1, 0};
bool out = is_symetric(vec);
1
vec = {0, 1, 2, 2, 1, 0};
out = is_symetric(vec);
1
vec = {0, 1, 2, 2, 22, 0};
out = is_symetric(vec);
0


all_comb

#Usage

std::vector<std::vector<bool>> all_comb(unsigned int &k, unsigned int &n)

#Description

Returns all the combinations of k elements in a set of n elements.

#Arguments

NameDefinition
k is the k value
n is the total number of the set

#Example(s)

unsigned int k = 5;
unsigned int n = 9;
std::vector<std::vector<bool>> outmatr = all_comb(k, n);
int i2;
for (int i = 0; i < outmatr.size(); ++i) {
for (i2 = 0; i2 < outmatr[0].size(); ++i2) {
std::cout << outmatr[i][i2] <<< " ";
};
std::cout << "\n";
};
1 1 1 1 1 0 0 0 0
1 1 1 1 0 1 0 0 0
1 1 1 1 0 0 1 0 0
1 1 1 1 0 0 0 1 0
1 1 1 1 0 0 0 0 1
1 1 1 0 1 1 0 0 0
1 1 1 0 1 0 1 0 0
1 1 1 0 1 0 0 1 0
1 1 1 0 1 0 0 0 1
1 1 1 0 0 1 1 0 0
1 1 1 0 0 1 0 1 0
1 1 1 0 0 1 0 0 1
1 1 1 0 0 0 1 1 0
1 1 1 0 0 0 1 0 1
1 1 1 0 0 0 0 1 1
1 1 0 1 1 1 0 0 0
1 1 0 1 1 0 1 0 0
1 1 0 1 1 0 0 1 0
1 1 0 1 1 0 0 0 1
1 1 0 1 0 1 1 0 0
1 1 0 1 0 1 0 1 0
1 1 0 1 0 1 0 0 1
1 1 0 1 0 0 1 1 0
1 1 0 1 0 0 1 0 1
1 1 0 1 0 0 0 1 1
1 1 0 0 1 1 1 0 0
1 1 0 0 1 1 0 1 0
1 1 0 0 1 1 0 0 1
1 1 0 0 1 0 1 1 0
1 1 0 0 1 0 1 0 1
1 1 0 0 1 0 0 1 1
1 1 0 0 0 1 1 1 0
1 1 0 0 0 1 1 0 1
1 1 0 0 0 1 0 1 1
1 1 0 0 0 0 1 1 1
1 0 1 1 1 1 0 0 0
1 0 1 1 1 0 1 0 0
1 0 1 1 1 0 0 1 0
1 0 1 1 1 0 0 0 1
1 0 1 1 0 1 1 0 0
1 0 1 1 0 1 0 1 0
1 0 1 1 0 1 0 0 1
1 0 1 1 0 0 1 1 0
1 0 1 1 0 0 1 0 1
1 0 1 1 0 0 0 1 1
1 0 1 0 1 1 1 0 0
1 0 1 0 1 1 0 1 0
1 0 1 0 1 1 0 0 1
1 0 1 0 1 0 1 1 0
1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 0 1 1
1 0 1 0 0 1 1 1 0
1 0 1 0 0 1 1 0 1
1 0 1 0 0 1 0 1 1
1 0 1 0 0 0 1 1 1
1 0 0 1 1 1 1 0 0
1 0 0 1 1 1 0 1 0
1 0 0 1 1 1 0 0 1
1 0 0 1 1 0 1 1 0
1 0 0 1 1 0 1 0 1
1 0 0 1 1 0 0 1 1
1 0 0 1 0 1 1 1 0
1 0 0 1 0 1 1 0 1
1 0 0 1 0 1 0 1 1
1 0 0 1 0 0 1 1 1
1 0 0 0 1 1 1 1 0
1 0 0 0 1 1 1 0 1
1 0 0 0 1 1 0 1 1
1 0 0 0 1 0 1 1 1
1 0 0 0 0 1 1 1 1
0 1 1 1 1 1 0 0 0
0 1 1 1 1 0 1 0 0
0 1 1 1 1 0 0 1 0
0 1 1 1 1 0 0 0 1
0 1 1 1 0 1 1 0 0
0 1 1 1 0 1 0 1 0
0 1 1 1 0 1 0 0 1
0 1 1 1 0 0 1 1 0
0 1 1 1 0 0 1 0 1
0 1 1 1 0 0 0 1 1
0 1 1 0 1 1 1 0 0
0 1 1 0 1 1 0 1 0
0 1 1 0 1 1 0 0 1
0 1 1 0 1 0 1 1 0
0 1 1 0 1 0 1 0 1
0 1 1 0 1 0 0 1 1
0 1 1 0 0 1 1 1 0
0 1 1 0 0 1 1 0 1
0 1 1 0 0 1 0 1 1
0 1 1 0 0 0 1 1 1
0 1 0 1 1 1 1 0 0
0 1 0 1 1 1 0 1 0
0 1 0 1 1 1 0 0 1
0 1 0 1 1 0 1 1 0
0 1 0 1 1 0 1 0 1
0 1 0 1 1 0 0 1 1
0 1 0 1 0 1 1 1 0
0 1 0 1 0 1 1 0 1
0 1 0 1 0 1 0 1 1
0 1 0 1 0 0 1 1 1
0 1 0 0 1 1 1 1 0
0 1 0 0 1 1 1 0 1
0 1 0 0 1 1 0 1 1
0 1 0 0 1 0 1 1 1
0 1 0 0 0 1 1 1 1
0 0 1 1 1 1 1 0 0
0 0 1 1 1 1 0 1 0
0 0 1 1 1 1 0 0 1
0 0 1 1 1 0 1 1 0
0 0 1 1 1 0 1 0 1
0 0 1 1 1 0 0 1 1
0 0 1 1 0 1 1 1 0
0 0 1 1 0 1 1 0 1
0 0 1 1 0 1 0 1 1
0 0 1 1 0 0 1 1 1
0 0 1 0 1 1 1 1 0
0 0 1 0 1 1 1 0 1
0 0 1 0 1 1 0 1 1
0 0 1 0 1 0 1 1 1
0 0 1 0 0 1 1 1 1
0 0 0 1 1 1 1 1 0
0 0 0 1 1 1 1 0 1
0 0 0 1 1 1 0 1 1
0 0 0 1 1 0 1 1 1
0 0 0 1 0 1 1 1 1
0 0 0 0 1 1 1 1 1
std::cout << outmatr.size() << "\n";
126


all_comb_iter

#Usage

unsigned int all_comb_iter(std::vector<bool> &x)

#Description

Returns the number of iterations to find the input boolean vector according to all_comb algorithm

#Arguments

NameDefinition
x is the input boolean vector

#Example(s)

std::vector<bool> teste_dq = {1, 0, 1, 1, 1, 1, 0};
unsigned int out = all_comb_iter(teste_dq);
11


all_comb_iterdq

#Usage

unsigned int all_comb_iterdq(std::deque<bool> &x)

#Description

Returns the number of iterations to find the input boolean deque according to all_comb algorithm

#Arguments

NameDefinition
x is the input boolean deque

#Example(s)

std::deque<bool> teste_dq = {1, 0, 1, 1, 1, 1, 0};
unsigned int out = all_comb_iterdq(teste_dq);
11


bool_gen

#Usage

std::vector<bool> bool_gen(unsigned int &k, unsigned int &n, double seed = 0)

#Description

Returns a boolean vector of size n, with k elements equal to 1

#Arguments

NameDefinition
k is the number of elements that should equal to 1
n is the size of the vector
seed 0, if the vector should be randomly generated, strictly positive values either

#Example(s)

unsigned int k = 5;
unsigned int n = 17;
std::vector<bool> out = bool_gen(k, n, 0);
print_nvec(out);
:0: 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1


Binary conversions

int_to_binarydq

#Usage

std::deque<bool> int_to_binarydq(unsigned int x)

#Description

Converts an unsigned int to a binary format as a boolean deque

#Arguments

NameDefinition
x is the input unsigned int

#Example(s)

std::deque<bool> rtn_dq = int_to_binarydq(1286);
1 0 1 0 0 0 0 0 1 1 0


binarydq_to_int

#Usage

unsigned int binarydq_to_int(std::deque<bool> &x)

#Description

Converts a binary format as a boolean deque to an unsigned int

#Arguments

NameDefinition
x is the input boolean std deque

#Example(s)

std::deque<bool> dq_input = {1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0};
unsigned int out = binarydq_to_int(rtn_dq);
1286


Unique string from int

letter_to_nb

#Usage

unsigned int letter_to_nb(std::string &x)

#Description

Returns an int corresponding to the input letter.

This algorithm can be used to get which unique id number it is, if we know that it has been generated with nb_to_letter function

#Arguments

NameDefinition
x is the input string

#Example(s)

std::string inpt_str = "ecfy";
unsigned int rtn_val = letter_to_nb(inpt_str);
std::cout << rtn_val << "\n";
90089

inpt_str = "ajf";
rtn_val = letter_to_nb(inpt_str);
std::cout << rtn_val << "\n";

942


nb_to_letter

#Usage

std::string nb_to_letter(unsigned int &x)

#Description

Returns a unique combination of letters based on an input number, see examples.

#Arguments

NameDefinition
x is the input number

#Example(s)

unsigned int inpt_val = 702;
std::string out_val = nb_to_letter(inpt_val);
std::cout << out_val << "\n";

"zz"

unsigned int inpt_val = 104601;
std::string out_val = nb_to_letter(inpt_val);
std::cout << out_val << "\n";

"exsc"


JSON

ValidateJSON

#Usage

bool ValidateJSON(std::string &x)

#Description

Returns 1 if the JSon is valid, 0 if not.

#Arguments

NameDefinition
x is the stdstring representing the JSon

#Example(s)

std::string x = "{\"name\" : \"JohnY Doe\",\"age\": 30,\"isStudent\": false,\"courses\": [\"Math\", {\"prefered1\" : \"Science\", \"prefered2\" : \"Mathsss\", \"intricated_list\" : [1, \"2\", 2, {\"AAA\" : 22}, 34]}, \"History\"],\"address\": {\"street\": \"123 Main St\",\"city\": \"Poissy\",\"postalCode\": 78300},\"graduationYear\": null}";
bool is_ok = ValidateJSON(x);
std::cout << "is_ok: " << is_ok << "\n";
1
x = "{\"name\" : \"JohnY Doe\",\"age\": 30,\"isStudent\": false,\"courses\": [\"Math\", {\"prefered1\" : \"Science\", \"prefered2\" : \"Mathsss\", \"intricated_list : [1, \"2\", 2, {\"AAA\" : 22}, 34]}, \"History\"],\"address\": {\"street\": \"123 Main St\",\"city\": \"Poissy\",\"postalCode\": 78300},\"graduationYear\": null}";
is_ok = ValidateJSON(x);
std::cout << "is_ok: " << is_ok << "\n";
0


GetStringJSON

#Usage

std::string GetStringJSON(std::string &x, std::vector<std::string> keys_vec)

#Description

Allows to get the string value from a JSON key.

#Arguments

NameDefinition
x is the string representing the JSON data
keys_vec is a string vector containing all the keys in order

#Example(s)

std::string x = "{\"name\" : \"JohnY Doe\",\"age\": 30,\"isStudent\": false,\"courses\": [\"Math\", {\"prefered1\" : \"Science\", \"prefered2\" : \"Mathsss\", \"intricated_list\" : [ \"oui\", {\"AAA\" : \"22\", \"AA\" : [{\"BB\" : \"okok\"}, 1, 2.23] }, 34 ]} , \"History\"],\"address\": {\"street\": \"123 Main St\",\"city\": \"Poissy\",\"postalCode\": 78300}, \"graduationYear\": \"2021\", \"price\" : \"22\"}";
std::vector<std::string> keys_vec = {"courses", "intricated_list", "AA", "BB"};
std::string rslt = GetStringJSON(x, keys_vec);
std::cout << rslt << "\n";
okok
keys_vec = {"address", "city"};
rslt = GetStringJSON(x, keys_vec);
std::cout << rslt << "\n";
Poissy
keys_vec = {"price"};
rslt = GetStringJSON(x, keys_vec);
std::cout << rslt << "\n";
22


GetIntJSON

#Usage

int GetIntJSON(std::string &x, std::vector<std::string> keys_vec)

#Description

Allow to get an int value from a JSON key.

#Arguments

NameDefinition
x is the string representing the JSON data
keys_vec is the vector containing the keys in order

#Example(s)

std::string x = "{\"name\" : \"JohnY Doe\",\"age\": 30,\"isStudent\": false,\"courses\": [\"Math\", {\"prefered1\" : \"Science\", \"prefered2\" : \"Mathsss\", \"intricated_list\" : [ \"oui\", {\"AAA\" : \"22\", \"AA\" : [{\"BB\" : \"okok\"}, 1, 2.23] }, 34 ]} , \"History\"],\"address\": {\"street\": \"123 Main St\",\"city\": \"Poissy\",\"postalCode\": 78300}, \"graduationYear\": \"2021\", \"price\" : 22}";
std::vector<std::string> keys_vec = {"price"};
int rslt = GetIntJSON(x, keys_vec);
std::cout << rslt << "\n";
22


The Matrix Object

Matrix

#Usage

Matrix matr(2d vector)

#Description

Create a Matrix with variadic number of vectors, each vector represents a column. Supports, transposition, determinant computation, display...

#Arguments

NameDefinition
See_below See below

#Example(s)

See below


Matrix.create_matr

#Usage

template <typename T, typename... T2> void create_matr(std::vector<T> &var1, std::vector<T2>&... var2)

#Description

After initializing a matrix with Matrix matr(matr1), you can create it giving it a variadic number of colums, if a column missmatch the expected rownumber, a rep_untl function is applied to it to fit the matrix requirements, see example.

#Arguments

NameDefinition
... variadic number of columns

#Example(s)

std::vector<int> matr1 = {};
int ncol = 0;
int nrow = 0;
Matrix<int> matr(matr1, nrow, ncol);

std::vector<int> col1 = {1, 2, 1, 2, 2, 1};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1};

matr.create_matr(col1, col2, col3, col4, col5);
1 55 1 1 1
2 2 12 2 2
1 11 1 1 16
2 2 2 22 22
2 1 55 6 33
1 1 55 1 1


Matrix.get_matr_raw

#Usage

const std::vector<TB>& get_matr_raw()

#Description

Returns the matrix as a 1D stl vector const reference.

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<int> matr1 = {};
int ncol = 0;
int nrow = 0;

Matrix<int> matr(matr1, nrow, ncol);

std::vector<int> col1 = {1, 2, 1, 2, 2, 1, 42};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1, 22};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55, 21};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1, 77};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1, 7};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1, 8};
std::vector<int> col7 = {45, 2, 11, 42, 71, 1, 8};
matr.create_matr(col1, col2, col3, col4, col5, col6, col7);
matr1 = matr.get_matr_raw();
print_nvec(matr1);
:0: 1 2 1 2 2 1 42 55 2 11
:10: 2 1 1 22 1 12 1 2 55 55
:20: 21 1 2 1 22 6 1 77 1 2
:30: 16 22 33 1 7 45 2 11 2 71
:40: 1 8 45 2 11 42 71 1 8


Matrix.get_matr_raw2

#Usage

std::vector<TB> get_matr_raw2()

#Description

Returns the matrix as a 1D stl vector.

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<int> matr1 = {};
int ncol = 0;
int nrow = 0;

Matrix<int> matr(matr1, nrow, ncol);

std::vector<int> col1 = {1, 2, 1, 2, 2, 1, 42};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1, 22};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55, 21};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1, 77};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1, 7};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1, 8};
std::vector<int> col7 = {45, 2, 11, 42, 71, 1, 8};
matr.create_matr(col1, col2, col3, col4, col5, col6, col7);
matr1 = matr.get_matr_raw2();
print_nvec(matr1);
:0: 1 2 1 2 2 1 42 55 2 11
:10: 2 1 1 22 1 12 1 2 55 55
:20: 21 1 2 1 22 6 1 77 1 2
:30: 16 22 33 1 7 45 2 11 2 71
:40: 1 8 45 2 11 42 71 1 8


Matrix.get_matr

#Usage

Matrix<TB> get_matr()

#Description

Returns the Matrix of the Matrix objects.

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<int> matr1 = {};
int ncol = 0;
int nrow = 0;

Matrix<int> matr(matr1, nrow, ncol);

std::vector<int> col1 = {1, 2, 1, 2, 2, 1, 42};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1, 22};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55, 21};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1, 77};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1, 7};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1, 8};
std::vector<int> col7 = {45, 2, 11, 42, 71, 1, 8};

matr.create_matr(col1, col2, col3, col4, col5);
matr.show();
1 55 1 1 1
2 2 12 2 2
1 11 1 1 16
2 2 2 22 22
2 1 55 6 33
1 1 55 1 1
42 22 21 77 7


Matrix.show

#Usage

void show()

#Description

Display your matrix.

#Arguments

NameDefinition
X NO ARGS

#Example(s)

matr.show();
1 55 1 1 1
2 2 12 2 2
1 11 1 1 16
2 2 2 22 22
2 1 55 6 33
1 1 55 1 1


Matrix.transpose

#Usage

Matrix<T> transpose

#Description

Returns the transpose of the matrix

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<std::vector<int>> matr1 = {};
Matrix<int> matr(matr1);

std::vector<int> col1 = {1, 2, 1, 2, 2, 1};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1};

matr.create_matr(col1, col2, col3, col4, col5);
Matrix<int> matr2 = matr.transpose();

matr.show();
std::cout << "\n";
matr2.show();
1 55 1 1 1
2 2 12 2 2
1 11 1 1 16
2 2 2 22 22
2 1 55 6 33
1 1 55 1 1

1 2 1 2 2 1
55 2 11 2 1 1
1 12 1 2 55 55
1 2 1 22 6 1
1 2 16 22 33 1


Matrix.det1

#Usage

double det1()

#Description

Returns the determinant of the matrix. Important, it uses a custom algorithm for finding the determinant, a Laplace extension without recursivity. See det2 and det3 for standard Laplace expansion and det3 for the other method.

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<std::vector<int>> matr1 = {};
std::vector<int> col1 = {1, 2, 1, 2, 2, 1};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1};
Matrix<int> matr3(matr1);
matr3.create_matr(col1, col2, col3, col4, col5, col6);
double detval = matr3.det();
-1.05546e+08


Matrix.det2

#Usage

double det2(const std::vector<TB>& M, int n) const

#Description

Returns the determinant of the matrix with standard Laplace expansion method.

#Arguments

NameDefinition
M is the matrix as a 1d stl vector
n is the number of rows or columns

#Example(s)

std::vector<std::vector<int>> matr1 = {};
std::vector<int> col1 = {1, 2, 1, 2, 2, 1};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1};
Matrix<int> matr3(matr1);
matr3.create_matr(col1, col2, col3, col4, col5, col6);
int nrow = 6;
matr1 = matr3.get_matr_raw();
double detval = matr3.det2(matr1, nrow);
-1.05546e+08


Matrix.det3

#Usage

double det3()

#Description

Returns the determinant of the matrix with EigenLU method. It is the most efficient method.

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<std::vector<int>> matr1 = {};
std::vector<int> col1 = {1, 2, 1, 2, 2, 1};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1};
Matrix<int> matr3(matr1);
matr3.create_matr(col1, col2, col3, col4, col5, col6);
double detval = matr3.det3();
-1.05546e+08


Matrix.get_dim

#Usage

std::vector<int> get_dim()

#Description

Returns the dimension of the matrix (nrow, ncol)

#Arguments

NameDefinition
X NO ARGS

#Example(s)

std::vector<std::vector<int>> matr1 = {};
std::vector<int> col1 = {1, 2, 1, 2, 2, 1};
std::vector<int> col2 = {55, 2, 11, 2, 1, 1};
std::vector<int> col3 = {1, 12, 1, 2, 55, 55};
std::vector<int> col4 = {1, 2, 1, 22, 6, 1};
std::vector<int> col5 = {1, 2, 16, 22, 33, 1};
std::vector<int> col6 = {45, 2, 11, 2, 71, 1};
Matrix<int> matr3(matr1);
matr3.create_matr(col1, col2, col3, col4, col5, col6);
std::vector<int> dim_vec = matr3.get_dim();
{6, 6}


Matrix.mult_scalar

#Usage

template <typename T> void mult_scalar(const T &val)

#Description

Multiplies each elements of the matrix by a given scalar.

#Arguments

NameDefinition
val the scalar

#Example(s)

int vl = 2;
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
matr.mult_scalar(vl);
matr.show();
2 4
6 8


Matrix.div_scalar

#Usage

template <typename T> void div_scalar(const T &val)

#Description

Divides each elements of the matrix by a given scalar.

#Arguments

NameDefinition
val the scalar

#Example(s)

double vl = 2;
std::vector<double> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
matr.div_scalar(vl);
matr.show();
0.5 1
1.5 2


Matrix.add_scalar

#Usage

template <typename T> void add_scalar(const T &val)

#Description

Adds each elements of the matrix by a given scalar. Note, this operation is mathematically incorrect, but it is a substitution to adding the matrix to another matrix where all elements is equal to the scalar to add. (less memory usage)

#Arguments

NameDefinition
val the scalar

#Example(s)

int vl = 2;
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
matr.add_scalar(vl);
matr.show();
3 4
5 6


Matrix.subs_scalar

#Usage

template <typename T> void subs_scalar(const T &val)

#Description

Substract each elements of the matrix by a given scalar. Note, this operation is mathematically incorrect, but it is a substitution to substracting the matrix to another matrix where all elements is equal to the scalar to substract. (less memory usage)

#Arguments

NameDefinition
val the scalar

#Example(s)

int vl = 2;
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
matr.subs_scalar(vl);
matr.show();
-1 0
1 2


Matrix.lambda_scalar

#Usage

template <typename Func> void lambda_scalar(Func f)

#Description

Apply a function to each elements of the matrix.

#Arguments

NameDefinition
f the function, takes 1 arg, the i-jnth element of the matrix

#Example(s)

int myfunc (int &x) {
return x * 3 + 5;
};
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
matr.lambda_scalar(myfunc);
matr.show();
8 11
14 17


Matrix.add_matr

#Usage

template <typename TB2> void add_matr(const Matrix<TB2> &matr)

#Description

Performs a Matrix addition.

#Arguments

NameDefinition
matr is the B matrix of A + B

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
matr.add_matr(matr2);
matr.show();
2 4
6 8


Matrix.subs_matr

#Usage

template <typename TB2> void subs_matr(const Matrix<TB2> &matr)

#Description

Performs a Matrix substraction.

#Arguments

NameDefinition
matr is the B matrix of A - B

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
matr.subs_matr(matr2);
matr.show();
0 0
0 0


Matrix.mult_matr

#Usage

template <typename TB2> void mult_matr(const Matrix<TB2> &matr)

#Description

Performs a Matrix multiplication (i-jnth element to i-jnth element).

#Arguments

NameDefinition
matr is the B matrix of A * B (as i-jnth element to i-jnth element)

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
matr.mult_matr(matr2);
matr.show();
1 4
9 16


Matrix.div_matr

#Usage

template <typename TB2> void div_matr(const Matrix<TB2> &matr)

#Description

Performs a Matrix division (i-jnth element to i-jnth element).

#Arguments

NameDefinition
matr is the B matrix of A / B (as i-jnth element to i-jnth element)

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
matr.div_matr(matr2);
matr.show();
1 1
1 1


Matrix.lambda_matr

#Usage

template <typename TB2, typename Func> void lambda_matr(const Matrix<TB2> &matr, Func f)

#Description

a generalized elementwise operator.

It allows you to define arbitrary mathematical operations between two matrices, not just addition or multiplication.

#Arguments

NameDefinition
matr is the B matrix of A / B (as i-jnth element to i-jnth element)
f is the function, takes 2 args, the first one is the i-jnth element from the Matrix object from which the function is applied, the second is the i-jnth element from the input Matrix

#Example(s)

int myfunc (int &vl1, int &vl2) {
return vl1 / vl2 + 1;
}
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
matr.lambda_matr(matr2, myfunc);
matr.show();
2 2
2 2


Matrix.mult_scalar_out

#Usage

template <typename T> Matrix<std::common_type_t<TB, T>> mult_scalar_out(const T &val)

#Description

This function performs an element-wise multiplication between a matrix and a

scalar. Unlike `mult_scalar()`, which modifies the current

matrix in-place and preserves its data type, `mult_scalar_out()` creates a

new matrix whose element type is automatically promoted to the most

expressive type of the operands (using `std::common_type_t`).

This allows safe arithmetic between matrices of different numeric types

without precision loss.

#Arguments

NameDefinition
val the scalar

#Example(s)

int vl = 2.5;
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
auto matr2 = matr.mult_scalar_out(vl);
matr2.show();
2.5 5.0
7.5 10.0


Matrix.div_scalar_out

#Usage

template <typename T> Matrix<std::common_type_t<TB, T>> div_scalar_out(const T &val)

#Description

This function performs an element-wise division between a matrix and a

scalar. Unlike `div_scalar()`, which modifies the current

matrix in-place and preserves its data type, `div_scalar_out()` creates a

new matrix whose element type is automatically promoted to the most

expressive type of the operands (using `std::common_type_t`).

This allows safe arithmetic between matrices of different numeric types

without precision loss.

#Arguments

NameDefinition
val the scalar

#Example(s)

double vl = 2;
std::vector<double> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
auto matr2 = matr.div_scalar_out(vl);
matr2.show();
0.5 1
1.5 2


Matrix.add_scalar_out

#Usage

template <typename T> Matrix<std::common_type_t<TB, T>> add_scalar_out(const T &val)

#Description

This function performs an element-wise addition between a matrix and

a scalar. Unlike `add_scalar()`, which modifies the current

matrix in-place and preserves its data type, `add_scalar_out()` creates a

new matrix whose element type is automatically promoted to the most

expressive type of the operands (using `std::common_type_t`).

This allows safe arithmetic between matrices of different numeric types

without precision loss.

Strictly mathematically speaking, wa can not add a scalar and a matrix, but for memory performance, imagine the scalar as a matrix of nm dimensions filled with the scalar value.

#Arguments

NameDefinition
val the scalar

#Example(s)

int vl = 2;
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
auto matr2 = matr.add_scalar_out(vl);
matr2.show();
3 4
5 6


Matrix.subs_scalar_out

#Usage

template <typename T> Matrix<std::common_type_t<TB, T>> subs_scalar_out(const T &val)

#Description

This function performs an element-wise substraction between a matrix and

a scalar. Unlike `subs_scalar()`, which modifies the current

matrix in-place and preserves its data type, `subs_scalar_out()` creates a

new matrix whose element type is automatically promoted to the most

expressive type of the operands (using `std::common_type_t`).

This allows safe arithmetic between matrices of different numeric types

without precision loss.

Strictly mathematically speaking, wa can not substract a scalar and a matrix, but for memory performance, imagine the scalar as a matrix of nm dimensions filled with the scalar value.

#Arguments

NameDefinition
val the scalar

#Example(s)

int vl = 2;
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
auto matr2 = matr.subs_scalar_out(vl);
matr2.show();
-1 0
1 2


Matrix.lambda_scalar_out

#Usage

template <typename Func> auto lambda_scalar_out(Func f)

#Description

Apply a function to each elements of the matrix. Returns a new matrix to keep precision of the most expressive type used.

#Arguments

NameDefinition
f the function, takes 1 arg, the i-jnth element of the matrix

#Example(s)

int myfunc (int &x) {
return x * 3 + 5;
};
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
auto matr2 = matr.lambda_scalar_out(myfunc);
matr2.show();
8 11
14 17


Matrix.add_matr_out

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> add_matr_out(const Matrix<TB2> &matr)

#Description

Performs a Matrix addition. Returns a new matrix to keep precision of the most expressive type used.

#Arguments

NameDefinition
matr is the B matrix of A + B

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
auto matr3 = matr.add_matr_out(matr2);
matr3.show();
2 4
6 8


Matrix.subs_matr_out

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> subs_matr_out(const Matrix<TB2> &matr)

#Description

Performs a Matrix substraction. Returns a matrix to keep the precision of the most expressive type used.

#Arguments

NameDefinition
matr is the B matrix of A - B

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
auto matr3 = matr.subs_matr_out(matr2);
matr3.show();
0 0
0 0


Matrix.mult_matr_out

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult_matr_out(const Matrix<TB2> &matr)

#Description

Performs a Matrix multiplication (i-jnth element to i-jnth element). Returns a matrix to keep precision of the most expressive type used.

#Arguments

NameDefinition
matr is the B matrix of A * B (as i-jnth element to i-jnth element)

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
auto matr3 = matr.mult_matr_out(matr2);
matr3.show();
1 4
9 16


Matrix.div_matr_out

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> div_matr_out(const Matrix<TB2> &matr)

#Description

Performs a Matrix division (i-jnth element to i-jnth element). Returns a new matrix to keep precision of the most expressive type used.

#Arguments

NameDefinition
matr is the B matrix of A / B (as i-jnth element to i-jnth element)

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
auto matr3 = matr.div_matr_out(matr2);
matr3.show();
1 1
1 1


Matrix.lambda_matr_out

#Usage

template <typename TB2, typename Func> auto lambda_matr_out(const Matrix<TB2> &matr, Func f)

#Description

A generalized elementwise operator.

It allows you to define arbitrary mathematical operations between two matrices, not just addition or multiplication. Returns a new matrix to keep precision of the most expressive type used.

#Arguments

NameDefinition
matr is the B matrix of A / B (as i-jnth element to i-jnth element)
f is the function, takes 2 args, the first one is the i-jnth element from the Matrix object from which the function is applied, the second is the i-jnth element from the input Matrix

#Example(s)

int myfunc (int &vl1, int &vl2) {
return vl1 / vl2 + 1;
}
std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
Matrix<int> matr2(vec, 2, 2);
auto matr3 = matr.lambda_matr_out(matr2, myfunc);
matr3.show();
2 2
2 2


Matrix.mult1

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult1(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with A as the Matrix from which the function is called, see example.

#Arguments

NameDefinition
matr is the B matrix

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6};
Matrix<int> matr(vec, 3, 2);
//@E std::vector<int> vec = {5, 6, 7, 8};
Matrix<int> matr2(vec, 2, 2);
Matrix<int> matr3 = matr.mult1(matr2);
matr3.show();
29 39
40 54
51 69


Matrix.mult2

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult2(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with B as the Matrix from which the function is called, see example.

#Arguments

NameDefinition
matr is the A matrix

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6};
Matrix<int> matr(vec, 2, 2);
//@E std::vector<int> vec = {5, 6, 7, 8};
Matrix<int> matr2(vec, 2, 2);
Matrix<int> matr3 = matr2.mult2(matr);
matr3.show();
29 39
40 54
51 69


Matrix.mult1_opt_raw

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult1_opt_raw(const Matrix<TB2> &matr)

#Description

Performs an optimized matrix multiplication as A * B, with A as the Matrix from which the function is called, see example. The result is the transpose of the actual result, it is usefull if you want to chain matrix multiplications in an optimized way. So for the end result, don't forget to transpose the output.

#Arguments

NameDefinition
matr is the B matrix

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6};
Matrix<int> matr(vec, 3, 2);
//@E std::vector<int> vec = {5, 6, 7, 8};
Matrix<int> matr2(vec, 2, 2);
Matrix<int> matr3 = matr.mult1_opt_raw(matr2);
matr3.show();
29 40 51
39 54 69


Matrix.mult2_opt_raw

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult2_opt_raw(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with B as the Matrix from which the function is called, see example.

#Arguments

NameDefinition
matr is the A matrix

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6};
Matrix<int> matr(vec, 2, 2);
//@E std::vector<int> vec = {5, 6, 7, 8};
Matrix<int> matr2(vec, 2, 2);
Matrix<int> matr3 = matr2.mult2_opt_raw(matr);
matr3.show();
29 40 51
39 54 69


Matrix.mult1_opt

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult1_opt(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with A as the Matrix from which the function is called, see example.

#Arguments

NameDefinition
matr is the B matrix

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6};
Matrix<int> matr(vec, 3, 2);
//@E std::vector<int> vec = {5, 6, 7, 8};
Matrix<int> matr2(vec, 2, 2);
Matrix<int> matr3 = matr.mult1_opt(matr2);
matr3.show();
29 39
40 54
51 69


Matrix.mult2_opt

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult2_opt(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with B as the Matrix from which the function is called, see example.

#Arguments

NameDefinition
matr is the A matrix

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
Matrix<int> matr(vec, 2, 2);
//@E std::vector<int> vec = {5, 6, 7, 8};
Matrix<int> matr2(vec, 2, 2);
Matrix<int> matr3 = matr2.mult2_opt(matr);
matr3.show();
29 39
40 54
51 69


Matrix.mult1_GPU

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult1(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with A as the Matrix from which the function is called, see example. This functions uses cuBLAS (nvidia graphics card), see how to set the GPU context for accelerated computing.

#Arguments

NameDefinition
matr is the B matrix

#Example(s)

CUBLASContext::init();
std::vector<float> a = {1,2,3,4, 5, 6};
std::vector<float> b = {5,6,7,8,9,10};
Matrix<float> A(a, 3, 2), B(b, 2, 3);
auto C = A.mult1_GPU(B);
C.show();
CUBLASContext::destroy();
Initialized GPU context
29 39 49
40 54 68
51 69 87
Destroyed GPU context


Matrix.mult2_GPU

#Usage

template <typename TB2> Matrix<std::common_type_t<TB, TB2>> mult2(const Matrix<TB2> &matr)

#Description

Performs a matrix multiplication as A * B, with B as the Matrix from which the function is called, see example. This functions uses cuBLAS (nvidia graphics card), see how to set the GPU context for accelerated computing.

#Arguments

NameDefinition
matr is the A matrix

#Example(s)

CUBLASContext::init();
std::vector<float> a = {1,2,3,4, 5, 6};
std::vector<float> b = {5,6,7,8,9,10};
Matrix<float> A(a, 3, 2), B(b, 2, 3);
auto C = B.mult2_GPU(A);
C.show();
CUBLASContext::destroy();
Initialized GPU context
29 39 49
40 54 68
51 69 87
Destroyed GPU context