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

Mapping complex sparse matrix in Eigen from MATLAB workspace

Tags: eigen/sparse matrix eigen/sparse matrix eigen/sparse matrix
(comma "," separated)
ferronli
Registered Member
Posts
1
Karma
0
Hello, everyone!

Here is my case: I am working on solving linear equation Ax = b by using Eigen solvers through mex function of Matlab. I have gotten a complex sparse matrix A and a sparse vector b from Matlab workspace. I want to map matrix A and vector b in Eigen sparse matrix format, after that use Eigen's linear equation solvers to solve, at last transfer the results x to Matlab workspace. However, since I am not good at C++ and not familiar with Eigen either. I am stuck at the first step, namely constructing the complex sparse matrix in Eigen accepted format. ???

I have found there is a following function in Eigen,
Code: Select all
Eigen::MappedSparseMatrix<double,RowMajor>  mat(rows, cols, nnz, row_ptr, col_index, values);

And I can use mxGetPr, mxGetPi, mxGetIr, mxGetJc, etc, these mex functions to get the info for the above "rows, cols, nnz, row_ptr, col_index, values". However, since in my case, matrix A is a complex sparse matrix. I am not sure whether "MappedSparseMatrix" can do that. If it can, how the format of "MappedSparseMatrix" should be ?
Like the following ?
Code: Select all
Eigen::MappedSparseMatrix<std::complex<double>> mat(rows, cols, nnz, row_ptr, col_index, values_complex);

If so, how should I construct that values_complex ?
Besides, I have found about a relevant topic before, https://forum.kde.org/viewtopic.php?f=74&t=89083
I can use the following codes to get a complex dense matrix.
Code: Select all
MatrixXcd mat(m,n);
mat.real() = Map<MatrixXd>(realData,m,n);
mat.imag() = Map<MatrixXd>(imagData,m,n);

However, since my matrix A is a sparse matrix. it seems that it will produce errors if I define mat as a complex sparse matrix like the following:
Code: Select all
 SparseMatrix<std::complex<double> > mat;
mat.real()  =  Map<SparseMatrix>(rows, cols, nnz, row_ptr, col_index, realData);
mat.imag() = Map<SparseMatrix>(rows, cols, nnz, row_ptr, col_index, imagData);


So can anyone provide some advice for that? Thanks very much for your kindly help!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS


Bookmarks



Who is online

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