Skip to content

Commit 2c757d7

Browse files
authored
Merge pull request #1 from dwest77a/CFAPyX
Merging required for this version
2 parents 560f4a6 + 7749fc7 commit 2c757d7

File tree

1 file changed

+2
-62
lines changed

1 file changed

+2
-62
lines changed

arraypartition/partition.py

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -125,66 +125,6 @@ def shape(self):
125125
@shape.setter
126126
def shape(self, value):
127127
self._shape = value
128-
129-
def _combine_slices(self, newslice):
130-
"""
131-
Combine existing ``extent`` attribute with a new set of slices.
132-
133-
:param newslice: (tuple) A set of slices to apply to the data
134-
'Super-Lazily', i.e the slices will be combined with existing information
135-
and applied later in the process.
136-
137-
:returns: The combined set of slices.
138-
"""
139-
140-
if len(newslice) != len(self.shape):
141-
if hasattr(self, 'active'):
142-
# Mean has already been computed. Raise an error here
143-
# since we should be down to dealing with numpy arrays now.
144-
raise ValueError(
145-
"Active chain broken - mean has already been accomplished."
146-
)
147-
148-
else:
149-
raise ValueError(
150-
"Compute chain broken - dimensions have been reduced already."
151-
)
152-
153-
def combine_sliced_dim(old, new, dim):
154-
155-
ostart = old.start or 0
156-
ostop = old.stop or self.shape[dim]
157-
ostep = old.step or 1
158-
159-
osize = (ostop - ostart)/ostep
160-
161-
nstart = new.start or 0
162-
nstop = new.stop or self.shape[dim]
163-
nstep = new.step or 1
164-
165-
nsize = (nstop - nstart)/nstep
166-
167-
if nsize > osize:
168-
raise IndexError(
169-
f'Attempted to slice dimension "{dim}" with new slice "({nstart},{nstop},{nstep})'
170-
f'but the dimension size is limited to {osize}.'
171-
)
172-
173-
start = ostart + ostep*nstart
174-
step = ostep * nstep
175-
stop = start + step * (nstop - nstart)
176-
177-
return slice(start, stop, step)
178-
179-
180-
if not self._extent:
181-
return newslice
182-
else:
183-
extent = list(self.get_extent())
184-
for dim in range(len(newslice)):
185-
if not _identical_extents(extent[dim], newslice[dim], self.shape[dim]):
186-
extent[dim] = combine_sliced_dim(extent[dim], newslice[dim], dim)
187-
return extent
188128

189129
def get_extent(self):
190130
return tuple(self._extent)
@@ -198,7 +138,7 @@ def copy(self, extent=None):
198138
"""
199139
kwargs = self.get_kwargs()
200140
if extent:
201-
kwargs['extent'] = self._combine_slices(extent)
141+
kwargs['extent'] = combine_slices(self.shape, list(self.get_extent()), extent)
202142

203143
new_instance = SuperLazyArrayLike(
204144
self.shape,
@@ -423,7 +363,7 @@ def copy(self, extent=None):
423363
"""
424364
kwargs = self.get_kwargs()
425365
if extent:
426-
kwargs['extent'] = self._combine_slices(extent)
366+
kwargs['extent'] = combine_slices(self.shape, list(self.get_extent()), extent)
427367

428368
new_instance = ArrayPartition(
429369
self.filename,

0 commit comments

Comments
 (0)