Jit.spill back to matrix

Thorvald's icon

Hey,

I'm making a patch where a matrix 1 goes into a jit.spill and then into a maximum, to find the highest value in that matrix. This value and its index must be sent to another matrix to be stored, and this process happens iteratively, so a stream of the highest value at any given moment is added to a matrix 2, and all of the values are stored.

How can i do this? Jit.fill seemed like the obvious option, but the jit.spill will only give me one number (the maximum) and all the rest are zeroes, and the zeroes will overwrite the other stored numbers. The jit.spill gives a list as an output, so i'm trying to convert the list back into a matrix. The matrix in question is 150x200, giving a list of 30000 which needs to be converted back to 150 rows and 200 columns. WHat's the best way to do this without, overwriting any on the previous data?

Rob Ramirez's icon

if you want to overwrite a single cell value in a matrix use the setcell message. if you want to convert a list to a matrix use jit.fill. If you want to convert a 1D matrix to a 2D matrix use jit.scanwrap.

TFL's icon

Here's my take for getting the max value and its coordinates:

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

...and then I remember I already saw that in the forum. So here is a better answer from Graham Wakefield, and some older approach there.

As for how to store that in another matrix, it is unclear how you want to store that exactly. Probably setcell is just what you need as Rob suggested.

Thorvald's icon

Using a 1D list instead of 2D and converting it using scanwrap worked, thanks Rob!

Seems like TFLs answer might be more efficient, will check it out, thanks:)

TFL's icon

For getting the max and its indices, GW's method is by far the most efficient so far:

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

I'm getting obsessed with these benchmarks...