From 1ec97406e56b0668f035948203e2fe8e7c230dc7 Mon Sep 17 00:00:00 2001 From: jvech Date: Sat, 5 Aug 2023 20:53:28 -0500 Subject: add: nn_backward() calloc error handling added --- src/nn.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/nn.c b/src/nn.c index 83fd77a..7744fd4 100644 --- a/src/nn.c +++ b/src/nn.c @@ -19,6 +19,8 @@ void nn_backward( double *delta = calloc(max_neurons, sizeof(double)); double *delta_next = calloc(max_neurons, sizeof(double)); + if (!dcost_out || !delta || !delta_next) goto nn_backward_error; + for (size_t i = 0; i < labels_shape[0]; i++) { for (size_t j = 0; j < labels_shape[0]; j++) { size_t index = i * labels_shape[1] + j; @@ -55,6 +57,10 @@ void nn_backward( free(dcost_out); free(delta); free(delta_next); + +nn_backward_error: + perror("nn_backward() Error"); + exit(1); } void nn_layer_backward( -- cgit v1.2.3-70-g09d2