-
Notifications
You must be signed in to change notification settings - Fork 1
/
linearAlg.h
132 lines (109 loc) · 5.92 KB
/
linearAlg.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef LINEAR_ALG
#define LINEAR_ALG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LA_MAX_INVERSE_SIZE 10
typedef struct matrix
{
int rows;
int columns;
float** entries;
} Matrix;
typedef struct vector
{
int rows;
float* entries;
} Vector;
//la for linear algebra
//=============== vectors ===============
void la_printVector(Vector *vector);
void laa_writeVectorBin(float *vector, int rows, FILE* filePointer);
void laa_readVectorBin(float* destVector, FILE* filePointer);
Vector *la_cloneVector(Vector *vector);
Vector *la_initVector(int rows, float intialValue);
Vector *la_initVectorArray(float *entries, int rows);
Vector *la_initZerosVector(int rows);
Vector *la_initRandVector(int rows, float from, float to);
void la_freeVector(Vector *vector);
// vector math:
float la_dot(Vector *a, Vector *b);
void la_multiplyMVTo(Matrix *a, Vector *b, Vector *destination);
Vector *la_multiplyMV(Matrix *a, Vector *b);
void la_addVectorsTo(Vector *a, Vector *b, Vector *destination);
Vector *la_addVectors(Vector *a, Vector *b);
void la_subtractVectorsTo(Vector *a, Vector *b, Vector *destination);
Vector *la_subtractVectors(Vector *a, Vector *b);
//=============== matrices ===============
void la_printMatrix(Matrix *matrix);
void laa_writeMatrixBin(float** matrix, int rows, int columns, FILE* filePointer);
void laa_readMatrixBin(float** destMatrix, FILE* filePointer);
Matrix *la_cloneMatrix(Matrix *matrix);
Matrix *la_initMatrix(int rows, int columns, float initialValue);
Matrix *la_initMatrixArray(float **entries, int rows, int columns);
Matrix *la_initZerosMatrix(int rows, int columns);
Matrix *la_initRandMatrix(int rows, int columns, float from, float to);
void la_freeMatrix(Matrix *matrix);
// matrix math:
void la_addToMatrix(Matrix *a, Matrix *b);
void la_subtractFromMatrix(Matrix *a, Matrix *b);
Matrix *la_addMatrix(Matrix *a, Matrix *b);
void la_addMatrixTo(Matrix *a, Matrix *b, Matrix *destination);
Matrix *la_subtractMatrix(Matrix *a, Matrix *b);
void la_subtractMatrixTo(Matrix *a, Matrix *b, Matrix *destination);
Matrix *la_transposed(Matrix *matrix);
Matrix *la_multiplyMM(Matrix *a, Matrix *b);
void la_multiplyMMTo(Matrix *a, Matrix *b, Matrix *destination);
void la_inverse(Matrix *matrix);
Matrix *la_getInverse(Matrix *matrix);
//=====================================================================================================================================
//=================================================== Linear algebra with arrays ======================================================
//=====================================================================================================================================
//=============== vectors ===============
void laa_printVector(float *vector, int columns);
float *laa_allocVector(int rows, float initialValue);
float *laa_allocVectorRaw(int rows);
float *laa_allocRandVector(int rows, float from, float to);
float *laa_cloneVector(float *cloneVector, int rows);
void laa_freeVector(float *vector);
void laa_setVectorTo(float *vector, int rows, float value);
void laa_setVectorToRand(float *vector, int rows);
void laa_copyVectorValues(float *copyFrom, float *pasteTo, int rows);
int laa_maxIndexValue(float* vector, int rows);
// vector math:
float laa_dot(float *a, float *b, int rows);
void laa_addVectorTo(float *a, float *b, float *destination, int rows);
void laa_subtractVectorsTo(float *a, float *b, float *destination, int rows);
float *laa_addVectors(float *a, float *b, int rows);
float *laa_subtractVectors(float *a, float *b, int rows);
void laa_multiplyMVTo(float **matrix, int rows, int columns, float *vector, float *destination);
float *laa_multiplyMV(float **matrix, int rows, int columns, float *vector);
void laa_multiplyVSTo(float* vector, int rows, float multiplier, float* destination);
float* laa_multiplyVS(float* vector, int rows, float multiplier);
//=============== matrices ===============
void laa_printMatrix(float **matrix, int rows, int columns);
float **laa_allocMatrix(int rows, int columns, float initialValue);
float **laa_allocMatrixRaw(int rows, int columns);
float **laa_allocRandMatrix(int rows, int columns, float from, float to);
float **laa_cloneMatrix(float **values, int rows, int columns);
float** cloneMatrix2dArray(int rows, int columns, float values[rows][columns]);
void laa_freeMatrix(float **matrix, int rows);
void laa_setMatrixTo(float **matrix, int rows, int columns, float value);
void laa_setMatrixToRand(float **matrix, int rows, int columns);
void laa_copyMatrixValues(float **copyFrom, float **pasteTo, int rows, int columns);
// matrix math:
void laa_addMatrixTo(float **a_matrixVals, float **b_matrixVals, float **destination, int rows, int columns);
float **laa_addMatrix(float **a_matrixVals, float **b_matrixVals, int rows, int columns);
void laa_subtractMatrixTo(float **a_matrixVals, float **b_matrixVals, float **destination, int rows, int columns);
float **laa_subtractMatrix(float **a_matrixVals, float **b_matrixVals, int rows, int columns);
float **laa_matrixDifference(float **a_matrixVals, float **b_matrixVals, int rows, int columns);
void laa_transposeTo(float **matrix, float **destination, int rows, int columns);
float **laa_transpose(float **matrix, int rows, int columns);
void laa_multiplyMMTo(float **a_matrixVals, int a_rows, int a_columns, float **b_matrixVals, int b_rows, int b_columns, float **destination);
void laa_multiplyMMReplace(float **a_matrixVals, int a_rows, int a_columns, float **b_matrixVals, int b_rows, int b_columns, float **destination);
float **laa_multiplyMM(float **a_matrixVals, int a_rows, int a_columns, float **b_matrixVals, int b_rows, int b_columns);
void laa_multiplyMSTo(float** matrixVals, int rows, int cols, float multiplier, float** destination);
float** laa_multiplyMS(float** matrixVals, int rows, int cols, float multiplier);
void laa_inverse(float **matrixEntries, int rows, int columns);
float **laa_getInverse(float **matrixEntries, int rows, int columns);
#endif