-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrix.h
95 lines (66 loc) · 1.36 KB
/
matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// matrix.h
//
// Copyright (c) 2015 e-k-m
//
#ifndef MATRIX_H
#define MATRIX_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// Library version
#define MATRIX_VERSION "0.0.1"
/*
* matrix_t struct.
*/
typedef struct matrix {
int height;
int width;
double* data;
} matrix_t;
#define ARRAY(...) ((double []){__VA_ARGS__})
/*
* matrix_t prototypes
*/
matrix_t *
matrix_new(int height, int width);
matrix_t *
matrix_from_array(int height, int width, double *data);
matrix_t *
matrix_copy(matrix_t *self);
void
matrix_destroy(matrix_t *self);
void
matrix_print(matrix_t *self);
matrix_t *
matrix_eye(int n);
double
matrix_get(matrix_t *self, int i, int j);
void
matrix_set(matrix_t *self, int i, int j, double value);
void
matrix_set_from_array(matrix_t *self, double *data, size_t size);
/*
* martix_t functions
*/
double
matrix_trace(matrix_t *self);
matrix_t *
matrix_transpose(matrix_t *self);
matrix_t *
matrix_mean(matrix_t *self);
matrix_t *
matrix_multiply(matrix_t *a, matrix_t *b);
matrix_t *
matrix_add(matrix_t *a, matrix_t *b);
matrix_t *
matrix_scale(matrix_t *self, double value);
void
matrix_swap_row(matrix_t *self, int p, int q);
matrix_t *
matrix_covariance(matrix_t *self);
matrix_t *
matrix_dot_product(matrix_t *a, matrix_t *b);
matrix_t *
matrix_dot_diagonal(matrix_t *a, matrix_t *b);
#endif /* MATRIX_H */