File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -248,24 +248,20 @@ class Array(object):
248248 `IndexError`.
249249 """
250250 # return an iterator over the absolute elements of a nested sequence
251- @staticmethod
252- def unroll_nest (hier , dimensions ):
253- weight = []
254- elc = 1
255- dims = list (dimensions [:- 1 ])
256- dims .reverse ()
257- for x in dims :
258- weight .insert (0 , elc )
259- elc *= x
260-
261- for x in range (elc ):
262- v = hier
263- for w in weight :
264- d , r = divmod (x , w )
265- v = v [d ]
266- x = r
267- for i in v :
268- yield i
251+ @classmethod
252+ def unroll_nest (typ , hier , dimensions , depth = 0 ):
253+ dsize = dimensions and dimensions [depth ] or 0
254+ if len (hier ) != dsize :
255+ raise ValueError ("list size not consistent with dimensions at axis " + str (depth ))
256+ r = []
257+ ndepth = depth + 1
258+ if ndepth == len (dimensions ):
259+ r = hier
260+ else :
261+ # go deeper
262+ for x in hier :
263+ r .extend (typ .unroll_nest (x , dimensions , ndepth ))
264+ return r
269265
270266 # Detect the dimensions of a nested sequence
271267 @staticmethod
You can’t perform that action at this time.
0 commit comments