Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behavior : parameters in reduction formula with symbolic variables ? #282

Closed
AdrienWohrer opened this issue Jan 5, 2023 · 1 comment

Comments

@AdrienWohrer
Copy link

Hi, and first of all thank you for this wonderful tool you have designed !

I am new to KeOps. When playing with pykeops, I tried to implement the following sum_reduction, over the gradient of a Gaussian kernel (by the way, I realize that it could be done more easily with autograd, but it's not my point here) :

def GaussGradKernel(gam,D):
x, y = Vi(0, D), Vj(1, D)
D2 = x.sqdist(y)
K = (-D2*gam/2).exp()
yo = -gam*K*(x-y)
return yo.sum_reduction(axis=1)

Here, gam is a regular Python float, and D a regular Python int. When I call G=GaussGradKernel(1.0,3), it succesfully creates a reduction formula, that I can then apply to any inputs x and y : G(x,y).

Now to my question. In the following code, the only difference is line 4, the additional parenthesis over gam/2.

def GaussGradKernel(gam,D):
x, y = Vi(0, D), Vj(1, D)
D2 = x.sqdist(y)
K = (-D2*(gam/2)).exp()
yo = -gam*K*(x-y)
return yo.sum_reduction(axis=1)

Oddly, this new code produces an error when I call the function G(x,y) :

Traceback (most recent call last):
File "........./tests.py", line 165, in res=G(xt,yt)
File "/home/adrien/.local/lib/python3.9/site-packages/pykeops/common/lazy_tensor.py", line 919, in call
self.callfun = self.Genred(
File "/home/adrien/.local/lib/python3.9/site-packages/pykeops/torch/generic/generic_red.py", line 485, in init
self.aliases = complete_aliases(
File "/home/adrien/.local/lib/python3.9/site-packages/pykeops/common/parse_type.py", line 40, in complete_aliases
aliases[newpos[i]] = extravars[newind[i]]
IndexError: list assignment index out of range

Where does this error come from ? I think that it happens only with symbolic variables. When x and y are basic, numeric LazyTensors with an actual content, the same code succeeds.

Thanks in advance for the explanations,
Adrien

joanglaunes pushed a commit that referenced this issue Jan 6, 2023
@AdrienWohrer
Copy link
Author

Thanks, your update fixed all the issues I had with parameters ! (Here and at other places.)

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

No branches or pull requests

2 participants