Re: [eigen] Let's get reshape in shape for 3.4

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On 21 February 2017 at 20:47, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:

On Tue, Feb 21, 2017 at 8:30 PM, Julian Kent <jkflying@xxxxxxxxx> wrote:
A question, is this implemented for sparse matrices as well?
 
Not yet, and I did not plan it for 3.4, but contributions are always welcome. Do you have use cases in mind?

I have a few specific use-cases where the current indexing was painful:

1) Getting many small (less than 15xk, k << n), dense subsets of a large, sparse matrix where I already know that all of the elements at the column/row indices I'm requesting are non-zero. I'm doing this with InnerIterator at the moment, but it isn't obvious what is happening due to the verbosity. The code would be much more readable if it was obvious that I was getting values at specific indexes.

2) Reordering with a subset at the same time. This could also be done with a lossy (non-square) permutation matrix. Instead I need to reorder the entire matrix, then take the subset with (for example) leftColumns or topRows. Even if the rest of the reorder due to the subset taken, what is done with the extra permutation indices in the ignored part of the matrix feels like an implementation detail I shouldn't have to worry about, and if the number of columns (or rows) I need is small, it feels like a waste constructing the entire permutation matrix (which is different in every case). I guess I could also do this with a SparseMatrix, but reshape would be much more concise.

3) Make a copy of a sparse matrix, but only keeping the pattern of non-zeros which are already present in the destination. Reshape would let me at least do this on a column-wise basis, using the indexes of the destination to get the data from the source. Like in 1), I'm doing this the long verbose way with InnerIterator at the moment.

Mostly though, it is for ease of translating algorithms from Matlab into Eigen. The closer the syntax, the less likely there are bugs. This is already a benefit of reshape for dense matrices, but I work mostly with sparse matrices.

--
Julian


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