Avoid loop

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Avoid loop

LucaLuca
hi,
look this piece of code :

  for gg=rowss:roww
                 v1=E(gg,Col)>maxRel;
                 
                 maxRel=max(E(gg,Col),maxRel);
                 minRel=!v1.*minRel+v1*9999999999999999999999;

                 minRel=min(E(gg,Col),minRel);
                 diff=maxRel-minRel;
                 rangeRel=max(diff,rangeRel);
  endfor

it's possible to avoid loop? (i'm refer to : for gg=rowss:roww)







--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Avoid loop

siko1056
On Mon, Feb 4, 2019 at 7:34 AM LucaLuca <[hidden email]> wrote:
hi,
look this piece of code :

  for gg=rowss:roww
                 v1=E(gg,Col)>maxRel;

                 maxRel=max(E(gg,Col),maxRel);
                 minRel=!v1.*minRel+v1*9999999999999999999999;

                 minRel=min(E(gg,Col),minRel);
                 diff=maxRel-minRel;
                 rangeRel=max(diff,rangeRel);
  endfor

it's possible to avoid loop? (i'm refer to : for gg=rowss:roww)


Please provide a more complete example (without undefined values) and
use https://pastebin.com/ or alike to share bigger code snippets.
In general your *Rel variables can be vectors and this might speed up things.

Best,
Kai 


Reply | Threaded
Open this post in threaded view
|

Re: Avoid loop

LucaLuca
Reply | Threaded
Open this post in threaded view
|

Re: Avoid loop

siko1056
On Tue, Feb 5, 2019 at 7:04 PM LucaLuca <[hidden email]> wrote:
hi siko...thank for answer

https://pastebin.com/Vz7s4hbn



Good to see the full code, now I know there is little hope for an easy vectorization to avoid the loop.
The important part was missing in your previous example.  The mean loop dependency is:

maxRel = some_val;
% ...
for gg = start:end
  % ...
  maxRel = max(new_val, maxRel);
  % ...
endfor

And similar things for minRel and so on. Thus in each inner loop the value of "maxRel" depends on the outcome of the previous loop.
I have no insight if this is really necessary. You might overthink your code or other followers of this mailing-list for sure have better ideas than I have ;-)

Best,
Kai


Reply | Threaded
Open this post in threaded view
|

Re: Avoid loop

turbofib