From dd313d75ddb873e657427049a66635c5238d8042 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 25 Oct 2024 14:20:18 -0400 Subject: [PATCH] silly boi --- CMakeLists.txt | 2 +- include/assign2/common.h | 10 ++++++++-- include/assign2/layer.h | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d60ed54..c8a9fb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(COSC-4P80-Assignment-2 VERSION 0.0.6) +project(COSC-4P80-Assignment-2 VERSION 0.0.7) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/assign2/common.h b/include/assign2/common.h index 1b3af1c..9fd58aa 100644 --- a/include/assign2/common.h +++ b/include/assign2/common.h @@ -102,10 +102,15 @@ namespace assign2 class weight_t { public: + void preallocate(blt::size_t amount) + { + data.resize(amount); + } + weight_view allocate_view(blt::size_t count) { - auto size = data.size(); - data.resize(size + count); + auto size = place; + place += count; return {&data[size], count}; } @@ -116,6 +121,7 @@ namespace assign2 } private: + blt::size_t place = 0; std::vector data; }; diff --git a/include/assign2/layer.h b/include/assign2/layer.h index 43c84ef..bfe41c0 100644 --- a/include/assign2/layer.h +++ b/include/assign2/layer.h @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include "blt/std/assert.h" #ifndef COSC_4P80_ASSIGNMENT_2_LAYER_H #define COSC_4P80_ASSIGNMENT_2_LAYER_H @@ -51,6 +52,7 @@ namespace assign2 { // delta for weights error = act->derivative(z) * next_error; + BLT_ASSERT(previous_outputs.size() == dw.size()); for (auto [prev_out, d_weight] : blt::zip(previous_outputs, dw)) { // dw / apply dw @@ -103,6 +105,8 @@ namespace assign2 in_size(in), out_size(out), act_func(act_func) { neurons.reserve(out_size); + weights.preallocate(in_size * out_size); + weight_derivatives.preallocate(in_size * out_size); for (blt::i32 i = 0; i < out_size; i++) { auto weight = weights.allocate_view(in_size);