def broadcastParentsFromPlan(slice, seldimpath, plan, origdims, bcdims, refslices, partial):#{{{ used_dims = [False,] * len(slice.dims) if not plan: return slice while True: #determine filter dim lastpos = slice.dims.matchDimPath(seldimpath) for filterpos in lastpos[::-1]: if(not used_dims[filterpos]): break else: break #pack up to and including filter dim packdepth = len(slice.dims) - filterpos if(packdepth): slice = PackArrayOp(slice,packdepth) #broadcast to constraint slice,splan = broadcast_fromplan(slice, refslices, plan, origdims, bcdims, partial) #adapt used_dims used_dims = dimpaths.applyPlan(used_dims,splan,newvalue=True,copyvalue=True,ensurevalue=True,existvalue=True) used_dims[filterpos] = True #unpack dims if(packdepth): slice = UnpackArrayOp(slice,packdepth) return slice#}}}
def filter(slice,constraint,seldimpath, ndim, mode="dim"):#{{{ used_dims = [False,] * len(slice.dims) while True: #determine filter dim lastpos = slice.dims.matchDimPath(seldimpath) for filterpos in lastpos[::-1]: if(not used_dims[filterpos]): break else: break #pack up to and including filter dim packdepth = len(slice.dims) - filterpos if(packdepth): tslice = PackArrayOp(slice,packdepth) else: tslice = slice #prepare adaptation of ndim.dependent if(not ndim is None): dep = list(ndim.dependent) while(len(dep) < len(constraint.dims)): dep.insert(0,False) #broadcast to constraint (tslice,tconstraint),(splan,cplan) = broadcast([tslice,constraint],mode=mode, partial=True) #adapt ndim to braodcast, apply filter #FIXME: change dependent dims of slice.type if(not ndim is None): if(isinstance(tconstraint.type,rtypes.TypeSlice) and seldimpath[-1].dependent): #if variable, extend variability ndep = dimpaths.applyPlan(dep[::-1],cplan,newvalue=True, copyvalue=True, ensurevalue=True) else: ndep = dimpaths.applyPlan(dep[::-1],cplan,newvalue=False) xndim = ndim.changeDependent(tuple(ndep[::-1]), tslice.dims) else: #optimization: do not broadcast array of integer dim, to later remove it if cplan and cplan[-1] == BCSOURCE: ndim = constraint.dims[-1] constraint = PackArrayOp(constraint) continue xndim = ndim slice = FilterOp(tslice,tconstraint,xndim,constraint) #adapt used_dims used_dims = dimpaths.applyPlan(used_dims,splan,newvalue=True,copyvalue=True,ensurevalue=True, existvalue=True) #handle dim removal, filter_dim is used if(ndim is None): #dimension removed/collapsed packdepth -= 1 del used_dims[len(cplan)] else: used_dims[len(cplan)] = True #unpack dims if(packdepth): slice = UnpackArrayOp(slice,packdepth) #break out of loop if there was only one dim match (necessary to prevent #bug in which a dimpath starting with root gets matched multiple times) if len(lastpos) <= 1: break return slice#}}}