Re: [eigen] Permutation times Sparse matrix
• To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
• Subject: Re: [eigen] Permutation times Sparse matrix
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Mon, 19 Sep 2016 22:22:21 +0200
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=apdfJvBHvDw8Cg/yMZ88tzsECvbJFM4xyaQ2/omRE7Y=; b=ksU1ZCs1sUFLpAIPm/xHLkPMsGWpW10T++EWA31x/Vn8wwvGWQcUDBRWJuQoFLWaAp TftjdwvX4dWAgCMLpbLYwqguxnjEtkgrE8fgKlUNqlaiMQjBcI9OtqzD88aWKEmLt+3g LR/pi6f0xlbMTrWhBAi37tLZXtSUXYnTm2UZwwjkB69aFehhfw+EhqWOHMr9UM/0lEQD xclOKBXDdkuygLfG7tGdHiF1+5pXLR4wSf6mNGYLGkUBBE6XTn292jGHnOPMpIqka66+ sWuOSr6iE5hkxa3xuhvrxxUggZP2HCeUss2cUa1QVooSBBfRx+LoY4TsYZ5ZMAimkD3K 6r5A==

hm, I think this is a bug on our side because:

- if L is dense, then we detect aliasing and apply the permutation in-place
- if L is sparse, then this should be fine because we never directly assign to a sparse matrix, but rather build a new one, and then perform a shallow copy (aka move-assignment).

After checking your example, it turns out that this has already been fixed in the 3.3 branch, but not in the 3.2 branch. A simple backport won't work here because the assignment/evaluation logic have been completely redesigned.

gael

On Mon, Sep 19, 2016 at 4:38 PM, Christoph Hertzberg wrote:
This looks like an aliasing problem. Just assign the result to a new matrix. Ideally, we could implement a "permute{Rows,Cols}InPlace" method for that use case. And we should probably warn more explicitly that sparse products are not aliasing-save.

Christoph

On 2016-09-19 16:29, Brad Bell wrote:
When I execute the program below I expect to get
L=
1 0
0 1
But I get
L =
0 0
0 0

# include <Eigen/SparseCore>
# include <iostream>
int main()
{   Eigen::SparseMatrix<double> L(2,2);
L.insert(0,0) = 1.0;
L.insert(1,1) = 1.0;
Eigen::PermutationMatrix<2,2> P;
P.setIdentity();
L = P * L;
std::cout << "L =\n" << Eigen::Matrix<double,2,2>(L) << "\n";
return 0;
}

--
Dipl. Inf., Dipl. Math. Christoph Hertzberg

Universität Bremen
FB 3 - Mathematik und Informatik
AG Robotik
Robert-Hooke-Straße 1
28359 Bremen, Germany

Zentrale: +49 421 178 45-6611

Robert-Hooke-Straße 5
28359 Bremen, Germany

Tel.:    +49 421 178 45-4021
Empfang: +49 421 178 45-6600
Fax:     +49 421 178 45-4150
E-Mail:  chtz@xxxxxxxxxxxxxxxxxxxxxxxx

Weitere Informationen: http://www.informatik.uni-bremen.de/robotik

 Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/