dmlfw (Daniyal Machine Learning Framework)

Core double precision matrix types and utilities. More...

#include <dmlfw_types.h>
Include dependency graph for dmlfw_mat_double.h:
This graph shows which files directly or indirectly include this file:

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_doubledmlfw_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_doubledmlfw_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_doubledmlfw_mat_double_create_identity_matrix (dimension_t rows)
 Creates an identity matrix of specified size.
 
dmlfw_mat_doubledmlfw_mat_double_create_new (dimension_t rows, dimension_t columns)
 Creates a new matrix with specified rows and columns.
 
dmlfw_mat_doubledmlfw_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_doubledmlfw_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_doubledmlfw_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_doubledmlfw_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_doubledmlfw_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_doubledmlfw_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.
 

Detailed Description

Core double precision matrix types and utilities.

Version
1.0
Date
2025-09-25

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.

Error Handling:

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.

Ownership:

Functions returning new matrix pointers transfer ownership to the caller, who is responsible for freeing with dmlfw_mat_double_destroy().

Indexing Notes:

Typedef Documentation

◆ dmlfw_mat_double

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.

Function Documentation

◆ dmlfw_mat_double_clone()

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.

Parameters
matrix_to_clone[in] Source matrix (must not be NULL).
new_matrix[in,out] Optional existing matrix to reuse, or NULL.
Returns
Pointer to cloned matrix, or NULL on error.
See also
dmlfw_mat_double_destroy
Note
Caller must free returned matrix if newly allocated.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error cloning matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
void dmlfw_get_error_string(char *error_string, uint32_t size)
Copies the last error message into the provided character buffer.
uint8_t dmlfw_error(void)
Checks if the last framework call resulted in an error.
void dmlfw_get_debug_string(char *debug_string, uint32_t size)
Copies detailed debug information about the last error into the provided character buffer.
struct __dmlfw_mat_double dmlfw_mat_double
Opaque structure representing a double precision matrix.
Definition dmlfw_mat_double.h:73
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_destroy(dmlfw_mat_double *matrix)
Destroys a matrix and frees all associated memory.

◆ dmlfw_mat_double_copy()

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.

Parameters
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
See also
dmlfw_mat_double_clone

Usage example:

dmlfw_mat_double_copy(dest, src, 0, 0, 1, 1, 3, 3);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error copying matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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_mat_double_create_column_vec()

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.

Parameters
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.
Returns
Pointer to the column vector containing the specified column, or NULL if an error occurs.
See also
dmlfw_mat_double_create_new
Note
If vector is NULL, a new one is allocated and ownership is transferred to caller.
Check errors with the centralized error API after the call.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error creating column vector: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.
void dmlfw_column_vec_double_destroy(dmlfw_column_vec_double *vector)
Destroys a column vector and frees its memory.
struct __dmlfw_column_vec_double dmlfw_column_vec_double
Opaque structure representing a column vector of doubles.
Definition dmlfw_vec_double.h:83

◆ dmlfw_mat_double_create_identity_matrix()

dmlfw_mat_double * dmlfw_mat_double_create_identity_matrix ( dimension_t  rows)

Creates an identity matrix of specified size.

Parameters
rows[in] Number of rows and columns (square matrix).
Returns
Pointer to identity matrix, or NULL on error.
See also
dmlfw_mat_double_destroy
Note
Caller must free the matrix with dmlfw_mat_double_destroy().

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error creating identity matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
dmlfw_mat_double * dmlfw_mat_double_create_identity_matrix(dimension_t rows)
Creates an identity matrix of specified size.

◆ dmlfw_mat_double_create_new()

dmlfw_mat_double * dmlfw_mat_double_create_new ( dimension_t  rows,
dimension_t  columns 
)

Creates a new matrix with specified rows and columns.

Parameters
rows[in] Number of rows (must be > 0).
columns[in] Number of columns (must be > 0).
Returns
Pointer to new matrix, or NULL if allocation fails or invalid args.
See also
dmlfw_mat_double_destroy
Note
Caller must free with dmlfw_mat_double_destroy().
Check errors with the centralized error API.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Create failed: %s\nDebug: %s\n", err, dbg);
return EXIT_FAILURE;
}
dmlfw_mat_double * dmlfw_mat_double_create_new(dimension_t rows, dimension_t columns)
Creates a new matrix with specified rows and columns.
Examples
example_dmlfw_error.c, and example_dmlfw_mat_double.c.

◆ dmlfw_mat_double_create_new_random_filled()

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

Parameters
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.
Returns
Pointer to created matrix, or NULL on error.
See also
dmlfw_mat_double_destroy
Note
Caller must free returned matrix.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error creating random matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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].

