Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

gradfuns.lua dimension problem on line 130 #176

Open
HeylenJonas opened this issue Nov 6, 2017 · 0 comments
Open

gradfuns.lua dimension problem on line 130 #176

HeylenJonas opened this issue Nov 6, 2017 · 0 comments

Comments

@HeylenJonas
Copy link

HeylenJonas commented Nov 6, 2017

Hi,
Still new to all of this so I'm not sure if this problem is caused by some underlying problem in my framework.
On line 130 of gradfuns.lua:
return torch.narrow(g, dim, torch.size(x, dim) + 1, torch.size(y, dim))
torch.size(x,dim) errors at some point.
The function is called multiple times.
First x is a tesor of size 3000x10, later 3000x9 and so on... and dim is 2. So far no problem.
Finally x is a vector of 3000 and dim is 2 -> error.
I fixed it for me by adding a few lines of code:

	if (torch.nDimension(x)>1) then
		size_x_dim = torch.size(x, dim)
	else
		size_x_dim = 1
	end
	local size_y_dim
	if (torch.nDimension(y)>1) then
		size_y_dim = torch.size(y, dim)
	else
		size_y_dim = 1
	end
	return torch.narrow(g, dim, size_x_dim + 1, size_y_dim)

Not the nicest way, but working.
I'm not sure why the code is not giving x as a tensor of size 3000x1 instead of a vector of size 3000?

Thanks,
Jonas

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant