Permalink
Browse files

Add test for (todo) struct support and ctypes function addressof

  • Loading branch information...
1 parent 59400c3 commit c4ecc2cdbdc51c3014a31f3d9814cd08b811d0a7 @markflorisson markflorisson committed Apr 4, 2013
Showing with 42 additions and 11 deletions.
  1. +7 −7 numba/codegen/llvmcontext.py
  2. +2 −4 numba/codegen/translate.py
  3. +33 −0 numba/tests/test_addressof.py
@@ -39,13 +39,13 @@ def __initialize(self, opt, cg, inline):
m = self.__module = lc.Module.new("numba_executable_module")
# Create the TargetMachine
features = ''
- try:
- from llvm.workaround.avx_support import detect_avx_support
- if not detect_avx_support():
- features = '-avx'
- except ImportError:
- # Old llvm, disable AVX for all
- features = '-avx'
+ # try:
+ # from llvm.workaround.avx_support import detect_avx_support
+ # if not detect_avx_support():
+ # features = '-avx'
+ # except ImportError:
+ # # Old llvm, disable AVX for all
+ features = '-avx'
tm = self.__machine = le.TargetMachine.new(opt=cg, cm=le.CM_JITDEFAULT,
features=features)
# Create the ExceutionEngine
@@ -8,7 +8,6 @@
from numba.llvm_types import _int1, _int32, _LLVMCaster
from numba.multiarray_api import MultiarrayAPI # not used
-from numba.symtab import Variable
from numba import typesystem
from numba import *
@@ -24,8 +23,7 @@
from numba import ndarray_helpers, error
from numba.typesystem import is_obj
from numba.utils import dump
-from numba import naming, metadata
-from numba.functions import keep_alive
+from numba import metadata
from numba.control_flow import ssa
from numba.support.numpy_support import sliceutils
from numba.nodes import constnodes
@@ -184,7 +182,7 @@ def _init_args(self):
variable = self.symtab.get(argname, None)
if self.renameable(variable):
- if argtype.is_struct:
+ if argtype.is_struct or argtype.is_reference:
larg = self._allocate_arg_local(argname, argtype, larg)
# Set value on first definition of the variable
@@ -20,6 +20,26 @@ def func(a, b):
def error_func():
pass
+# TODO: struct pointer support
+
+before_computed_column = struct([
+ ('x', float32),
+ ('y', float32)])
+
+with_computed_column = struct([
+ ('mean', float32),
+ ('x', float32),
+ ('y', float32)])
+
+signature = void(with_computed_column.ref(),
+ before_computed_column.ref())
+
+# @jit(signature, nopython=True)
+def cc_kernel(dst, src):
+ dst.mean = (src.x + src.y) / 2.0
+ dst.x = src.x
+ dst.y = src.y
+
#------------------------------------------------------------------------
# Tests
#------------------------------------------------------------------------
@@ -48,5 +68,18 @@ def test_addressof_error(arg, **kwds):
"""
return numba.addressof(arg, **kwds)
+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
+
numba.testmod()

0 comments on commit c4ecc2c

Please sign in to comment.