help-octave
[Top][All Lists]
Advanced

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

## Re: Indirect Addressing Question

 From: Paul Kienzle Subject: Re: Indirect Addressing Question Date: Wed, 14 Nov 2001 16:43:55 -0500

```Here is yet another solution, but it requires Andy Adler's sparse functions from
octave-forge:

q = [1:10];
idx = [5,1,1,1,2,2];
projection = sum(sparse(1:length(idx),idx,q(idx)+10));
used = find(projection);
q(used) = projection(used);
q
q =

33  24   3   4  15   6   7   8   9  10

Unfortunately, the sum function will turn the sparse matrix into a full
matrix before doing its business, so this doesn't scale.

Andy, is there is sparse sum function?

Anyone want to take a shot at modifying the interpreter so that you can
overload functions for user-defined types?

An alternative would be to replace the builtin function sum with a new one
from sparse/sum.cc which tests if the type is sparse and if not calls
the builtin sum function, but Octave won't support that either.  Besides,
it is even ickier.

Paul Kienzle
address@hidden

Mirek Kwasniak wrote:

> Hi,
>
> I have an alternative to Etienne. I solved Andreas problem this way:
>
>
>       [qv qcount] = count_unique(q(1:5));
>       a(qv)=a(qv)+10.*qcount
>
> Where count_unique is defined as below:
>
>     function [ y, count ] = count_unique( x )
>
>        if length(x)==0;
>          y=[];
>          return;
>        end;
>
>        y = sort( x );
>        i = find( diff( [ inf; y(:) ] ) ~= 0 ) ;
>        y = y( i );
>
>        if nargout > 1
>          count = diff([ i(:); length(x)+1 ]);
>          count = reshape( count, size(y) );
>        end
>
> It is maybe not so universal (works only on vectors) but I use
> count_unique for many similar problems.
>
> Mirek
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```

reply via email to

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