tBuLi/kingdon

Register custom expressions for codegen and caching

Closed this issue · 0 comments

tBuLi commented

Currently we predefine certain operators for codegen, whose resulting functions are cached. However, users should also be able to register their own expressions for codegen, which will benefit from all the same infrastructure.

Example of a potential syntax:

myfunc = lambda x, y, z: x * y + z
alg.exprs.register(myfunc, name="myfunc")

# Call the function
res = alg.exprs.myfunc(x, y, z)

Calling it this way will ensure we can perform our usual symbolically optimized codegen, and can cache the result such that subsequent evaluation will be fast.

All the existing GA operators such as gp, proj etc. should also be moved to alg.exprs.