help-octave
[Top][All Lists]
Advanced

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

Re: cumulative maximum (was: 'for' loop vectorization)


From: Jordi Gutiérrez Hermoso
Subject: Re: cumulative maximum (was: 'for' loop vectorization)
Date: Wed, 7 Nov 2007 14:34:22 -0600

On 07/11/2007, Hermann Schwarting <address@hidden> wrote:
> Am Dienstag, 23. Oktober 2007 schrieb Jordi Gutiérrez Hermoso:
>
> > On 23/10/2007, Hermann Schwarting <address@hidden> wrote:
> > > The more I think about it, it looks like I can't vectorize this.
> > > It's a bit similar to a cumulative maximum, which can't be
> > > vectorized either, I think.
> >
> > It can be, but my vectorisation runs slower than the unvectorised
> > code. :-(
> >
> >      a = max(triu(repmat(a(:),1,length(a))))
> >
> > The triu call is the bottleneck, it seems, which mystifies me.
>
> I was wrong. Here is a recursive version of cummax that needs O(log2
> n) recursions and is faster than a naïve implementation.

Ooh, clever. Very nice. Recursion still seems like cheating when it
comes to vectorising code, but it worked very well here.

> The use of triu() is prohibitive if the input is a large vector, because of
> memory consumption.

Your vectors were of the order of 500 ~ 800, which wasn't too large
for my proposal (he says defensively). :-)

- Jordi G. H.



reply via email to

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