alib
Universal C Library Collection for Machine Learning & Artificial Intelligence
Loading...
Searching...
No Matches
la.h
Go to the documentation of this file.
1
10#ifndef LA_H
11#define LA_H
12
13#include <stddef.h>
14#include <assert.h>
15#include <stdlib.h>
16#include <stdio.h>
17#include <string.h>
18
22typedef struct la_matrix {
23 size_t rows;
24 size_t cols;
25 size_t stride;
26 double* data;
53#define la_matrix_element(matrix, row, col) \
54 (matrix).data[(row) * (matrix).stride + (col)]
55
79la_matrix la_matrix_alloc(size_t rows, size_t cols);
80
102
130void la_matrix_fill(la_matrix matrix, double value);
131
162void la_matrix_rand(la_matrix matrix, double minvalue, double maxvalue);
163
200
283
336
363
419la_matrix la_submatrix(la_matrix src, size_t row_start, size_t col_start,
420 size_t new_rows, size_t new_cols);
421
450void la_matrix_fprint(la_matrix matrix, char* name, int precision,
451 int digits_before_dot, FILE* fp);
452
475#define la_matrix_print(matrix) \
476 la_matrix_fprint((matrix), #matrix, 6, 3, stdout)
477
511void la_matrix_fprint_simul(la_matrix* matrices, char** names, size_t n,
512 int precision, int digits_before_dot, FILE* fp);
513
562 double (*f)(double));
563
585
611
635void la_matrix_multiply_by_const(la_matrix src, const double x);
636
657void la_matrix_get_max_index(la_matrix src, size_t* x, size_t* y);
658
679void la_matrix_get_min_index(la_matrix src, size_t* x, size_t* y);
680
681#endif
void la_matrix_copy(la_matrix dest, la_matrix src)
Copy the contents of one matrix to another matrix.
la_matrix la_submatrix(la_matrix src, size_t row_start, size_t col_start, size_t new_rows, size_t new_cols)
Extract a submatrix from a given matrix.
void la_matrix_multiply_by_const(la_matrix src, const double x)
Multiply all elements of the matrix by a constant.
void la_matrix_sum_rows(la_matrix dest, la_matrix src)
Calculate the sum of elements in each row of the source matrix and store the result in the destinatio...
void la_matrix_add(la_matrix a, la_matrix b, la_matrix result)
Add two matrices element-wise and store the result in a third matrix.
struct la_matrix la_matrix
Structure representing a matrix.
void la_matrix_fill(la_matrix matrix, double value)
Fill a matrix with a specific value.
void la_matrix_T_copy(la_matrix dest, la_matrix src)
Copy the transpose of the source matrix to the destination matrix.
la_matrix la_matrix_alloc(size_t rows, size_t cols)
Allocate memory for a matrix.
void la_matrix_get_max_index(la_matrix src, size_t *x, size_t *y)
Get the indices of the maximum element in the matrix.
void la_matrix_multiply(la_matrix a, la_matrix b, la_matrix result)
Multiply two matrices and store the result in a third matrix.
void la_matrix_get_min_index(la_matrix src, size_t *x, size_t *y)
Get the indices of the minimum element in the matrix.
void la_matrix_apply_function(la_matrix dest, la_matrix src, double(*f)(double))
Apply a function to each element of the source matrix and store the result in the destination matrix.
void la_matrix_subtract(la_matrix a, la_matrix b, la_matrix result)
Subtract two matrices element-wise and store the result in a third matrix.
void la_matrix_rand(la_matrix matrix, double minvalue, double maxvalue)
Fill a matrix with random values within a specified range.
double la_matrix_sum(la_matrix src)
Calculate the sum of all elements in the matrix.
void la_matrix_fprint(la_matrix matrix, char *name, int precision, int digits_before_dot, FILE *fp)
Print the contents of a matrix to a file with a specified precision.
void la_matrix_fprint_simul(la_matrix *matrices, char **names, size_t n, int precision, int digits_before_dot, FILE *fp)
Print the contents of multiple matrices to a file with a specified precision.
void la_matrix_free(la_matrix matrix)
Free memory for a matrix.
Structure representing a matrix.
Definition la.h:22
size_t rows
Definition la.h:23
size_t cols
Definition la.h:24
size_t stride
Definition la.h:25
double * data
Definition la.h:26