@parametrize(Base1, specialized_class1, obj1, obj2)
def test_staticmethods(obj):
    assert obj.static1() == 10.0
    assert obj.static2(10.0) == 20.0
    assert obj.static3(5.0, 6.0) == 30.0
    assert obj.static4(5.0, 6.0) == 30.0


@parametrize(Base1, specialized_class1, obj1, obj2)
def test_classmethods(obj):
    assert obj.class1() == 10.0
    assert obj.class2(10.0) == 20.0
    assert obj.class3(5.0, 6.0) == 30.0
    assert obj.class4(5.0, 6.0) == 30.0


@parametrize(obj1)
def test_specialized_unbound(obj):
    assert type(obj) is specialized_class1
    assert specialized_class1.getvalue(obj) == 10.0


@parametrize(obj2)
def test_specialized_unbound2(obj):
    assert issubclass(type(obj), Base1)
    assert type(obj).getvalue(obj) == 11


if __name__ == '__main__':
    main()
Exemplo n.º 2
0
    return Base, Derived

#------------------------------------------------------------------------
# Tests
#------------------------------------------------------------------------

@parametrize(jit, autojit)
def test_baseclass_attrs(compiler):
    Base = make_base(compiler)

    assert Base(10, 11.0).value1 == 10.0
    assert Base(10, 11.0).value2 == 11

    obj = Base(10, 11.0)
    obj.setvalue(12)
    assert obj.getvalue1() == 12.0

@parametrize(jit) #, autojit)
def test_derivedclass_attrs(compiler):
    Base, Derived = make_derived(compiler)

    obj = Derived(10, 11.0)
    obj.setvalue(9)
    assert obj.value3 == 9.0


if __name__ == '__main__':
    # test_derivedclass_attrs(autojit)
    main()
Exemplo n.º 3
0
    return ra

class TestIssue57(unittest.TestCase):
    def test_ra_numba(self):
        test_fn = jit('f4[:,:](i2,f4[:,:])')(ra_numba)
        lat = np.deg2rad(np.ones((5, 5), dtype=np.float32) * 45.)
        control_arr = ra_numpy(120, lat)
        test_arr = test_fn(120, lat)
        self.assertTrue(np.allclose(test_arr, control_arr))

def benchmark(test_fn=None, control_fn=None):
    if test_fn is None:
        test_fn = jit('f4[:,:](i2,f4[:,:])')(ra_numba)
    if control_fn is None:
        control_fn = ra_numpy
    lat = np.deg2rad(np.ones((2000, 2000), dtype=np.float32) * 45.)
    t0 = time.time()
    control_arr = control_fn(120, lat)
    t1 = time.time()
    test_arr = test_fn(120, lat)
    t2 = time.time()
    dt0 = t1 - t0
    dt1 = t2 - t1
    logger.info('Control time %0.6fs, test time %0.6fs' % (dt0, dt1))
    assert np.allclose(test_arr, control_arr)
    return dt0, dt1

if __name__ == "__main__":
    test_support.main()
Exemplo n.º 4
0
from numba.testing import test_support

import numpy

import unittest

# NOTE: See also numba.tests.ops.test_binary_ops


def maxstar1d(a, b):
    M = a.shape[0]
    res = numpy.empty(M)
    for i in range(M):
        res[i] = numpy.max(a[i], b[i]) + numpy.log1p(
            numpy.exp(-numpy.abs(a[i] - b[i])))
    return res


class TestIssue56(unittest.TestCase):
    def test_maxstar1d(self):
        test_fn = jit('f8[:](f8[:],f8[:])')(maxstar1d)
        test_a = numpy.random.random(10)
        test_b = numpy.random.random(10)
        self.assertTrue(
            numpy.allclose(test_fn(test_a, test_b), maxstar1d(test_a, test_b)))


if __name__ == "__main__":
    #    TestIssue56("test_maxstar1d").debug()
    test_support.main()