Angka  0.0.1
A C library focusing on data manipulation and visualization
vector.h File Reference

the library for vector data manipulation More...

Go to the source code of this file.

Data Structures

struct  s_vector
 creating vector data type in this library More...
 

Typedefs

typedef char * p_vectorString_t
 vector string typedef More...
 
typedef struct s_vector AgxVector
 creating vector data type in this library More...
 

Functions

AgxVectoragx_vector_new (int size)
 create an empty vector with a certain size More...
 
int agx_vector_set_item (AgxVector *vec, int index, double val)
 set value in a certain element of vector More...
 
int agx_vector_get_item (AgxVector *vec, int index, double *output)
 get value in a certain element of vector More...
 
p_vectorString_t agx_vector_to_string (AgxVector *vec, int islong)
 convert vector to string using malloc More...
 
void agx_vector_delete (AgxVector **vec)
 delete vector More...
 
AgxVectoragx_vector_new_random (int size, double min, double max)
 create a vector with random values More...
 
AgxVectoragx_vector_new_from_array (double *ndarray_in, int size)
 create a new vector from C array More...
 
void agx_vector_to_array (AgxVector *vec, double **ndarray_out, int *size)
 passing the array reference to ndarray_out More...
 
int agx_vector_print (AgxVector *vec, int islong)
 print vector in the console More...
 
int agx_vector_append_value (AgxVector *vec, double val)
 append vector with a value in the end of vector array More...
 
int agx_vector_append_vector (AgxVector *vec_target, AgxVector *vec_another)
 append vector with another vector and overwriting More...
 
int agx_vector_print_partial (AgxVector *vec)
 print the partial of vector More...
 
int agx_vector_print_full (AgxVector *vec)
 print the full of vector More...
 
int agx_vector_add_by_value (AgxVector *vec, double val)
 adding all elements of vector by a value More...
 
int agx_vector_substract_by_value (AgxVector *vec, double val)
 substracting all elements of vector by a value More...
 
int agx_vector_multiply_by_value (AgxVector *vec, double val)
 multiplying all elements of vector by a value More...
 
int agx_vector_divide_by_value (AgxVector *vec, double val)
 dividing all elements of vector by a value More...
 
int agx_vector_change_elements_by_value (AgxVector *vec, double val)
 changing all elements of vector by a value More...
 
AgxVectoragx_vector_new_constant (int size, double val)
 create agx_vector_new with a constant value More...
 
AgxVectoragx_vector_new_duplicate_size (AgxVector *vec)
 create agx_vector_new by using the size of another vector More...
 
int agx_vector_copy_elements (AgxVector *src, AgxVector *target)
 copy all elements of a vector to a target vector More...
 
AgxVectoragx_vector_new_copy (AgxVector *vec)
 create agx_vector_new by copying another vector More...
 
AgxVectoragx_vector_new_zero (int size)
 create agx_vector_new_constant with zero value More...
 
AgxVectoragx_vector_new_linspace (double min, double max, int size)
 create a new range vector by using the size value More...
 
AgxVectoragx_vector_new_arange (int min, int step, int max)
 create a new range vector using the interval value More...
 
AgxVectoragx_vector_new_arange_double (double min, double step, double max)
 create a new range vector using the interval value More...
 
double agx_vector_min (AgxVector *vec)
 looking for the minimum value of vector More...
 
double agx_vector_max (AgxVector *vec)
 looking for the maximum value of vector More...
 
AgxVectoragx_vector_new_values (double *array, int size)
 create a vector from C array More...
 
void agx_vector_input_function (AgxVector *vec, void(*function)(double *))
 change each element of vector based on a certain function More...
 
void agx_vector_sin (AgxVector *vec)
 the sinus of each element of the vector More...
 
void agx_sin (double *val)
 the double sinus More...
 
int agx_vector_isexist (AgxVector *vec, int idx1, int idx2, double val)
 checking a value is exist on the vector in a certain indexes range More...
 
int agx_vector_sort (AgxVector *vec)
 sorting the elements of vector from minimum to maximum More...
 

Detailed Description

the library for vector data manipulation

Typedef Documentation

◆ AgxVector

typedef struct s_vector AgxVector

creating vector data type in this library

after this struct is created, we need to delete unused using agx_vector_delete. Usually we call this struct using its typedef AgxVector

◆ p_vectorString_t

typedef char* p_vectorString_t

vector string typedef

it is used for indentifying that this typedef need to be delete in memory before quit a program. Deleting this type can use agx_data_delete in standard.h.

Function Documentation

◆ agx_sin()

void agx_sin ( double *  val)

the double sinus

◆ agx_vector_add_by_value()

int agx_vector_add_by_value ( AgxVector vec,
double  val 
)

adding all elements of vector by a value

Returns
0 if success, -1 if error.

◆ agx_vector_append_value()

int agx_vector_append_value ( AgxVector vec,
double  val 
)

append vector with a value in the end of vector array

Returns
-1 if error, 0 if success.

◆ agx_vector_append_vector()

int agx_vector_append_vector ( AgxVector vec_target,
AgxVector vec_another 
)

append vector with another vector and overwriting

Returns
0 if success, -1 if error.

◆ agx_vector_change_elements_by_value()

int agx_vector_change_elements_by_value ( AgxVector vec,
double  val 
)

changing all elements of vector by a value

Returns
0 if success, -1 if error.

◆ agx_vector_copy_elements()

int agx_vector_copy_elements ( AgxVector src,
AgxVector target 
)

copy all elements of a vector to a target vector

Returns
0 if success, -1 if error.
Note
both vectors must be the same size

◆ agx_vector_delete()

void agx_vector_delete ( AgxVector **  vec)

delete vector

◆ agx_vector_divide_by_value()

int agx_vector_divide_by_value ( AgxVector vec,
double  val 
)

dividing all elements of vector by a value

Returns
0 if success, -1 if error.

◆ agx_vector_get_item()

int agx_vector_get_item ( AgxVector vec,
int  index,
double *  output 
)

get value in a certain element of vector

Parameters
outputis the output of getting the value.
Returns
-1 if error, 0 if success.

◆ agx_vector_input_function()

void agx_vector_input_function ( AgxVector vec,
void(*)(double *)  function 
)

change each element of vector based on a certain function

Note
the input of function should be only one and double pointer

◆ agx_vector_isexist()

int agx_vector_isexist ( AgxVector vec,
int  idx1,
int  idx2,
double  val 
)

checking a value is exist on the vector in a certain indexes range

Note
index i where idx1 <= i <= idx2

◆ agx_vector_max()

double agx_vector_max ( AgxVector vec)

looking for the maximum value of vector

◆ agx_vector_min()

double agx_vector_min ( AgxVector vec)

looking for the minimum value of vector

◆ agx_vector_multiply_by_value()

int agx_vector_multiply_by_value ( AgxVector vec,
double  val 
)

multiplying all elements of vector by a value

Returns
0 if success, -1 if error.

◆ agx_vector_new()

AgxVector* agx_vector_new ( int  size)

create an empty vector with a certain size

Note
we can use agx_vector_new_zero to make sure that the initial value for each element is zero.
Returns
NULL if cannot be allocated

◆ agx_vector_new_arange()

AgxVector* agx_vector_new_arange ( int  min,
int  step,
int  max 
)

create a new range vector using the interval value

Parameters
stepthe interval value
Returns
AgxVector, NULL if error.
Note
the input is integer and the output is a double array

◆ agx_vector_new_arange_double()

AgxVector* agx_vector_new_arange_double ( double  min,
double  step,
double  max 
)

create a new range vector using the interval value

Parameters
stepthe interval value
Returns
AgxVector, NULL if error.
Note
the input is double and the output is a double array

◆ agx_vector_new_constant()

AgxVector* agx_vector_new_constant ( int  size,
double  val 
)

create agx_vector_new with a constant value

Returns
AgxVector, NULL if error.

◆ agx_vector_new_copy()

AgxVector* agx_vector_new_copy ( AgxVector vec)

create agx_vector_new by copying another vector

Returns
AgxVector, NULL if error.

◆ agx_vector_new_duplicate_size()

AgxVector* agx_vector_new_duplicate_size ( AgxVector vec)

create agx_vector_new by using the size of another vector

Returns
AgxVector, NULL if error.

◆ agx_vector_new_from_array()

AgxVector* agx_vector_new_from_array ( double *  ndarray_in,
int  size 
)

create a new vector from C array

Note
return NULL if cannot be allocated

◆ agx_vector_new_linspace()

AgxVector* agx_vector_new_linspace ( double  min,
double  max,
int  size 
)

create a new range vector by using the size value

Returns
AgxVector, NULL if error.

◆ agx_vector_new_random()

AgxVector* agx_vector_new_random ( int  size,
double  min,
double  max 
)

create a vector with random values

Note
return NULL if cannot be allocated.

◆ agx_vector_new_values()

AgxVector* agx_vector_new_values ( double *  array,
int  size 
)

create a vector from C array

Returns
AgxVector, NULL if error.

◆ agx_vector_new_zero()

AgxVector* agx_vector_new_zero ( int  size)

create agx_vector_new_constant with zero value

Returns
AgxVector, NULL if error.

◆ agx_vector_print()

int agx_vector_print ( AgxVector vec,
int  islong 
)

print vector in the console

it is using agx_vector_to_string to create a string vector and this function has automatically delete the return of agx_vector_to_string

Parameters
islongBOOLEAN for deciding that it is partial (0) or full vector (1) that need to be printed
Note
return -1 if error, 0 if success.

◆ agx_vector_print_full()

int agx_vector_print_full ( AgxVector vec)

print the full of vector

it is based on agx_vector_print with islong = 1

Returns
0 if success, -1 if error.

◆ agx_vector_print_partial()

int agx_vector_print_partial ( AgxVector vec)

print the partial of vector

it is based on agx_vector_print with islong = 0

Returns
0 if success, -1 if error.

◆ agx_vector_set_item()

int agx_vector_set_item ( AgxVector vec,
int  index,
double  val 
)

set value in a certain element of vector

Parameters
vecoverwrite the existing vector
indexthe index of vector
valthe value for that index
Returns
negative value if error, 0 if success.

◆ agx_vector_sin()

void agx_vector_sin ( AgxVector vec)

the sinus of each element of the vector

◆ agx_vector_sort()

int agx_vector_sort ( AgxVector vec)

sorting the elements of vector from minimum to maximum

Returns
0 if success, -1 if error.

◆ agx_vector_substract_by_value()

int agx_vector_substract_by_value ( AgxVector vec,
double  val 
)

substracting all elements of vector by a value

Returns
0 if success, -1 if error.

◆ agx_vector_to_array()

void agx_vector_to_array ( AgxVector vec,
double **  ndarray_out,
int *  size 
)

passing the array reference to ndarray_out

Warning
it is still not recommended to use it, especially after wrapping to Python due to being not able to deal with the data malloc in ndarray_out

◆ agx_vector_to_string()

p_vectorString_t agx_vector_to_string ( AgxVector vec,
int  islong 
)

convert vector to string using malloc

it is used for saving the string before put in the print function

Note
we need to delete this manually using agx_data_delete because it remains in memory. return NULL if error.