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

the library for matrix data manipulation More...

Go to the source code of this file.

Data Structures

struct  s_matrix
 creating matrix data type in this library More...
 

Typedefs

typedef char * p_matrixString_t
 matrix string typedef More...
 
typedef struct s_matrix AgxMatrix
 creating matrix data type in this library More...
 

Functions

AgxMatrixagx_matrix_new (int row, int column)
 create an empty matrix with a certain row and column More...
 
void agx_matrix_delete (AgxMatrix **mat)
 delete matrix More...
 
int agx_matrix_change_elements_by_value (AgxMatrix *mat, double val)
 change all elements of matrix by a value More...
 
AgxMatrixagx_matrix_new_constant (int row, int column, double val)
 create a new matrix with a constant value More...
 
AgxMatrixagx_matrix_new_random (int row, int column, double min, double max)
 create a new matrix with some random values More...
 
AgxMatrixagx_matrix_new_from_array (double *ndarray_in, int dim1, int dim2)
 create a new matrix from C array More...
 
void agx_matrix_to_array (AgxMatrix *mat, double **ndarray_out, int *dim1, int *dim2)
 passing the array reference to ndarray_out More...
 
int agx_matrix_row_col_to_index (AgxMatrix *mat, int row, int col)
 change row and col values to index of array matrix More...
 
int agx_matrix_set_item (AgxMatrix *mat, int row, int col, double val)
 set a value in a corresponding row and column More...
 
int agx_matrix_get_item (AgxMatrix *mat, int row, int col, double *output)
 get the value from matrix based on row and column More...
 
p_matrixString_t agx_matrix_to_string (AgxMatrix *mat, int islong)
 change a matrix to matrix string More...
 
int agx_matrix_print (AgxMatrix *mat, int islong)
 print a matrix in the console with islong parameter More...
 
int agx_matrix_print_partial (AgxMatrix *mat)
 print a matrix in a partial form (islong = 0) More...
 
int agx_matrix_print_full (AgxMatrix *mat)
 print a matrix in a full form (islong = 1) More...
 
int agx_matrix_add_by_value (AgxMatrix *mat, double val)
 adding all elements of matrix by a value More...
 
int agx_matrix_substract_by_value (AgxMatrix *mat, double val)
 substracting all elements of matrix by a value More...
 
int agx_matrix_multiply_by_value (AgxMatrix *mat, double val)
 multiplying all elements of matrix by a value More...
 
int agx_matrix_divide_by_value (AgxMatrix *mat, double val)
 dividing all elements of matrix by a value More...
 
AgxMatrixagx_matrix_new_duplicate_size (AgxMatrix *mat)
 create a new matrix based on the row of col values on another matrix More...
 
int agx_matrix_copy_elements (AgxMatrix *src, AgxMatrix *target)
 copy all elements of the vector to the target vector More...
 
int agx_matrix_copy_shape (AgxMatrix *src, AgxMatrix *target)
 copy shape the vector to the target vector More...
 
int agx_matrix_transpose (AgxMatrix *mat)
 transpose the matrix More...
 
AgxMatrixagx_matrix_new_copy (AgxMatrix *mat)
 copy the matrix More...
 
AgxMatrixagx_matrix_new_from_vector (AgxVector *vec)
 create a new matrix based on the vector More...
 
AgxMatrixagx_matrix_new_identity (int size)
 create a new identity matrix (m x m) More...
 
AgxMatrixagx_matrix_new_zero (int row, int col)
 create a new zero matrix More...
 
AgxMatrixagx_matrix_new_multiplication (AgxMatrix *mat1, AgxMatrix *mat2)
 matrix multiplication and stored in the new matrix More...
 
AgxVectoragx_vector_new_from_matrix (AgxMatrix *mat)
 create a new vector from the matrix More...
 
AgxMatrixagx_matrix_new_extract_column (AgxMatrix *mat, int col)
 create a new matrix based on a certain column values More...
 
AgxMatrixagx_matrix_new_extract_row (AgxMatrix *mat, int row)
 create a new matrix based on a certain row values More...
 
AgxMatrixagx_matrix_new_extract_row_col (AgxMatrix *mat, int row1, int row2, int col1, int col2)
 create a new matrix based on a certain row and column range More...
 
double agx_matrix_min (AgxMatrix *mat)
 look for a minimum value of the matrix More...
 
double agx_matrix_max (AgxMatrix *mat)
 look for a maximum value of the matrix More...
 

Detailed Description

the library for matrix data manipulation

Typedef Documentation

◆ AgxMatrix

typedef struct s_matrix AgxMatrix

creating matrix data type in this library

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

◆ p_matrixString_t

typedef char* p_matrixString_t

matrix 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_matrix_add_by_value()

int agx_matrix_add_by_value ( AgxMatrix mat,
double  val 
)

adding all elements of matrix by a value

Returns
0 if success, -1 if error.

◆ agx_matrix_change_elements_by_value()

int agx_matrix_change_elements_by_value ( AgxMatrix mat,
double  val 
)

change all elements of matrix by a value

Returns
0 if success, -1 if error.

◆ agx_matrix_copy_elements()

int agx_matrix_copy_elements ( AgxMatrix src,
AgxMatrix target 
)

copy all elements of the vector to the target vector

Returns
0 if success, -1 if error.
Note
the col and row values must be the same

◆ agx_matrix_copy_shape()

