Robotran C Documentation
Functions
mbs_1D_array.c File Reference
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include "mbs_message.h"
#include "mbs_1D_array.h"

Functions

int mbs_linspace (double start, double stop, int num, double *linspace)
 
double * mbs_linspace_0 (double start, double stop, int num)
 Allocate an evenly spaced numbers over the specified range. More...
 
double * mbs_linspace_1 (double start, double stop, int num)
 Allocate an evenly spaced numbers over the specified range. More...
 
double * mbs_arange_0 (double start, double stop, double step, int with_end, int *size)
 Allocate an a array with specified step between two values. More...
 
double * mbs_drand_0 (int num, double min, double max)
 Allocate an array with the specified random number in the specified range. More...
 
double * mbs_drand_1 (int num, double min, double max)
 Allocate an array with the specified random number in the specified range. More...
 
int binary_search_0 (double *array, double value, int id_min, int id_max)
 
int get_dinterval_binary_0 (double *array, int size, double value, int *index, int lim_check)
 Find the index of the highest value in the array lower or equal than the value. More...
 
int get_dinterval_binary_1 (double *array, int size, double value, int *index, int lim_check)
 Find the index of the highest value in the array lower or equal than the value. More...
 
int get_dinterval_binary_from_index_0 (double *array, int size, double value, int *index, int lim_check, int verbose)
 Find the index of the highest value in the array lower or equal than the value. More...
 
int get_dinterval_binary_from_index_1 (double *array, int size, double value, int *index, int lim_check, int verbose)
 Find the index of the highest value in the array lower or equal than the value. More...
 
int save_ivec_0 (int *vec, int size, char *name, int row)
 save a (x sized) vector of integers in the specified file, starting with index 0 The file is open with the option "wt" More...
 
int save_ivec_1 (int *vec, int size, char *name, int row)
 save a (x sized) vector of integers in the specified file, starting with index 0 The file is open with the option "wt" More...
 
double scalar_product (double v1[4], double v2[4])
 Compute and return the scalar product of 2 vectors with first index is 1. More...
 
double scalar_product_0 (double *v1, double *v2, int n)
 Compute and return the scalar product of 2 vectors with first index is 0. More...
 
void vector_sum (double v1[4], double v2[4], double v_dest[4])
 Sum each component of 2 vectors in a third vector. The first index is 1. More...
 
void sum_dvec_0 (double *v1, double *v2, int size, double *v_dest)
 Sum each component of 2 array in a third vector. More...
 
void vector_diff (double v1[4], double v2[4], double v_dest[4])
 Subtract each component of 2 vectors in a third vector. The first index is 1. More...
 
void diff_dvec_0 (double *v1, double *v2, int size, double *v_dest)
 Subtract each component of 2 array in a third vector. More...
 
void cross_product (double v1[4], double v2[4], double v_dest[4])
 Compute the cross product of 2 vectors in a third vector. The first index is 1. More...
 
void number_product (double s, double v1[4], double v_dest[4])
 Compute the product of a vector by a real. The first index is 1. More...
 
int * get_ivec_0 (int l_v)
 create (with memory allocation) a vector (length l_v) of integers, starting at index 0 More...
 
int * get_ivec_1 (int l_v)
 create (with memory allocation) a vector (length l_v) of integers, starting at index 1 More...
 
void free_ivec_0 (int *vec)
 release memory for a vector of integers, starting with index 0 More...
 
void free_ivec_1 (int *vec)
 release memory for a vector of integers, starting with index 1 More...
 
void copy_ivec_0 (int *vec_src, int *vec_dest, int l_v)
 Copy the content of a vector(of size l_v) of integers to a second vector, starting with index 0. More...
 
void copy_ivec_1 (int *vec_src, int *vec_dest, int l_v)
 Copy the content of a vector (of size l_v) of integers to a second vector, starting with index 1. More...
 
int * re_copy_ivec_0 (int *src, int s_nx, int *dest, int d_nx)
 Copy an array of int into another, reallocate the destination if required. More...
 
int * re_copy_ivec_1 (int *src, int s_nx, int *dest, int d_nx)
 
void print_ivec_0 (int *vec, int l_v)
 print a (l_v sized) vector of integers in console, starting with index 0 More...
 
void print_ivec_1 (int *vec)
 print a vector (of size specified in vec[0]) of integers in console, starting with index 1 More...
 
int code_ivec_0 (FILE *file_out, int *values, const char *name, int size)
 Write C-code to allocate and fill an array of integers. More...
 
int code_ivec_1 (FILE *file_out, int *values, const char *name, int size)
 Write C-code to allocate and fill an array of integers. More...
 
void sort_ivec_0 (int *vec_src, int *vec_dest, int l_v)
 sort the first (l_v sized) vector of integers into the second vector, starting with index 0 More...
 
void sort_dvec_0 (double *vec_src, double *vec_dest, int l_v)
 sort the first (l_v sized) vector of double into the second vector, starting with index 0 More...
 
void sort_ivec_1 (int *vec_src, int *vec_dest, int l_v)
 sort the first (x sized) vector of integers into the second vector, starting with index 1 More...
 
void sort_inplace_ivec_1 (int *vec, int l_v)
 sort and modify the (x sized) vector of integers, starting with index 1 The "Bubble sort" is used, complexity is O(n^2) More...
 
void f0123_ivec_0 (int *vec, int l_v)
 Fill the (l_v sized) vector of integers as [0 1 2 3 ... l_v-1], starting with index 0. More...
 
