コード例 #1
0
ファイル: test_addressof.py プロジェクト: meteogrid/numba
def test_addressof(arg):
    """
    >>> func = test_addressof(func)
    >>> assert func.restype == ctypes.c_int32
    >>> assert func.argtypes == (ctypes.c_int32, ctypes.c_int32)
    >>> func(5, 2)
    10
    """
    return numba.addressof(arg)
コード例 #2
0
ファイル: test_addressof.py プロジェクト: meteogrid/numba
def test_addressof(arg):
    """
    >>> func = test_addressof(func)
    >>> assert func.restype == ctypes.c_int32
    >>> assert func.argtypes == (ctypes.c_int32, ctypes.c_int32)
    >>> func(5, 2)
    10
    """
    return numba.addressof(arg)
コード例 #3
0
ファイル: test_addressof.py プロジェクト: meteogrid/numba
def test_address_of_struct_function():
    S1 = before_computed_column.to_ctypes()
    S2 = with_computed_column.to_ctypes()
    ctypes_kernel = numba.addressof(cc_kernel)

    s1 = S1(10, 5)
    s2 = S2(0, 0, 0)
    ctypes_kernel(s2, s1)

    assert s2.x == s1.x
    assert s2.y == s1.y
    assert s2.mean == (s1.x + s1.y) / 2.0
コード例 #4
0
ファイル: test_addressof.py プロジェクト: meteogrid/numba
def test_address_of_struct_function():
    S1 = before_computed_column.to_ctypes()
    S2 = with_computed_column.to_ctypes()
    ctypes_kernel = numba.addressof(cc_kernel)

    s1 = S1(10, 5)
    s2 = S2(0, 0, 0)
    ctypes_kernel(s2, s1)

    assert s2.x == s1.x
    assert s2.y == s1.y
    assert s2.mean == (s1.x + s1.y) / 2.0
コード例 #5
0
ファイル: test_addressof.py プロジェクト: meteogrid/numba
def test_addressof_error(arg, **kwds):
    """
    >>> test_addressof_error(error_func)
    Traceback (most recent call last):
        ...
    TypeError: Object is not a jit function

    >>> test_addressof_error(func, propagate=False)
    Traceback (most recent call last):
        ...
    ValueError: Writing unraisable exception is not yet supported
    """
    return numba.addressof(arg, **kwds)
コード例 #6
0
ファイル: test_addressof.py プロジェクト: meteogrid/numba
def test_addressof_error(arg, **kwds):
    """
    >>> test_addressof_error(error_func)
    Traceback (most recent call last):
        ...
    TypeError: Object is not a jit function

    >>> test_addressof_error(func, propagate=False)
    Traceback (most recent call last):
        ...
    ValueError: Writing unraisable exception is not yet supported
    """
    return numba.addressof(arg, **kwds)
コード例 #7
0
ファイル: test_unpacking.py プロジェクト: ASPP/numba
    def test_unpacking(self):
        lunpack  = jit(int_(list_(int_, 2)))(unpack)
        tunpack  = jit(int_(tuple_(int_, 2)))(unpack)
        tounpack = jit(int_(tuple_(object_, 2)))(unpack)
        iunpack  = jit(int_(object_))(unpack)
        sunpack  = jit(int_(object_))(unpack)
        punpack  = jit(int_(shape_t), wrap=False)(unpack)

        self.assertEqual(lunpack([5, 6]), 30)
        self.assertEqual(tunpack((5, 6)), 30)
        self.assertEqual(tounpack((5, 6)), 30)
        # self.assertEqual(iunpack(Iterable()), 30)
        self.assertEqual(sunpack(Sequence()), 30)

        c_punpack = nb.addressof(punpack)
        self.assertEqual(c_punpack(A.ctypes.shape), 30)
コード例 #8
0
ファイル: test_unpacking.py プロジェクト: winstonewert/numba
    def test_unpacking(self):
        lunpack = jit(int_(list_(int_, 2)))(unpack)
        tunpack = jit(int_(tuple_(int_, 2)))(unpack)
        tounpack = jit(int_(tuple_(object_, 2)))(unpack)
        iunpack = jit(int_(object_))(unpack)
        sunpack = jit(int_(object_))(unpack)
        punpack = jit(int_(shape_t), wrap=False)(unpack)

        self.assertEqual(lunpack([5, 6]), 30)
        self.assertEqual(tunpack((5, 6)), 30)
        self.assertEqual(tounpack((5, 6)), 30)
        # self.assertEqual(iunpack(Iterable()), 30)
        self.assertEqual(sunpack(Sequence()), 30)

        c_punpack = nb.addressof(punpack)
        self.assertEqual(c_punpack(A.ctypes.shape), 30)
コード例 #9
0
ファイル: test_llarray.py プロジェクト: ASPP/numba
@jit(void(double[:, :]), array=MyArray, wrap=False, nopython=True)
def use_array(A):
    """simple test function"""
    for i in range(A.shape[0]):
        for j in range(A.shape[1]):
            A[i, j] = i * A.shape[1] + j

@jit(object_(double[:, :]), array=MyArray, wrap=False)
def get_attributes(A):
    return A.shape[0], A.shape[1], A.strides[0], A.strides[1]

# ______________________________________________________________________

# Ctypes functions
c_use_array      = numba.addressof(use_array)
c_get_attributes = numba.addressof(get_attributes)

c_use_array.argtypes      = [ctypes.POINTER(CtypesArray)]
c_get_attributes.argtypes = [ctypes.POINTER(CtypesArray)]

# ______________________________________________________________________
# Utils

Array = namedtuple('Array', ['handle', 'array', 'data', 'shape', 'strides'])

def make_array():
    """Make a double[*, 10] ctypes-allocated array"""
    empty = lambda c_type, args: ctypes.cast(
        (c_type * len(args))(*args), ctypes.POINTER(c_type))
コード例 #10
0
ファイル: test_llarray.py プロジェクト: winstonewert/numba
def use_array(A):
    """simple test function"""
    for i in range(A.shape[0]):
        for j in range(A.shape[1]):
            A[i, j] = i * A.shape[1] + j


@jit(object_(double[:, :]), array=MyArray, wrap=False)
def get_attributes(A):
    return A.shape[0], A.shape[1], A.strides[0], A.strides[1]


# ______________________________________________________________________

# Ctypes functions
c_use_array = numba.addressof(use_array)
c_get_attributes = numba.addressof(get_attributes)

c_use_array.argtypes = [ctypes.POINTER(CtypesArray)]
c_get_attributes.argtypes = [ctypes.POINTER(CtypesArray)]

# ______________________________________________________________________
# Utils

Array = namedtuple('Array', ['handle', 'array', 'data', 'shape', 'strides'])


def make_array():
    """Make a double[*, 10] ctypes-allocated array"""
    empty = lambda c_type, args: ctypes.cast((c_type * len(args))
                                             (*args), ctypes.POINTER(c_type))