New user self-registration is disabled due to spam. Please email eigen-core-team @ if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 449 - Allow conservative resize in sparse matrix
Summary: Allow conservative resize in sparse matrix
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: unspecified
Hardware: All All
: Normal enhancement
Assignee: Nobody
Depends on:
Reported: 2012-04-17 12:29 UTC by Benjamin Piwowarski
Modified: 2012-07-19 00:14 UTC (History)
2 users (show)

Patch against head that implements conservativeResize for SparseMatrix (7.10 KB, patch)
2012-05-09 12:05 UTC, Benjamin Piwowarski
no flags Details | Diff

Description Benjamin Piwowarski 2012-04-17 12:29:41 UTC
In one of my class, I need to update a sparse matrix by adding new columns to a sparse matrix, but there is no conservative reside method for sparse matrices for the moment.

Implementing it would probably require at the same time 
1) to grow the OuterIndexPtrs 
2) to reserve space

so I would suggest to implement

conservativeResize(Index rows, Index cols, const SizesType &reserveSizes)

Some other methods could be built from this, like

conservativeResize(Index rows, Index cols, Index reserveSize) where the reserveSize is used when greater than the actual size
conservativeResize(Index rows, Index cols) where everything is kept as is (but OuterIndexPtrs)
Comment 1 Gael Guennebaud 2012-05-01 21:17:48 UTC
To keep the API as simple as possible I would only implement the conservativeResize(Index rows, Index cols) variant. Reserving space can be done in a second time by calling reserve(reserveSize). Patch welcome.
Comment 2 Benjamin Piwowarski 2012-05-09 12:04:42 UTC
Please find a patch implementing conservativeResize (along with corresponding tests). 

Notice that the type of memory structures was changed from Index[] to Index * in order to use std::realloc.

Comment 3 Benjamin Piwowarski 2012-05-09 12:05:44 UTC
Created attachment 269 [details]
Patch against head that implements conservativeResize for SparseMatrix
Comment 4 Gael Guennebaud 2012-05-14 13:05:36 UTC
thanks for the patch, I'm too busy ATM, I'll look at it next week.
Comment 5 Benjamin Piwowarski 2012-07-17 11:36:18 UTC
Hi, any news on this before the source tree diverges too much from the revision I was based on? Thanks.
Comment 6 Gael Guennebaud 2012-07-19 00:08:23 UTC
Thanks again for this patch, it is very good. Applied:
changeset:   e09c6ff59f38
user:        bpiwowar
date:        2012-07-19 00:07:06
summary:     bug 449: add SparseMatrix::conservativeResize feature
Comment 7 Gael Guennebaud 2012-07-19 00:11:45 UTC
btw, for the reserve stuff, we could add a reserve method to  "SparseInnerVectorSet<SparseMatrix<_Scalar, _Options, _Index>, Size>" so that one can easily reserve space for a given set of rows or columns. The only trick is to factor the implementation with the implementation of SparseMatrix::reserve. To this end, one could implement a protected low level method of SparseMatrix. So I'm re-opening.
Comment 8 Gael Guennebaud 2012-07-19 00:14:08 UTC
(hit the button too fast) The relation with conservativeResize is that when you add new columns or rows you probably only want to reserve space for the ones only which are obtained as follow, e.g.:


Note You need to log in before you can comment on or make changes to this bug.