Ejemplo n.º 1
0
def test_add_multiple_ndarrays():
    a = symbol("a", "5 * 4 * int64")
    b = symbol("b", "5 * 4 * float32")
    x = np.arange(9, dtype="int64").reshape(3, 3)
    y = (x + 1).astype("float32")
    expr = sin(a) + 2 * b
    scope = {a: x, b: y}
    expected = sin(x) + 2 * y

    # check that we cast correctly
    assert expr.dshape == dshape("5 * 4 * float64")

    np.testing.assert_array_equal(compute(expr, scope), expected)
    np.testing.assert_array_equal(compute(expr, scope, optimize=False), expected)
Ejemplo n.º 2
0
def test_add_multiple_ndarrays():
    a = symbol('a', '5 * 4 * int64')
    b = symbol('b', '5 * 4 * float32')
    x = np.arange(9, dtype='int64').reshape(3, 3)
    y = (x + 1).astype('float32')
    expr = sin(a) + 2 * b
    scope = {a: x, b: y}
    expected = sin(x) + 2 * y

    # check that we cast correctly
    assert expr.dshape == dshape('5 * 4 * float64')

    np.testing.assert_array_equal(compute(expr, scope), expected)
    np.testing.assert_array_equal(compute(expr, scope, optimize=False),
                                  expected)
Ejemplo n.º 3
0
    def test_compound(self):
        s = t.amount.mean()
        r = compute(s, data)
        assert isinstance(r, float)

        expr = cos(s) ** 2 + sin(s) ** 2
        result = compute(expr, data)
        expected = math.cos(r) ** 2 + math.sin(r) ** 2
        assert result == expected
Ejemplo n.º 4
0
    def test_compound(self):
        s = t.amount.mean()
        r = compute(s, data)
        assert isinstance(r, float)

        expr = cos(s)**2 + sin(s)**2
        result = compute(expr, data)
        expected = math.cos(r)**2 + math.sin(r)**2
        assert result == expected
Ejemplo n.º 5
0
def test_scalar_arithmetic():
    x = symbol('x', 'real')
    y = symbol('y', 'real')
    assert compute(x + y, {x: 2, y: 3}) == 5
    assert compute_up(x + y, 2, 3) == 5
    assert compute_up(x * y, 2, 3) == 6
    assert compute_up(x / y, 6, 3) == 2
    assert compute_up(x % y, 4, 3) == 1
    assert compute_up(x ** y, 4, 3) == 64

    assert compute(x + 1, {x: 2}) == 3
    assert compute(x * 2, {x: 2}) == 4
    assert compute(1 + x, {x: 2}) == 3
    assert compute(2 * x, {x: 2}) == 4

    assert compute_up(-x, 1) == -1

    assert compute_up(blaze.sin(x), 1) == math.sin(1)
Ejemplo n.º 6
0
def test_scalar_arithmetic():
    x = Symbol('x', 'real')
    y = Symbol('y', 'real')
    assert compute(x + y, {x: 2, y: 3}) == 5
    assert compute_up(x + y, 2, 3) == 5
    assert compute_up(x * y, 2, 3) == 6
    assert compute_up(x / y, 6, 3) == 2
    assert compute_up(x % y, 4, 3) == 1
    assert compute_up(x**y, 4, 3) == 64

    assert compute(x + 1, {x: 2}) == 3
    assert compute(x * 2, {x: 2}) == 4
    assert compute(1 + x, {x: 2}) == 3
    assert compute(2 * x, {x: 2}) == 4

    assert compute_up(-x, 1) == -1

    assert compute_up(blaze.sin(x), 1) == math.sin(1)
Ejemplo n.º 7
0
 def distance(lat1, lon1, lat2, lon2, R=3959):
     # http://andrew.hedges.name/experiments/haversine/
     dlon = radians(lon2 - lon1)
     dlat = radians(lat2 - lat1)
     a = sin(dlat / 2.0) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2.0) ** 2
     return R * 2 * atan2(sqrt(a), sqrt(1 - a))
Ejemplo n.º 8
0
 def distance(lat1, lon1, lat2, lon2, R=3959):
     # http://andrew.hedges.name/experiments/haversine/
     dlon = radians(lon2 - lon1)
     dlat = radians(lat2 - lat1)
     a = sin(dlat / 2.0) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2.0) ** 2
     return R * 2 * atan2(sqrt(a), sqrt(1 - a))
Ejemplo n.º 9
0
 def myfunc(x):
     return myother((cos(x) + sin(x)) ** 2 / math.pi)
Ejemplo n.º 10
0
 def myfunc(x):
     return (cos(x) + sin(x)) ** 2 / math.pi
Ejemplo n.º 11
0
 def myfunc(x):
     return myother((cos(x) + sin(x))**2 / math.pi)
Ejemplo n.º 12
0
 def myfunc(x):
     return (cos(x) + sin(x))**2 / math.pi
Ejemplo n.º 13
0
 def test_sin(self):
     a = blaze.array([0, math.pi/6, math.pi/3, 0.5*math.pi,
                      math.pi, 1.5*math.pi, 2*math.pi])
     b = blaze.array([0, 0.5, 0.5*blaze.sqrt(3), 1, 0, -1, 0])
     assert_allclose(blaze.sin(a), b, rtol=1e-15, atol=1e-15)
     assert_allclose(blaze.sin(-a), -b, rtol=1e-15, atol=1e-15)