getkeops / keops

KErnel OPerationS, on CPUs and GPUs, with autodiff and without memory overflows
https://www.kernel-operations.io
MIT License
1.04k stars 63 forks source link

Add `Atan` to KeOps #132

Closed kshitij12345 closed 3 years ago

kshitij12345 commented 3 years ago

Adds atan

Test Plan:

import pykeops
pykeops.clean_pykeops()
import torch
from pykeops.torch import LazyTensor

device = 'cpu'

x = torch.rand(1000, 1) - 0.5
y = x.data.clone()
x = x.to(device)
y = y.to(device)
x.requires_grad = True
y.requires_grad = True

x_i = LazyTensor(x[:, None])
atanx_i = x_i.unary('Atan')

s1 = atanx_i.sum(0)
s2 = torch.sum(torch.atan(y))
print("s1 - s2", torch.abs(s1 - s2).item())
assert torch.abs(s1 - s2) < 1e-3, torch.abs(s1 - s2)

s1.backward()
s2.backward()

print("grad_s1 - grad_s2", torch.max(torch.abs(x.grad - y.grad)).item())
assert torch.max(torch.abs(x.grad - y.grad)) < 1e-3
kshitij12345 commented 3 years ago

Don't think the failures are related to PR.

joanglaunes commented 3 years ago

Hello @kshitij12345, Yes definitely the failure has nothing to do with your input, sorry about this.

kshitij12345 commented 3 years ago

@joanglaunes What would be the way forward? Is it fixed in the master?

Thanks!

joanglaunes commented 3 years ago

Hello @kshitij12345 , The previous issue was fixed but there is another issue currently with the CI. As soon as it will be ok I will merge your branch. Sorry for the delay.

kshitij12345 commented 3 years ago

@joanglaunes, Sure let me know if I will have to merge or rebase the latest master.

joanglaunes commented 3 years ago

Hello @kshitij12345 , Ok so we solved the issue, so I just merged your branch now. And the test you posted works ok. Thanks again!