602
2013-05-18 10:41:02 +0000
[Feature request] more functions for the selfadjointView class
2019-12-04 12:19:48 +0000
1
1
1
Unclassified
Eigen
Core - general
unspecified
All
All
NEW
Normal
Unknown
---
1
elisa.friebel
eigen.nobody
chtz
gael.guennebaud
godeffroy.valet
jacob.benoit.1
oldest_to_newest
2395
0
elisa.friebel
2013-05-18 10:41:02 +0000
Dear Eigen developers,
First, I want to emphasise the benefit of a class for symmetric matrices as proposed in http://eigen.tuxfamily.org/bz/show_bug.cgi?id=42. But I need not only for dense but also for sparse matrices.
Second, as a temporary alternative it would be useful to add some features for the selfadjointView class.
For example for sparse matrices the expression
sm2.selfadjointView<Lower>() = sm1.selfadjointView<Upper>(); //copies the upper triangular part to the lower triangular
is possible while the same code with dense matrices gives compiler errors. The line
m.triangularView()=m2;
works. It would be nice if that was available in the selfadjointView class, too.
On the other hand the selfadjointView class combined with the operator () only works for dense matrices: The line
m.selfadjointView<Eigen::Upper>()(0,2)=11;
compiles but with a SparseMatrix sm
sm.selfadjointView<Eigen::Upper>()(0,2)=11
it does not.
In my opinion it makes sense that the call
m.selfadjointView<Eigen::Upper>()(1,0)
evaluates to the the entry (0,1) in m because we're looking at its selfadjoint.In the current implementation this code leads to a range check error.
2396
1
gael.guennebaud
2013-05-21 23:46:48 +0000
(In reply to comment #0)
> First, I want to emphasise the benefit of a class for symmetric matrices as
> proposed in http://eigen.tuxfamily.org/bz/show_bug.cgi?id=42. But I need not
> only for dense but also for sparse matrices.
Such compact representations of triangular/selfadjoint matrices are useless for sparse storages that are already compact, and the one of SparseMatrix.
> For example for sparse matrices the expression
>
> sm2.selfadjointView<Lower>() = sm1.selfadjointView<Upper>(); //copies the
> upper triangular part to the lower triangular
>
> is possible while the same code with dense matrices gives compiler errors.
good point.
> On the other hand the selfadjointView class combined with the operator () only
> works for dense matrices: The line
>
> m.selfadjointView<Eigen::Upper>()(0,2)=11;
>
> compiles but with a SparseMatrix sm
>
> sm.selfadjointView<Eigen::Upper>()(0,2)=11
>
> it does not.
That's on purpose. A(0,2) = 11 is not even allowed with A sparse.
> In my opinion it makes sense that the call
>
> m.selfadjointView<Eigen::Upper>()(1,0)
>
> evaluates to the the entry (0,1) in m because we're looking at its
> selfadjoint.In the current implementation this code leads to a range check
> error.
That's also on purpose for the following two reasons:
1- it could only be read-only because for complexes we would have to conjugate the new values (would be possible with a proxy object, but that would be overkill)
2- this would kill the performance of SelfadjointView::operator(i,j)
3375
2
godeffroy.valet
2014-05-27 18:59:11 +0000
Hello,
I reply to this post instead of creating a new one.
For my application, I would like to be able to make arithmetic operations like A=k*B+C, where k is a scalar and A,B,C self-adjoint matrices. Only a triangular part of the derived matrix would be referenced so that no unnecessary processing is done (like twice the same).
I would also like to be able to use .block<>() on it, and it would be great if it returned a SelfAdjointView of the block in case the requested block is on the diagonal.
What do you think ? Did I miss something ? I feel that for now, it can only be used with very few specific functions or convert back to its derived type.
Thank you.
3376
3
chtz
2014-05-27 19:17:26 +0000
(In reply to comment #2)
> For my application, I would like to be able to make arithmetic operations like
> A=k*B+C, where k is a scalar and A,B,C self-adjoint matrices. Only a triangular
> part of the derived matrix would be referenced so that no unnecessary
> processing is done (like twice the same).
You can already do
A.triangularView<Upper>() = k*B+C;
and Eigen will only access and process the upper half of each matrix (same is possible with Lower, of course).
> I would also like to be able to use .block<>() on it, and it would be great if
> it returned a SelfAdjointView of the block in case the requested block is on
> the diagonal.
For generic blocks this will not be possible, because we would need to know at compile-time that the block is on the diagonal. It could be possible for the special case of topLeftCorner and bottomRightCorner, but still we'd have to be sure that both dimensions are the same.
If you know that the blocks you are accessing are self-adjoint, simply add an .selfAdjointView() after the .block(...).
> What do you think ? Did I miss something ? I feel that for now, it can only be
> used with very few specific functions or convert back to its derived type.
I agree that there are many cases where directly declaring a SelfAdjointMatrix would be more handy than having to add selfAdjoitView all the time.
And these types should implement basic arithmetic operations and also give compile errors, if non-selfadjoint matrices are assigned.
3378
4
godeffroy.valet
2014-05-27 19:46:24 +0000
(In reply to comment #3)
> You can already do
> A.triangularView<Upper>() = k*B+C;
> and Eigen will only access and process the upper half of each matrix (same is
> possible with Lower, of course).
Yes. I do it right now.
The issue is that I use a Matrix4f Q, and afterwards, I access Q.block<3,3>(0,0) , Qc.block<1,3>(3,0) and Q.block<3,1>(0,3). So, if the blocks were at least mapped to the corresponding values in the upper triangular part of Q (not as trivial as with a full matrix but doable), I could use them easily.
So, for now, I have to use Q.block<3,3>(0,0).selfAdjointView() and Qc.block<3,1>(0,3).transpose() and Q.triangularView<Upper>() = k*B+C;. And all those functions could be hidden from my code.
> I agree that there are many cases where directly declaring a SelfAdjointMatrix
> would be more handy than having to add selfAdjoitView all the time.
> And these types should implement basic arithmetic operations and also give
> compile errors, if non-selfadjoint matrices are assigned.
Exactly what I thought, like the already implemented DiagonalMatrix for diagonal matrices for example.
Is there reasons not having this SelfAdjointMatrix type ? (I agree that my blocks are easy ones and that the general case would be more arguable though)
9046
5
eigen.nobody
2019-12-04 12:19:48 +0000
-- GitLab Migration Automatic Message --
This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/602.