简体   繁体   中英

Does Eigen “Sparse matrix format” example contains error?

Eigen 3.3.7 documentation for SparceMatrix http://eigen.tuxfamily.org/dox/group__TutorialSparse.html seems to contain an error in Sparse matrix format section:

This storage scheme is better explained on an example. The following matrix

0   3   0   0   0
22  0   0   0   17
7   5   0   1   0
0   0   0   0   0
0   0   14  0   8

and one of its possible sparse, column major representation:

Values:         22  7   _   3   5   14  _   _   1   _   17  8
InnerIndices:   1   2   _   0   2   4   _   _   2   _   1   4
OuterStarts:    0   3   5   8   10  12
InnerNNZs:      2   2   1   1   2   

If 14 is moved from the third column to the second (ie its indices changed from [4,2] to [4,1]), then the first two arrays, Values and InnerIndices , make sense. OuterStarts doesn't seem to be correct for either 14 position, while InnerNNZs makes sense for 14 being in [4,2] element of the matrix, but is inconsistent with Values array.

Is this example incorrect or am I missing something?

In general, what is the best way of figuring out Eigen , besides examining the source code? I normally look at tests and examples, but building most benchmark and tests for sparse matrices results in compilation errors (were these tests written for older version of Eigen and not updated for version 3?)...

The key is that the user is supposed to reserve at least as many entries per column as they need. In this example the user only reserved 2 entries for the second column, so if you were to try to add another entry to that column, it would probably require an expensive reallocation, or at least a complicated shift to "steal" an unused entry from another column. (I have no idea how this is implemented.)

Upon a cursory look at the documentation you linked to, I didn't see anything about moving entries like you're trying to do. I'm not sure that Eigen supports such an operation. (Correct me if I'm wrong.) I'm also not sure why you would want to do that.

Your final question is probably too broad. I'm not an expert at Eigen, but it seems like a mature, powerful, and well-documented library. If you have any specific problems compiling examples, you should post them here or on an Eigen specific forum. Many people at scicomp.SE are well-versed in Eigen and are accommodating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM