commit 1d7f709e5bcc8bbc4ac70f9e1d56eb1744e81142 Author: = <=> Date: Mon Jul 9 09:21:21 2018 +0200 Initial commit diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..68ddd4f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.10) +project(MatrixTests C) + +set(CMAKE_C_STANDARD 11) + +add_executable(MatrixTests main.c) +target_link_libraries(MatrixTests m) \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..30ab6f2 --- /dev/null +++ b/main.c @@ -0,0 +1,159 @@ +#include +#include +#include +#include + +float vectors_dot_prod(const float *x, const float *y, int n) { + float res = 0.0; + int i; + for (i = 0; i < n; i++) { + res += x[i] * y[i]; + } + return res; +} + +float** Make2DFloatArray(int arraySizeX, int arraySizeY) { + float** theArray; + theArray = (float**) malloc(arraySizeX*sizeof(float*)); + for (int i = 0; i < arraySizeX; i++) + theArray[i] = (float*) malloc(arraySizeY*sizeof(float)); + return theArray; +} + +float calc_sigmoid(float x) { + + return (1 / (1 + expf(-x))); +} + +float sigmoid_deriv(float x) { + float sigmoid_computed = calc_sigmoid(x); + return sigmoid_computed * (1 - sigmoid_computed); +} + +float* vector_matrix_prod(float **x, const float *y, int rows, int cols) { + int col, row; + float *result = (float *)malloc(cols * sizeof(float *)); + float res; + + for (col = 0; col < cols; col++) { + int column = col; + res = 0.0; + for (row = 0; row < rows; row++) { + res += y[row] * x[row][column]; + } + result[column] = res; + } + return result; +} + +void print_vector(float *x, int size) { + printf("Vector is\n"); + for (int i = 0; i < size; i++) { + printf("%f\t", x[i]); + } + printf("\n\n"); +} + +void print_matrix(float **x, int rows, int cols) { + printf("Matrix is\n"); + + for (int row=0; row < rows; row++) { + for (int col=0; col < cols; col++) { + printf("%f\t", x[row][col]); + } + printf("\n"); + } +} + +float genRand() +{ + float num = ((float)rand()/(float)(RAND_MAX/2)) - 1; + return num; +} + +float* create_starting_board() { + float* input = (float *)malloc(26 * sizeof(float *)); + float tmp_input[26] = {0, 2, 0, 0, 0, 0, -5, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -2, 0}; + for (int i=0; i < 26; i++) { + input[i] = tmp_input[i]; + } + return input; +} + + +float* create_1D_layer(int size) { + float *input = (float *)malloc(size * sizeof(float *)); + + int i; + for (i=0; i