Commit bfeb12e9 authored by Gilles Guitton's avatar Gilles Guitton

Merge commit '5eda768c' into develop

For use of a cleaner Slices object without waiting the merge of new datamodel slices mechanism.
parents 2204fc4f 5eda768c
......@@ -257,7 +257,7 @@ class Slices(tuple):
raise Exception('Unexpected type for dimsizes.')
# Check slices input type
if slices is None:
_slices = [slice(None)] * len(dimsizes)
_slices = [slice(None)] * len(_dimsizes)
elif isinstance(slices, (slice, int)):
_slices = [slices]
elif isinstance(slices, tuple):
......@@ -602,17 +602,21 @@ class Slices(tuple):
return None, None
outmin = int(np.maximum(0, outmin))
outmax = int(np.minimum(abssize - 1, outmax))
# TMP check
if outmin < 0 or outmin >= abssize or outmax < 0 or outmax >= abssize:
raise Exception()
# Check outmin / outmax
assert outmin >= 0 and outmin < abssize and \
outmax >= 0 and outmax < abssize
# Find insub min and max
inmin = int(absmin + outmin * abs(absstep) - submin)
inmax = int(absmin + outmax * abs(absstep) - submin)
# TMP check
if inmin < 0 or inmin >= subsize or inmax < 0 or inmax >= subsize:
raise Exception()
# Check inmin / inmax
assert inmin >= 0 and inmin < subsize and \
inmax >= 0 and inmax < subsize
# Make slices
if absstep > 0:
if self._is_index[i]:
assert outmin == outmax and inmin == inmax
outsub_slices.append(outmin)
insub_slices.append(inmin)
elif absstep > 0:
outsub_slices.append(slice(outmin, outmax+1, 1))
insub_slices.append(slice(inmin, inmax+1, absstep))
else:
......@@ -623,10 +627,9 @@ class Slices(tuple):
else:
instop = inmin - 1
insub_slices.append(slice(inmax, instop, absstep))
res = (Slices(outsub_slices, shp), Slices(insub_slices, sub_size))
# TMP check
for size1, size2 in zip(res[0].shape(), res[1].shape()):
if size1 != size2:
raise Exception()
res = (Slices(tuple(outsub_slices), shp),
Slices(tuple(insub_slices), sub_size))
# Check shapes
assert res[0].shape() == res[1].shape()
return res
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment