Love crashing when flattening nested tables

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

Love crashing when flattening nested tables

Post by DustinEwan »

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.

The code in question is:

Code: Select all

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
This causes Love to hard crash, no error.

Can anybody help?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love crashing when flattening nested tables

Post by kikito »

Hi there!

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.
When I write def I mean function.
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

Re: Love crashing when flattening nested tables

Post by DustinEwan »

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.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love crashing when flattening nested tables

Post by kikito »

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.
:D 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.
When I write def I mean function.
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

Re: Love crashing when flattening nested tables

Post by DustinEwan »

hehe... oopsie. I see

Well, lemme give that a try. I was just using default config. Could you enable the console in 0.5?
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

Re: Love crashing when flattening nested tables

Post by DustinEwan »

Oh wow, that was quite revealing.

Each neuron was only supposed to have 4 weights... but apparently it had 4080 o.O

Wonder what the hell was causing that...

Well, time to debug that. Thanks for the trick! ;)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love crashing when flattening nested tables

Post by kikito »

:) Glad I could help!

By the way, what are you up to? Neural networks? Are you programming Bartbes 2.0 ?
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love crashing when flattening nested tables

Post by Robin »

kikito wrote:Are you programming Bartbes 2.0 ?
Another bartbes? Dear heavens, please, no! One is quite enough.

;)
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Love crashing when flattening nested tables

Post by bartbes »

My Neural Networking attempts failed (well, they might have worked, they just didn't the way I wanted them to work), so he's not me...
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

Re: Love crashing when flattening nested tables

Post by DustinEwan »

Well, I don't really know what Bartbes is, let alone 2.0, but I'm just going for a simple Neural Network and genetic algorithm.

I'll release the source code when I'm satisfied, but it's mostly just for learning/fun.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests