Skip to content

Commit

Permalink
Halo fixes?
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward committed Apr 25, 2024
1 parent 6727bb0 commit cfc270f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pyop3/array/harray.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def data_with_halos(self):

@property
def data_rw_with_halos(self):
self._check_no_copy_access()
return self.buffer.data_rw[self.axes._buffer_indices_ghost]
self._check_no_copy_access(include_ghost_points=True)
return self.buffer.data_rw_with_halos[self.axes._buffer_indices_ghost]

@property
def data_ro_with_halos(self):
Expand All @@ -272,7 +272,7 @@ def data_ro_with_halos(self):
"Read-only access to the array is provided with a copy, "
"consider avoiding if possible."
)
return self.buffer.data_ro[self.axes._buffer_indices_ghost]
return self.buffer.data_ro_with_halos[self.axes._buffer_indices_ghost]

@property
def data_wo_with_halos(self):
Expand All @@ -283,11 +283,16 @@ def data_wo_with_halos(self):
When this is called we set roots_valid, claiming that any (lazy) 'in-flight' writes
can be dropped.
"""
self._check_no_copy_access()
return self.buffer.data_wo[self.axes._buffer_indices_ghost]
self._check_no_copy_access(include_ghost_points=True)
return self.buffer.data_wo_with_halos[self.axes._buffer_indices_ghost]

def _check_no_copy_access(self):
if not isinstance(self.axes._buffer_indices, slice):
def _check_no_copy_access(self, *, include_ghost_points=False):
if include_ghost_points:
buffer_indices = self.axes._buffer_indices_ghost
else:
buffer_indices = self.axes._buffer_indices

if not isinstance(buffer_indices, slice):
raise FancyIndexWriteException(
"Writing to the array directly is not supported for "
"non-trivially indexed (i.e. sliced) arrays."
Expand Down
42 changes: 42 additions & 0 deletions pyop3/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,48 @@ def data_wo(self):
self._leaves_valid = False
return self._owned_data

@property
@not_in_flight
@deprecated(".data_rw_with_halos")
def data_with_halos(self):
return self.data_rw_with_halos

@property
@not_in_flight
def data_rw_with_halos(self):
self.state += 1

if not self._roots_valid:
self._reduce_leaves_to_roots()

# modifying owned values invalidates ghosts
self._leaves_valid = False
return self._data

@property
@not_in_flight
def data_ro_with_halos(self):
if not self._roots_valid:
self._reduce_leaves_to_roots()
return readonly(self._data)

@property
@not_in_flight
def data_wo_with_halos(self):
"""
Have to be careful. If not setting all values (i.e. subsets) should call
`reduce_leaves_to_roots` first.
When this is called we set roots_valid, claiming that any (lazy) 'in-flight' writes
can be dropped.
"""
self.state += 1

# pending writes can be dropped
self._pending_reduction = None
self._leaves_valid = False
return self._data

def copy(self):
return type(self)(
self.shape,
Expand Down

0 comments on commit cfc270f

Please sign in to comment.