[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
-------------------------------------------------------------
- Indirect Addressing Question, Etienne Grossmann, 2001/11/14
- Re: Indirect Addressing Question, Mirek Kwasniak, 2001/11/14
- Re: Indirect Addressing Question,
Paul Kienzle <=
- overloading functions (Was: Indirect Addressing Question), adler, 2001/11/15
- Re: overloading functions (Was: Indirect Addressing Question), Paul Kienzle, 2001/11/16
- Re: overloading functions (Was: Indirect Addressing Question), John W. Eaton, 2001/11/16
- Re: overloading functions (Was: Indirect Addressing Question), adler, 2001/11/16
- Re: overloading functions, Paul Kienzle, 2001/11/20
- semantics of sum, prod, cumsum etc., adler, 2001/11/22
- Re: Indirect Addressing Question, adler, 2001/11/15