Extension of begin for gmic?

I would like to do beginx(); or beginy(); or beginz(); or beginc(); in gmic. The reason why I would like to see these is that one can make variables only once for x or y and thereby avoiding speed issues. Are these possible now?

f beginx(foo=x);foo*y

This is equilavent to:

 for(x=0,x<w,x++,
     foo=x;
     for(y=0,y<h,y++,
         foo*y;
     );
 );

Additional idea, I would like to do iv#channel or iv#perchannel inside fill.

I am not quite sure about begin() to begin with.

The second idea has been on my wish list since the beginning but something that I have kept to myself; e.g., you could do i0 but not iv0.

begin can be used to evaluate result of variable only once. So you don’t have to reassign variables per pixels. It sped my filter significantly. It can also be used to enable dynamic variables like the case of altern in Chaos formula found in rep_thorn_fractal. the result of altern in one pixel gets passed to the next pixel instead of starting over with assigned variable.

Could you give me a dead simple foo example of reassignment and its begin() version? Sorry about making this a Q&A but I am curious now. I hope to have a firmer grasp of the concept.

f "begin(a=5;b=cos(a);foo=(a+b));"

This is equal to #almost now that I checked again#

a=5;
b=cos(a);
foo=(a+b);
#for(x,y)loop_here#

a,b,foo are only evaluated once.

It seem like G’MIC assigns foo to all pixels, but however, it skips over begin() per pixel. altern=0 gets skipped over in the case of rep_tfrac.

There is no need for beginx(), beginy() or beginz().
Because, if you want to evaluate an expression only once per row, for instance:

eval. ">begin(foo = 0);
      !x?( foo+=1 ); # Do it only for each row
      0;  # Do nothing
      end( print(foo) );"
1 Like

It’s hard to express what I’m thinking in words, but I guess that after the end statement, whatever variable assigned in there is no longer being reassigned right? It’s a bit confusing, and @afre himself isn’t sure on begin().

I just learned what begin does after using it after a while. However, I don’t think it actually does what I need in certain cases.

Using this code

channels 0
f "
begin(foo=0);
!x?(foo+=1);
end(print(foo));"

I note that the only areas that have been affected are those in coordinate=0 where x is x or y or z.

As fill function loops pixel by pixel, what I would like to have is something like this instead to speed calculation.

for(yy=0,yy<h,y++
begin()
for(xx,xx<w,x++,
);
);

So, instead of having to loop per pixels by pixels, I definitely would like the choice to avoid doing that for at least one axis. Would that improve speeding of function? Or would I have to do a loop within a predefined vector, and then use vectors to search for value, so that I can mimic the above code?