Refactor.

Modify the way CDefinition is specialized.
This commit is contained in:
Siu Kwan Lam 2012-08-07 16:55:33 -07:00
commit 2acc070984
4 changed files with 96 additions and 51 deletions

View file

@ -1,13 +1,20 @@
'''
Test parallel-vectorize with numpy.fromfunc.
Uses the work load from test_parallel_vectorize.
'''
from test_parallel_vectorize import *
import numpy as np
def main():
module = Module.new(__name__)
PUfuncDef = ParallelUFuncPosix.specialize(num_thread=2)
SPUF = SpecializedParallelUFunc.specialize(
PUfuncDef, UFuncCore_D_D, Work_D_D)
sppufunc = SPUF.define(module)
spufdef = SpecializedParallelUFunc(ParallelUFuncPosix(num_thread=2),
UFuncCore_D_D(),
Work_D_D())
sppufunc = spufdef(module)
module.verify()
@ -27,6 +34,11 @@ def main():
ptr_t = long # py2 only
# Becareful that fromfunc does not provide full error checking yet.
# If typenum is out-of-bound, we have nasty memory corruptions.
# For instance, -1 for typenum will cause segfault.
# If elements of type-list (2nd arg) is tuple instead,
# there will also memory corruption. (Seems like code rewrite.)
typenum = np.dtype(np.double).num
ufunc = np.fromfunc([ptr_t(funcptr)], [[typenum, typenum]], 1, 1, [None])