int agx_matrix_copy_shape ( AgxMatrix src,
AgxMatrix target 
)

copy shape the vector to the target vector

Returns
0 if success, -1 if error.
Note
both matrix must have the same size

◆ agx_matrix_delete()

void agx_matrix_delete ( AgxMatrix **  mat)

delete matrix

◆ agx_matrix_divide_by_value()

int agx_matrix_divide_by_value ( AgxMatrix mat,
double  val 
)

dividing all elements of matrix by a value

Returns
0 if success, -1 if error.

◆ agx_matrix_get_item()

int agx_matrix_get_item ( AgxMatrix mat,
int  row,
int  col,
double *  output 
)

get the value from matrix based on row and column

Returns
0 if success, -1 if error.

◆ agx_matrix_max()

double agx_matrix_max ( AgxMatrix mat)

look for a maximum value of the matrix

◆ agx_matrix_min()

double agx_matrix_min ( AgxMatrix mat)

look for a minimum value of the matrix

◆ agx_matrix_multiply_by_value()

int agx_matrix_multiply_by_value ( AgxMatrix mat,
double  val 
)

multiplying all elements of matrix by a value

Returns
0 if success, -1 if error.

◆ agx_matrix_new()

AgxMatrix* agx_matrix_new ( int  row,
int  column 
)

create an empty matrix with a certain row and column

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

◆ agx_matrix_new_constant()

AgxMatrix* agx_matrix_new_constant ( int  row,
int  column,
double  val 
)

create a new matrix with a constant value

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_copy()

AgxMatrix* agx_matrix_new_copy ( AgxMatrix mat)

copy the matrix

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_duplicate_size()

AgxMatrix* agx_matrix_new_duplicate_size ( AgxMatrix mat)

create a new matrix based on the row of col values on another matrix

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_extract_column()

AgxMatrix* agx_matrix_new_extract_column ( AgxMatrix mat,
int  col 
)

create a new matrix based on a certain column values

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_extract_row()

AgxMatrix* agx_matrix_new_extract_row ( AgxMatrix mat,
int  row 
)

create a new matrix based on a certain row values

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_extract_row_col()

AgxMatrix* agx_matrix_new_extract_row_col ( AgxMatrix mat,
int  row1,
int  row2,
int  col1,
int  col2 
)

create a new matrix based on a certain row and column range

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_from_array()

AgxMatrix* agx_matrix_new_from_array ( double *  ndarray_in,
int  dim1,
int  dim2 
)

create a new matrix from C array

Parameters
dim1equals to row number
dim2equals to column number
Returns
AgxMatrix, NULL if error.
Note
this function is prioritized to be a Python wrapping

◆ agx_matrix_new_from_vector()

AgxMatrix* agx_matrix_new_from_vector ( AgxVector vec)

create a new matrix based on the vector

Returns
AgxMatrix, NULL if error.
Note
it will create a shape (1 x n)

◆ agx_matrix_new_identity()

AgxMatrix* agx_matrix_new_identity ( int  size)

create a new identity matrix (m x m)

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_multiplication()

AgxMatrix* agx_matrix_new_multiplication ( AgxMatrix mat1,
AgxMatrix mat2 
)

matrix multiplication and stored in the new matrix

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_random()

AgxMatrix* agx_matrix_new_random ( int  row,
int  column,
double  min,
double  max 
)

create a new matrix with some random values

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_new_zero()

AgxMatrix* agx_matrix_new_zero ( int  row,
int  col 
)

create a new zero matrix

Returns
AgxMatrix, NULL if error.

◆ agx_matrix_print()

int agx_matrix_print ( AgxMatrix mat,
int  islong 
)

print a matrix in the console with islong parameter

Returns
0 if success, -1 if error.

◆ agx_matrix_print_full()

int agx_matrix_print_full ( AgxMatrix mat)

print a matrix in a full form (islong = 1)

Returns
0 if success, -1 if error.

◆ agx_matrix_print_partial()

int agx_matrix_print_partial ( AgxMatrix mat)

print a matrix in a partial form (islong = 0)

Returns
0 if success, -1 if error.

◆ agx_matrix_row_col_to_index()

int agx_matrix_row_col_to_index ( AgxMatrix mat,
int  row,
int  col 
)

change row and col values to index of array matrix

◆ agx_matrix_set_item()

int agx_matrix_set_item ( AgxMatrix mat,
int  row,
int  col,
double  val 
)

set a value in a corresponding row and column

Returns
0 if success, -1 if error.

◆ agx_matrix_substract_by_value()

int agx_matrix_substract_by_value ( AgxMatrix mat,
double  val 
)

substracting all elements of matrix by a value

Returns
0 if success, -1 if error.

◆ agx_matrix_to_array()

void agx_matrix_to_array ( AgxMatrix mat,
double **  ndarray_out,
int *  dim1,
int *  dim2 
)

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_matrix_to_string()

p_matrixString_t agx_matrix_to_string ( AgxMatrix mat,
int  islong 
)

change a matrix to matrix string

Returns
NULL if error.
Note
you need to delete this manually after using it.

◆ agx_matrix_transpose()

int agx_matrix_transpose ( AgxMatrix mat)

transpose the matrix

Returns
0 if success, -1 if error.

◆ agx_vector_new_from_matrix()

AgxVector* agx_vector_new_from_matrix ( AgxMatrix mat)

create a new vector from the matrix

Returns
AgxVector, NULL if error.