void conc_ivec_0 (int *vec1_src, int l_vec1, int *vec2_src, int l_vec2, int *vec_dest)
 concatenate the first (l_v1 sized) vector and the second (l_v2 sized) vectors of integers into the third (size >=l_v1+l_v2) vector (without memory allocation), starting with index 0 More...
 
void conc_ivec_1 (int *vec1_src, int l_vec1, int *vec2_src, int l_vec2, int *vec_dest)
 concatenate the first (l_v1 sized) vector and the second (l_v2 sized) vectors of integers into the third (size >=l_v1+l_v2) vector (without memory allocation), starting with index 1 More...
 
int slct_ivec_0 (int *vec_src, int l_vec1, int *vec_ind_src, int l_vec2, int *vec_dest)
 fill the third (l_v2 sized) vector by slicing the first (l_v1 sized) vector of integers at the indexes specified in the second (l_v2 sized) vector, starting with index 0 More...
 
int find_ivec_0 (int *vec, int l_v, int f)
 return the index of the value f in the (x sized) vector vec of integers, starting with index 0. Return -1 if not found. More...
 
int find_dvec_0 (double *vec, int l_v, double f)
 return the index of the value f in the (x sized) vector vec of doubles, starting with index 0. Return -1 if not found. More...
 
int find_ivec_1 (int *vec, int l_v, int f)
 return the index of the value f in the (x sized) vector vec of integers, starting with index 1. Return -1 if not found. More...
 
int same_ivec_0 (int *v1, int *v2, int size)
 Compare if two vector are the same. More...
 
int same_ivec_1 (int *v1, int *v2)
 Compare if two vector are the same. More...
 
double * get_dvec_0 (int l_v)
 create (with memory allocation) a vector (length l_v) of doubles, starting at index 0 More...
 
double * get_dvec_1 (int l_v)
 create (with memory allocation) a vector (length l_v) of doubles, starting at index 1 More...
 
void free_dvec_0 (double *vec)
 release memory for a vector of doubles, starting at index 0 More...
 
void free_dvec_1 (double *vec)
 release memory for a vector of doubles, starting at index 1 More...
 
void copy_dvec_0 (double *vec_src, double *vec_dest, int l_v)
 Copy the content of a vector (of sizel_v) of doubles to a second vector, starting with index 0. More...
 
void copy_dvec_1 (double *vec_src, double *vec_dest)
 Copy the content of a vector (of size specified in vec_src[0]) of doubles to a second vector, starting with index 1. More...
 
double * convert_dvec_0_to_1 (double *src, int size, int free_src)
 Copy a dvec0 into a new allocated dvec1. More...
 
double * convert_dvec_1_to_0 (double *src, int size, int free_src)
 Copy a dvec1 into a new allocated dvec0. More...
 
double * re_copy_dvec_0 (double *src, int s_nx, double *dest, int d_nx)
 Copy an array of double into another, reallocate the destination if required. More...
 
double * re_copy_dvec_1 (double *src, int s_nx, double *dest, int d_nx)
 Copy an array of double into another, reallocate the destination if required. More...
 
void print_dvec_0 (double *vec, int l_v)
 print a (x sized) vector of doubles in console, starting with index 0 More...
 
void print_format_dvec_0 (double *vec, int l_v, char *format)
 print a (x sized) vector of doubles in console, starting with index 0 More...
 
int code_dvec_0 (FILE *file_out, double *values, const char *name, int size)
 Write C-code to allocate and fill an array of double. More...
 
int code_dvec_1 (FILE *file_out, double *values, const char *name, int size)
 Write C-code to allocate and fill an array of double. More...
 
void print_dvec_1 (double *vec)
 print a vector (of size specified in vec[0]) of doubles in console, starting with index 1 More...
 
void save_dvec_0 (double *vec, int l_v, char *name)
 save a (x sized) vector of doubles in the specified file, starting with index 0 The file is open with the option "wt" More...
 
void pick_and_place_dvec_1 (double *src, int *index, int n, double *dest)
 Pick the values from an array and set them in the destination array at the specified index. More...
 
void pick_and_place_dvec_0 (double *src, int *index, int n, double *dest)
 Pick the values from an array and set them in the destination array at the specified index. More...
 
void slct_dvec_1 (double *vec_src, int *vec_ind_src, int l_v, double *vec_dest)
 fill the third vector by slicing the first vector of doubles at the indexes specified in the second (x sized) vector, starting with index 1 More...
 
int slct_dvec_0 (double *vec_src, int l_v1, int *vec_ind_src, int l_v2, double *vec_dest)
 fill the third (l_v2 sized) vector by slicing the first (l_v1 sized) vector of doubles at the indexes specified in the second (l_v2 sized) vector, starting with index 0 More...
 
int any_dvec_0 (double *vec, int l_v)
 check if all values of a [l_v sized] vector of doubles are equal to 0, return 0 in that case, starting with index 0 More...
 
void value_dvec_0 (double value, double *vec, int l_v)
 set all the element of a [l_v sized] vector of doubles to a value, starting with index 0 More...
 
void value_dvec_1 (double value, double *vec)
 set all the element of a vector of doubles to zero, starting with index 1 More...
 
void zeros_dvec_0 (double *vec, int l_v)
 set all the element of a [l_v sized] vector of doubles to zero, starting with index 0 More...
 
void zeros_dvec_1 (double *vec)
 set all the element of a vector of doubles to zero, starting with index 1 More...
 
void opposite_dvec_0 (double *vec, int n)
 function to take the opposite of a given vector (minus in front of each entry) More...
 
