Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b0fcd32
Added rudimentary support for complex numbers (no arithmetic yet).
Jun 26, 2012
2aa4873
Reindent tabs to spaces (inconsistent indentation)
markflorisson Jun 26, 2012
358cdca
Add gitignore
markflorisson Jun 26, 2012
0316248
Add minivect as submodule to numba
markflorisson Jun 26, 2012
1be7392
Add type system with slicable types and LLVM conversion
markflorisson Jun 26, 2012
4bf3e3a
Add type conversion from Python to Numba and Numba to LLVM
markflorisson Jun 27, 2012
d05f9b5
Added type inference
markflorisson Jun 27, 2012
9568936
Adapt translater to use new type system and symbol table (not finished)
markflorisson Jun 28, 2012
2758807
Get example compiling and callable
markflorisson Jun 28, 2012
d7681ae
Create new Variable when assigning to variables
markflorisson Jun 29, 2012
eedcd85
Restore numba_compile default signature
markflorisson Jun 29, 2012
9e48690
Undo minivect symlink
markflorisson Jun 29, 2012
b80ad3a
Add submodule notice
markflorisson Jun 29, 2012
e248ff2
Compile for loops
markflorisson Jun 30, 2012
d554b85
Get for loops running
markflorisson Jun 30, 2012
1e6e639
Support Py_ssize_t type and PyObject_Length() for len(obj)
markflorisson Jun 30, 2012
f0b9932
Incorporate pymothoa
markflorisson Jul 4, 2012
65d59d5
Implement type inference on an AST
markflorisson Jul 4, 2012
5200b7f
Add type inference for numpy attributes (dtypes, *_like, arange)
markflorisson Jul 4, 2012
9491cde
Copy over ast code generator & numba translator
markflorisson Jul 5, 2012
f324e2c
Add slicing and indexing to type inference (tuples, slices, ellipsis,…
markflorisson Jul 5, 2012
f68f8f6
Start adapting code generation to ASTs
markflorisson Jul 5, 2012
993b9cc
Support None as newaxis index
markflorisson Jul 5, 2012
340e2a3
Continue translating code generator to ASTs
markflorisson Jul 5, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reindent tabs to spaces (inconsistent indentation)
  • Loading branch information
markflorisson committed Jun 27, 2012
commit 2aa4873b9eb9090dc1ee859657ecbc979aa03577
6 changes: 3 additions & 3 deletions numba/ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def op_BINARY_ADD(self, i, op, arg):
arg1 = self.stack.pop(-1)
r = arg1 + arg2
self.stack.append(r)
if (id(arg1) in self.watcher.svars
if (id(arg1) in self.watcher.svars
or id(arg2) in self.watcher.svars):
s1 = self.watcher.svars.get(id(arg1), arg1)
s2 = self.watcher.svars.get(id(arg2), arg2)
Expand All @@ -91,7 +91,7 @@ def op_BINARY_SUBTRACT(self, i, op, arg):
arg1 = self.stack.pop(-1)
r = arg1 - arg2
self.stack.append(r)
if (id(arg1) in self.watcher.svars
if (id(arg1) in self.watcher.svars
or id(arg2) in self.watcher.svars):
s1 = self.watcher.svars.get(id(arg1), arg1)
s2 = self.watcher.svars.get(id(arg2), arg2)
Expand All @@ -102,7 +102,7 @@ def op_BINARY_MULTIPLY(self, i, op, arg):
arg1 = self.stack.pop(-1)
r = arg1 * arg2
self.stack.append(r)
if (id(arg1) in self.watcher.svars
if (id(arg1) in self.watcher.svars
or id(arg2) in self.watcher.svars):
s1 = self.watcher.svars.get(id(arg1), arg1)
s2 = self.watcher.svars.get(id(arg2), arg2)
Expand Down
32 changes: 16 additions & 16 deletions numba/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# that creates a fast version of Python code using LLVM
# It maintains the generic function call for situations
# where it cannot figure out a fast version, and specializes
# based on the types that are passed in.
# It maintains a dictionary keyed by python code +
# argument-types with a tuple of either
# based on the types that are passed in.
# It maintains a dictionary keyed by python code +
# argument-types with a tuple of either
# (bitcode-file-name, function_name)
# or (llvm mod object and llvm func object)

Expand All @@ -16,23 +16,23 @@ class CallSite(object):
# func = Callsite(*args, **kwds)(func)
# args[0] cannot be callable
def __init__(self, *args, **kwds):
# True if this instance is now a function
# True if this instance is now a function
self._isfunc = False
self._args = args
if len(args) > 1 and callable(args[0]):
self._tocall = args[0]
self._isfunc = True
self._args = args[1:]

def __call__(self, *args, **kwds):
if self._isfunc:
return self._tocall(*args, **kwds)
else:
if len(args) < 1 or not callable(args[0]):
raise ValueError, "decorated object must be callable"
self._tocall = args[0]
self._isfunc = True
return self
def __call__(self, *args, **kwds):
if self._isfunc:
return self._tocall(*args, **kwds)
else:
if len(args) < 1 or not callable(args[0]):
raise ValueError, "decorated object must be callable"
self._tocall = args[0]
self._isfunc = True
return self

# A simple fast-vectorize example

Expand All @@ -58,9 +58,9 @@ def vectorize(func):
t = __tr_map__[func]
return t.make_ufunc()
except:
print "Warning: Could not create fast version..."
import numpy
return numpy.vectorize(func)
print "Warning: Could not create fast version..."
import numpy
return numpy.vectorize(func)

# XXX Proposed name; compile() would mask builtin of same name.
def numba_compile(*args, **kws):
Expand Down
63 changes: 26 additions & 37 deletions numba/kerneltranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
_void_star, # base
_void_star, # descr
lc.Type.int(32), # flags
_void_star, # weakreflist
_void_star, # weakreflist
_void_star, # maskna_dtype
_void_star, # maskna_data
_intp_star, # masna_strides
Expand Down Expand Up @@ -89,17 +89,17 @@ def __init__(self, base, args):
self.args = args


# Variables placed on the stack.
# Variables placed on the stack.
# They allow an indirection
# So, that when used in an operation, the correct
# LLVM type can be inserted.
# LLVM type can be inserted.
class Variable(object):
def __init__(self, val):
if isinstance(val, Variable):
self.val = val.val
self._llvm = val._llvm
self.typ = val.typ
return
return
self.val = val
if isinstance(val, lc.Value):
self._llvm = val
Expand All @@ -110,7 +110,7 @@ def __init__(self, val):
self.typ = pythontype_to_strtype(val.dtype)
else:
self.typ = pythontype_to_strtype(type(val))

def llvm(self, typ=None, mod=None):
if self._llvm:
if typ is not None and typ != self.typ:
Expand All @@ -124,15 +124,15 @@ def llvm(self, typ=None, mod=None):
elif typ == 'f32':
res = lc.Constant.real(lc.Type.float(), float(self.val))
elif typ[0] == 'i':
res = lc.Constant.int(lc.Type.int(int(typ[1:])),
res = lc.Constant.int(lc.Type.int(int(typ[1:])),
int(self.val))
elif typ[0] == 'func':
res = map_to_function(self.val, typ[1:], mod)
elif typ[:3] == 'arr':
pass
return res

# Add complex, unsigned, and bool
# Add complex, unsigned, and bool
def str_to_llvmtype(str):
if str[0] == 'f':
if str[1:] == '32':
Expand All @@ -158,7 +158,7 @@ def typcmp(type1, type2):
return -1

# Both inputs are Variable objects
# Resolves types on one of them.
# Resolves types on one of them.
# Won't work if both need resolving
# Does not up-cast llvm types
def resolve_type(arg1, arg2):
Expand All @@ -168,10 +168,10 @@ def resolve_type(arg1, arg2):
typ = arg2.typ
else:
raise TypeError, "Both types not valid"

return typ, arg1.llvm(typ), arg2.llvm(typ)

# This won't convert any llvm types. It assumes
# This won't convert any llvm types. It assumes
# the llvm types in args are either fixed or not-yet specified.
def func_resolve_type(mod, func, args):
# already an llvm function
Expand Down Expand Up @@ -232,7 +232,7 @@ def __init__(self, func):
except KeyError:
self._myglobals[name] = __builtin__.__getattribute__(name)

self.mod = lc.Module.new(func.func_name+'_mod')
self.mod = lc.Module.new(func.func_name+'_mod')

self._delaylist = [range, xrange, enumerate]
self.setup_func()
Expand All @@ -241,17 +241,17 @@ def setup_func(self):
# XXX: Fix the typing here.
double = lc.Type.double()
# The return type will not be known until the return
# function is created. So, we will need to
# function is created. So, we will need to
# walk through the code twice....
# Once to get the type of the return, and again to
# emit the instructions.
# Once to get the type of the return, and again to
# emit the instructions.
# Or, we assume the function has been called already
# and the return type is transknown and passed in.
# and the return type is transknown and passed in.
self.ret_ltype = double
# The arg_ltypes we will be able to get from what is passed in
argnames = self.fco.co_varnames[:self.fco.co_argcount]
self.arg_ltypes = [double for arg in argnames]
ty_func = lc.Type.function(self.ret_ltype, self.arg_ltypes)
ty_func = lc.Type.function(self.ret_ltype, self.arg_ltypes)
self.lfunc = self.mod.add_function(ty_func, self.func.func_name)
self._locals = [None]*len(self.fco.co_varnames)
for i, name in enumerate(argnames):
Expand All @@ -267,12 +267,12 @@ def translate(self):
"""
for i, op, arg in itercode(self.costr):
name = opcode.opname[op]
# Change the builder if the line-number
# is in the list of blocks.
# Change the builder if the line-number
# is in the list of blocks.
if i in self.blocks.keys():
self.builder = lc.Builder.new(self.blocks[i])
getattr(self, 'op_'+name)(i, op, arg)

# Perform code optimization
fpm = lp.FunctionPassManager.new(self.mod)
fpm.initialize()
Expand All @@ -285,10 +285,10 @@ def make_ufunc(self, name=None):
ee = le.ExecutionEngine.new(self.mod)
if name is None:
name = self.func.func_name
return core.make_ufunc(ee.get_pointer_to_function(self.lfunc),
return core.make_ufunc(ee.get_pointer_to_function(self.lfunc),
name)

# This won't convert any llvm types. It assumes
# This won't convert any llvm types. It assumes
# the llvm types in args are either fixed or not-yet specified.
def func_resolve_type(self, func, args):
# already an llvm function
Expand Down Expand Up @@ -327,8 +327,8 @@ def op_LOAD_GLOBAL(self, i, op, arg):

def op_LOAD_CONST(self, i, op, arg):
const = Variable(self.constants[arg])
self.stack.append(const)
self.stack.append(const)

def op_BINARY_ADD(self, i, op, arg):
arg2 = self.stack.pop(-1)
arg1 = self.stack.pop(-1)
Expand All @@ -348,7 +348,7 @@ def op_BINARY_SUBTRACT(self, i, op, arg):
else: # typ[0] == 'i'
res = self.builder.sub(arg1, arg2)
self.stack.append(Variable(res))

def op_BINARY_MULTIPLY(self, i, op, arg):
arg2 = self.stack.pop(-1)
arg1 = self.stack.pop(-1)
Expand Down Expand Up @@ -399,10 +399,10 @@ def op_COMPARE_OP(self, i, op, arg):
arg1 = self.stack.pop(-1)
typ, arg1, arg2 = resolve_type(arg1, arg2)
if typ[0] == 'f':
res = self.builder.fcmp(_compare_mapping_float[cmpop],
res = self.builder.fcmp(_compare_mapping_float[cmpop],
arg1, arg2)
else: # integer FIXME: need unsigned as well...
res = self.builer.icmp(_compare_mapping_sint[cmpop],
res = self.builer.icmp(_compare_mapping_sint[cmpop],
arg1, arg2)
self.stack.append(Variable(res))

Expand Down Expand Up @@ -432,14 +432,3 @@ def op_CALL_FUNCTION(self, i, op, arg):

def op_GET_ITER(self, i, op, arg):
pass











2 changes: 1 addition & 1 deletion numba/llvm_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
_void_star, # base
_void_star, # descr
_int32, # flags
_void_star, # weakreflist
_void_star, # weakreflist
_void_star, # maskna_dtype
_void_star, # maskna_data
_intp_star, # masna_strides
Expand Down
Loading