dmlfw (Daniyal Machine Learning Framework)
|
Core double precision matrix types and utilities. More...
#include <dmlfw_types.h>
Go to the source code of this file.
typedef struct __dmlfw_mat_double | dmlfw_mat_double |
Opaque structure representing a double precision matrix. | |
dmlfw_mat_double * | dmlfw_mat_double_clone (dmlfw_mat_double *matrix_to_clone, dmlfw_mat_double *new_matrix) |
Clones a matrix into a new or existing matrix container. | |
void | dmlfw_mat_double_copy (dmlfw_mat_double *target, dmlfw_mat_double *source, index_t target_row_index, index_t target_column_index, index_t source_from_row_index, index_t source_from_column_index, index_t source_to_row_index, index_t source_to_column_index) |
Copies a submatrix from source to target at specified offsets. | |
dmlfw_column_vec_double * | dmlfw_mat_double_create_column_vec (dmlfw_mat_double *matrix, index_t column_index, dmlfw_column_vec_double *vector) |
Creates or fills a column vector from the specified column of the matrix. | |
dmlfw_mat_double * | dmlfw_mat_double_create_identity_matrix (dimension_t rows) |
Creates an identity matrix of specified size. | |
dmlfw_mat_double * | dmlfw_mat_double_create_new (dimension_t rows, dimension_t columns) |
Creates a new matrix with specified rows and columns. | |
dmlfw_mat_double * | dmlfw_mat_double_create_new_random_filled (dimension_t rows, dimension_t columns, double min, double max, dmlfw_mat_double *new_matrix) |
Creates a matrix filled with random values within [min, max]. | |
void | dmlfw_mat_double_destroy (dmlfw_mat_double *matrix) |
Destroys a matrix and frees all associated memory. | |
void | dmlfw_mat_double_fill (dmlfw_mat_double *matrix, index_t from_row_index, index_t from_column_index, index_t to_row_index, index_t to_column_index, double value) |
Fills a subregion of the matrix with the specified value. | |
dmlfw_mat_double * | dmlfw_mat_double_from_csv (const char *csv_file_name, dmlfw_mat_double *matrix, dmlfw_row_vec_string **header) |
Loads a matrix and header from a CSV file. | |
double | dmlfw_mat_double_get (dmlfw_mat_double *matrix, index_t row, index_t column) |
Returns value at a specific matrix position. | |
dmlfw_mat_double * | dmlfw_mat_double_get_block_from_csv (const char *csv_file_name, dmlfw_mat_double *matrix, uint64_t from_row, uint64_t how_many_rows, long *pos) |
Loads a block of rows from a CSV file into a matrix. | |
void | dmlfw_mat_double_get_dimensions (dmlfw_mat_double *matrix, dimension_t *rows, dimension_t *columns) |
Retrieves the matrix dimensions. | |
double | dmlfw_mat_double_get_maximum (dmlfw_mat_double *matrix, index_t start_row_index, index_t start_column_index, index_t end_row_index, index_t end_column_index) |
Finds the maximum value in a specified submatrix region. | |
double | dmlfw_mat_double_get_mean (dmlfw_mat_double *matrix, index_t start_row_index, index_t start_column_index, index_t end_row_index, index_t end_column_index) |
Computes the mean of elements in a specified submatrix region. | |
double | dmlfw_mat_double_get_minimum (dmlfw_mat_double *matrix, index_t start_row_index, index_t start_column_index, index_t end_row_index, index_t end_column_index) |
Finds the minimum value in a specified submatrix region. | |
double | dmlfw_mat_double_get_standard_deviation (dmlfw_mat_double *matrix, index_t start_row_index, index_t start_column_index, index_t end_row_index, index_t end_column_index) |
Calculates the standard deviation of elements in a specified submatrix region. | |
void | dmlfw_mat_double_get_training_testing_data (const char *csv_file_name, dmlfw_mat_double **training_data_matrix, dmlfw_mat_double **testing_data_matrix, uint8_t testing_data_percentage) |
Splits data from a CSV file into training and testing matrices. | |
void | dmlfw_mat_double_insert_columns (dmlfw_mat_double **matrix, index_t at_index, dimension_t number_of_columns) |
Inserts columns into a matrix at a specified index. | |
dmlfw_mat_double * | dmlfw_mat_double_inverse (dmlfw_mat_double *matrix_to_inverse, dmlfw_mat_double *new_matrix) |
Computes the inverse of a square matrix using Gaussian elimination. | |
void | dmlfw_mat_double_left_shift (dmlfw_mat_double *matrix, dimension_t how_many_places_to_shift) |
Left shifts matrix elements by specified number of places. | |
void | dmlfw_mat_double_reshape (dmlfw_mat_double **matrix_to_reshape, dimension_t new_rows_count, dimension_t new_columns_count) |
Reshapes a matrix to new row and column counts. | |
void | dmlfw_mat_double_right_shift (dmlfw_mat_double *matrix, dimension_t how_many_places_to_shift) |
Right shifts matrix elements by specified number of places. | |
void | dmlfw_mat_double_set (dmlfw_mat_double *matrix, index_t row, index_t column, double value) |
Sets value at a specific matrix position. | |
dmlfw_mat_double * | dmlfw_mat_double_shuffle (dmlfw_mat_double *matrix, uint8_t how_many_times_to_shuffle, dmlfw_mat_double *shuffled_matrix) |
Returns a shuffled version of the matrix, shuffling rows specified times. | |
void | dmlfw_mat_double_to_csv (dmlfw_mat_double *matrix, const char *csv_file_name, dmlfw_row_vec_string *header) |
Saves a matrix and its header to a CSV file. | |
dmlfw_mat_double * | dmlfw_mat_double_transpose (dmlfw_mat_double *matrix, dmlfw_mat_double *transposed_matrix) |
Transposes a matrix. | |
void | dmlfw_mat_double_truncate (dmlfw_mat_double **matrix, index_t from_row_index, index_t from_column_index, index_t to_row_index, index_t to_column_index) |
Truncates the specified matrix to a subregion. | |
Core double precision matrix types and utilities.
This header defines opaque matrix structures for double precision floating-point data. It provides APIs for creation, destruction, element access and mutation, CSV import/export, matrix operations such as transpose, reshape, shuffle, block extraction, and statistical functions.
All functions report errors via the centralized error API. Use dmlfw_error()
to check for errors after calls. dmlfw_get_error_string()
and dmlfw_get_debug_string()
provide error information.
Functions returning new matrix pointers transfer ownership to the caller, who is responsible for freeing with dmlfw_mat_double_destroy()
.
dmlfw_mat_double_get_block_from_csv()
which may use one-based indexing (documented explicitly in their parameter list).typedef struct __dmlfw_mat_double dmlfw_mat_double |
Opaque structure representing a double precision matrix.
The internal representation is hidden. Use the provided API functions to create, manipulate, and destroy instances.
dmlfw_mat_double * dmlfw_mat_double_clone | ( | dmlfw_mat_double * | matrix_to_clone, |
dmlfw_mat_double * | new_matrix | ||
) |
Clones a matrix into a new or existing matrix container.
matrix_to_clone | [in] Source matrix (must not be NULL). |
new_matrix | [in,out] Optional existing matrix to reuse, or NULL. |
Usage example:
void dmlfw_mat_double_copy | ( | dmlfw_mat_double * | target, |
dmlfw_mat_double * | source, | ||
index_t | target_row_index, | ||
index_t | target_column_index, | ||
index_t | source_from_row_index, | ||
index_t | source_from_column_index, | ||
index_t | source_to_row_index, | ||
index_t | source_to_column_index | ||
) |
Copies a submatrix from source to target at specified offsets.
target | [in,out] Destination matrix (non-NULL). |
source | [in] Source matrix (non-NULL). |
target_row_index | [in] row index to start copy at in target |
target_column_index | [in] column index to start copy at in target |
source_from_row_index | [in] start row index in source |
source_from_column_index | [in] start column index in source |
source_to_row_index | [in] end row index in source |
source_to_column_index | [in] end column index in source |
Usage example:
dmlfw_column_vec_double * dmlfw_mat_double_create_column_vec | ( | dmlfw_mat_double * | matrix, |
index_t | column_index, | ||
dmlfw_column_vec_double * | vector | ||
) |
Creates or fills a column vector from the specified column of the matrix.
matrix | [in] Matrix (must not be NULL). |
column_index | [in] index of the column to extract. |
vector | [in,out] Optional existing column vector to reuse, or NULL. |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_create_identity_matrix | ( | dimension_t | rows | ) |
Creates an identity matrix of specified size.
rows | [in] Number of rows and columns (square matrix). |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_create_new | ( | dimension_t | rows, |
dimension_t | columns | ||
) |
Creates a new matrix with specified rows and columns.
rows | [in] Number of rows (must be > 0). |
columns | [in] Number of columns (must be > 0). |
dmlfw_mat_double_destroy()
. Usage example:
dmlfw_mat_double * dmlfw_mat_double_create_new_random_filled | ( | dimension_t | rows, |
dimension_t | columns, | ||
double | min, | ||
double | max, | ||
dmlfw_mat_double * | new_matrix | ||
) |
Creates a matrix filled with random values within [min, max].
rows | [in] Number of rows (must be > 0). |
columns | [in] Number of columns (must be > 0). |
min | [in] Minimum random value. |
max | [in] Maximum random value. |
new_matrix | [in,out] Optional existing matrix to reuse, or NULL. |
Usage example:
void dmlfw_mat_double_destroy | ( | dmlfw_mat_double * | matrix | ) |
Destroys a matrix and frees all associated memory.
matrix | [in] Pointer to matrix, or NULL (no-op). |
Usage example:
void dmlfw_mat_double_fill | ( | dmlfw_mat_double * | matrix, |
index_t | from_row_index, | ||
index_t | from_column_index, | ||
index_t | to_row_index, | ||
index_t | to_column_index, | ||
double | value | ||
) |
Fills a subregion of the matrix with the specified value.
matrix | [in,out] Matrix to fill (must not be NULL). |
from_row_index | [in] starting row index of the subregion |
from_column_index | [in] starting column index of the subregion |
to_row_index | [in] ending row index of the subregion |
to_column_index | [in] ending column index of the subregion |
value | [in] The value to fill in the specified subregion |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_from_csv | ( | const char * | csv_file_name, |
dmlfw_mat_double * | matrix, | ||
dmlfw_row_vec_string ** | header | ||
) |
Loads a matrix and header from a CSV file.
csv_file_name | [in] CSV file path (non-NULL). |
matrix | [in,out] Optional matrix to reuse; if NULL a new matrix is allocated. |
header | [out] Pointer to receive newly allocated header (non-NULL). |
Usage example:
double dmlfw_mat_double_get | ( | dmlfw_mat_double * | matrix, |
index_t | row, | ||
index_t | column | ||
) |
Returns value at a specific matrix position.
matrix | [in] Matrix (non-NULL). |
row | [in] row index. |
column | [in] column index. |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_get_block_from_csv | ( | const char * | csv_file_name, |
dmlfw_mat_double * | matrix, | ||
uint64_t | from_row, | ||
uint64_t | how_many_rows, | ||
long * | pos | ||
) |
Loads a block of rows from a CSV file into a matrix.
csv_file_name | [in] Path to the CSV file (non-null). |
matrix | [in,out] Optional matrix to reuse, or NULL. |
from_row | [in] Start row (1-based, first row is 1) |
how_many_rows | [in] Number of rows to load. |
pos | [in,out] Optional file position pointer for resuming read, pass NULL if not used. |
Usage example:
void dmlfw_mat_double_get_dimensions | ( | dmlfw_mat_double * | matrix, |
dimension_t * | rows, | ||
dimension_t * | columns | ||
) |
Retrieves the matrix dimensions.
matrix | [in] Matrix (non-NULL). |
rows | [out] Pointer to store row count (non-NULL). |
columns | [out] Pointer to store column count (non-NULL). |
Usage example:
double dmlfw_mat_double_get_maximum | ( | dmlfw_mat_double * | matrix, |
index_t | start_row_index, | ||
index_t | start_column_index, | ||
index_t | end_row_index, | ||
index_t | end_column_index | ||
) |
Finds the maximum value in a specified submatrix region.
matrix | [in] Matrix (must not be NULL). |
start_row_index | [in] starting row |
start_column_index | [in] starting column |
end_row_index | [in] ending row |
end_column_index | [in] ending column |
double dmlfw_mat_double_get_mean | ( | dmlfw_mat_double * | matrix, |
index_t | start_row_index, | ||
index_t | start_column_index, | ||
index_t | end_row_index, | ||
index_t | end_column_index | ||
) |
Computes the mean of elements in a specified submatrix region.
matrix | [in] Matrix (must not be NULL). |
start_row_index | [in] starting row |
start_column_index | [in] starting column |
end_row_index | [in] ending row |
end_column_index | [in] ending column |
Usage example:
double dmlfw_mat_double_get_minimum | ( | dmlfw_mat_double * | matrix, |
index_t | start_row_index, | ||
index_t | start_column_index, | ||
index_t | end_row_index, | ||
index_t | end_column_index | ||
) |
Finds the minimum value in a specified submatrix region.
matrix | [in] Matrix (must not be NULL). |
start_row_index | [in] starting row |
start_column_index | [in] starting column |
end_row_index | [in] ending row |
end_column_index | [in] ending column |
double dmlfw_mat_double_get_standard_deviation | ( | dmlfw_mat_double * | matrix, |
index_t | start_row_index, | ||
index_t | start_column_index, | ||
index_t | end_row_index, | ||
index_t | end_column_index | ||
) |
Calculates the standard deviation of elements in a specified submatrix region.
matrix | [in] Matrix (must not be NULL). |
start_row_index | [in] starting row |
start_column_index | [in] starting column |
end_row_index | [in] ending row |
end_column_index | [in] ending column |
Usage example:
void dmlfw_mat_double_get_training_testing_data | ( | const char * | csv_file_name, |
dmlfw_mat_double ** | training_data_matrix, | ||
dmlfw_mat_double ** | testing_data_matrix, | ||
uint8_t | testing_data_percentage | ||
) |
Splits data from a CSV file into training and testing matrices.
csv_file_name | [in] Path to CSV file (must not be NULL). |
training_data_matrix | [out] Pointer to hold training data matrix. |
testing_data_matrix | [out] Pointer to hold testing data matrix. |
testing_data_percentage | [in] Percentage (0-100) of data for testing. |
Usage example:
void dmlfw_mat_double_insert_columns | ( | dmlfw_mat_double ** | matrix, |
index_t | at_index, | ||
dimension_t | number_of_columns | ||
) |
Inserts columns into a matrix at a specified index.
matrix | [in,out] Pointer to matrix pointer to modify. |
at_index | [in] column index at which to insert |
number_of_columns | [in] Number of columns to insert |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_inverse | ( | dmlfw_mat_double * | matrix_to_inverse, |
dmlfw_mat_double * | new_matrix | ||
) |
Computes the inverse of a square matrix using Gaussian elimination.
matrix_to_inverse | [in] Matrix to invert (must not be NULL, square). |
new_matrix | [in,out] Optional container to store inverse, or NULL to allocate. |
Usage example:
void dmlfw_mat_double_left_shift | ( | dmlfw_mat_double * | matrix, |
dimension_t | how_many_places_to_shift | ||
) |
Left shifts matrix elements by specified number of places.
matrix | [in,out] Matrix to shift (must not be NULL). |
how_many_places_to_shift | [in] Number of positions to shift left (must be > 0). |
Usage example:
void dmlfw_mat_double_reshape | ( | dmlfw_mat_double ** | matrix_to_reshape, |
dimension_t | new_rows_count, | ||
dimension_t | new_columns_count | ||
) |
Reshapes a matrix to new row and column counts.
matrix_to_reshape | [in,out] Pointer to matrix pointer to reshape. |
new_rows_count | [in] New number of rows (must be > 0). |
new_columns_count | [in] New number of columns (must be > 0). |
Usage example:
void dmlfw_mat_double_right_shift | ( | dmlfw_mat_double * | matrix, |
dimension_t | how_many_places_to_shift | ||
) |
Right shifts matrix elements by specified number of places.
matrix | [in,out] Matrix to shift (must not be NULL). |
how_many_places_to_shift | [in] Number of positions to shift right (must be > 0). |
Usage example:
void dmlfw_mat_double_set | ( | dmlfw_mat_double * | matrix, |
index_t | row, | ||
index_t | column, | ||
double | value | ||
) |
Sets value at a specific matrix position.
matrix | [in,out] Matrix (non-NULL). |
row | [in] row index. |
column | [in] column index. |
value | [in] Value to set. |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_shuffle | ( | dmlfw_mat_double * | matrix, |
uint8_t | how_many_times_to_shuffle, | ||
dmlfw_mat_double * | shuffled_matrix | ||
) |
Returns a shuffled version of the matrix, shuffling rows specified times.
matrix | [in] Source matrix (must not be NULL). |
how_many_times_to_shuffle | [in] Number of shuffle iterations (non-zero). |
shuffled_matrix | [in,out] Optional matrix to receive shuffled output, or NULL. |
Usage example:
void dmlfw_mat_double_to_csv | ( | dmlfw_mat_double * | matrix, |
const char * | csv_file_name, | ||
dmlfw_row_vec_string * | header | ||
) |
Saves a matrix and its header to a CSV file.
matrix | [in] Matrix to save (must not be NULL). |
csv_file_name | [in] Output CSV file path (must not be NULL). |
header | [in] Row vector header (must not be NULL). |
Usage example:
dmlfw_mat_double * dmlfw_mat_double_transpose | ( | dmlfw_mat_double * | matrix, |
dmlfw_mat_double * | transposed_matrix | ||
) |
Transposes a matrix.
matrix | [in] Matrix to transpose (must not be NULL). |
transposed_matrix | [in,out] Optional matrix to receive transpose, or NULL. |
Usage example:
void dmlfw_mat_double_truncate | ( | dmlfw_mat_double ** | matrix, |
index_t | from_row_index, | ||
index_t | from_column_index, | ||
index_t | to_row_index, | ||
index_t | to_column_index | ||
) |
Truncates the specified matrix to a subregion.
matrix | [in,out] Pointer to matrix pointer to modify. |
from_row_index | [in] starting row index |
from_column_index | [in] starting column index |
to_row_index | [in] ending row index |
to_column_index | [in] ending column index |
Usage example: