dmlfw (Daniyal Machine Learning Framework)

Core mathematical vector and matrix functions. More...

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

Go to the source code of this file.

Functions

dmlfw_column_vec_doubledmlfw_column_vec_double_log (dmlfw_column_vec_double *vector, dmlfw_column_vec_double *new_vector)
 Applies natural logarithm element-wise to column vector.
 
dmlfw_column_vec_doubledmlfw_column_vec_double_sigmoid (dmlfw_column_vec_double *vector, dmlfw_column_vec_double *new_vector)
 Applies sigmoid function element-wise to column vector.
 
double dmlfw_column_vec_double_sum (dmlfw_column_vec_double *vector)
 Computes sum of all values in column vector.
 
dmlfw_mat_doubledmlfw_mat_double_sigmoid (dmlfw_mat_double *matrix, dmlfw_mat_double *new_matrix)
 Applies sigmoid function element-wise to a matrix.
 

Detailed Description

Core mathematical vector and matrix functions.

Version
1.0
Date
2025-09-25

This module provides functions for common mathematical transformations (sigmoid, log) and reductions (sum) on double precision vectors and matrices, supporting ML and numeric data workflows.

Error Handling:

All functions use a centralized error API. After calls, check dmlfw_error() and access full details via dmlfw_get_error_string() and dmlfw_get_debug_string().

Ownership:

Functions that allocate new containers (vectors/matrices) transfer ownership to caller. Returned vectors/matrices must be destroyed with the appropriate API function.

Function Documentation

◆ dmlfw_column_vec_double_log()

dmlfw_column_vec_double * dmlfw_column_vec_double_log ( dmlfw_column_vec_double vector,
dmlfw_column_vec_double new_vector 
)

Applies natural logarithm element-wise to column vector.

If new_vector is NULL, allocates a new container; otherwise, fills provided container. Input and output sizes must match if container is reused.

Parameters
vector[in] Source column vector (non-NULL).
new_vector[in,out] Optional result vector. If NULL, allocated.
Returns
Pointer to result 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 in log: %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.
dmlfw_column_vec_double * dmlfw_column_vec_double_log(dmlfw_column_vec_double *vector, dmlfw_column_vec_double *new_vector)
Applies natural logarithm element-wise to column vector.
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_column_vec_double_sigmoid()

dmlfw_column_vec_double * dmlfw_column_vec_double_sigmoid ( dmlfw_column_vec_double vector,
dmlfw_column_vec_double new_vector 
)

Applies sigmoid function element-wise to column vector.

If new_vector is NULL, allocates a result container; otherwise, fills provided container. Input and output sizes must match if container is reused.

Parameters
vector[in] Source column vector (non-NULL).
new_vector[in,out] Optional result vector to fill. If NULL, allocated.
Returns
Pointer to result 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 in sigmoid: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
dmlfw_column_vec_double * dmlfw_column_vec_double_sigmoid(dmlfw_column_vec_double *vector, dmlfw_column_vec_double *new_vector)
Applies sigmoid function element-wise to column vector.
Examples
example_dmlfw_math_operations.c.

◆ dmlfw_column_vec_double_sum()

double dmlfw_column_vec_double_sum ( dmlfw_column_vec_double vector)

Computes sum of all values in column vector.

Parameters
vector[in] Source vector.
Returns
Sum or 0.0 on error.

Usage example:

char err[512], dbg[512];
double total = dmlfw_column_vec_double_sum(vec);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error in sum: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
printf("Sum: %lf\n", total);
double dmlfw_column_vec_double_sum(dmlfw_column_vec_double *vector)
Computes sum of all values in column vector.
Examples
example_dmlfw_math_operations.c.

◆ dmlfw_mat_double_sigmoid()

dmlfw_mat_double * dmlfw_mat_double_sigmoid ( dmlfw_mat_double matrix,
dmlfw_mat_double new_matrix 
)

Applies sigmoid function element-wise to a matrix.

If new_matrix is NULL, allocates a new matrix; otherwise, fills provided container. Dimensions must match if container is reused.

Parameters
matrix[in] Source matrix (non-NULL).
new_matrix[in,out] Optional result matrix. If NULL, allocated.
Returns
Pointer to result matrix 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 in sigmoid matrix: %s\nDebug info: %s\n", err, dbg);
return EXIT_FAILURE;
}
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_mat_double_sigmoid(dmlfw_mat_double *matrix, dmlfw_mat_double *new_matrix)
Applies sigmoid function element-wise to a matrix.