Exemplo n.º 1
0
 def test_exp_values(self):
     x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
     y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     for ds in ['float32', 'float64']:
         log2_ = 0.69314718055994530943
         xf = blaze.array(x, dshape=ds)
         yf = blaze.array(y, dshape=ds)*log2_
         result = blaze.exp(yf)
         assert_almost_equal(result, xf)
Exemplo n.º 2
0
            print(expected)
            if isinstance(result, float):
                assert abs(result - expected) < 0.001
            else:
                assert result == expected

exprs = [
    t['amount'],
    t['amount'] == 100,
    t['amount'].truncate(150),
    t[t['name'] == 'Alice'],
    t[t['amount'] == 0],
    t[t['amount'] > 150],
    t['amount'] + t['id'],
    t['amount'] % t['id'],
    exp(t['amount']),
    by(t['name'], total=t['amount'].sum()),
    by(t['name'], total=(t['amount'] + 1).sum()),
    (t['amount'] * 1).label('foo'),
    t.map(lambda tup: tup[1] + tup[2], 'real'),
    t.like(name='Alice'),
    t['amount'].apply(identity, 'var * real', splittable=True),
    t['amount'].map(inc, 'int')]


def test_spark_basic(rdd):
    check_exprs_against_python(exprs, data, rdd)


def check_exprs_against_python(exprs, data, rdd):
    any_bad = False
Exemplo n.º 3
0
 def test_expm1(self):
     assert_almost_equal(blaze.expm1(0.2), blaze.exp(0.2)-1)
     assert_almost_equal(blaze.expm1(1e-6), blaze.exp(1e-6)-1)
Exemplo n.º 4
0
@pytest.mark.parametrize('expr', reduction_exprs)
def test_reductions(expr, rdd):
    result = compute(expr, rdd)
    expected = compute(expr, data)
    if not result == expected:
        print(result)
        print(expected)
        if isinstance(result, float):
            assert abs(result - expected) < 0.001
        else:
            assert result == expected


exprs = (t['amount'], t['amount'] == 100, t['amount'].truncate(150),
         t[t['name'] == 'Alice'], t[t['amount'] == 0], t[t['amount'] > 150],
         t['amount'] + t['id'], t['amount'] % t['id'], exp(t['amount']),
         by(t['name'], total=t['amount'].sum()),
         by(t['name'],
            total=(t['amount'] + 1).sum()), (t['amount'] * 1).label('foo'),
         t.map(lambda tup: tup[1] + tup[2], 'real'), t[t.name.like('Alice')],
         t['amount'].apply(identity, 'var * real', splittable=True),
         t['amount'].map(lambda x: x + 1, 'int'))

exprs = list(zip(map(str, exprs), exprs))


def tuplify(x):
    return tuple(x) if isinstance(x, list) else x


@pytest.mark.parametrize(['string', 'expr'], exprs)