Calculate the sum of all cells in a jitter matrix
Hi,
I am trying to calculate the sum of all cells in a jitter matrix.
Does anyone know how to do this with jit.gen ?
Thanks
[jit.3m] gives you the average: multiply by the number of cells to get total sum.
or [jit.dimop @op + @step -1 -1]
Thanks Jean-François.
I was already using [jit.3m].
I need this operation to calculate the euclidean distance between two matrices (not the distance from cell to cell but from the matrices as a whole).
This gets rather slow so I moved to [jit.gen].
It works much faster but I don't seem to find a way to sum all cells inside [jit.gen].
Also: I get slightly incorrect numbers working with [jit.3m].
I can't figure out why ...
I didn't know of this one [jit.dimop @op + @step -1 -1]
Thanks again.
Very interesting. I'm not sure the incorrect result comes from jit.3m. Don't have the time right know to make a proper test, but it would be easy, using a defined matrix instead of jit.noise.
Anyway, here is a patch with 2 other solutions.
And here, a patch to kind-of-test how fast each solution is. Best solution is indeed with jit.gen, but jit.op is already more than twice as fast as jit.expr.
Precision problems indeed. Both jit.3m and jit.dimop solutions sometimes give false results. Are c74 listening?
Yes, it's very strange, there's some precision issue.
Anyway ... I still wonder if the sum of all cells could be achieved using [jit.gen].
Any ideas in this direction would be much appreciated.
Given the way jit.gen works, and given the operators available, it looks like it is not possible. Remember that the output of jit.gen is a matrix with the same {size, type, planecount} as its leftmost input incoming matrix, and that gen operators are applied to all cells in a matrix. jit.gen is really like jit.expr & jit.op, (or jit.repos if you use swiz & sample). Yet, I hope someone with a deeper jit.gen knowledge will jump in with a solution!
Thanks again Jean-François. That seems very reasonable.
Do you think a new topic should be created about those precision issues in [jit.3m] and [jit.dimop] ?
I was looking for this as well, and after some digging I found a solution for jit.gen, I believe. Here goes, perhaps someone else will be looking for this someday.
I tested your previous patches and apparently the precision errors still exist.
====
UPDATE:
If I use this in a more elaborate gen patch I get the following error which I don't understand how to solve:
gen_domain: jit.gen: [string "gen2.jit.Types"]:207: type is not a sampler