diff --git a/make.sh b/make.sh index db0cb65..bf89eb1 100755 --- a/make.sh +++ b/make.sh @@ -18,3 +18,21 @@ if [[ $1 == "preview" ]]; then exit fi fi + +if [[ $1 == "test" ]]; then + [[ $2 ]] || set -- "$1" "build" + if [[ $2 == "build" ]]; then + mkdir -p out + for i in $(ls test); do + gcc "test/$i" -o "out/test_$(echo $i | awk -F. '{print $1}')" $FLAGS + done + exit + elif [[ $2 == "run" ]]; then + $0 test build + for i in $(ls out/test_*); do + echo "--- $i ---" + $i + done + exit + fi +fi diff --git a/test/neuron_io.c b/test/neuron_io.c new file mode 100644 index 0000000..27d4805 --- /dev/null +++ b/test/neuron_io.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include "../src/mnist/neuron_io.c" + + +Neurone* creer_neurone(int nb_sortants) { + Neurone* neurone = malloc(2*sizeof(float*)+6*sizeof(float)); + neurone->poids_sortants = malloc(sizeof(float)*nb_sortants); + neurone->dw = malloc(sizeof(float)*nb_sortants); + + for (int i=0; i < nb_sortants; i++) { + neurone->poids_sortants[i] = 0.5; + neurone->dw[i] = 0.0; + } + neurone->activation = 0.0; + neurone->biais = 0.0; + neurone->z = 0.0; + neurone->dactivation = 0.0; + neurone->dbiais = 0.0; + neurone->dz = 0.0; + + return neurone; +} + + +Couche* creer_couche(int nb_neurones, int nb_sortants) { + Couche* couche = malloc(sizeof(int)+sizeof(Neurone**)); + Neurone** tab = malloc(sizeof(Neurone*)*nb_neurones); + + couche->nb_neurone = nb_neurones; + couche->neurone = tab; + + for (int i=0; icouche = malloc(sizeof(Couche*)*nb_couches); + int nb_neurones[nb_couches+1]; + + reseau->nb_couche = nb_couches; + + for (int i=0; i < nb_couches; i++) { + nb_neurones[i] = i*(nb_min_neurones-nb_max_neurones)/(nb_couches-1) + nb_max_neurones; + } + nb_neurones[nb_couches] = 0; + + for (int i=0; i < nb_couches; i++) { + reseau->couche[i] = creer_couche(nb_neurones[i], nb_neurones[i+1]); + } + return reseau; +} + +int main() { + Reseau* reseau = creer_reseau(5, 300, 10); + ecrire_reseau(".test-cache/neuron_io.bin", reseau); + return 1; +} \ No newline at end of file