MCPcopy Create free account
hub / github.com/numpy/numpy / __iter__

Method __iter__

numpy/lib/arrayterator.py:175–219  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

173 zip(self.start, self.stop, self.step))
174
175 def __iter__(self):
176 # Skip arrays with degenerate dimensions
177 if [dim for dim in self.shape if dim <= 0]:
178 return
179
180 start = self.start[:]
181 stop = self.stop[:]
182 step = self.step[:]
183 ndims = self.var.ndim
184
185 while True:
186 count = self.buf_size or reduce(mul, self.shape)
187
188 # iterate over each dimension, looking for the
189 # running dimension (ie, the dimension along which
190 # the blocks will be built from)
191 rundim = 0
192 for i in range(ndims-1, -1, -1):
193 # if count is zero we ran out of elements to read
194 # along higher dimensions, so we read only a single position
195 if count == 0:
196 stop[i] = start[i]+1
197 elif count <= self.shape[i]:
198 # limit along this dimension
199 stop[i] = start[i] + count*step[i]
200 rundim = i
201 else:
202 # read everything along this dimension
203 stop[i] = self.stop[i]
204 stop[i] = min(self.stop[i], stop[i])
205 count = count//self.shape[i]
206
207 # yield a block
208 slice_ = tuple(slice(*t) for t in zip(start, stop, step))
209 yield self.var[slice_]
210
211 # Update start position, taking care of overflow to
212 # other dimensions
213 start[rundim] = stop[rundim] # start where we stopped
214 for i in range(ndims-1, 0, -1):
215 if start[i] >= self.stop[i]:
216 start[i] = self.start[i]
217 start[i-1] += self.step[i-1]
218 if start[0] >= self.stop[0]:
219 return

Callers

nothing calls this directly

Calls 1

minFunction · 0.50

Tested by

no test coverage detected