getkeops / keops

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

Add `Asin` to KeOps #129

Closed kshitij12345 closed 3 years ago

kshitij12345 commented 3 years ago

Adds asin

Test Plan:

import 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])
asinx_i = x_i.unary('Asin')

s1 = asinx_i.sum(0)
s2 = torch.sum(torch.asin(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