Beispiel #1
0
"""
>>> test_valid_compare()
>>> invalid_compare(np.arange(10))
Traceback (most recent call last):
      ...
NumbaError: 27:11: Cannot determine truth value of boolean array (use any or all)
"""

import numpy as np
from numba import autojit, jit, double, b1

def array(a):
    return a > 0.1

#fails too
#array_nb = jit(b1[:](double[:]))(array)
def test_valid_compare():
    array_nb = autojit(array)
    a = np.random.rand(1e6)
    assert np.allclose(array(a), array_nb(a))

@autojit
def invalid_compare(a):
    return 1 < a < 2


if __name__ == '__main__':
    from numba.testing import test_support
    test_support.testmod()
    a = float(a)
    b = a * a  # + 1j # Promotion issue
    return inner


@autojit
def test_cellvar_promotion_error(a):
    """
    >>> from numba.minivect import minierror
    >>> try:
    ...     test_cellvar_promotion_error(10)
    ... except error.UnpromotableTypeError as e:
    ...     print(sorted(e.args, key=str))
    [(int, string)]
    """
    b = int(a) * 2

    @jit(void())
    def inner():
        print((a * b))

    inner()
    a = np.empty(10, dtype=np.double)
    b = "hello"
    return inner


#test_cellvar_promotion(10)
#test_cellvar_promotion_error(10)
testmod()
Beispiel #3
0
@autojit_py3doc
def listcomp_const_condition_false():
    """
    >>> listcomp_const_condition_false()
    []
    """
    return [x*2 for x in range(3) if 0]

@autojit_py3doc
def listcomp_const_condition_true():
    """
    >>> listcomp_const_condition_true()
    [0, 2, 4]
    """
    return [x*2 for x in range(3) if 1]


if __name__ == '__main__':
#    print test_pointer_arithmetic()
#    a = np.array([1, 2, 3, 4], dtype=np.float32)
#    print test_pointer_indexing(a.ctypes.data, float32.pointer())
    pass

#int_runvar()
#smoketest()
#list_genexp()
#test_listcomp()
# smoketest()
testmod()
Beispiel #4
0
>>> invalid_compare(np.arange(10))
Traceback (most recent call last):
      ...
NumbaError: 27:11: Cannot determine truth value of boolean array (use any or all)
"""

import numpy as np
from numba import autojit, jit, double, b1


def array(a):
    return a > 0.1


#fails too
#array_nb = jit(b1[:](double[:]))(array)
def test_valid_compare():
    array_nb = autojit(array)
    a = np.random.rand(1e6)
    assert np.allclose(array(a), array_nb(a))


@autojit(warnstyle="simple")
def invalid_compare(a):
    return 1 < a < 2


if __name__ == '__main__':
    from numba.testing import test_support
    test_support.testmod()