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_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 norm (double v[4])
 DEPRECATED: See norm_dvec_1(). More...
 
void normalize (double v[4], double vn[4])
 DEPRECATED: See normalize_dvec_1() 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 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 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...
 
double norm_dvec_0 (double *vec, int l_v)
 compute the norm of a [l_v sized] vector of doubles, starting with index 0 More...
 
double norm_dvec_1 (double *vec, int l_v)
 compute the norm of a [l_v sized] vector of doubles, starting with index 1 More...
 
void normalize_dvec_0 (double *vec, double *vn, int l_v)
 Compute the normalize vector with starting with index 0. More...
 
void normalize_dvec_1 (double *vec, double *vn, int l_v)
 Compute the normalize vector with first index is 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...
 

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.

◆ 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)

◆ 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.

◆ norm()

double norm ( double  v[4])

DEPRECATED: See norm_dvec_1().

Compute the Euclidean norm of a double vector with first index is 1. The vector has unused index 0. See get_dvec_1() to such vector creation.

Parameters
[in]vvector of size 4 with first element unused.
Returns
The norm of the vector v.

◆ norm_dvec_0()

double norm_dvec_0 ( double *  vec,
int  l_v 
)

compute the norm of a [l_v sized] vector of doubles, starting with index 0

Parameters
[in]vecthe vector of doubles
[in]l_vthe size of the vector
Returns
the norm of the vector: $ \sqrt { \sum {(vec_{i}^{2})}} $

◆ norm_dvec_1()

double norm_dvec_1 ( double *  vec,
int  l_v 
)

compute the norm of a [l_v sized] vector of doubles, starting with index 1

Parameters
[in]vecthe vector of doubles
[in]l_vthe size of the vector (0 element not taken into account)
Returns
the norm of the vector: $ \sqrt { \sum_{i=1}^{i=x} {(vec_{i}^{2})}} $

◆ normalize()

void normalize ( double  v[4],
double  vn[4] 
)

DEPRECATED: See normalize_dvec_1()

Compute the normalize vector with first index is 1. The vector has unused index 0. See get_dvec_1() to such vector creation.
WARNING: if norm(v) is 0, a division by 0 will occurs.

Parameters
[in]vvector of size 4 with first element unused.
[in,out]vnthe normalized vector v, index starting at 1.

◆ normalize_dvec_0()

void normalize_dvec_0 ( double *  vec,
double *  vn,
int  l_v 
)

Compute the normalize vector with starting with index 0.

WARNING: if the norm of vec is 0, a division by 0 will occurs.

Parameters
[in]vecvector of double to be normalized.
[in,out]vnthe normalized vector vec.
[in]l_vthe size of the vector.

◆ normalize_dvec_1()

void normalize_dvec_1 ( double *  vec,
double *  vn,
int  l_v 
)

Compute the normalize vector with first index is 1.

The vector has unused index 0. See get_dvec_1() to such vector creation.
WARNING: if norm(v) is 0, a division by 0 will occurs.

Parameters
[in]vecvector of double to be normalized with first element unused.
[in,out]vnthe normalized vector vec, with first element unused.
[in]l_vthe size of the vector (0 element not taken into account)

◆ 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.

◆ 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)

◆ 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