Ejemplo n.º 1
0
def test_hyp2f1_real_some_points():
    pts = [
        (1, 2, 3, 0),
        (1. / 3, 2. / 3, 5. / 6, 27. / 32),
        (1. / 4, 1. / 2, 3. / 4, 80. / 81),
        (2, -2, -3, 3),
        (2, -3, -2, 3),
        (2, -1.5, -1.5, 3),
        (1, 2, 3, 0),
        (0.7235, -1, -5, 0.3),
        (0.25, 1. / 3, 2, 0.999),
        (0.25, 1. / 3, 2, -1),
        (2, 3, 5, 0.99),
        (3. / 2, -0.5, 3, 0.99),
        (2, 2.5, -3.25, 0.999),
        (-8, 18.016500331508873, 10.805295997850628, 0.90875647507000001),
        (-10, 900, -10.5, 0.99),
        (-10, 900, 10.5, 0.99),
        (-1, 2, 1, 1.0),
        (-1, 2, 1, -1.0),
        (-3, 13, 5, 1.0),
        (-3, 13, 5, -1.0),
    ]
    dataset = [p + (float(mpmath.hyp2f1(*p)), ) for p in pts]
    dataset = np.array(dataset, dtype=np.float_)

    FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-10).check()
Ejemplo n.º 2
0
def test_expi_complex():
    dataset = []
    for r in np.logspace(-99, 2, 10):
        for p in np.linspace(0, 2 * np.pi, 30):
            z = r * np.exp(1j * p)
            dataset.append((z, complex(mpmath.ei(z))))
    dataset = np.array(dataset, dtype=np.complex_)

    FuncData(sc.expi, dataset, 0, 1).check()
Ejemplo n.º 3
0
def test_hyp2f1_strange_points():
    pts = [
        (2, -1, -1, 0.7),
        (2, -2, -2, 0.7),
    ]
    kw = dict(eliminate=True)
    dataset = [p + (float(mpmath.hyp2f1(*p, **kw)), ) for p in pts]
    dataset = np.array(dataset, dtype=np.float_)

    FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-10).check()
Ejemplo n.º 4
0
def test_hyp2f1_real_some():
    dataset = []
    for a in [-10, -5, -1.8, 1.8, 5, 10]:
        for b in [-2.5, -1, 1, 7.4]:
            for c in [-9, -1.8, 5, 20.4]:
                for z in [-10, -1.01, -0.99, 0, 0.6, 0.95, 1.5, 10]:
                    try:
                        v = float(mpmath.hyp2f1(a, b, c, z))
                    except:
                        continue
                    dataset.append((a, b, c, z, v))
    dataset = np.array(dataset, dtype=np.float_)
    FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-9).check()
Ejemplo n.º 5
0
    def check_poly(self,
                   func,
                   cls,
                   param_ranges=[],
                   x_range=[],
                   nn=10,
                   nparam=10,
                   nx=10,
                   rtol=1e-8):
        np.random.seed(1234)

        dataset = []
        for n in np.arange(nn):
            params = [
                a + (b - a) * np.random.rand(nparam) for a, b in param_ranges
            ]
            params = np.asarray(params).T
            if not param_ranges:
                params = [0]
            for p in params:
                if param_ranges:
                    p = (n, ) + tuple(p)
                else:
                    p = (n, )
                x = x_range[0] + (x_range[1] - x_range[0]) * np.random.rand(nx)
                x[0] = x_range[0]  # always include domain start point
                x[1] = x_range[1]  # always include domain end point
                poly = np.poly1d(cls(*p))
                z = np.c_[np.tile(p, (nx, 1)), x, poly(x)]
                dataset.append(z)

        dataset = np.concatenate(dataset, axis=0)

        def polyfunc(*p):
            p = (p[0].astype(int), ) + p[1:]
            return func(*p)

        olderr = np.seterr(all='raise')
        try:
            ds = FuncData(polyfunc,
                          dataset,
                          range(len(param_ranges) + 2),
                          -1,
                          rtol=rtol)
            ds.check()
        finally:
            np.seterr(**olderr)
Ejemplo n.º 6
0
def test_hyp2f1_some_points_2():
    # Taken from mpmath unit tests -- this point failed for mpmath 0.13 but
    # was fixed in their SVN since then
    pts = [
        (112, (51, 10), (-9, 10), -0.99999),
        (10, -900, 10.5, 0.99),
        (10, -900, -10.5, 0.99),
    ]

    def fev(x):
        if isinstance(x, tuple):
            return float(x[0]) / x[1]
        else:
            return x

    dataset = [tuple(map(fev, p)) + (float(mpmath.hyp2f1(*p)), ) for p in pts]
    dataset = np.array(dataset, dtype=np.float_)

    FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-10).check()
Ejemplo n.º 7
0
def test_lpmv():
    pts = []
    for x in [-0.99, -0.557, 1e-6, 0.132, 1]:
        pts.extend([
            (1, 1, x),
            (1, -1, x),
            (-1, 1, x),
            (-1, -2, x),
            (1, 1.7, x),
            (1, -1.7, x),
            (-1, 1.7, x),
            (-1, -2.7, x),
            (1, 10, x),
            (1, 11, x),
            (3, 8, x),
            (5, 11, x),
            (-3, 8, x),
            (-5, 11, x),
            (3, -8, x),
            (5, -11, x),
            (-3, -8, x),
            (-5, -11, x),
            (3, 8.3, x),
            (5, 11.3, x),
            (-3, 8.3, x),
            (-5, 11.3, x),
            (3, -8.3, x),
            (5, -11.3, x),
            (-3, -8.3, x),
            (-5, -11.3, x),
        ])

    dataset = [p + (mpmath.legenp(p[1], p[0], p[2]), ) for p in pts]
    dataset = np.array(dataset, dtype=np.float_)

    evf = lambda mu, nu, x: sc.lpmv(mu.astype(int), nu, x)
    FuncData(evf, dataset, (0, 1, 2), 3, rtol=1e-10, atol=1e-14).check()
