|Re: [eigen] [Sparse] element acces in a cwise unary op on an Eigen::Sparse|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] [Sparse] element acces in a cwise unary op on an Eigen::Sparse
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Thu, 25 Nov 2010 17:36:59 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=yEnWZkA1B7jmlEhJSoI56vTc/3a3eyz4Oqj/3cnq5zc=; b=i2oFM8IO3onidJ62PUQaAkvwAuv1jwSziKrXA99zR18SxYHLow7QeTXTssprbegnJS dvoEM3/DX9URIyFGtkv6wKDqAtxrIO/uxajrWhMCMlKsUhxUnLR5ivnoQcpycANlWr1D rE1FMlxEBtcGvDhHTufaFKKXM5DdQJ1ZcXSlE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=BxaV1ELFW9VE/LKb7Nqh+0W9vAQx35ziFTNTdMLsdScCLfEuOJrZ/dNm2yqHhKtKOC cxwxysza8Zf59BNugj2YbDCissfEZItZ7rFeXXBYTl08SGZSW2eU/yZLtv2MtpmUdAIy krppqmgnyRWhnvj1pS+2D8Po0/5NFnzDd037k=
On Thu, Nov 25, 2010 at 3:50 PM, <bernard.hugueney@xxxxxxxxxx> wrote:
> Hi Gael,
> Thanks for your answer.
> On Thu, 25 Nov 2010 13:13:59 +0100, Gael Guennebaud
> <gael.guennebaud@xxxxxxxxx> wrote:
>> Random access to a sparse matrix is inherently very inefficient, and
>> so I decided not to support it. Instead use iterators and/or, some
> I am fully aware that is dumb to iterate over the whole virtual matrix
> however, the decision was not mine to make.
> Give that I had to enable some operations that result in a dense matrix
> (e.g. "or equal" logical ops between sparse matrices where 0. <= 0.
> so my result is full) because i am reimplementing an already existing API
> knew that the result would have to be large (i.e. dense) and slow to
Do you mean that the existing API implies random access to your
(sparse) objects ? and you cannot extend to support iterators ?
Otherwise, if what you want is to be explicitly aware of the zeros,
for each column or row j do
int prev = 0;
for(InnerIterator it(mat,j); it; ++it)
int i = it.index();
// (i0,j) is a zero
prev = i+1;
// (i,j) is a non zero
but I feel that won't address your issue, right?
Actually, I'm reluctant to add a coeff() method to matrix base because
then it will become too easy to mix dense/sparse objects in a very
very inefficient way... I'm even not sure that was a good idea to add
coeff() method to SparseMatrix and the likes.
On the other hand I also agree that if we support coeff() for sparse
object with storage, it makes sense to do so for unary expressions,
especially for trivial ones like your cast example ! For binary
expressions that's another story because the sparse pattern change.
So maybe here is a compromise:
- remove the coeff() and coeffRef() methods.
- instead add a searchCoeff(i,j) method returning an iterator. It
would evaluate to false if the coefficient does not exist. Otherwise
one could overwrite the value doing it.value() = x;
This solution clearly say that this operation is going to be slow, and
I think this is even more powerful.
> thank for the suggestion, but I' did not have much better luck with
oops, indeed, sorry, it is implemented only for objects with storage.
> Btw, à propos Eigen::Sparse<bool> :
> - it would be nice to be able to set the default value to «true».
I see your point. but on the other hand for other scalar types default
value of non zero is zero, so...
Actually I plane to support SparseMatrix<void> where only the pattern
will be stored. This is equivalent to a "Sparse<bool>" where all non
zeros are true. Maybe this is what you were looking for when declaring
a Eigen::Sparse<bool> ?
> - template<> struct scalar_fuzzy_impl<bool> seemed to be missing an
> isMuchSmallerThan() for some sparse operation but I fail
> to be able to reproduce the error (I rewrote the code that was triggering it
> :( )
> Best Regards,