[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: simple vector to matrix transformation
From: |
Mike Miller |
Subject: |
Re: simple vector to matrix transformation |
Date: |
Tue, 22 Jun 1999 15:14:38 -0500 (CDT) |
On Tue, 22 Jun 1999, Jonathan King wrote:
> On my machine, this is a factor of 6 or so faster still in Matlab, anyway:
>
> >> tic; b=a*ones(1,1000); toc
> elapsed_time =
> 0.3294
>
> >> tic; b=a(:,ones(1,1000)); toc
> elapsed_time =
> 0.0562
>
> If memory serves, octave was similarly faster using the indexing-only
> approach.
Strangely, see below, the version of octave I am running takes takes about
3.4 times as long with Jon's method! Jon and I discussed this and he
recommended a third method for comparison (the third one shown below), but
that did slightly worse. The results shown here are actually median times
from about 5 runs. The results are the same, and highly replicable, using
cputime.
Octave, version 2.0.13 (sparc-sun-solaris2.5).
octave:1> t0=time; b=a*ones(1,1000); time-t0
ans = 0.10594
octave:2> t0=time; b=a(:,ones(1,1000)); time-t0
ans = 0.36502
octave:3> t0=time; b=a(1:1000,ones(1,1000)); time-t0
ans = 0.39385
As Jon King put it, "...that second one is doing no multiplications, ends
up with the same size matrix, constructs no temporaries...something is
screwy." I agree. Am I doing something wrong, or is octave doing some
extra work in there somewhere?
Regards,
Mike
--
Michael B. Miller
University of Missouri--Columbia
http://taxa.psyc.missouri.edu/~mbmiller/
---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL. To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------