Executing a jit.gen function on each cell

junjk's icon

EDIT: In case somebody else makes the same mistake that I did, the tl;dr is that jit.gen uses floating point values between 0. and 1., not integers between 0 and 255. Oops.

I feel like I must be missing something very basic on how jit.gen processes incoming matrices. I want to perform some function on the value of each cell, but I am at a loss.

Let's say (as a basic example) that I have a 2x2 single plane output from jit.noise. Each of its four cells contains a value between 0 and 255. What if I want to "round" each cell, as in:

if (in1 > 127){
out1 = 255;
} else {
out1 = 0;
}

Obviously, this trivial example could be accomplished with jit.op or any number of other ways, but let's say I have a lot more programmatic logic at work. How do I accomplish this within jit.gen? I would have thought a codebox containing the above would do it but apparently not... Thanks in advance!

junjk's icon

A little more, in hope of clarity:

If I were doing this in a regular programming language, I would expect it to look something like:

a = [ [ noise(), noise() ], [ noise(), noise() ] ]
b = []
for x in a:
b[x] = []
for y in a[x]:
b[x][y] = 255 if a[x][y] > 127 else 0

Anything that could clarify how jit.gen works in array terms would be especially nice...

junjk's icon

Apparently, it is that simple - it's just that in jit.gen values are 0. - 1., not 0 - 255...

Federico-AmazingMaxStuff's icon

Exactly JUNJK, consider jit.gen like a for loop iterating over every cell in your matrix (more than one dimension means nested for loops), I would say. As you discover, values are floating point and get rescaled between 0. and 1.