void opposite_dvec_1 (double *vec)
 function to take the opposite of a given vector (minus in front of each entry) More...
 
int same_dvec_0 (double *v1, double *v2, int size)
 Compare if two vector of floats are the same. More...
 
int same_dvec_1 (double *v1, double *v2)
 Compare if two vector of floats are the same. More...
 
int max_dvec_0 (double *vec, int size)
 Find the index of the maximum value in the array. More...
 
int max_dvec_1 (double *vec)
 Find the index of the maximum value in the vector. More...
 

Detailed Description

This c file implements utilities functions about 1D arrays of doubles and integers.

Some utilities functions about such arrays are implemented in useful_functions.c.

Creation date: 04-04-2022

Author
Robotran team

(c) Universite catholique de Louvain

Function Documentation

◆ any_dvec_0()

int any_dvec_0 ( double *  vec,
int  l_v 
)

check if all values of a [l_v sized] vector of doubles are equal to 0, return 0 in that case, starting with index 0

Parameters
[in]vecthe vector to be checked
[in]l_vthe size of the vector
Returns
0 if all element are null; 1 otherwise

◆ binary_search_0()

int binary_search_0 ( double *  array,
double  value,
int  id_min,
int  id_max 
)

◆ code_dvec_0()

int code_dvec_0 ( FILE *  file_out,
double *  values,
const char *  name,
int  size 
)

Write C-code to allocate and fill an array of double.

The code will assign the variable to NULL if values is NULL or size is 0.

Parameters
file_outStream in which writing the values.
valuesPointer to the array to be written (index starts at 0).
nameName of the variable to be filled.
sizeThe number of element in the array.
Returns
Negative in case of error, 0 if code was generated, positive if no code has to be generated

◆ code_dvec_1()

int code_dvec_1 ( FILE *  file_out,
double *  values,
const char *  name,
int  size 
)

Write C-code to allocate and fill an array of double.

The code will assign the variable to NULL if values is NULL.

Parameters
file_outStream in which writing the values.
valuesPointer to the array to be written (index starts at 1).
nameName of the variable to be filled.
sizeThe number of element in the array (without counting index 0).
Returns
Negative in case of error, 0 if code was generated, positive if no code has to be generated

◆ code_ivec_0()

int code_ivec_0 ( FILE *  file_out,
int *  values,
const char *  name,
int  size 
)

Write C-code to allocate and fill an array of integers.

The code will assign the variable to NULL if values is NULL or size is 0.

Parameters
file_outStream in which writing the values.
valuesPointer to the array to be written (index starts at 0).
nameName of the variable to be filled.
sizeThe number of element in the array.
Returns
Negative in case of error, 0 if code was generated, positive if no code has to be generated

◆ code_ivec_1()

int code_ivec_1 ( FILE *  file_out,
int *  values,
const char *  name,
int  size 
)

Write C-code to allocate and fill an array of integers.

The code will assign the variable to NULL if values is NULL.

Parameters
file_outStream in which writing the values.
valuesPointer to the array to be written (index starts at 1).
nameName of the variable to be filled.
sizeThe number of element in the array (without counting index 0).
Returns
Negative in case of error, 0 if code was generated, positive if no code has to be generated

◆ conc_ivec_0()

void conc_ivec_0 ( int *  vec1_src,
int  l_v1,
int *  vec2_src,
int  l_v2,
int *  vec_dest 
)

concatenate the first (l_v1 sized) vector and the second (l_v2 sized) vectors of integers into the third (size >=l_v1+l_v2) vector (without memory allocation), starting with index 0

Parameters
[in]vec1_srcthe first vector to be concatenated
[in]l_v1the size of the first vector
[in]vec2_srcthe second vector to be concatenated
[in]l_v2the size of the second vector
[out]vec_destthe concatenation of both vector such as vec_dest = [vec1_src vec2_src]. The vector have to be already allocated to a sufficient size.

◆ conc_ivec_1()

void conc_ivec_1 ( int *  vec1_src,
int  l_v1,
int *  vec2_src,
int  l_v2,
int *  vec3 
)

concatenate the first (l_v1 sized) vector and the second (l_v2 sized) vectors of integers into the third (size >=l_v1+l_v2) vector (without memory allocation), starting with index 1

Parameters
[in]vec1_srcthe first vector to be concatenated, starting with index 1
[in]l_v1the size of the first vector (0 element not taken into account)
[in]vec2_srcthe second vector to be concatenated, starting with index 1
[in]l_v2the size of the second vector (0 element not taken into account)
[out]vec3the concatenation of both vector such as vec3 = [vec1_src vec2_src], starting with index 1. The vector have to be already allocated to a sufficient size.

◆ convert_dvec_0_to_1()

double* convert_dvec_0_to_1 ( double *  src,
int  size,
int  free_src 
)

Copy a dvec0 into a new allocated dvec1.

Parameters
srcThe source array with index starting at 0.
sizeThe number of element in the source array.
free_srcFlag to free the memory pointed by src.
Returns
Pointer to a dvec1 containing the values of the dvec0.

◆ convert_dvec_1_to_0()

double* convert_dvec_1_to_0 ( double *  src,
int  size,
int  free_src 
)

Copy a dvec1 into a new allocated dvec0.

Parameters
srcThe source array with index starting at 1.
sizeThe number of elements (index 0 not counted) in the source array.
free_srcFlag to free the memory pointed by src.
Returns
Pointer to a dvec1 containing the values of the dvec0.

◆ copy_dvec_0()

void copy_dvec_0 ( double *  vec_src,
double *  vec_dest,
int  l_v 
)

