[Gridflow-dev] feature request: [#shuffle]

Claude Heiland-Allen claudiusmaximus at goto10.org
Tue Jan 10 20:09:15 EST 2006


Hi all,

I'm working on something, and would find it really handy to have a 
[#shuffle] object that would take an input grid's 'vectors' and swap 
them with each other to give a random permutation.

method init (int dimension)
   * dimension is optional (default is ???)
   * if negative it is counted from the last dimension backwards

inlet 0 method grid (grid(d0 d1 d2 ... dN) grid)
   * see below

inlet 1 method int
   * sets dimension

outlet 0 method grid (grid(d0 d1 d2 ... dN) grid)

:: here is below ::

inlet 0 method grid (grid(d0 d1 d2 ... dN) grid)

Given a grid G and a dimension index d:

Let D be d after wrapping negative indices,
Let dim_(n) be the size of dimension n of grid G,
Let grid[i] be the grid found at the index i of dimension 0 of grid,
Let Swap(g1,g2) perform an in-place swap of two subgrids of equal size,
Let Rand(i) be (roughly) equivalent to standard C "rand()%i",

Then #shuffle(G, d) does the following:

for(int i_0 = 0; i_0 < dim_(0); (i_0)++) {
   for(int i_1 = 0; i_1 < dim_(1); (i_1)++) {
     :
     for(int i_(D-1) = 0; i_(D-1) < dim_(D-1) {
       Swap(grid[       i_0 ][       i_1 ]...[       i_(D-1) ],
            grid[Rand(dim_0)][Rand(dim_1)]...[Rand(dim_(D-1))])
     }
     :
   }
}
outlet(G)


Does this seem useful to anyone else but me?

Does my pseudo-code implementation seem correct and/or reasonable?

Is there a faster algorithm out there to randomly permute?
  (I admit I haven't looked...)

What are the chances of this being implemented and debugged by anyone 
other than myself within two weeks?

Alternatively, is there a way to do this (efficiently) within Pd+GF or 
Pd+GF+Ruby?


Many thanks for your attention,


Claude
-- 
http://claudiusmaximus.goto10.org



More information about the Gridflow-dev mailing list