Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
implement fcncache
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Oct 12, 2017
1 parent c6f68cc commit ba56c6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 12 additions & 2 deletions arrowed/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def __call__(self, resolved, *args):
else:
return out

def compile(function, paramtypes, env={}, numbaargs={"nopython": True, "nogil": True}, debug=False):
def compile(function, paramtypes, env={}, numbaargs={"nopython": True, "nogil": True}, fcncache=None, debug=False):
if fcncache is not None:
fcnkey = (function, tuple(sorted(paramtypes.items())), tuple(sorted(env.items())), tuple(sorted(numbaargs.items())))
if fcnkey in fcncache:
return fcncache[fcnkey]

# turn the 'function' argument into the syntax tree of a function
if isinstance(function, string_types):
sourcefile = "<string>"
Expand Down Expand Up @@ -199,7 +204,12 @@ def sym(key):
# print(projection.format(" "))
print("")

return Compiled(transformed, parameters, env, numbaargs)
out = Compiled(transformed, parameters, env, numbaargs)

if fcncache is not None:
fcncache[fcnkey] = out

return out

################################################################ functions inserted into code

Expand Down
8 changes: 4 additions & 4 deletions arrowed/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ def hasbase(self, base):
def proxy(self, index=0):
raise TypeError("cannot get a proxy for an unresolved ObjectArrayMap; call the resolved method first or pass a source to this method")

def compile(self, function, paramtypes={}, env={}, numba={"nopython": True, "nogil": True}, debug=False):
def compile(self, function, paramtypes={}, env={}, numba={"nopython": True, "nogil": True}, fcncache=None, debug=False):
import arrowed.compiler
paramtypes = paramtypes.copy()
paramtypes[0] = self

return arrowed.compiler.compile(function, paramtypes, env=env, numbaargs=numba, debug=debug)
return arrowed.compiler.compile(function, paramtypes, env=env, numbaargs=numba, fcncache=fcncache, debug=debug)

def run(self, function, paramtypes={}, env={}, numba={"nopython": True, "nogil": True}, debug=False, *args):
def run(self, function, paramtypes={}, env={}, numba={"nopython": True, "nogil": True}, fcncache=None, debug=False, *args):
import arrowed.compiler

if not isinstance(function, arrowed.compiler.Compiled):
base = self
while base.base is not None:
base = base.base
function = base.compile(function, paramtypes=paramtypes, env=env, numba=numba, debug=debug)
function = base.compile(function, paramtypes=paramtypes, env=env, numba=numba, fcncache=fcncache, debug=debug)

return function(self, *args)

Expand Down
2 changes: 1 addition & 1 deletion arrowed/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import re

__version__ = "0.0.10"
__version__ = "0.0.11"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down

0 comments on commit ba56c6e

Please sign in to comment.