dmlfw (Daniyal Machine Learning Framework)

Core double precision vector and matrix arithmetic operations. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

dmlfw_column_vec_doubledmlfw_add_double_column_vector (dmlfw_column_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *new_vector)
 Adds two column vectors element-wise.
 
dmlfw_mat_doubledmlfw_add_double_matrix_with_matrix (dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *new_matrix)
 Adds two matrices element-wise.
 
dmlfw_column_vec_doubledmlfw_element_wise_multiply_double_column_vector (dmlfw_column_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *new_vector)
 Element-wise multiply two column vectors.
 
dmlfw_column_vec_doubledmlfw_multiply_double_matrix_with_column_vector (dmlfw_mat_double *left_matrix, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *product_vector)
 Multiplies a matrix with a column vector, producing a column vector.
 
dmlfw_mat_doubledmlfw_multiply_double_matrix_with_matrix (dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *product_matrix)
 Multiplies two matrices.
 
dmlfw_mat_doubledmlfw_multiply_double_matrix_with_matrix_strassens (dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *new_matrix)
 Multiplies two square matrices using Strassen's algorithm.
 
dmlfw_column_vec_doubledmlfw_multiply_double_row_vector_with_column_vector (dmlfw_row_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *product_vector)
 Multiplies a row vector with a column vector, producing a single-value column vector.
 
dmlfw_column_vec_doubledmlfw_multiply_double_scalar_with_column_vector (double scalar_value, dmlfw_column_vec_double *vector, dmlfw_column_vec_double *product_vector)
 Multiplies a scalar with a column vector.
 
dmlfw_column_vec_doubledmlfw_subtract_double_column_vector (dmlfw_column_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *difference_vector)
 Subtracts two column vectors element-wise.
 
dmlfw_column_vec_doubledmlfw_subtract_double_column_vector_from_scalar (dmlfw_column_vec_double *vector, double scalar_value, dmlfw_column_vec_double *new_vector)
 Subtracts each element of a column vector from a scalar.
 
dmlfw_mat_doubledmlfw_subtract_double_matrix_from_matrix (dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *new_matrix)
 Subtracts second matrix from first element-wise.
 

Detailed Description

Core double precision vector and matrix arithmetic operations.

Version
1.0
Date
2025-09-25

This module provides fundamental arithmetic operations specialized for double precision vectors and matrices, including multiplication, addition, subtraction, scalar scaling, and advanced matrix multiplication algorithms like Strassen’s method.

Error Handling:

Functions validate all input pointers and vector/matrix dimensions. Errors are reported through a centralized error API. After calling functions, check dmlfw_error() and retrieve error details via dmlfw_get_error_string() and dmlfw_get_debug_string().

Ownership:

Inputs are owned by the caller. Functions allocate new output vectors/matrices if corresponding pointers are NULL. Any allocated output vectors/matrices are owned by the caller who must free them.

Function Documentation

◆ dmlfw_add_double_column_vector()

dmlfw_column_vec_double * dmlfw_add_double_column_vector ( dmlfw_column_vec_double left_vector,
dmlfw_column_vec_double right_vector,
dmlfw_column_vec_double new_vector 
)

Adds two column vectors element-wise.

Parameters
left_vector[in] First vector (non-NULL).
right_vector[in] Second vector (non-NULL).
new_vector[in,out] Optional output vector, same size. If NULL, new vector allocated.
Returns
Pointer to output vector or NULL on error.
Note
Vectors must have equal size.

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 adding vectors: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use sum...
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.
dmlfw_column_vec_double * dmlfw_add_double_column_vector(dmlfw_column_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *new_vector)
Adds two column vectors element-wise.
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_add_double_matrix_with_matrix()

dmlfw_mat_double * dmlfw_add_double_matrix_with_matrix ( dmlfw_mat_double left_matrix,
dmlfw_mat_double right_matrix,
dmlfw_mat_double new_matrix 
)

Adds two matrices element-wise.

Parameters
left_matrix[in] First matrix (non-NULL).
right_matrix[in] Second matrix (non-NULL).
new_matrix[in,out] Optional output matrix, must match input sizes. If NULL, new matrix allocated.
Returns
Pointer to sum matrix or NULL on error.
Note
Matrices must be of equal dimensions.

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 adding matrices: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use sum
struct __dmlfw_mat_double dmlfw_mat_double
Opaque structure representing a double precision matrix.
Definition dmlfw_mat_double.h:73
void dmlfw_mat_double_destroy(dmlfw_mat_double *matrix)
Destroys a matrix and frees all associated memory.
dmlfw_mat_double * dmlfw_add_double_matrix_with_matrix(dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *new_matrix)
Adds two matrices element-wise.