Ejemplo n.º 8
0
def test_hyp2f1_real_random():
    dataset = []

    npoints = 500
    dataset = np.zeros((npoints, 5), np.float_)

    np.random.seed(1234)
    dataset[:, 0] = np.random.pareto(1.5, npoints)
    dataset[:, 1] = np.random.pareto(1.5, npoints)
    dataset[:, 2] = np.random.pareto(1.5, npoints)
    dataset[:, 3] = 2 * np.random.rand(npoints) - 1

    dataset[:, 0] *= (-1)**np.random.randint(2, npoints)
    dataset[:, 1] *= (-1)**np.random.randint(2, npoints)
    dataset[:, 2] *= (-1)**np.random.randint(2, npoints)

    for ds in dataset:
        if mpmath.__version__ < '0.14':
            # mpmath < 0.14 fails for c too much smaller than a, b
            if abs(ds[:2]).max() > abs(ds[2]):
                ds[2] = abs(ds[:2]).max()
        ds[4] = float(mpmath.hyp2f1(*tuple(ds[:4])))

    FuncData(sc.hyp2f1, dataset, (0, 1, 2, 3), 4, rtol=1e-9).check()
Ejemplo n.º 9
0
def test_values():
    assert_(isnan(lambertw(nan)))
    assert_equal(lambertw(inf,1).real, inf)
    assert_equal(lambertw(inf,1).imag, 2*pi)
    assert_equal(lambertw(-inf,1).real, inf)
    assert_equal(lambertw(-inf,1).imag, 3*pi)

    assert_equal(lambertw(1.), lambertw(1., 0))

    data = [
        (0,0, 0),
        (0+0j,0, 0),
        (inf,0, inf),
        (0,-1, -inf),
        (0,1, -inf),
        (0,3, -inf),
        (e,0, 1),
        (1,0, 0.567143290409783873),
        (-pi/2,0, 1j*pi/2),
        (-log(2)/2,0, -log(2)),
        (0.25,0, 0.203888354702240164),
        (-0.25,0, -0.357402956181388903),
        (-1./10000,0, -0.000100010001500266719),
        (-0.25,-1, -2.15329236411034965),
        (0.25,-1, -3.00899800997004620-4.07652978899159763j),
        (-0.25,-1, -2.15329236411034965),
        (0.25,1, -3.00899800997004620+4.07652978899159763j),
        (-0.25,1, -3.48973228422959210+7.41405453009603664j),
        (-4,0, 0.67881197132094523+1.91195078174339937j),
        (-4,1, -0.66743107129800988+7.76827456802783084j),
        (-4,-1, 0.67881197132094523-1.91195078174339937j),
        (1000,0, 5.24960285240159623),
        (1000,1, 4.91492239981054535+5.44652615979447070j),
        (1000,-1, 4.91492239981054535-5.44652615979447070j),
        (1000,5, 3.5010625305312892+29.9614548941181328j),
        (3+4j,0, 1.281561806123775878+0.533095222020971071j),
        (-0.4+0.4j,0, -0.10396515323290657+0.61899273315171632j),
        (3+4j,1, -0.11691092896595324+5.61888039871282334j),
        (3+4j,-1, 0.25856740686699742-3.85211668616143559j),
        (-0.5,-1, -0.794023632344689368-0.770111750510379110j),
        (-1./10000,1, -11.82350837248724344+6.80546081842002101j),
        (-1./10000,-1, -11.6671145325663544),
        (-1./10000,-2, -11.82350837248724344-6.80546081842002101j),
        (-1./100000,4, -14.9186890769540539+26.1856750178782046j),
        (-1./100000,5, -15.0931437726379218666+32.5525721210262290086j),
        ((2+1j)/10,0, 0.173704503762911669+0.071781336752835511j),
        ((2+1j)/10,1, -3.21746028349820063+4.56175438896292539j),
        ((2+1j)/10,-1, -3.03781405002993088-3.53946629633505737j),
        ((2+1j)/10,4, -4.6878509692773249+23.8313630697683291j),
        (-(2+1j)/10,0, -0.226933772515757933-0.164986470020154580j),
        (-(2+1j)/10,1, -2.43569517046110001+0.76974067544756289j),
        (-(2+1j)/10,-1, -3.54858738151989450-6.91627921869943589j),
        (-(2+1j)/10,4, -4.5500846928118151+20.6672982215434637j),
        (pi,0, 1.073658194796149172092178407024821347547745350410314531),

        # Former bug in generated branch,
        (-0.5+0.002j,0, -0.78917138132659918344 + 0.76743539379990327749j),
        (-0.5-0.002j,0, -0.78917138132659918344 - 0.76743539379990327749j),
        (-0.448+0.4j,0, -0.11855133765652382241 + 0.66570534313583423116j),
        (-0.448-0.4j,0, -0.11855133765652382241 - 0.66570534313583423116j),
    ]
    data = array(data, dtype=complex_)

    def w(x, y):
        return lambertw(x, y.real.astype(int))
    olderr = np.seterr(all='ignore')
    try:
        FuncData(w, data, (0,1), 2, rtol=1e-10, atol=1e-13).check()
    finally:
        np.seterr(**olderr)
Ejemplo n.º 10
0
def data(func, dataname, *a, **kw):
    kw.setdefault('dataname', dataname)
    return FuncData(func, DATASETS[dataname], *a, **kw)