Skip to content

Commit

Permalink
Add inputs and outputs property for directly accessing sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
sailist committed Feb 10, 2023
1 parent 0b7e859 commit 2a0a52c
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/lumo/data/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ def __init__(self):

self._iter_cache = {}

def copy(self):
db = DatasetBuilder()
db._prop = copy.copy(self._prop)
db._idx_keys = copy.copy(self._idx_keys)
db._data = copy.copy(self._data)
db._outs = copy.deepcopy(self._outs)
db._transforms = copy.copy(self._transforms)
db._outkeys = copy.copy(self._outkeys)
return db

def __repr__(self):

if self.sized:
Expand Down Expand Up @@ -129,6 +119,23 @@ def _update_len(self):
self._prop['__clen__'] = res
return res

@property
def inputs(self):
return self._data

@property
def outputs(self):
mapping = {}
for key, outkeys in self._outs.items():
if key == '::idx::':
source = range(len(self))
else:
source = self._data[key]

for outkey in outkeys:
mapping[outkey] = source
return mapping

@property
def mode(self):
return self._prop.get('mode', 'zip')
Expand All @@ -149,6 +156,16 @@ def pseudo_length(self) -> int:
def pseudo_repeat(self) -> int:
return self._prop.get('pseudo_repeat', None)

def copy(self):
db = DatasetBuilder()
db._prop = copy.copy(self._prop)
db._idx_keys = copy.copy(self._idx_keys)
db._data = copy.copy(self._data)
db._outs = copy.deepcopy(self._outs)
db._transforms = copy.copy(self._transforms)
db._outkeys = copy.copy(self._outkeys)
return db

def subset(self, indices: Sequence[int]):
self._prop['subindices'] = np.array(indices)
self._update_len()
Expand Down

0 comments on commit 2a0a52c

Please sign in to comment.