◆ dmlfw_element_wise_multiply_double_column_vector()

dmlfw_column_vec_double * dmlfw_element_wise_multiply_double_column_vector ( dmlfw_column_vec_double left_vector,
dmlfw_column_vec_double right_vector,
dmlfw_column_vec_double new_vector 
)

Element-wise multiply two column vectors.

Parameters
left_vector[in] First vector (non-NULL).
right_vector[in] Second vector (non-NULL).
new_vector[in,out] Optional output vector, same size as inputs. If NULL, new vector allocated.
Returns
Pointer to output vector or NULL on error.
Note
Vectors must have equal size.

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 element-wise multiplication: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use result...
dmlfw_column_vec_double * dmlfw_element_wise_multiply_double_column_vector(dmlfw_column_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *new_vector)
Element-wise multiply two column vectors.

◆ dmlfw_multiply_double_matrix_with_column_vector()

dmlfw_column_vec_double * dmlfw_multiply_double_matrix_with_column_vector ( dmlfw_mat_double left_matrix,
dmlfw_column_vec_double right_vector,
dmlfw_column_vec_double product_vector 
)

Multiplies a matrix with a column vector, producing a column vector.

Parameters
left_matrix[in] Input matrix (non-NULL).
right_vector[in] Column vector (non-NULL).
product_vector[in,out] Optional output vector with size matching matrix rows. If NULL, a new vector is allocated.
Returns
Pointer to output column vector or NULL on error.
Note
Matrix columns must match vector size.
See also
dmlfw_multiply_double_row_vector_with_column_vector

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 multiplying matrix and vector: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use result...
dmlfw_column_vec_double * dmlfw_multiply_double_matrix_with_column_vector(dmlfw_mat_double *left_matrix, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *product_vector)
Multiplies a matrix with a column vector, producing a column vector.

◆ dmlfw_multiply_double_matrix_with_matrix()

dmlfw_mat_double * dmlfw_multiply_double_matrix_with_matrix ( dmlfw_mat_double left_matrix,
dmlfw_mat_double right_matrix,
dmlfw_mat_double product_matrix 
)

Multiplies two matrices.

Parameters
left_matrix[in] Left matrix (non-NULL).
right_matrix[in] Right matrix (non-NULL).
product_matrix[in,out] Optional output matrix with appropriate dimensions. If NULL, a new matrix is allocated.
Returns
Pointer to product matrix or NULL on error.
Note
Left matrix columns must match right matrix rows.

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 multiplying matrices: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use prod
dmlfw_mat_double * dmlfw_multiply_double_matrix_with_matrix(dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *product_matrix)
Multiplies two matrices.

◆ dmlfw_multiply_double_matrix_with_matrix_strassens()

dmlfw_mat_double * dmlfw_multiply_double_matrix_with_matrix_strassens ( dmlfw_mat_double left_matrix,
dmlfw_mat_double right_matrix,
dmlfw_mat_double new_matrix 
)

Multiplies two square matrices using Strassen's algorithm.

Parameters
left_matrix[in] Left square matrix with power-of-two dimensions (non-NULL).
right_matrix[in] Right square matrix matching left matrix dimensions (non-NULL).
new_matrix[in,out] Optional output matrix, square of same size. If NULL, new matrix allocated.
Returns
Pointer to product matrix or NULL on error.
Note
Dimensions must be power-of-two for Strassen's algorithm.

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 multiplying matrices with Strassen's: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use prod
dmlfw_mat_double * dmlfw_multiply_double_matrix_with_matrix_strassens(dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *new_matrix)
Multiplies two square matrices using Strassen's algorithm.

◆ dmlfw_multiply_double_row_vector_with_column_vector()

dmlfw_column_vec_double * dmlfw_multiply_double_row_vector_with_column_vector ( dmlfw_row_vec_double left_vector,
dmlfw_column_vec_double right_vector,
dmlfw_column_vec_double product_vector 
)

Multiplies a row vector with a column vector, producing a single-value column vector.

