def test_install(): @lift('x -> x -> x', {'x': array_like}) def nadd(a,b,o): return np.add(a,b,o) costfn = lambda x: 0 # Anywhere an add is term is found replace with the simple NumPy # dispatch. install('FizzPop(a,b);*',nadd,costfn) expr = AAppl(ATerm('FizzPop'), [AInt(1), AInt(2)]) fn, cost = _dispatch.dispatcher.dispatch(expr) assert fn.fn == nadd.fn assert cost == 0
# These are side-effectful functions which install the core # functions into the RTS dispatcher. # The signature for PythonF # :signature: ATerm pattern matching signature # :fn: Python callable instance # :mayblock: Whether calling this function may block a thread. # ( i.e. it waits on a disk or socket ) install( 'Add(a,b) ; contig', PythonF(np.add.types, np.add, False), zerocost ) install( 'Mul(a,b) ; contig', PythonF(np.multiply.types, np.multiply, False), zerocost ) install( 'Abs(a) ; contig', PythonF(np.abs.types, np.abs, False), zerocost )