Copy the content of a vector (of sizel_v) of doubles to a second vector, starting with index 0.

Parameters
[in]vec_srcthe original vector of doubles, starting with index 0
[out]vec_destthe copy of vec1_src, starting with index 0
[in]

◆ copy_dvec_1()

void copy_dvec_1 ( double *  vec_src,
double *  vec_dest 
)

Copy the content of a vector (of size specified in vec_src[0]) of doubles to a second vector, starting with index 1.

Parameters
[in]vec_srcthe original vector of doubles(of size specified in vec_src[0]), starting with index 1
[out]vec_dest(already allocated at size specified in vec_src[0]) the copy of vec1_src, starting with index 1

◆ copy_ivec_0()

void copy_ivec_0 ( int *  vec_src,
int *  vec_dest,
int  l_v 
)

Copy the content of a vector(of size l_v) of integers to a second vector, starting with index 0.

Parameters
[in]vec_srcthe original vector of integer, starting with index 0
[out]vec_dstthe copy of vec_src, starting with index 0
[in]l_vsize of the vectors

◆ copy_ivec_1()

void copy_ivec_1 ( int *  vec_src,
int *  vec_dest,
int  l_v 
)

Copy the content of a vector (of size l_v) of integers to a second vector, starting with index 1.

Parameters
[in]vec_srcthe original vector of integer, starting with index 1
[out]vec_destthe copy of vec_src, starting with index 1
[in]l_vsize of the vectors (0 element not taken into account)

◆ cross_product()

void cross_product ( double  v1[4],
double  v2[4],
double  v_dest[4] 
)

Compute the cross product of 2 vectors in a third vector. The first index is 1.

The vectors have unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]v1vector of size 4 with first element unused.
[in]v2vector of size 4 with first element unused.
[in,out]vvector of size 4 such as $ \overrightarrow{v} = \overrightarrow{v1} \times \overrightarrow{v2} $ with first element unused.

◆ diff_dvec_0()

void diff_dvec_0 ( double *  v1,
double *  v2,
int  size,
double *  v_dest 
)

Subtract each component of 2 array in a third vector.

The vectors starts at index 0. See get_dvec_0() to such vector creation.

Parameters
[in]v1,v2The vector to be subtracted.
[in]sizesize of the arrays.
[out]v_destResults array suach as $ v_dest_{i} = v1_{i} - v2_{i} $. The results array can be one of the input array.

◆ f0123_ivec_0()

void f0123_ivec_0 ( int *  vec,
int  l_v 
)

Fill the (l_v sized) vector of integers as [0 1 2 3 ... l_v-1], starting with index 0.

Parameters
[out]vecthe vector to be filled
[in]l_vthe size of the vector

◆ find_dvec_0()

int find_dvec_0 ( double *  vec,
int  l_v,
double  f 
)

return the index of the value f in the (x sized) vector vec of doubles, starting with index 0. Return -1 if not found.

Parameters
[in]veca vector of double, starting with index 0
[in]l_vthe size of the vector
[in]fthe double to look after in the vector
Returns
-1 if f does not belong to vec, otherwise it returns the index of f in vec.

◆ find_ivec_0()

int find_ivec_0 ( int *  vec,
int  l_v,
int  f 
)

return the index of the value f in the (x sized) vector vec of integers, starting with index 0. Return -1 if not found.

Parameters
[in]veca vector of integers, starting with index 0
[in]l_vthe size of the vector
[in]fthe integer to look after in the vector
Returns
-1 if f does not belong to vec, otherwise it returns the index of f in vec.

◆ find_ivec_1()

int find_ivec_1 ( int *  vec,
int  l_v,
int  f 
)

return the index of the value f in the (x sized) vector vec of integers, starting with index 1. Return -1 if not found.

Parameters
[in]veca vector of integers, starting with index 1
[in]l_vthe size of the vector (0 element not taken into account)
[in]fthe integer to look after in the vector
Returns
-1 if f does not belong to vec, otherwise it returns the index of f in vec.

◆ free_dvec_0()

void free_dvec_0 ( double *  vec)

release memory for a vector of doubles, starting at index 0

Parameters
[out]veca vector of doubles

◆ free_dvec_1()

void free_dvec_1 ( double *  vec)

release memory for a vector of doubles, starting at index 1

Parameters
[out]veca vector of doubles

◆ free_ivec_0()

void free_ivec_0 ( int *  vec)

release memory for a vector of integers, starting with index 0

Parameters
[out]veca vector of integers

◆ free_ivec_1()

void free_ivec_1 ( int *  vec)

release memory for a vector of integers, starting with index 1

Parameters
[out]veca vector of integers

◆ get_dinterval_binary_0()

int get_dinterval_binary_0 ( double *  array,
int  size,
double  value,
int *  index,
int  lim_check 
)

Find the index of the highest value in the array lower or equal than the value.

A binary search algorithm is used accros the whole array range. If the lim_check is not enabled, the behavior is undefined if the value is outside the array range.

The array is of type get_dvec_0().

Parameters
[in]arrayArray in which the interval is looked after. The array must be sorted and stricly increasing.
[in]sizeThe number of elements in the array.
[in]valueThe value to be located.
[out]indexStore in this adress the index of the highest element in the array that is lower or equal to value. This index is not modified if the value is outside the range of the array (if lim_check is enable).
[in]lim_checkIf true (not equal to 0) check that the value is in the range of the array.
Returns
Null (0) value or a negative value in case of error if lim_check is true:
  • -1: value lower than input array minimum value
  • -2: value higher than input array maximum value