Parameters
left_vector[in] Left row vector (non-NULL).
right_vector[in] Right column vector (non-NULL).
product_vector[in,out] Optional pre-allocated output vector, size must be 1. If NULL, a new vector is allocated.
Returns
Pointer to the resulting single-value column vector or NULL on error.
Note
Input vectors must have the same size.
See also
dmlfw_multiply_double_matrix_with_column_vector

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 multiplying vectors: %s\nDebug info: %s\n", err, dbg);
// Cleanup if needed
return NULL;
}
// Use result...
dmlfw_column_vec_double * dmlfw_multiply_double_row_vector_with_column_vector(dmlfw_row_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *product_vector)
Multiplies a row vector with a column vector, producing a single-value column vector.
Examples
example_dmlfw_operations_double.c.

◆ dmlfw_multiply_double_scalar_with_column_vector()

dmlfw_column_vec_double * dmlfw_multiply_double_scalar_with_column_vector ( double  scalar_value,
dmlfw_column_vec_double vector,
dmlfw_column_vec_double product_vector 
)

Multiplies a scalar with a column vector.

Parameters
scalar_value[in] Scalar to multiply.
vector[in] Input vector (non-NULL).
product_vector[in,out] Optional output vector matching input size. If NULL, a new vector is allocated.
Returns
Pointer to product vector or NULL on error.
See also
dmlfw_multiply_double_row_vector_with_column_vector

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 scaling vector: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use prod...
dmlfw_column_vec_double * dmlfw_multiply_double_scalar_with_column_vector(double scalar_value, dmlfw_column_vec_double *vector, dmlfw_column_vec_double *product_vector)
Multiplies a scalar with a column vector.

◆ dmlfw_subtract_double_column_vector()

dmlfw_column_vec_double * dmlfw_subtract_double_column_vector ( dmlfw_column_vec_double left_vector,
dmlfw_column_vec_double right_vector,
dmlfw_column_vec_double difference_vector 
)

Subtracts two column vectors element-wise.

Parameters
left_vector[in] Minuend vector (non-NULL).
right_vector[in] Subtrahend vector (non-NULL).
difference_vector[in,out] Optional output vector matching input size. If NULL, a new vector is allocated.
Returns
Pointer to difference vector or NULL on error.
Note
Vectors must have the same size.
See also
dmlfw_add_double_column_vector

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 subtracting vectors: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use diff...
dmlfw_column_vec_double * dmlfw_subtract_double_column_vector(dmlfw_column_vec_double *left_vector, dmlfw_column_vec_double *right_vector, dmlfw_column_vec_double *difference_vector)
Subtracts two column vectors element-wise.

◆ dmlfw_subtract_double_column_vector_from_scalar()

dmlfw_column_vec_double * dmlfw_subtract_double_column_vector_from_scalar ( dmlfw_column_vec_double vector,
double  scalar_value,
dmlfw_column_vec_double new_vector 
)

Subtracts each element of a column vector from a scalar.

Parameters
vector[in] Input vector (non-NULL).
scalar_value[in] Scalar to subtract from.
new_vector[in,out] Optional output vector same size as input. If NULL, new vector allocated.
Returns
Pointer to output vector or NULL on error.

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 subtracting scalar from vector: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use result...
dmlfw_column_vec_double * dmlfw_subtract_double_column_vector_from_scalar(dmlfw_column_vec_double *vector, double scalar_value, dmlfw_column_vec_double *new_vector)
Subtracts each element of a column vector from a scalar.

◆ dmlfw_subtract_double_matrix_from_matrix()

dmlfw_mat_double * dmlfw_subtract_double_matrix_from_matrix ( dmlfw_mat_double left_matrix,
dmlfw_mat_double right_matrix,
dmlfw_mat_double new_matrix 
)

Subtracts second matrix from first element-wise.

Parameters
left_matrix[in] Minuend matrix (non-NULL).
right_matrix[in] Subtrahend matrix (non-NULL).
new_matrix[in,out] Optional output matrix, must match input sizes. If NULL, new matrix allocated.
Returns
Pointer to difference matrix or NULL on error.
Note
Matrices must be of equal dimensions.

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 subtracting matrices: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use diff
dmlfw_mat_double * dmlfw_subtract_double_matrix_from_matrix(dmlfw_mat_double *left_matrix, dmlfw_mat_double *right_matrix, dmlfw_mat_double *new_matrix)
Subtracts second matrix from first element-wise.