◆ dmlfw_mat_double_destroy()

void dmlfw_mat_double_destroy ( dmlfw_mat_double matrix)

Destroys a matrix and frees all associated memory.

Parameters
matrix[in] Pointer to matrix, or NULL (no-op).
See also
dmlfw_mat_double_create_new

Usage example:

Examples
example_dmlfw_error.c, example_dmlfw_mat_double.c, and example_dmlfw_scale_double.c.

◆ dmlfw_mat_double_fill()

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.

Parameters
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
See also
dmlfw_mat_double_get
dmlfw_mat_double_set
Note
Indices are clamped if out-of-bounds.
Error status is set if ranges are invalid or matrix is NULL.

Usage example:

char err[512], dbg[512];
dmlfw_mat_double_fill(mat, 1, 1, 3, 3, 5.5);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error filling matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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_from_csv()

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.

Parameters
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).
Returns
Pointer to loaded matrix, or NULL on error.
Note
Caller must free returned matrix and header.
Header is always a row vector.
Check errors with the centralized error API.

Usage example:

char err[512], dbg[512];
dmlfw_mat_double *mat = NULL;
dmlfw_row_vec_string *header = NULL;
mat = dmlfw_mat_double_from_csv("data.csv", NULL, &header);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Load failed: %s\nDebug: %s\n", err, dbg);
return EXIT_FAILURE;
}
dmlfw_vec_string_destroy(header);
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.
struct __dmlfw_row_vec_string dmlfw_row_vec_string
Opaque structure representing a row vector of strings.
Definition dmlfw_vec_string.h:82

◆ dmlfw_mat_double_get()

double dmlfw_mat_double_get ( dmlfw_mat_double matrix,
index_t  row,
index_t  column 
)

Returns value at a specific matrix position.

Parameters
matrix[in] Matrix (non-NULL).
row[in] row index.
column[in] column index.
Returns
Value at position or 0.0 if error.
See also
dmlfw_mat_double_set
Note
Checks bounds and errors.

Usage example:

double val = dmlfw_mat_double_get(mat, 1, 2);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Failed to retrieve value from (1,2) : %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
printf("Value: %lf\n", val);
double dmlfw_mat_double_get(dmlfw_mat_double *matrix, index_t row, index_t column)
Returns value at a specific matrix position.
Examples
example_dmlfw_mat_double.c.

◆ dmlfw_mat_double_get_block_from_csv()

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.

Parameters
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.
Returns
Pointer to loaded matrix, or NULL on error.
See also
dmlfw_mat_double_from_csv
Note
Caller frees returned matrix.

Usage example:

char err[512], dbg[512];
dmlfw_mat_double *block = dmlfw_mat_double_get_block_from_csv("data.csv", NULL, 1, 10, NULL);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error loading CSV block: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.

◆ dmlfw_mat_double_get_dimensions()

void dmlfw_mat_double_get_dimensions ( dmlfw_mat_double matrix,
dimension_t rows,
dimension_t columns 
)

Retrieves the matrix dimensions.

Parameters
matrix[in] Matrix (non-NULL).
rows[out] Pointer to store row count (non-NULL).
columns[out] Pointer to store column count (non-NULL).
See also
dmlfw_mat_double_create_new

Usage example:

dimension_t rows, cols;
void dmlfw_mat_double_get_dimensions(dmlfw_mat_double *matrix, dimension_t *rows, dimension_t *columns)
Retrieves the matrix dimensions.
uint32_t dimension_t
Represents the size or dimension of a data structure (uint32_t).
Definition dmlfw_types.h:26

◆ dmlfw_mat_double_get_maximum()

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.

Parameters
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
Returns
Maximum value in the submatrix or 0.0 if error occurred.
Note
Indices are clamped to valid ranges.
Check errors using the centralized error API.

◆ dmlfw_mat_double_get_mean()

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.

Parameters
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
Returns
Mean value or 0.0 if an error occurred.
See also
dmlfw_mat_double_get_standard_deviation
Note
Indices are clamped to valid ranges.
Check errors using the centralized error API.

Usage example:

char err[512], dbg[512];
double mean_val = dmlfw_mat_double_get_mean(mat, 0, 0, 4, 4);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error computing mean: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
else {
printf("Mean value: %lf\n", mean_val);
}
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.

◆ dmlfw_mat_double_get_minimum()

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.

Parameters
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
Returns
Minimum value or 0.0 if an error occurred.

◆ dmlfw_mat_double_get_standard_deviation()

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.