◆ get_dinterval_binary_1()

int get_dinterval_binary_1 ( double *  array,
int  size,
double  value,
int *  index,
int  lim_check 
)

Find the index of the highest value in the array lower or equal than the value.

This function calls get_dinterval_binary_0(), refers to it for implementation details.

The array is of type get_dvec_1().

Parameters
[in]arrayArray in which the interval is looked after. The array must be sorted and stricly increasing. The first element (index=0) of the array is not considered.
[in]sizeThe number of elements (index 0 not taken into account) in the array.
[in]valueThe value to be located.
[out]indexStore in this adress the index of the highest element in the array that is lower or equal to value. This index is not modified if the value is outside the range of the array (if lim_check is enable).
[in]lim_checkIf true (not equal to 0) check that the value is in the range of the array.
Returns
Null (0) value or a negative value in case of error if lim_check is true. See get_dinterval_binary_0() for details.

◆ get_dinterval_binary_from_index_0()

int get_dinterval_binary_from_index_0 ( double *  array,
int  size,
double  value,
int *  index,
int  lim_check,
int  verbose 
)

Find the index of the highest value in the array lower or equal than the value.

A binary search algorithm is used between the upper or lower end of the array and the currently stored index. If the lim_check is not enabled, the behavior is undefined if the value is outside the array range.

The array is of type get_dvec_0().

Parameters
[in]arrayArray in which the interval is looked after. The array must be sorted and stricly increasing.
[in]sizeThe number of elements in the array.
[in]valueThe value to be located.
[in,out]indexUse the index stored in the adress to initialize the binary search. Then store in this adress the index of the highest element in the array that is lower or equal to value. This index is not modified if the value is outside the range of the array (if lim_check is enable).
[in]lim_checkIf true (not equal to 0) check that the value is in the range of the array.
[in]verboseIf true (not equal to 0) a message is raised if the initial index lead to use the full array width.
Returns
Null (0) value or a negative value in case of error if lim_check is true:
  • -1: value lower than input array minimum value
  • -2: value higher than input array maximum value

◆ get_dinterval_binary_from_index_1()

int get_dinterval_binary_from_index_1 ( double *  array,
int  size,
double  value,
int *  index,
int  lim_check,
int  verbose 
)

Find the index of the highest value in the array lower or equal than the value.

This function calls get_dinterval_binary_from_index_0(), refers to it for implementation details.

The array is of type get_dvec_1().

Parameters
[in]arrayArray in which the interval is looked after. The array must be sorted and stricly increasing.
[in]sizeThe number of elements in the array.
[in]valueThe value to be located.
[in,out]indexUse the index stored in the adress to initialize the binary search. Then store in this adress the index of the highest element in the array that is lower or equal to value. This index is not modified if the value is outside the range of the array (if lim_check is enable).
[in]lim_checkIf true (not equal to 0) check that the value is in the range of the array.
[in]verboseIf true (not equal to 0) a message is raised if the initial index lead to use the full array width.
Returns
Null (0) value or a negative value in case of error if lim_check is true. See get_dinterval_binary_from_index_0() for details.

◆ get_dvec_0()

double* get_dvec_0 ( int  l_v)

create (with memory allocation) a vector (length l_v) of doubles, starting at index 0

Parameters
[in]l_vsize of the vector
Returns
requested vector

◆ get_dvec_1()

double* get_dvec_1 ( int  l_v)

create (with memory allocation) a vector (length l_v) of doubles, starting at index 1

Parameters
[in]l_vsize of the vector (0 element not taken into account)
Returns
requested vector (element 0 receivesl_v: the size without this element)

◆ get_ivec_0()

int* get_ivec_0 ( int  l_v)

create (with memory allocation) a vector (length l_v) of integers, starting at index 0

Parameters
[in]l_v= size of the vector
Returns
requested vector

◆ get_ivec_1()

int* get_ivec_1 ( int  l_v)

create (with memory allocation) a vector (length l_v) of integers, starting at index 1

Parameters
[in]l_v= size of the vector (0 element not taken into account)
Returns
requested vector (element 0 receives l_v: the size without this element)

◆ max_dvec_0()

int max_dvec_0 ( double *  vec,
int  size 
)

Find the index of the maximum value in the array.

In case of multiple maximum, only the first index is returned.

Parameters
[in]vecA vector of floats, starting with index 0.
[in]sizeThe number of elements in the array.
Returns
The index of the maximum value, negative in case of error.

◆ max_dvec_1()

int max_dvec_1 ( double *  vec)

Find the index of the maximum value in the vector.

In case of multiple maximum, only the first index is returned.

Parameters
[in]vecA vector of floats, starting with index 1.
Returns
The index of the maximum value, negative in case of error.

◆ mbs_arange_0()

double* mbs_arange_0 ( double  start,
double  stop,
double  step,
int  with_end,
int *  size 
)

Allocate an a array with specified step between two values.

The array is of type get_dvec_0().

Parameters
[in]startThe beginning of the range.
[in]stopThe end point of the range (included).
[in]stepThe distance between 2 data.
[in]with_endIf True, ensure that the closing value is in the array. As a consequence the step between the last two points may not reach the specified value.
[out]sizeThe number of element in the returned array. Null value is an error code.
Returns
The pointer to the array containing the evenly spaced numbers.

◆ mbs_drand_0()

double* mbs_drand_0 ( int  num,
double  min,
double  max 
)

Allocate an array with the specified random number in the specified range.

This function uses the rand() function of stdlib, consider to call srand() to ensure reproductible/non-reproductible randomized vectors.

Providing the same value for min and max will generate an array with all elements to be equal to this value.

The array is of type get_dvec_0().

Parameters
[in]numThe number of points (geather than 0).
[in]minThe beginning of the range.
[in]maxThe end point of the range.
Returns
The pointer to the array containing the random numbers.

◆ mbs_drand_1()

double* mbs_drand_1 ( int  num,
double  min,
double  max 
)

Allocate an array with the specified random number in the specified range.

See mbs_drand_0() for details except that the array is of type get_dvec_1().

Parameters
[in]numThe number of points (geather than 0).
[in]minThe beginning of the range.
[in]maxThe end point of the range.
Returns
The pointer to the array containing the random numbers.

◆ mbs_linspace()

int mbs_linspace ( double  start,
double  stop,
int  num,
double *  linspace 
)

◆ mbs_linspace_0()

double* mbs_linspace_0 ( double  start,
double  stop,
int  num 
)

Allocate an evenly spaced numbers over the specified range.

The array is of type get_dvec_0().

Parameters
[in]startThe beginning of the range.
[in]stopThe end point of the range (included).
[in]numThe number of points (geather than 0).
Returns
The pointer to the array containing the evenly spaced numbers.

◆ mbs_linspace_1()

double* mbs_linspace_1 ( double  start,
double  stop,
int  num 
)

Allocate an evenly spaced numbers over the specified range.

The array is of type get_dvec_1().

Parameters
[in]startThe beginning of the range.
[in]stopThe end point of the range (included).
[in]numThe number of points (geather than 0).
Returns
The pointer to the array containing the evenly spaced numbers.

◆ number_product()

void number_product ( double  s,
double  v1[4],
double  v_dest[4] 
)

Compute the product of a vector by a real. The first index is 1.

The vector has unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]sreal that will multiply the vector.
[in]v1vector of size 4 to be multiplied. The first index is 1.
[in,out]v_destvector of size 4 such as $ v_dest_{i}=v1_{i}s $. The first index is 1.

◆ opposite_dvec_0()

void opposite_dvec_0 ( double *  vec,
int  n 
)

function to take the opposite of a given vector (minus in front of each entry)

Parameters
[in]vecthe vector, vec
[in]nthe vecotr size, n

◆ opposite_dvec_1()

void opposite_dvec_1 ( double *  vec)

function to take the opposite of a given vector (minus in front of each entry)

Parameters
[in]vecthe vector, vec (starting at one)

◆ pick_and_place_dvec_0()

void pick_and_place_dvec_0 ( double *  src,
int *  index,
int  n,
double *  dest 
)

Pick the values from an array and set them in the destination array at the specified index.

This function can be seen as the opposite of slct_dvec_0. The src and index arrays are starting with index 0!

Parameters
srcthe vector containing the original values of doubles to be copied.
indexthe vector containing the indexes of the value in the destination array.
nthe number of indexes to be read (the first n indexes are read).
destthe destination array such as for i=0:n-1 { dest[index[i]] = src[i] }

◆ pick_and_place_dvec_1()

void pick_and_place_dvec_1 ( double *  src,
int *  index,
int  n,
double *  dest 
)

Pick the values from an array and set them in the destination array at the specified index.

This function can be seen as the opposite of slct_dvec_0 but for d_vec_1 array. The src and index arrays are starting with index 1!

Parameters
srcthe vector containing the original values of doubles to be copied.
indexthe vector containing the indexes of the value in the destination array.
nthe number of indexes to be read (the first n indexes are read).
destthe destination array such as: for i=1:n { dest[index[i]] = src[i] }

◆ print_dvec_0()

void print_dvec_0 ( double *  vec,
int  nb_r 
)

print a (x sized) vector of doubles in console, starting with index 0

call print_format_dvec_0 with default parameter (format = "%f").

Parameters
[in]vecthe vector to be printed
[in]nb_rthe size of the vector

◆ print_dvec_1()

void print_dvec_1 ( double *  vec)

print a vector (of size specified in vec[0]) of doubles in console, starting with index 1

Parameters
[in]vecthe vector to be printed

◆ print_format_dvec_0()

void print_format_dvec_0 ( double *  vec,
int  nb_r,
char *  format 
)

print a (x sized) vector of doubles in console, starting with index 0

Parameters
[in]vecthe vector to be printed
[in]nb_rthe size of the vector
[in]formatthe chosen format. default is "%f". can be something like "%.6f"

◆ print_ivec_0()

void print_ivec_0 ( int *  vec,
int  l_v 
)

print a (l_v sized) vector of integers in console, starting with index 0

Parameters
[in]vecthe vector to be printed
[in]l_vthe size of the vector

◆ print_ivec_1()

void print_ivec_1 ( int *  vec)

print a vector (of size specified in vec[0]) of integers in console, starting with index 1

Parameters
[in]vecthe vector to be printed

◆ re_copy_dvec_0()

double* re_copy_dvec_0 ( double *  src,
int  s_nx,
double *  dest,
int  d_nx 
)

Copy an array of double into another, reallocate the destination if required.

Parameters
[in]srcSource array to be copied, NULL pointer will free dest.
[in]s_nxSize of the source array, 0 value will free dest.
[out]destDestination array to be filled. The array is reallocated if s_nx does not match d_nx. It is allocated if NULL is provided.
[in]d_nxSize of the source array. If 0, dest is reallocated.
Returns
NULL (if dest has been freed) or the adress of the filled array

◆ re_copy_dvec_1()

