I'm trying to flatten some nested tables. Well, I'm actually not flatting nested tables, just extracting the data from the innermost nested table into a flat table.
function NeuralNetwork:GetWeights()
-- Initialize Empty Weights Table
Weights = {}
-- Iterate Layers, Then Neurons, Then Weights
for i,layer in ipairs(self.Layers) do
for j,neuron in ipairs(layer.Neurons) do
for k,weight in ipairs(neuron.InputWeights) do
-- Add each weight to our Weights table
table.insert(Weights, weight)
end
end
end
return Weights
end
The code looks good. If you get no error, how do you know that the error is there, and not somewhere else?
Have you tried "printing" everything already? (i.e. print('entering layer ' .. i) ... print('entering neuron ' .. j) etc. This will tell you where it is failing.
Finally, how many objects are we talking about? Maybe it is just a problem of memory overflowing.
I tried printing, but Love doesn't return to the draw function until that function has finished executing, so I get no output. I tested that this function was what was causing the crash by commenting everything else and having love.update only call this function. No function call, no crash.
As for memory overflow, I wouldn't imagine that would be the case. For the size of the network I'm using (very small) there should only be 96 weights in the table once it has finished flattening (4 weights per neuron, 8 neurons per layer, 3 layers of neurons). That seems like a small number to me.. way too small for a memory overflow.
I tried printing, but Love doesn't return to the draw function until that function has finished executing, so I get no output. I tested that this function was what was causing the crash by commenting everything else and having love.update only call this function. No function call, no crash.
I meant the *other* print. On the console, not on the canvas. Just "print", not "love.graphics.print".
If you are on windows, you might have to activate the console in the config file in order to see its output.