class ParticleField(object): def __init__(self): self._group = Syncgroup() self._varnames = [] # keep varnames as list to preserve order def __setattr__(self, name, value): if isinstance(value, CLVar): if not(name in self._varnames): self._group.add(value) self._varnames.append(name) object.__setattr__(self, name, value) else: object.__getattribute__(self, name).value = value.value else: if isinstance(value, np.ndarray) and (name in self._varnames): object.__getattribute__(self, name).value = value else: object.__setattr__(self, name, value) def __len__(self): return len(self._group._vars[0]) def setup_vec(self, *args): for arg in args: self.__setattr__(arg, CLReal4()) def setup_scal(self, *args): for arg in args: self.__setattr__(arg, CLReal()) def setup_int(self, *args): for arg in args: self.__setattr__(arg, CLInt()) def set_length(self, value): self._group._vars[0].shape = (value,) + self._group._vars[0].shape[1:]
#CLController().set_device_cpu() from numcl.group import Syncgroup from numcl.CLTypes import * from indexing import ZIndex pnp = np.array(np.random.rand(1000000,4)*100, dtype=np.float64) p = CLReal4() p.value = pnp i = CLUInt(len(p)) zind = ZIndex(posarg=p, index=i, h=1.) zind() #print i """ inp = np.array([9, 6, 3, 7, 3, 6, 0, 1, 3, 5], dtype=np.uint32) inp.shape = (len(inp),1) i = CLUInt(len(inp)) i.value = inp i2np = np.array(np.random.rand(100000000,1)*100, dtype=np.uint32) i2np.shape = (len(i2np),1) i2 = CLUInt(len(i2np)) i2.value = i2np#""" group = Syncgroup(p) group.setup_sort(i) group.sort() print i #rint np.sort(inp2, axis=0) #print group._grid
def __init__(self): self._group = Syncgroup() self._varnames = [] # keep varnames as list to preserve order