Parameters
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
Returns
Standard deviation or 0.0 if an error occurred.
See also
dmlfw_mat_double_get_mean
Note
Indices are clamped.
Check errors using the centralized error API.

Usage example:

char err[512], dbg[512];
double std_dev = dmlfw_mat_double_get_standard_deviation(mat, 0, 0, 4, 4);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error computing standard deviation: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
else {
printf("Standard deviation: %lf\n", std_dev);
}
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.

◆ dmlfw_mat_double_get_training_testing_data()

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.

Parameters
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.
See also
dmlfw_mat_double_from_csv
Note
Caller is responsible for destroying returned matrices.
Check errors using the centralized error API.

Usage example:

char err[512], dbg[512];
dmlfw_mat_double *train = NULL;
dmlfw_mat_double *test = NULL;
dmlfw_mat_double_get_training_testing_data("dataset.csv", &train, &test, 20);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error splitting dataset: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
else {
// use train and test...
}
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.

◆ dmlfw_mat_double_insert_columns()

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.

Parameters
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
See also
dmlfw_mat_double_clone

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error inserting columns: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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_inverse()

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.

Parameters
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.
Returns
Pointer to inverse matrix, or NULL if error.
See also
dmlfw_mat_double_create_new
dmlfw_mat_double_clone
Note
Caller must free returned matrix.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error computing inverse: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.

◆ dmlfw_mat_double_left_shift()

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.

Parameters
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).
See also
dmlfw_mat_double_right_shift
Note
Vacated positions are set to zero.
Error is set if invalid parameters.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error in left shift: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.

◆ dmlfw_mat_double_reshape()

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.

Parameters
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).
See also
dmlfw_mat_double_clone
Note
Original matrix is destroyed and replaced on success.
Sets error and NULLs pointer if failure occurs.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error reshaping matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.

◆ dmlfw_mat_double_right_shift()

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.

Parameters
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).
See also
dmlfw_mat_double_left_shift
Note
Vacated positions are set to zero.
Error is set if invalid parameters.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error in right shift: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.

◆ dmlfw_mat_double_set()

void dmlfw_mat_double_set ( dmlfw_mat_double matrix,
index_t  row,
index_t  column,
double  value 
)

Sets value at a specific matrix position.

Parameters
matrix[in,out] Matrix (non-NULL).
row[in] row index.
column[in] column index.
value[in] Value to set.
See also
dmlfw_mat_double_get
Note
Checks bounds and errors.

Usage example:

dmlfw_mat_double_set(mat, 1, 2, 3.14);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Failed to set value at (1,2) : %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
void dmlfw_mat_double_set(dmlfw_mat_double *matrix, index_t row, index_t column, double value)
Sets value at a specific matrix position.
Examples
example_dmlfw_mat_double.c.

◆ dmlfw_mat_double_shuffle()

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.

Parameters
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.
Returns
Pointer to matrix containing shuffled rows, or NULL if an error occurs.
See also
dmlfw_mat_double_clone
Note
If shuffled_matrix is NULL, a new matrix is allocated and ownership is transferred.
Check errors with the centralized error API after the call.

Usage example:

char err[512], dbg[512];
dmlfw_mat_double *shuffled = dmlfw_mat_double_shuffle(mat, 10, NULL);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error shuffling matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.

◆ dmlfw_mat_double_to_csv()

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.

Parameters
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).
See also
dmlfw_mat_double_from_csv
Note
File is overwritten if it exists.
Header row vector size must exactly match the number of matrix columns.
Check errors with the centralized error API after the call.

Usage example:

char err[512], dbg[512];
dmlfw_mat_double_to_csv(mat, "output.csv", header);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error exporting matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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_transpose()

dmlfw_mat_double * dmlfw_mat_double_transpose ( dmlfw_mat_double matrix,
dmlfw_mat_double transposed_matrix 
)

Transposes a matrix.

Parameters
matrix[in] Matrix to transpose (must not be NULL).
transposed_matrix[in,out] Optional matrix to receive transpose, or NULL.
Returns
Pointer to the transposed matrix or NULL on error.
See also
dmlfw_mat_double_clone
Note
Caller owns newly created matrices.
Check errors with the centralized error API after the call.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error transposing matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
dmlfw_mat_double * dmlfw_mat_double_transpose(dmlfw_mat_double *matrix, dmlfw_mat_double *transposed_matrix)
Transposes a matrix.

◆ dmlfw_mat_double_truncate()

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.

Parameters
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
See also
dmlfw_mat_double_clone

Usage example:

char err[512], dbg[512];
dmlfw_mat_double_truncate(&mat, 0, 0, 3, 3);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error truncating matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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.