help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any possible optimization?


From: Sergei Steshenko
Subject: Re: Any possible optimization?
Date: Tue, 11 Jan 2011 04:43:22 -0800 (PST)


--- On Tue, 1/11/11, Daniel Arteaga <address@hidden> wrote:

> From: Daniel Arteaga <address@hidden>
> Subject: Re: Any possible optimization?
> To: address@hidden
> Date: Tuesday, January 11, 2011, 2:30 AM
> Al 10/01/11 18:39, En/na CdeMills ha
> escrit:
> 
> > If the function is called many times from the same
> place, the best way is to
> > not use function call at all and vectorise the code.
> Let say that your
> > points coordinates are in row matrices:
> > aa = b-a; bb = c-d; cc = c-a;
> > my_idet = 1./(aa(:, 1).*bb(:, 2)-aa(:, 2).*bb(:, 1));
> > s = (bb(:, 2).*cc(:, 1) - bb(:, 1).*cc(:,
> 1)).*my_idet;
> > t = (aa(:, 1).*cc(:, 2) - aa(:, 2).*cc(:,
> 1)).*my_idet;
> > 
> > This way, there is no 'for' loop, nor function call.
> 
> I cannot vectorize this part of my code since the
> calculation at a given iteration depends on the previous
> iteration. Any suggestion of how this situation can be
> handled more efficiently is welcome.
> 
> To give background, I'm exploring a terrain map composed of
> triangles, and the goal is to obtain a section of the map by
> intersecting a given direction with the vertices of the
> triangles. The triangle to explore depends on the previous
> segment intersected.
> 
> > The names of variables
> > should not alias function names (det). The last small
> optimisation is that
> > (I learned it a long time ago), floating point
> division is slower than
> > multiplication, so the inverse of the determinant is
> computed only once.
> 
> I just implemented this, and the performance gains are very
> modest. Interesting to take into account nevertheless.
> 
> Thank you very much,
> 
> Daniel
> 

Maybe intermediate variables for

aa(:, 1)
aa(:, 2)
bb(:, 1)
bb(:, 2)
cc(:, 1)

can help a little.

Regards,
  Sergei.



      


reply via email to

[Prev in Thread] Current Thread [Next in Thread]