On Thu, 8 Sep 2011, Allin Cottrell wrote:
On Thu, 8 Sep 2011, Allin Cottrell wrote:
> [...] The operation Artur mentions, namely assigning a
> scalar value to a single element of a matrix, is a special
> case of assignment to a sub-matrix, which has the general
> form:
>
> M[r1:r2,c1:c2] = <expression>
>
> where the r's and c's are expressions that evaluate to row
> and column indices. This demands a lot more parsing effort
> than assigning a scalar value to a place in a series (where
> the only valid specifier on the left is a single observation
> number).
>
> We could maybe write a dedicated, faster function for the
> special case, but even then we first have to figure out that
> we're actually in that special case.
In fact quite a nice speed-up was available here. Things
should look better in current CVS.
Small testcase:
<hansl>
matrix tt = {}
loop foreach k 1000 2000 4000 --quiet
n = $k
X = mnormal(n, n)
set stopwatch
loop i=1..n --quiet
loop j=1..n --quiet
scalar a = X[i,j]
end loop
end loop
tt |= $stopwatch
end loop
print tt
</hansl>
Before:
? print tt
tt (3 x 1)
1.8
7.21
29.04
After:
tt (3 x 1)
1.73
7.03
28.63
Not bad at all, I say.
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti