[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Applying function to vector by index
From: |
Paul Kienzle |
Subject: |
Re: Applying function to vector by index |
Date: |
Thu, 12 Dec 2002 16:32:13 -0500 |
User-agent: |
Mutt/1.2.5.1i |
On Thu, Dec 12, 2002 at 02:10:14PM -0500, Andy Adler wrote:
> On Thu, 12 Dec 2002, Paul Kienzle wrote:
> >
> > Personally I would rather not have functions spontaneously converting
> > sparse matrices to full since really small sparse matrices can form
> > really big full matrices, but I also would not want to introduce
> > needless incompatibilities.
> >
>
> Converting to full can save memory. Consider your cos(sparse) example.
> It takes less memory to encode it as full than in a big sparse (BS)
> matrix.
There are two views of what an element-wise operation on a sparse matrix
should produce: the operation applied just to explicit values (i.e., sparse
is just a tagged vector where you can do certain operations based on the
tags like sum/min/max, as well as matrix products and decompositions), or
the operation applied to the implicit zeros as well (i.e., sparse is just
a condensed representation of a full matrix).
I can see advantages to each, and I have slight personal preference for the
first, but the second also makes sense, and since it is compatible with
matlab, I would argue for the second. Given that, by all means, if f(0)
is not zero, then f(A) should return f(full(A)).
>
> > BTW, I notice that
> > sparse(1,1,0)
> > returns the following:
> > Compressed Column Sparse (rows=1, cols=1, nnz=1)
> > (1 , 1) -> 0
> > and
> > [i,j,v] = spfind(sparse(1,1,0))
> > returns
> > i = 1
> > j = 1
> > v = 0
>
> I have code which goes through the matrices generated to
> remove zeros introduces this (and in other subtle) ways.
> I guess I forgot to apply it in this case.
>
> My current opinion is that I'll try to stay Matlab compatible
> unless it is really non-sensical.
I agree doing whatever matlab does for sparse(1,1,0) makes
sense.
I prefer correctness to compatibility, though, so I would
rather have sparse(eye(2)).^(-1+1i) return [1 NaN;NaN 1]
than [1 0;0 1].
In your code this should be simple enough: if 0^x is non-zero
expand to full then do 0^x, otherwise just do 0^x on your own
vector. Just make sure your 0^x is the same as what octave
uses for scalar 0^x so that it is consistent.
- Paul
>
> Andy
>
>
-------------------------------------------------------------
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
-------------------------------------------------------------
- Re: Applying function to vector by index, (continued)
- Re: Applying function to vector by index, Iago Mosqueira, 2002/12/09
- Re: Applying function to vector by index, Paul Kienzle, 2002/12/09
- Re: Applying function to vector by index, Paul Kienzle, 2002/12/09
- Re: Applying function to vector by index, Andy Adler, 2002/12/09
- Re: Applying function to vector by index, Schloegl Alois, 2002/12/10
- Re: Applying function to vector by index, Paul Kienzle, 2002/12/12
- Re: Applying function to vector by index, Andy Adler, 2002/12/12
- Re: Applying function to vector by index, Schloegl Alois, 2002/12/12
- Re: Applying function to vector by index, Paul Kienzle, 2002/12/12
- Re: Applying function to vector by index, Andy Adler, 2002/12/12
- Re: Applying function to vector by index,
Paul Kienzle <=
- Re: Applying function to vector by index, Andy Adler, 2002/12/11
- Re: Applying function to vector by index, Mike Miller, 2002/12/09