double* re_copy_dvec_1 ( double *  src,
int  s_nx,
double *  dest,
int  d_nx 
)

Copy an array of double into another, reallocate the destination if required.

Parameters
[in]srcSource array to be copied, NULL pointer will free dest.
[in]s_nxSize of the source array, 0 value will create a dvec_1 of null size.
[out]destDestination array to be filled. The array is reallocated if s_nx does not match d_nx. It is allocated if NULL is provided.
[in]d_nxSize of the source array.
Returns
NULL (if dest has been freed) or the adress of the filled array

◆ re_copy_ivec_0()

int * re_copy_ivec_0 ( int *  src,
int  s_nx,
int *  dest,
int  d_nx 
)

Copy an array of int into another, reallocate the destination if required.

Parameters
[in]srcSource array to be copied, NULL pointer will free dest.
[in]s_nxSize of the source array, 0 value will create a dvec_1 of null size.
[out]destDestination array to be filled. The array is reallocated if s_nx does not match d_nx. It is allocated if NULL is provided.
[in]d_nxSize of the source array.
Returns
NULL if dest has been freed, the adress of the array otherwhise.

◆ re_copy_ivec_1()

int* re_copy_ivec_1 ( int *  src,
int  s_nx,
int *  dest,
int  d_nx 
)

◆ same_dvec_0()

int same_dvec_0 ( double *  v1,
double *  v2,
int  size 
)

Compare if two vector of floats are the same.

Parameters
[in]v1A vector of floats, starting with index 0.
[in]v2A vector of floats, starting with index 0.
[in]sizeThe number of elements in the arrays.
Returns
1 if vector are the same, 0 otherwise.

◆ same_dvec_1()

int same_dvec_1 ( double *  v1,
double *  v2 
)

Compare if two vector of floats are the same.

Parameters
[in]v1A vector of floats, starting with index 1
[in]v2A vector of floats, starting with index 1
Returns
1 if vector are the same, 0 otherwise.

◆ same_ivec_0()

int same_ivec_0 ( int *  v1,
int *  v2,
int  size 
)

Compare if two vector are the same.

Parameters
[in]v1A vector of integers, starting with index 0.
[in]v2A vector of integers, starting with index 0.
[in]sizeThe number of elements in the arrays.
Returns
1 if vector are the same, 0 otherwise.

◆ same_ivec_1()

int same_ivec_1 ( int *  v1,
int *  v2 
)

Compare if two vector are the same.

Parameters
[in]v1A vector of integers, starting with index 1
[in]v2A vector of integers, starting with index 1
Returns
1 if vector are the same, 0 otherwise.

◆ save_dvec_0()

void save_dvec_0 ( double *  vec,
int  nb_r,
char *  name 
)

save a (x sized) vector of doubles in the specified file, starting with index 0 The file is open with the option "wt"

Parameters
[in]vecthe vector to save, starting with index 0
[in]nb_rthe size of the vector
[in]namethe path an name of the file in which saving the vector

◆ save_ivec_0()

int save_ivec_0 ( int *  vec,
int  size,
char *  name,
int  row 
)

save a (x sized) vector of integers in the specified file, starting with index 0 The file is open with the option "wt"

Parameters
[in]vecThe vector to save, starting with index 0. If the provided pointer is NULL, but a non-null size is given, an error code is generated.
[in]sizeThe size of the vector. If the size is null, an empty file is created.
[in]nameThe path an name of the file in which saving the vector.
[in]rowIf non-zero, the vector is saved as a row in the file (one value per line). Otherwhise the vector is saved on a line.
Returns
status:
  • Negative, error encountered, vector not saved.
  • 0, normal output.

◆ save_ivec_1()

int save_ivec_1 ( int *  vec,
int  size,
char *  name,
int  row 
)

save a (x sized) vector of integers in the specified file, starting with index 0 The file is open with the option "wt"

Parameters
[in]vecThe vector to save, starting with index 0. If the provided pointer is NULL, but a non-null size is given, an error code is generated.
[in]sizeThe size of the vector. If the size is null, an empty file is created.
[in]nameThe path an name of the file in which saving the vector.
[in]rowIf non-zero, the vector is saved as a row in the file (one value per line). Otherwhise the vector is saved on a line.
Returns
status:
  • Negative, error encountered, vector not saved.
  • 0, normal output.

◆ scalar_product()

double scalar_product ( double  v1[4],
double  v2[4] 
)

Compute and return the scalar product of 2 vectors with first index is 1.

The vectors have unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]v1vector of size 4 with first element unused.
[in]v2vector of size 4 with first element unused.
Returns
The scalar product between v1 and v2

◆ scalar_product_0()

double scalar_product_0 ( double *  v1,
double *  v2,
int  n 
)

Compute and return the scalar product of 2 vectors with first index is 0.

The vectors have unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]v1first vector.
[in]v2second vector.
[in]nsize of the vector.
Returns
The scalar product between v1 and v2

◆ slct_dvec_0()

int slct_dvec_0 ( double *  vec1_src,
int  l_v1,
int *  vec_ind_src,
int  l_v2,
double *  vec_dest 
)

fill the third (l_v2 sized) vector by slicing the first (l_v1 sized) vector of doubles at the indexes specified in the second (l_v2 sized) vector, starting with index 0

Parameters
[in]vec1_srcthe vector containing the original values of doubles to be sliced
[in]l_v1the size of the vector vec1_src
[in]vec_ind_srcthe vector containing the indexes of the slices
[in]l_v2the size of the vector vec_ind_src,
[out]vec_destthe sliced vector such as vec_dest[i] = vec1_src[vec_ind_src[i]], starting with index 0. The vector have to be already allocated to a sufficient (l_v2) size.
Returns
0 if no error, -1 if a slice index is over x1, -2 if the slice number is negative.

