Reverse 'Sample'

    Aug 09 2012 | 11:28 am
    I'm trying to write a jit.gen patch to resample an input matrix based upon cell addresses contained within a plane of the matrix itself. For example, the matrix has two planes, the first is data, the second is a target cell address. Cell 0 contains value 65 and a target address of 10. The gen patch should look at the second plane and move the data value to this cell address in the output matrix.
    It seems the 'sample' object can only select cells from an incoming matrix. Is there a way to do a 'reverse sample' and select a cell in the output matrix to be written to rather than processing them in order?

    • Aug 09 2012 | 2:05 pm
      I realize it's not jit.gen, but I think the standard Jitter object jit.repos could do something like what you want (precede it with jit.unpack, then use the second plane to reposition the first plane).
    • Aug 09 2012 | 5:47 pm
      Unfortunately this is not possible. A matrix input can be sampled from at any position but you can't write to arbitrary locations of the output. Conceptually, Gen code is designed to be run once per cell of the output matrix, and each cell is unaware of what is happening with the other cells. This is consistent with how GLSL code is written.
    • Aug 12 2012 | 9:11 pm
      @David The kinds of algorithms you're describing are referred to as "gather" and "scatter". [sample] does a gather operation and you want to do a scatter. Sometimes it's possible to recast a scatter operation as a gather by performing intermediate calculations such as sorting or binning. In your case, you're going to want to sort your cells according to the second plane and then through some mechanism read from a group of neighboring cells with the same destination in order to accomplish the task you're working on. It's not a trivial task to do these kinds of things and lots of GPGPU research has been dedicated to solving these kinds of problems efficiently.
    • Aug 13 2012 | 1:01 pm
      Thanks for the information Wesley. I'll do some research and see if I can find an efficient solution.