Is there a way to import modules from a CPython script, but run them in PyPy?
The problem is that I have a code that uses lots of SciPy (and NumPy), but there are parts of the code that could be optimized with PyPy.
Here's a random example of what I would like to do:
sub_run_in_pypy.py module:
#assuming this can be optimized with PyPy
def function_a(foo):
return foo**2
main_run_in_cpython.py module:
import scipy.stats as stats
#assuming this exists:
import import_function_for_pypy
pypy_imported_function = import_function_for_pypy(module_name=sub_run_in_pypy, function_name=function_a)
x = stats.t.rvs(5, loc=0, scale=1, size=1)
print pypy_imported_function(x)
If this does not exist, why not?
Edit: As Bakuriu inferred, I was suggesting it could potentially be something that runs in a separate process. Would this add too much overhead?