summaryrefslogtreecommitdiff
path: root/matrix.c
diff options
context:
space:
mode:
authorSoikk2022-08-28 22:29:18 +0200
committerSoikk2022-08-28 22:29:18 +0200
commit2d044eaa3691fa24fb503af433b13a4c269aaab2 (patch)
treecfa1b0cc67cafd03f6fadba7b7152594720b0f93 /matrix.c
parent079823dcab9444e252e853f8edfed881174d437e (diff)
downloadsoikk-matrix-2d044eaa3691fa24fb503af433b13a4c269aaab2.tar.xz
soikk-matrix-2d044eaa3691fa24fb503af433b13a4c269aaab2.tar.zst
Added Hadamard product and dot product
Diffstat (limited to 'matrix.c')
-rw-r--r--matrix.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/matrix.c b/matrix.c
index b3b71b0..14b7940 100644
--- a/matrix.c
+++ b/matrix.c
@@ -116,6 +116,20 @@ matrix *multiplyMatrices(matrix *m1, matrix *m2){
return r;
}
+matrix *HadamardProduct(matrix *m1, matrix *m2){
+ if(!sameDimensions(m1, m2)){
+ fprintf(stderr, "Wrong dimensions (%dx%d != %dx%d)\n", m1->rows, m1->cols, m2->rows, m2->cols);
+ return NULL;
+ }
+ matrix *r = newMatrix(m1->rows, m1->cols);
+ for(int i = 0; i < r->rows; ++i){
+ for(int j = 0; j < r->cols; ++j){
+ r->data[i][j] = m1->data[i][j] * m2->data[i][j];
+ }
+ }
+ return r;
+}
+
static inline bool isSquare(matrix *m){
return m->rows == m->cols;
}
@@ -179,6 +193,10 @@ matrix *transpose(matrix *m){
return r;
}
+matrix *dotProduct(matrix *m1, matrix *m2){
+ return multiplyMatrices(m1, transpose(m2));
+}
+
matrix *adjugate(matrix *m){
return transpose(cofactor(m));
}
@@ -208,6 +226,7 @@ matrix *raiseMatrix(matrix *m, int n){
return r;
}
+
/*int main(){
int input = 784, hidden = 300, output = 10;