Python wrapper with test for Legendre transform

This commit is contained in:
Dag Sverre Seljebotn 2015-04-22 13:18:43 +02:00
parent 351180baf4
commit 0a0cad34aa
11 changed files with 165 additions and 0 deletions

View file

@ -0,0 +1 @@
# empty

View file

@ -0,0 +1,29 @@
import numpy as np
from scipy.special import legendre
import libsharp
def test_legendre_transform():
lmax = 20
ntheta = 19
l = np.arange(lmax + 1)
bl = np.exp(-l*(l+1))
bl *= (2 * l + 1)
theta = np.linspace(0, np.pi, ntheta, endpoint=True)
x = np.cos(theta)
# Compute truth using scipy.special.legendre
P = np.zeros((ntheta, lmax + 1))
for l in range(lmax + 1):
P[:, l] = legendre(l)(x)
y0 = np.dot(P, bl)
# double-precision
y = libsharp.legendre_transform(x, bl)
assert np.max(np.abs(y - y) / np.abs(y)) < 1e-12
# single-precision
y32 = libsharp.legendre_transform(x.astype(np.float32), bl)
assert np.max(np.abs(y32 - y) / np.abs(y32)) < 1e-4