Facial Recognition
UsePCAtoperformfacialrecognition
 All Classes Files Functions Variables Typedefs Macros
linalg.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <math.h>
13 #include <time.h>
14 #include <assert.h>
15 
17 #define MAT(m, x, y) (m->data[(x * m->col) + y])
18 #define VEC(v, x) (v->data[x])
20 
27 typedef struct _vector {
29  size_t size;
31  size_t padding;
33  double data[];
34 } vector;
35 
40 typedef struct _matrix {
42  size_t row;
44  size_t col;
46  double data[];
47 } matrix;
48 
49 
56 vector* vector_create(size_t size);
57 
65 matrix* matrix_create(size_t row, size_t col);
66 
78 matrix* vec_to_mat(vector* vec, int orientation);
79 
91 vector* mat_to_vec(matrix* mat);
92 
100 void matrix_reshape(matrix* mat, size_t row, size_t col);
101 
111 double dot_product(const double* left, const double* right, int length);
112 
121 vector* vecscalar_multiply(const vector* vec, const double scalar);
122 
131  vector* vecscalar_divide(const vector* vec, const double scalar);
132 
133 
143  vector* vecmat_multiply(const vector* vec, const matrix* mat);
144 
154 vector* matvec_multiply(const matrix* mat, const vector* vec);
155 
161 void mat_print(const matrix* mat);
162 
168 void vec_print (const vector* vec);
169 
177 matrix* matmat_multiply(const matrix* left, const matrix* right);
178 
186 matrix* matmat_addition(const matrix* left, const matrix* right);
187 
195 matrix* matmat_subtraction(const matrix* left, const matrix* right);
196 
205 matrix* matscalar_multiply(const matrix* mat, const double scalar);
206 
215 matrix* matscalar_divide(const matrix* mat, const double scalar);
216 
223 matrix* mat_transpose(const matrix* mat);
224 
232 void vec_append(vector** vec_a, vector* vec_b);
233 
246 void eigen(int N, double a[], int it_max, double v[], double d[], int* it_num, int* rot_num);
247 
253 void mat_identity(int n, double a[]);
254 
261 void diag_vector(int n, double a[], double v[]);
262 
272 double frobenius_norm(int n, int k, double a[], double x[], double lambda[]);
273 
280 matrix* covmat(matrix* mat);
281 
288 vector* compute_average(matrix* images, int num_images);
289 
290 
291 
represents a matrix between matrix and vector they are able to be casted into one another ...
Definition: linalg.h:40
double data[]
the elements of the vector
Definition: linalg.h:33
void vec_print(const vector *vec)
prints the vector this function will not modify the vector and print to stdout
Definition: linalg.c:121
double dot_product(const double *left, const double *right, int length)
Performs dot product on two double* this function will malloc for the user a double arrays must be of...
Definition: linalg.c:57
vector * vecscalar_divide(const vector *vec, const double scalar)
Performs scalar division of a vector this function will malloc for the user a vector*.
Definition: linalg.c:74
matrix * matmat_multiply(const matrix *left, const matrix *right)
Performs standard matrix multiplication this function will malloc for the user a matrix*.
Definition: linalg.c:129
matrix * matrix_create(size_t row, size_t col)
Creates a matrix this function will malloc the exact space for the required dimensions.
Definition: linalg.c:22
struct _matrix matrix
represents a matrix between matrix and vector they are able to be casted into one another ...
size_t row
the number of rows in the matrix
Definition: linalg.h:42
matrix * covmat(matrix *mat)
computes the variance covariance matrix
Definition: linalg.c:397
struct _vector vector
represents a vector padding is to make sure that matrix and vector both have the same byte size and a...
matrix * vec_to_mat(vector *vec, int orientation)
Converts vector into matrix this function will "cast" the vector into a matrix by using the fact that...
Definition: linalg.c:33
void vec_append(vector **vec_a, vector *vec_b)
Appends vector b to vector a this function will realloc for the user vector a and free vector b...
Definition: linalg.c:192
void eigen(int N, double a[], int it_max, double v[], double d[], int *it_num, int *rot_num)
Performs Jacobi eigenvalue iteration this function will required the user to pass in non-null it_num ...
Definition: linalg.c:212
matrix * mat_transpose(const matrix *mat)
Performs matrix transpose this function will malloc for the user a matrix*.
Definition: linalg.c:181
void matrix_reshape(matrix *mat, size_t row, size_t col)
Reshapes the matrix this function will reshape the matrix in constant time.
Definition: linalg.c:51
vector * compute_average(matrix *images, int num_images)
computes the average matrix of all the *vector images
Definition: linalg.c:407
vector * mat_to_vec(matrix *mat)
Converts matrix into vector this function will "cast" the matrix into a vector by using the fact that...
Definition: linalg.c:43
vector * vecscalar_multiply(const vector *vec, const double scalar)
Performs scalar multiplication of a vector this function will malloc for the user a vector*...
Definition: linalg.c:66
void diag_vector(int n, double a[], double v[])
gets the diagonal entries
Definition: linalg.c:363
matrix * matmat_subtraction(const matrix *left, const matrix *right)
Performs standard matrix subtration this function will malloc for the user a matrix*.
Definition: linalg.c:154
vector * vector_create(size_t size)
Creates a vector this function will malloc the exact space for the required dimensions.
Definition: linalg.c:11
void mat_identity(int n, double a[])
modifies a matrix to be the identity matrix of size n
Definition: linalg.c:347
size_t col
the number of columns in the matrix
Definition: linalg.h:44
matrix * matscalar_multiply(const matrix *mat, const double scalar)
Performs scalar multiplication of a matrix this function will malloc for the user a matrix*...
Definition: linalg.c:165
matrix * matscalar_divide(const matrix *mat, const double scalar)
Performs scalar division of a matrix this function will malloc for the user a matrix*.
Definition: linalg.c:176
vector * matvec_multiply(const matrix *mat, const vector *vec)
Performs matrix vector multiplication this function will malloc for the user a vector* if the matrix ...
Definition: linalg.c:95
size_t padding
unused value but important as padding
Definition: linalg.h:31
void mat_print(const matrix *mat)
prints the matrix this function will not modify the matrix and print to stdout
Definition: linalg.c:107
vector * vecmat_multiply(const vector *vec, const matrix *mat)
Performs vector matrix multiplication this function will malloc for the user a vector* if the vector ...
Definition: linalg.c:80
matrix * matmat_addition(const matrix *left, const matrix *right)
Performs standard matrix addition this function will malloc for the user a matrix*.
Definition: linalg.c:143
double frobenius_norm(int n, int k, double a[], double x[], double lambda[])
computes the Frobenius norm in a right eigensystem
Definition: linalg.c:371
double data[]
row wise expansion of the elements in the matrix
Definition: linalg.h:46
size_t size
the number of elements in the vector
Definition: linalg.h:29
represents a vector padding is to make sure that matrix and vector both have the same byte size and a...
Definition: linalg.h:27