HolyFuckItsAlive #13

Merged
jastornig merged 105 commits from Delta-Error-Test into main 2023-09-23 22:27:54 +02:00
3 changed files with 35 additions and 9 deletions
Showing only changes of commit 9d150c04c5 - Show all commits

View file

@ -3,4 +3,4 @@ project(c_net C)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
add_executable(c_net main.c) add_executable(c_net main.c matrix.c)

6
main.c
View file

@ -1,5 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "matrix.h"
#include <stdio.h>
int main() { int main() {
printf("Hello World");
return 0;
} }

View file

@ -49,7 +49,7 @@ void matrix_free(Matrix* matrix) {
void matrix_print(Matrix *matrix) { void matrix_print(Matrix *matrix) {
// print the dimensions of the matrix // print the dimensions of the matrix
printf("Rows: %d, Columns: %d", matrix->rows, matrix->columns); printf("Rows: %d, Columns: %d\n", matrix->rows, matrix->columns);
// loop through all values and format them into the correct matrix representation // loop through all values and format them into the correct matrix representation
for (int i = 0; i < matrix->rows; i++) { for (int i = 0; i < matrix->rows; i++) {
@ -92,12 +92,12 @@ Matrix* multiply(Matrix* matrix1, Matrix* matrix2) {
exit(1); exit(1);
} }
// crate result matrix // create result matrix
Matrix* result_matrix = matrix_create(matrix1->rows, matrix1->columns); Matrix* result_matrix = matrix_create(matrix1->rows, matrix1->columns);
// multiply the values and save them into the result matrix // multiply the values and save them into the result matrix
for (int i = 0; i < matrix1->rows; i++) { for (int i = 0; i < matrix1->rows; i++) {
for (int j = 0; j < ; j++) { for (int j = 0; j < matrix1->columns; j++) {
result_matrix->numbers[i][j] = matrix1->numbers[i][j] * matrix2->numbers[i][j]; result_matrix->numbers[i][j] = matrix1->numbers[i][j] * matrix2->numbers[i][j];
} }
} }
@ -114,7 +114,7 @@ Matrix* add(Matrix* matrix1, Matrix* matrix2) {
exit(1); exit(1);
} }
// crate result matrix // create result matrix
Matrix* result_matrix = matrix_create(matrix1->rows, matrix1->columns); Matrix* result_matrix = matrix_create(matrix1->rows, matrix1->columns);
// add the value of the number in matrix 1 to the value of the number in matrix 2 // add the value of the number in matrix 1 to the value of the number in matrix 2
@ -136,7 +136,7 @@ Matrix* subtract(Matrix* matrix1, Matrix* matrix2) {
exit(1); exit(1);
} }
// crate result matrix // create result matrix
Matrix* result_matrix = matrix_create(matrix1->rows, matrix1->columns); Matrix* result_matrix = matrix_create(matrix1->rows, matrix1->columns);
// subtract the value of the number in matrix 2 from the value of the number in matrix 1 // subtract the value of the number in matrix 2 from the value of the number in matrix 1
@ -170,7 +170,7 @@ Matrix* dot(Matrix* matrix1, Matrix* matrix2) {
// sum up the products and save them into the result matrix // sum up the products and save them into the result matrix
result_matrix->numbers[i][j] = 0; result_matrix->numbers[i][j] = 0;
for (int k = 0; k < matrix2->rows; k++) { for (int k = 0; k < matrix2->rows; k++) {
result_matrix->numbers[i][j] += matrix1[i][k] * matrix2[k][j]; result_matrix->numbers[i][j] += matrix1->numbers[i][k] * matrix2->numbers[k][j];
} }
} }
} }
@ -243,3 +243,27 @@ Matrix* transpose(Matrix* matrix) {
return result_matrix; return result_matrix;
} }
Matrix* matrix_flatten(Matrix* matrix, int axis) {
// Axis = 0 -> Column Vector, Axis = 1 -> Row Vector
Matrix* result_matrix;
// Column Vector
if (axis == 0) {
result_matrix = matrix_create(matrix -> rows * matrix -> columns, 1);
}
// Row Vector
else if (axis == 1) {
result_matrix = matrix_create(1, matrix -> rows * matrix -> columns);
} else {
printf("ERROR: Argument must be 1 or 0 (matrix_flatten");
exit(EXIT_FAILURE);
}
for (int i = 0; i < matrix->rows; i++) {
for (int j = 0; j < matrix->columns; j++) {
if (axis == 0) result_matrix->numbers[i * matrix->columns + j][0] = matrix->numbers[i][j];
else if (axis == 1) result_matrix->numbers[0][i * matrix->columns + j] = matrix->numbers[i][j];
}
}
return mat;
}