change dim of matrix without altering data

    Jan 07 2013 | 3:34 am
    Is there an optimal way to do this? Say for example I have a "char 5 5" matrix and I want to change it to a "char 1 25" matrix. Where the underlying data doesn't change and isn't copied, just the way its dimmed is changed. Hoping there was something like jit.coerce for changing the dimension...

    • Jan 07 2013 | 5:08 pm
      Here's one way.
    • Jan 08 2013 | 1:53 am
      Thanks Chistopher. I actually am using the jit.spill and jit.fill technique now but its slow - even slower since I have 4 plane matrices and got to split apart the planes and rejoin them after. The thing that grabs me is that data is exactly the same before and after: in the "4 char 5 5" to "4 char 1 25" conversion example both matrices have the same 25 RGB values in the same order (I think). Can't I leave the data intact and un-copied and just "header munge" (disclaimer: I'm not really sure what that means) the matrix dimensions. This would all happen in a billionth of a millisecond with one object, as opposed to the slow rube goldberg contraption I am using now ;) Anybody?
    • Jan 08 2013 | 6:33 am
      Sure, the data is the same, and in fact I think (I haven't looked at the Jitter SDK in a long time) that the internal storage method is extremely similar, so it would probably not be too tough to make a single Jitter object that does what you're suggesting (just changes the matrix dimensions while holding the same data). But I'm not aware of any object that does that, and as you can see there's more than one way to "flatten" a 2D matrix into a 1D matrix (by rows top to bottom, or by columns left to right, or by rows bottom to top, or by columns right to left, or by some other algorithm), not to mention trying to figure out a generalizable way to convert any matrix dimension to any other matrix dimension while still retaining the data in a knowable order.
      So you might ask yourself why you need to do this conversion. Is it possible that you can just change your ideas about how to access the data in its original form? That is, what can you do with data in a 25x1 matrix that you can't do with it in a 5x5 matrix?
    • Jan 08 2013 | 8:01 am
      hey, you can use jit.scanwrap:
    • Jan 08 2013 | 2:52 pm
      There ya go! Thanks, Tobias. I forgot about that one.
    • Jan 09 2013 | 2:05 am
      Thats the ticket! Thank Tobias - and I thought I searched through all those those jit objects that I've never used and understood poorly, but there it is. Thanks Christopher, for the spending the time to help solve my problem. BTW, in answer to your question of what I can do with a "4 char 25 1" matrix that I can't do with a "4 char 5 5" matrix: I need to output every frame of a playing video as a list to send to an array of LED tiles. But I need to reorder the pixels so that each tile's pixels are sent out in consecutive order. To complicate matters I am trying to create a generalized solution for arrays of different sizes and configurations. I've tried a variety of solutions - currently I'm using javascript to create the right number of tile-sized jit.submatrix objects and stepping through the tile array a tile at a time. The new solution I'm investigating is to use jit.expr to reorder the pixels in a single step but the only algorithm I could muster involved "flattening" the video data to one dimension so that I only needed to calculate my displacements in x. Also trying to figure out if I can do this somehow in Gen, but so far this is exceeding my capabilities - the normalization of x and y coordinates in Gen has complicated my determination of a displacement algorithm...