David Bateman | 1 Jul 2007 01:00
Picon

accumarray

I have no idea if the attached function is really useful, but it is a
Matlab core function. I saw it as a request on the Wiki and thought it
would be fairly trivial to implement a version of it.

Matlab has this as a builtin function, so I'm sure that Matlab is
significantly faster for its version of this function. Thought I'd tried
to keep the code vectorized as much as I could. Include this function in
the CVS Jon if you want it..

Cheers
David
Attachment (accumarray.m): text/x-objcsrc, 5124 bytes
etienne | 1 Jul 2007 23:27
Picon

Re: accumarray


  Hi David,

On Sat, June 30, 2007 16:00, David Bateman wrote:
# I have no idea if the attached function is really useful, but it is a

it would be useful at least for me. I would have adopted if it had been around when
I first wrote a similar function "result = loop_add (add_to_what, add_where, add_what)".

  The answer to your question depends more on users than maintainers, doesn't it?

  Cheers,

  Etienne

# Matlab core function. I saw it as a request on the Wiki and thought it
# would be fairly trivial to implement a version of it.
#
# Matlab has this as a builtin function, so I'm sure that Matlab is
# significantly faster for its version of this function. Thought I'd tried
# to keep the code vectorized as much as I could. Include this function in
# the CVS Jon if you want it..
#
# Cheers
# David
#

--

-- 
http://www.isr.ist.utl.pt/~etienne

(Continue reading)

David Bateman | 2 Jul 2007 21:31
Picon

Re: accumarray

etienne <at> isr.ist.utl.pt wrote:
>   Hi David,
> 
> On Sat, June 30, 2007 16:00, David Bateman wrote:
> # I have no idea if the attached function is really useful, but it is a
> 
> it would be useful at least for me. I would have adopted if it had been around when
> I first wrote a similar function "result = loop_add (add_to_what, add_where, add_what)".
> 
>   The answer to your question depends more on users than maintainers, doesn't it?

Yes, but maintainers are also users as well :-) .... In any case the
main issue I see is that this isn't a builtin version and so might be
limited in speed relative to the matlab version. Though if it is
adequate I see no reason to write it as an oct-file. In any case if it
does need to be written as an Octave file, having a good m-file version
that is consistent with the matlab version is a good first step.

Unfortunately I'm traveling at the moment and can not test this code
against matlab for speed. Frankly if its less that a factor of 5 slower
than matlab I see no reason to write it as an oct-file..

Cheers
David

> 
>   Cheers,
> 
>   Etienne
> 
(Continue reading)

etienne | 3 Jul 2007 07:50
Picon

Re: accumarray


On Mon, July 2, 2007 12:31, David Bateman wrote:
# etienne <at> isr.ist.utl.pt wrote:
#>   Hi David,
#>
#> On Sat, June 30, 2007 16:00, David Bateman wrote:
#> # I have no idea if the attached function is really useful, but it is a
#>
#> it would be useful at least for me. I would have adopted if it had been around when
#> I first wrote a similar function "result = loop_add (add_to_what, add_where, add_what)".
#>
#>   The answer to your question depends more on users than maintainers, doesn't it?
#
# Yes, but maintainers are also users as well :-) .... In any case the
# main issue I see is that this isn't a builtin version and so might be
# limited in speed relative to the matlab version. Though if it is
# adequate I see no reason to write it as an oct-file. In any case if it
# does need to be written as an Octave file, having a good m-file version
# that is consistent with the matlab version is a good first step.
#
# Unfortunately I'm traveling at the moment and can not test this code
# against matlab for speed. Frankly if its less that a factor of 5 slower
# than matlab I see no reason to write it as an oct-file..

  I would say that correct but slow code is better than no code at all.

  Cheers,

  Etienne

(Continue reading)

David Bateman | 5 Jul 2007 11:57

Re: accumarray

etienne <at> isr.ist.utl.pt wrote:
>   I would say that correct but slow code is better than no code at all.
>
>   Cheers,
>
>   Etienne
>
>   
Well, I'm back in the office and tried the accumarray in matlab for
speed and got the following results

vals = 1:1e4;
subs = randint(1e4,2,1024) + 1;
t = 0;
for i=1:10,
  t0 = cputime();
  A = accumarray (subs, vals, [1024,1024]);
  t = t + cputime() - t0;
end;
fprintf('Time %g s\n', t / 10);

MatlabR2007a
Time 0.016 s

Octave 2.9.12
Time 1.21592 s

So there is a factor of 76 difference in speed for this example. So
Etienne how useful is this function, and what portion of your simulation
time will be spent in it?
(Continue reading)

etienne | 5 Jul 2007 16:20
Picon

Re: accumarray


  Hi David,

On Thu, July 5, 2007 02:57, David Bateman wrote:
# etienne <at> isr.ist.utl.pt wrote:
#>   I would say that correct but slow code is better than no code at all.
#>
#>   Cheers,
#>
#>   Etienne
#>
#>
# Well, I'm back in the office and tried the accumarray in matlab for
# speed and got the following results
#
# vals = 1:1e4;
# subs = randint(1e4,2,1024) + 1;
# t = 0;
# for i=1:10,
#   t0 = cputime();
#   A = accumarray (subs, vals, [1024,1024]);
#   t = t + cputime() - t0;
# end;
# fprintf('Time %g s\n', t / 10);
#
# MatlabR2007a
# Time 0.016 s
#
# Octave 2.9.12
# Time 1.21592 s
(Continue reading)

David Bateman | 5 Jul 2007 16:41

Re: accumarray

etienne <at> isr.ist.utl.pt wrote:
>   Hi David,
>
> On Thu, July 5, 2007 02:57, David Bateman wrote:
> # etienne <at> isr.ist.utl.pt wrote:
> #>   I would say that correct but slow code is better than no code at all.
> #>
> #>   Cheers,
> #>
> #>   Etienne
> #>
> #>
> # Well, I'm back in the office and tried the accumarray in matlab for
> # speed and got the following results
> #
> # vals = 1:1e4;
> # subs = randint(1e4,2,1024) + 1;
> # t = 0;
> # for i=1:10,
> #   t0 = cputime();
> #   A = accumarray (subs, vals, [1024,1024]);
> #   t = t + cputime() - t0;
> # end;
> # fprintf('Time %g s\n', t / 10);
> #
> # MatlabR2007a
> # Time 0.016 s
> #
> # Octave 2.9.12
> # Time 1.21592 s
(Continue reading)

John W. Eaton | 5 Jul 2007 18:57
Picon

Re: accumarray

On  5-Jul-2007, David Bateman wrote:

| I believe that the code is probably fine.. John want me to commit it?

Yes, please do.

Thanks,

jwe


Gmane