Skip to content
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

compiler: Fix pickling of aliasing SparseFunction #2148

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion devito/types/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ def coordinates(self):

@property
def coordinates_data(self):
return self.coordinates.data.view(np.ndarray)
try:
return self.coordinates.data.view(np.ndarray)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.data._local

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it gets fixed in your PR, I'm merging

except AttributeError:
return None

@cached_property
def _point_symbols(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,25 @@ def test_receiver(self, pickle):
assert np.all(new_rec.data == 1)
assert np.all(new_rec.coordinates.data == [[0.], [1.], [2.]])

def test_alias_sparse_function(self, pickle):
grid = Grid(shape=(3,))
sf = SparseFunction(name='sf', grid=grid, npoint=3, space_order=2,
coordinates=[(0.,), (1.,), (2.,)])
sf.data[0] = 1.

# Create alias
f0 = sf._rebuild(name='f0', alias=True)

pkl_f0 = pickle.dumps(f0)
new_f0 = pickle.loads(pkl_f0)

assert f0.data is None and new_f0.data is None
assert f0.coordinates.data is None and new_f0.coordinates.data is None

assert sf.space_order == f0.space_order == new_f0.space_order
assert sf.dtype == f0.dtype == new_f0.dtype
assert sf.npoint == f0.npoint == new_f0.npoint


@pytest.mark.parametrize('pickle', [pickle0, pickle1])
class TestOperator(object):
Expand Down