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

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




On Wed, Feb 22, 2017 at 11:49 AM, Julian Kent <jkflying@xxxxxxxxx> wrote:
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.

How SparseMatrix::reshaped() would help here? If the sparsity pattern of the k columns are the same, you could map the 15xk block as a dense _expression_:

auto Ab = MatrixXd::Map(&A.coeffRef(i,j), 15, k, OuterStride<>(A.col(i).nonZeros());
 
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.

yes, that's a very common operation, but not related to reshape. It's related to the indexing feature that has yet to be ported to the sparse world (should not be too difficult), and yes that one is very useful! Example:

subset = A(selectedRows, selectedColumns);
 
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.

again, I don't see how reshape could help. Indexing on a per column basis might help, but a more general solution would be to provide a way to tell Eigen that the sparse assignment can be done in-place together with mechanisms to manipulate sparsity patterns.

gael
 

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/