Skip to content

Commit

Permalink
feat(containers): remove '.copy' method from ContainerBase.
Browse files Browse the repository at this point in the history
This method has been implemented in 'MemDiskGroup' in 'caput.memh5', so
there is no need to overwrite it here now.
  • Loading branch information
ljgray committed Mar 27, 2023
1 parent 83d4a55 commit 46d8be5
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions draco/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,62 +491,6 @@ def _make_selections(cls, sel_args):

return selections

def copy(self, shared=None):
"""Copy this container, optionally sharing the source datasets.
This routine will create a copy of the container. By default this is
as full copy with the contents fully independent. However, a set of
dataset names can be given that will share the same data as the
source to save memory for large datasets. These will just view the
same memory, so any modification to either the original or the copy
will be visible to the other. This includes all write operations,
addition and removal of attributes, redistribution etc. This
functionality should be used with caution and clearly documented.
Parameters
----------
shared : list, optional
A list of datasets whose content will be shared with the original.
Returns
-------
copy : subclass of ContainerBase
The copied container.
"""
new_cont = self.__class__(
attrs_from=self,
axes_from=self,
skip_datasets=True,
distributed=self.distributed,
comm=self.comm,
)

# Loop over datasets that exist in the source and either add a view of
# the source dataset, or perform a full copy
for name, data in self.datasets.items():
if shared and name in shared:
# TODO: find a way to do this that doesn't depend on the
# internal implementation of BasicCont and MemGroup
# NOTE: we don't use `.view()` on the RHS here as we want to
# preserve the shared data through redistributions
new_cont._data._get_storage()[name] = self._data._get_storage()[name]
else:
dset = new_cont.add_dataset(name)

# Ensure that we have exactly the same distribution
if dset.distributed:
dset.redistribute(data.distributed_axis)

# Copy over the data and attributes
dset[:] = data[:]
memh5.copyattrs(data.attrs, dset.attrs)
# TODO Is there a case where these properties don't exist?
dset.chunks = data.chunks
dset.compression = data.compression
dset.compression_opts = data.compression_opts

return new_cont


class TableBase(ContainerBase):
"""A base class for containers holding tables of data.
Expand Down

0 comments on commit 46d8be5

Please sign in to comment.