This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Two questions about sparse matrices

Tags: None
(comma "," separated)
mbraun92
Registered Member
Posts
10
Karma
0

Two questions about sparse matrices

Mon Sep 05, 2011 12:19 am
Hi. I've been doing a deep dive intp Eigen this weekend, and I've come across two issues/questions with sparse matrices:

1. I have another routine that generates some data in CSC format, and stores this data in two integer arrays (for the column pointers and row indices) and one double array for the values. I know that if I wanted to access this data from an existing Eigen SparseMatrix object, I could use the _innerIndexPtr(), _outerIndexPtr() and _valuePtr() functions. But what if I wanted a new SparseMatrix object to refer to the existing C arrays?

Let k be the number of rows/columns (the matrices are square), and let nnz be the number of non-zeros. Is there anything wrong with doing something like:

SparseMatrix<double> M(k,k);
M.reserve(nnz);
M._innerIndexPtr() = ptr_to_inner_indices;
M._outerIndexPtr() = ptr_to_outer_indices;
M._valuePtr() = ptr_to_values;

Or, would this mess things up in some way? I suppose I could always copy the data over, but I'd rather not have to do that. But if copying is the right way to go, is there a good way to copy the arrays themselves, instead of copying element by element using startVec() and insertBack()?

I should note that my program proceeds, the values in the matrix could change, but the sparsity structure and indices never will. Also, the existing routine that I use (not of my own creation) does not necessarily guarantee that the inner indices are in order (the outer ones definitely are).


2. Next, suppose that L is a lower triangular matrix, and I want to solve LL'y = b for y. In dense matrix world, I can do, with no problem,

y = L.triangularView<Lower>().solve(b);
L.triangularView<Lower>().transpose().solveInPlace(y);

When L is a SparseMatrix object, however, the first line compiles, but for the second line, I get a compiler error:

error: class "Eigen::Transpose<const Eigen::SparseTriangularView<Eigen::SparseMatrix<double, 0, int>, 1>>" has no member "solveInPlace"
L.triangularView<Lower>().transpose().solveInPlace(y);

I am including both the <Eigen/Sparse> and <unsupported/Eigen/SparseExtra> headers.

I understand that the SparseMatrix API is still in development, and that the solvers are unsupported. But I am wondering if this should still work now, if there is a workaround, or if I will need to wait until a future release.

Thanks in advance for your help.

Michael
ErlendA
Registered Member
Posts
12
Karma
0
OS
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
solveInPlace as been deprecated, just go with the y = L<...>.solve(y);
mbraun92
Registered Member
Posts
10
Karma
0
Thanks for your help. I decided to go a different way (it turns out I did need to copy the data for other reasons), but it is good to know about the MappedSparseMatrix, and that solveInPlace is deprecated.

And thanks again for leading the development of such a useful package.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]