Skip to content

Commit

Permalink
[DataSet] Remove old, unused indexing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleas-k committed Sep 27, 2019
1 parent 03402e3 commit 2e7ea70
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions nixio/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,91 +116,6 @@ def append(self, data, axis=0):
sl = tuple(slice(o, c+o) for o, c in zip(offset, count))
self._write_data(data, sl)

@staticmethod
def __index_to_tuple(index):
tidx = type(index)

if tidx == tuple:
return index
elif tidx == int or tidx == slice:
return (index, )
elif tidx == type(Ellipsis):
return ()
else:
raise IndexError("Unsupported index")

@staticmethod
def __complete_slices(shape, index):
if type(index) is slice:
if index.step is not None:
raise IndexError('Invalid index, stepping unsupported')
start = index.start
stop = index.stop
if start is None:
start = 0
elif start < 0:
start = shape + start
if stop is None:
stop = shape
elif stop < 0:
stop = shape + stop
index = slice(start, stop, index.step)
elif type(index) is int:
if index < 0:
index = shape + index
index = slice(index, index+1)
else:
index = slice(index, index+1)
elif index is None:
index = slice(0, shape)
else:
raise IndexError('Invalid index')
return index

@staticmethod
def __fill_none(shape, index, to_replace=1):
size = len(shape) - len(index) + to_replace
return tuple([None] * size)

def __tuple_to_count_offset_shape(self, index):
# precondition: type(index) == tuple and len(index) >= 1
fill_none = self.__fill_none
shape = self.shape

if index[0] is Ellipsis:
index = fill_none(shape, index) + index[1:]
if index[-1] is Ellipsis:
# if we have a trailing ellipsis we just cut it away
# and let complete_slices do the right thing
index = index[:-1]

# here we handle Ellipsis in the middle of the tuple
# we *can* only handle one, if there are more, then
# __complete_slices will raise a InvalidIndex error
pos = index.index(Ellipsis) if Ellipsis in index else -1
if pos > -1:
index = index[:pos] + fill_none(shape, index) + index[pos+1:]

# in python3 map does not work with None therefore if
# len(shape) != len(index) we wont get the expected
# result. We therefore need to fill up the missing values
index = index + fill_none(shape, index, to_replace=0)

completed = list(map(self.__complete_slices, shape, index))
combined = list(map(lambda s: (s.start, s.stop), completed))
count = tuple(x[1] - x[0] for x in combined)
offset = [x for x in zip(*combined)][0]

# drop all indices from count that came from single ints
# NB: special case when we only have ints, e.g. (int, ) then
# we get back the empty tuple and this is what we want,
# because it indicates a scalar result
squeezed = map(lambda i, c: c if type(i) != int
else None, index, count)
shape = list(filter(lambda x: x is not None, squeezed))

return count, offset, shape

def _write_data(self, data, sl=None):
dataset = self._h5group.get_dataset("data")
dataset.write_data(data, sl)
Expand Down

0 comments on commit 2e7ea70

Please sign in to comment.