Closed Reptorian1125 closed 1 year ago
Please find a minimal use case when v2s()
exhibits a strange behavior. It's not possible for me to spend 1h trying to understand what is your issue.
Here's a minimal use case:
foo:
100,1,1,1,:"
begin(
v=vectorw(0);
);
v[x]=int(u(0,100));
end(
set('{}',v2s(v,0));
);"
echo ${}
Output of ${} differs from image values.
It's not a problem with v2s()
. It's because in the end()
bloc, the value of v
is not what you expect, as print(v)
can tell you. This is due to the multi-threaded evaluation of your expression (replace :
by >
, and it will work).
Code put in begin()
and end()
is always executed by thread0
(main thread). In your case, what the evaluation does is:
thread0
creates a vector v
of size 100
and fill it with 0
.N
threads.thread0
fills the beginning of this vector, i.e. only the first M
values).end()
block, the v
that is referred to is the one from thread0
, so it has only the first coefficient filled with something.You have to understand that there are actually as many independent v
vector-valued variables as they are running threads. If you want to "merge" all these resulting v
into something, you must explicitly tell the evaluator, by adding for instance
merge(v,+)
at the beginning of the end()
block.
Another solution is to disable the multi-threading evaluation, by adding >
at the beginning of the expression.
Okay, now I understand why my original find_factors_of didn't work. I was thinking of avoiding to have multiple independent vector at first and it worked for a good time and lost sight at how the code runs. Anyways, I amended the suggested change here - https://github.com/GreycLab/gmic-community/commit/99a7b0ca97e3efd3350fbad4e2fe5cfcb3ef4f37 . And it works as expected.
It seems that rep_find_factors_of is broken for some number. For instance 756.
Pay attention to the data, and the echo output near "G'MIC Interpreter". They're different for this number and some few other number. But, yet 256,100, and many other numbers work fine. This points to v2s() issues.
Here's the modified command for rep_find_factors_of for testing purpose only.
Note that in the last display instance, it appears there's all the numbers which are the factor of 756. However, it doesn't show up with ${} for some reason. Another number which is wrong is 1110. This only happens with some numbers. In many cases, it works as expected.