-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix regression on gufunc serialization #6826
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import unittest | ||
import pickle | ||
|
||
import numpy as np | ||
import numpy.core.umath_tests as ut | ||
|
||
from numba import void, float32, jit, guvectorize | ||
from numba.np.ufunc import GUVectorize | ||
from numba.tests.support import tag, TestCase | ||
import unittest | ||
|
||
|
||
def matmulcore(A, B, C): | ||
|
@@ -281,5 +283,90 @@ class TestGUVectorizeScalarParallel(TestGUVectorizeScalar): | |
target = 'parallel' | ||
|
||
|
||
class TestGUVectorizePickling(TestCase): | ||
def test_pickle_gufunc_non_dyanmic(self): | ||
"""Non-dynamic gufunc. | ||
""" | ||
@guvectorize(["f8,f8[:]"], "()->()") | ||
def double(x, out): | ||
out[:] = x * 2 | ||
|
||
# pickle | ||
ser = pickle.dumps(double) | ||
cloned = pickle.loads(ser) | ||
|
||
cloned.disable_compile() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this has any effect but is harmless. |
||
|
||
# scalar version | ||
self.assertPreciseEqual(double(0.5), cloned(0.5)) | ||
# array version | ||
arr = np.arange(10) | ||
self.assertPreciseEqual(double(arr), cloned(arr)) | ||
|
||
def test_pickle_gufunc_dyanmic_null_init(self): | ||
"""Dynamic gufunc w/o prepopulating before pickling. | ||
""" | ||
@guvectorize("()->()") | ||
def double(x, out): | ||
out[:] = x * 2 | ||
|
||
# pickle | ||
ser = pickle.dumps(double) | ||
cloned = pickle.loads(ser) | ||
|
||
# scalar version | ||
expect = np.zeros(1) | ||
got = np.zeros(1) | ||
double(0.5, out=expect) | ||
cloned(0.5, out=got) | ||
self.assertPreciseEqual(expect, got) | ||
# array version | ||
arr = np.arange(10) | ||
expect = np.zeros_like(arr) | ||
got = np.zeros_like(arr) | ||
double(arr, out=expect) | ||
cloned(arr, out=got) | ||
self.assertPreciseEqual(expect, got) | ||
|
||
def test_pickle_gufunc_dyanmic_initialized(self): | ||
"""Dynamic gufunc prepopulated before pickling. | ||
|
||
Once unpickled, we disable compilation to verify that the gufunc | ||
compilation state is carried over. | ||
""" | ||
@guvectorize("()->()") | ||
def double(x, out): | ||
out[:] = x * 2 | ||
|
||
# prepopulate scalar | ||
expect = np.zeros(1) | ||
got = np.zeros(1) | ||
double(0.5, out=expect) | ||
# prepopulate array | ||
arr = np.arange(10) | ||
expect = np.zeros_like(arr) | ||
got = np.zeros_like(arr) | ||
double(arr, out=expect) | ||
|
||
# pickle | ||
ser = pickle.dumps(double) | ||
cloned = pickle.loads(ser) | ||
|
||
# disable compilation | ||
cloned.disable_compile() | ||
# scalar version | ||
expect = np.zeros(1) | ||
got = np.zeros(1) | ||
double(0.5, out=expect) | ||
cloned(0.5, out=got) | ||
self.assertPreciseEqual(expect, got) | ||
# array version | ||
expect = np.zeros_like(arr) | ||
got = np.zeros_like(arr) | ||
double(arr, out=expect) | ||
cloned(arr, out=got) | ||
self.assertPreciseEqual(expect, got) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if these tests ought to also check, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These attributes are now tested explicitly |
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think
self._frozen
should be in here, it is transmittable state and should prevent further compilation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed