How to duplicate input matrix M number of times?

lightspeed.johnny's icon

Need some more help from the smart jitter people...

Let's say I have an input matrix that is a single dimension of length N, and a dial control that lets the user chooser a number, M, between 0 and lets say 5. M is the number of duplicates*.

What is the best way to duplicate this matrix M times (creating discrete copies, i.e., not references to the original but independent copies) and concatenating each duplicate to a final output matrix that is of length N*(M+1) - i.e. if M is 0, then the output is just the original matrix, if M is 1, then the output is the original matrix concated with a copy... etc...

Here is a simple block diagram:

lightspeed.johnny's icon

I have been struggling with this all day and not getting very far...

I was trying to find an elegant solution - but it feels like I am going to have to use some type of scripting object to add/delete the duplicate matrices and handle all of the dynamic connections. I was really hoping there would be a more elegant solution - but I am not good enough at jitter to figure that out.

Also, I can't figure out how to use jit.glue to glue together a set of matrices. I keep getting mismatch dim errors - all of my input matrices are 1 dimensional and it seems jit.glue really wants to use a 2 dimensional matrix. How do I tell jit.glue that my matrix only has 1 dimension? Uhg - pulling my hair out with this one.

Here is my playground patch.

Max Patch
Copy patch and select New From Clipboard in Max.

Anyone have any suggestions?

Update: fixed connection issue with duplicate matrices

Tobias Rosenberger's icon
Max Patch
Copy patch and select New From Clipboard in Max.

i would glue once into the largest size and then use submatrix to reference a specific dimension:

LSka's icon
Max Patch
Copy patch and select New From Clipboard in Max.

if you specify "5 1" as dims for you matrices, jit.glue accepts them.
Then you can set the maximum number of rows in jit.glue and dynamically change it using the dial:

lightspeed.johnny's icon

if you specify "5 1" as dims for you matrices, jit.glue accepts them.
Then you can set the maximum number of rows in jit.glue and dynamically change it using the dial:

Beautiful! Thank you guys very much!

I did not know that specifying the dim as "5 1" is different than just specifying the dim as "5"... interesting... but your example is almost exactly what I was looking for. I can stop hating jit.glue now!

The only issue I see now (which could be a negligible one - will need to do some testing), is that say I set the number of duplicates to 0 - all of the duplicate matrices are still running through their op objects - taking up needless CPU cycles - they just aren't being concatenated by jit.glue.

In my real world patch, the size of the input matrix is actually something like 1000 / (M+1) 3d points (3 planes), i.e., the total number of points in the final matrix is always the same. So when M is 0, the original matrix is going to contain 1000 or so 3d points - and my ops are actually much more mathematically complex than just + val. But so far, CPU usage is staying under control given the nice multithreaded nature of MOPs.

I'll have to look into if this is a performance issue or not - maybe I can use routes to "mute" or not send output matrices to the jit.op objects - reducing the CPU load.

Thanks everyone!