Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar authored Dec 13, 2022
1 parent 65cb7ac commit 2e8fc97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/column.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class Column:
@property
def children(self) -> Tuple[ColumnBase, ...]: ...
def set_base_children(self, value: Tuple[ColumnBase, ...]) -> None: ...
def _detach_refs(self, zero_copied=False) -> None: ...
def _buffers_shallow_copied(self) -> bool: ...
def _unlink_shared_buffers(self, zero_copied=False) -> None: ...
def _is_shared_buffers(self) -> bool: ...
def _buffers_zero_copied(self) -> bool: ...
def _mimic_inplace(
self, other_col: ColumnBase, inplace=False
Expand Down
18 changes: 9 additions & 9 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,20 @@ cdef class Column:
self._children = None
self._base_children = value

def _buffers_shallow_copied(self) -> bool:
def _is_shared_buffers(self) -> bool:
"""
Determines if any of the buffers underneath the column
have been shallow copied
have been shared else-where.
"""
data_shallow_copied = (
is_data_shared = (
isinstance(self.base_data, CopyOnWriteBuffer) and
self.base_data._shallow_copied()
self.base_data._is_shared()
)
mask_shallow_copied = (
is_mask_shared = (
isinstance(self.base_mask, CopyOnWriteBuffer) and
self.base_mask._shallow_copied()
self.base_mask._is_shared()
)
return mask_shallow_copied or data_shallow_copied
return is_mask_shared or is_data_shared

def _buffers_zero_copied(self):
data_zero_copied = (
Expand All @@ -339,12 +339,12 @@ cdef class Column:
)
return data_zero_copied or mask_zero_copied

def _detach_refs(self, zero_copied=False):
def _unlink_shared_buffers(self, zero_copied=False):
"""
Detaches a column from its current Buffers by making
a true deep-copy.
"""
if not self._buffers_zero_copied() and self._buffers_shallow_copied():
if not self._buffers_zero_copied() and self._is_shared_buffers():
new_col = self.force_deep_copy()
self._offset = new_col.offset
self._size = new_col.size
Expand Down
10 changes: 5 additions & 5 deletions python/cudf/cudf/core/buffer/cow_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def _from_host_memory(cls: Type[T], data: Any) -> T:
ret._finalize_init()
return ret

def _shallow_copied(self):
def _is_shared(self):
"""
Return `True` if shallow copies of `self` exist.
Return `True` if `self`'s memory is shared with other columns.
"""
return len(self.__class__._instances[(self.ptr, self.size)]) > 1

Expand Down Expand Up @@ -128,15 +128,15 @@ def __cuda_array_interface__(self) -> dict:
# control over knowing if a third-party library
# has modified the data this Buffer is
# pointing to.
self._detach_refs(zero_copied=True)
self._unlink_shared_buffers(zero_copied=True)

result = self._cuda_array_interface_readonly
result["data"] = (self.ptr, False)
return result

def _detach_refs(self, zero_copied=False):
def _unlink_shared_buffers(self, zero_copied=False):
"""
Detaches a Buffer from it's weak-references by making
Unlinks a Buffer if it is shared with other buffers(i.e., weak references exist) by making
a true deep-copy.
"""
if not self._zero_copied and self._shallow_copied():
Expand Down

0 comments on commit 2e8fc97

Please sign in to comment.