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

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

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: Re: [eigen] Let's get reshape in shape for 3.4*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Wed, 22 Feb 2017 12:20:57 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=zI5Cz06T4YVFrKwZozZzrJ/8KG+9QEUcIMNk1YxOq2Q=; b=HDXPUmT+LoXt15rcN5vTgeP4WmTmIY5iZGs18/N5fLibSS/jb4ZmB6QBAl68TZ8iy7 FnemuM+DAX/l93mvjmpx+kltFY10mSjAn101FBJYdJf5Vgv6ZUl4rRUJ7MEc5Lbi8jnW 38eV5o4wRd3vP9BGGWDdFWMD5nMYwhP5o/z0QAV8NAFwVxddv+Y4hNQNnq7i9Oe6G3Ae LyqaVaFkPTVknA34rf1gCMAE4vZTkp06nxFm1GhWo8uZyNISvrPA1ol9DdZZHPDZZx/7 PwyyksZFKPHYzQDXposnSmqZhHRBXRBoSPQsl0+1UGBz1L99BlyK10yhj1UfO6AGk8+5 KHuw==

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

**References**:**Re: [eigen] Let's get reshape in shape for 3.4***From:*Gael Guennebaud

**Re: [eigen] Let's get reshape in shape for 3.4***From:*Julian Kent

**Re: [eigen] Let's get reshape in shape for 3.4***From:*Gael Guennebaud

**Re: [eigen] Let's get reshape in shape for 3.4***From:*Julian Kent

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Let's get reshape in shape for 3.4** - Next by Date:
**Re: [eigen] Let's get reshape in shape for 3.4** - Previous by thread:
**Re: [eigen] Let's get reshape in shape for 3.4** - Next by thread:
**Re: [eigen] Let's get reshape in shape for 3.4**

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