@vectorize'd functions can't be pickled
See original GitHub issuenumba 0.37.0, Python 3.6, Anaconda 5, Linux 64-bit
Being able to pickle (the reference to) a function is a fundamental prerequisite to dask.distributed. Functions wrapped with @vectorize fail to pickle, whereas @guvectorize has no issues. I’ve tried both with and without explicit signatures.
From the documentation for @vectorize:
If signatures is non-empty, then the decorator will compile the user Python function into a Numpy ufunc. If no signatures are given, then the decorator will wrap the user Python function in a DUFunc instance
However, it looks like the above is not true - @vectorize always returns a DUFunc, whereas @guvectorize returns a ufunc:
import pickle
from numba import vectorize, guvectorize
@vectorize(["float64(float64)"])
def inc1(x):
return x + 1
@guvectorize(["void(float64, float64[:])"], "()->()")
def inc2(x, out):
out[0] = x + 1
print(type(inc2))
print(pickle.dumps(inc2))
print(type(inc1))
print(pickle.dumps(inc1))
Output:
<class 'numpy.ufunc'>
b'\x80\x03cnumpy.core\n_ufunc_reconstruct\nq\x00X\x0b\x00\x00\x00__mp_main__q\x01X\x04\x00\x00\x00inc2q\x02\x86q\x03Rq\x04.'
<class 'numba.npyufunc.dufunc.DUFunc'>
Traceback (most recent call last):
File "vectorize_pickle.py", line 15, in <module>
print(pickle.dumps(inc1))
TypeError: can't pickle DUFunc objects
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cannot pickle and unpickle vectorized functions. #8099 - GitHub
Problem I tried to pickle and unpickle an object that contains attributes of vectorized functions that were created with numpy.frompyfunc.
Read more >Python Multiprocessing error "Can't pickle <ufunc '<lambda ...
Within it I have the following two functions: ... run into the error Can't pickle <ufunc '<lambda> (vectorized)'>: it's not found as main....
Read more >Can't pickle <class 'Vector'>: attribute lookup Vector on builtins ...
As you can't pickle mathutils.Vector directly you need to convert it to an object that can be pickled. This also means you need...
Read more >Do Not Use Python Pickle Unless You Know All These Points
Pickle's Pros. Pickle constructs arbitrary Python objects by invoking arbitrary functions, that's why it is not secure. However, this enables it ...
Read more >Python's Pickle: Pickling Explained | Analytics Vidhya | - Medium
“Pickling” is the process whereby a Python object hierarchy is converted into ... (which can't represent pointer sharing); however it means that non-Python ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It will be fixed, but I am not sure when. We’re aware that
jitclass
needs some work, we added a tag a while back to group all the things may need a fix https://github.com/numba/numba/issues?q=is%3Aissue+is%3Aopen+label%3Ajitclass, there’s quite a few 😃Thank you for quick response. Is there any estimation, whether (and possibly when) it will be fixed? But i absolutely understand, if it has low preference.