updates with new features in Onyx
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 16 Feb 2021 14:02:30 +0000 (08:02 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 23 Feb 2021 04:00:15 +0000 (22:00 -0600)
src/mnist.onyx
src/neuralnet.onyx

index c2d5e828fa38778aec06a7fea607a30c457bc404..620041878b13093d5786a0f35479f2a66d0de437 100644 (file)
@@ -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;
index 92c1424a82aab85165f2b02e03d1bbe5a8539ce0..2c608b9537a3d0bd1d095dd0485e22f25a34ae3d 100644 (file)
@@ -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);