[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: 'for' loop vectorization
From: |
Francesco Potorti` |
Subject: |
Fwd: 'for' loop vectorization |
Date: |
Thu, 25 Oct 2007 14:23:57 +0200 |
This mail does not contain references to previous mails on the subject,
as I am writing without being subscribed to this list.
I do not know if this piece of information can add anything to the
discussion, but I can make two observations. First is that I managed to
obtain a humble 10% improvement over triu.m by vectorising it like this:
octave> n=5000; a=ones(n,n);
octave> function z=vtriu(z) n=rows(z); z((1:n)'*ones(1,n)>ones(n,1)*(1:n))=0;
end
octave> t=cputime;b=triu(a);cputime-t
ans = 1.7081
octave> t=cputime;c=vtriu(a);cputime-t
ans = 1.5081
octave> all(all(b==c))
ans = 1
The idea is that I build a vector of the matrix indices that are under
the diagonal, and then I zero them.
Maybe some variation on this concept could make triu and tril faster.
Second is an observation on the proposed cumulative max function using
triu: it requires space proportional to n^2 for a vector of length n, so
it is not abvious that is worth optimising, because it cannot be used
for big vectors, that is, vectors of length n such that n^2 does not fit
into memory.
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
Web: http://fly.isti.cnr.it/ Key: fly.isti.cnr.it/public.key
- Fwd: 'for' loop vectorization,
Francesco Potorti` <=