From 93e3cc32452ddb86944f6a4975f018d841047d76 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 16 Feb 2021 08:02:30 -0600 Subject: [PATCH] updates with new features in Onyx --- src/mnist.onyx | 14 +++++++------- src/neuralnet.onyx | 7 +------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/mnist.onyx b/src/mnist.onyx index c2d5e82..6200418 100644 --- a/src/mnist.onyx +++ b/src/mnist.onyx @@ -1,4 +1,4 @@ -#load "core/std/wasi" +#load "core/std" #load_path "src" #load "neuralnet" @@ -110,18 +110,18 @@ train :: ( sample_num := random.between(0, training_example_count); dataloader_get_item(dataloader, sample_num, ^sample); - (*nn)->forward(sample.input); - (*nn)->backward(sample.output, criterion); + nn->forward(sample.input); + nn->backward(sample.output, criterion); label, _ := array.greatest(sample.output); - prediction := (*nn)->get_prediction(); + prediction := nn->get_prediction(); if prediction == label do past_100_correct += 1; } optimizer_step(optimizer); if batch_num % (100 / batch_size) == 0 { - loss := (*nn)->get_loss(sample.output, criterion); + loss := nn->get_loss(sample.output, criterion); printf("Loss: %f Correct: %i / 100\n", cast(f32) loss, past_100_correct); past_100_correct = 0; @@ -168,12 +168,12 @@ main :: (args: [] cstr) { color := 94; if prediction != label do color = 91; - output := (*nn)->get_output(); + output := nn->get_output(); print_colored_array(sample.output, label, color); print_colored_array(output, prediction, color); - loss := (*nn)->get_loss(sample.output, criterion); + loss := nn->get_loss(sample.output, criterion); printf("Loss: %f Correct: %i / 100\n", cast(f32) loss, past_100_correct); past_100_correct = 0; diff --git a/src/neuralnet.onyx b/src/neuralnet.onyx index 92c1424..2c608b9 100644 --- a/src/neuralnet.onyx +++ b/src/neuralnet.onyx @@ -20,12 +20,7 @@ NeuralNet :: struct { make :: (layer_sizes: ..i32) -> NeuralNet { net : NeuralNet; - - // BUGFIX: It should be possible to omit 'NeuralNet.' here because - // init is defined in the same scope. This is happening because at - // parse time, these functions are not being entered in the correct - // scope and thus are not resolving the correct symbols. - NeuralNet.init(^net, layer_sizes.count); + init(^net, layer_sizes.count); layer_allocator := alloc.arena.make_allocator(^net.layer_arena); -- 2.25.1