◆ slct_dvec_1()

void slct_dvec_1 ( double *  vec1_src,
int *  vec_ind_src,
int  l_v,
double *  vec3 
)

fill the third vector by slicing the first vector of doubles at the indexes specified in the second (x sized) vector, starting with index 1

Parameters
[in]vec1_srcthe vector containing the original values of doubles to be sliced
[in]vec_ind_srcthe vector containing the indexes of the slices
[in]l_vthe size of the vector vec_ind_src,
[out]vec3the sliced vector such as for i=1:x { vec3[i] = vec1_src[vec_ind_src[i]] }, starting with index 1. The vector have to be already allocated to a sufficient size.

◆ slct_ivec_0()

int slct_ivec_0 ( int *  vec1_src,
int  l_v1,
int *  vec_ind_src,
int  l_v2,
int *  vec1_dest 
)

fill the third (l_v2 sized) vector by slicing the first (l_v1 sized) vector of integers at the indexes specified in the second (l_v2 sized) vector, starting with index 0

Parameters
[in]vec1_srcthe vector containing the original values to be sliced
[in]l_v1the size of the vector vec1_src
[in]vec_ind_srcthe vector containing the indexes of the slices
[in]l_v2the size of the vector vec_ind_src,
[out]vec_destthe sliced vector such as vec3[i] = vec1_src[vec_ind_src[i]], starting with index 0. The vector have to be already allocated to a sufficient (l_v2) size.
Returns
0 if no error, -1 if a slice index is over x1, -2 if the slice number is negative.

◆ sort_dvec_0()

void sort_dvec_0 ( double *  vec_src,
double *  vec_dest,
int  l_v 
)

sort the first (l_v sized) vector of double into the second vector, starting with index 0

Parameters
[in]vec_srcthe vector to be sorted
[out]vec_destthe sorted vector
[in]l_vthe size of the vectors

◆ sort_inplace_ivec_1()

void sort_inplace_ivec_1 ( int *  vec,
int  l_v 
)

sort and modify the (x sized) vector of integers, starting with index 1 The "Bubble sort" is used, complexity is O(n^2)

Parameters
[in,out]vecthe vector to be sorted
[in]l_vthe size of the vector (0 element not taken into account)

◆ sort_ivec_0()

void sort_ivec_0 ( int *  vec_src,
int *  vec_dest,
int  l_v 
)

sort the first (l_v sized) vector of integers into the second vector, starting with index 0

Parameters
[in]vec_srcthe vector to be sorted
[out]vec_destthe sorted vector
[in]l_vthe size of the vectors

◆ sort_ivec_1()

void sort_ivec_1 ( int *  vec_src,
int *  vec_dest,
int  l_v 
)

sort the first (x sized) vector of integers into the second vector, starting with index 1

Parameters
[in]vec_srcthe vector to be sorted, starting with index 1
[out]vec_destthe sorted vector, starting with index 1
[in]l_vthe size of the vectors (0 element not taken into account)

◆ sum_dvec_0()

void sum_dvec_0 ( double *  v1,
double *  v2,
int  size,
double *  v_dest 
)

Sum each component of 2 array in a third vector.

The vectors starts at index 0. See get_dvec_0() to such vector creation.

Parameters
[in]v1,v2The vector to be summed.
[in]sizesize of the arrays.
[out]v_destResults array suach as $ v_dest_{i} = v1_{i} + v2_{i} $. The results array can be one of the input array.

◆ value_dvec_0()

void value_dvec_0 ( double  value,
double *  vec,
int  l_v 
)

set all the element of a [l_v sized] vector of doubles to a value, starting with index 0

Parameters
[in]valueThe value to be assigned to the vector.
[in]vecthe vector to be nullified, starting with index 0
[in]l_vthe size of the vector

◆ value_dvec_1()

void value_dvec_1 ( double  value,
double *  vec 
)

set all the element of a vector of doubles to zero, starting with index 1

Parameters
[in]valueThe value to be assigned to the vector.
[in,out]vecthe vector to be nullified, starting with index 1

◆ vector_diff()

void vector_diff ( double  v1[4],
double  v2[4],
double  v_dest[4] 
)

Subtract each component of 2 vectors in a third vector. The first index is 1.

The vectors have unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]v1vector of size 4 with first element unused.
[in]v2vector of size 4 with first element unused.
[in,out]vvector of size 4 such as $ v_{i} = v1_{i} - v2_{i} $ with first element unused.

◆ vector_sum()

void vector_sum ( double  v1[4],
double  v2[4],
double  v_dest[4] 
)

Sum each component of 2 vectors in a third vector. The first index is 1.

The vectors have unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]v1vector of size 4 with first element unused.
[in]v2vector of size 4 with first element unused.
[in,out]v_destvector of size 4 such as $ v_dest_{i} = v1_{i} + v2_{i} $

◆ zeros_dvec_0()

void zeros_dvec_0 ( double *  vec,
int  l_v 
)

set all the element of a [l_v sized] vector of doubles to zero, starting with index 0

Parameters
[in]vecthe vector to be nullified, starting with index 0
[in]l_vthe size of the vector

◆ zeros_dvec_1()

void zeros_dvec_1 ( double *  vec)

set all the element of a vector of doubles to zero, starting with index 1

Parameters
[in,out]vecthe vector to be nullified, starting with index 1