0
votes

I have two sparse matrices A and B and I want to compute X as X = A\B also the same solution to the equation A*X = B
Is there a library in C++ that has this functionality?, I tried Eigen with SparseLU solver but it's taking too much time, when dealing with very large sparse matrices ((6*6)millions), much longer than Matlab.
any ideas?
Edit:
Here's the solving snippet in Eigen and OpenCV, the matrix is originally an image, the output is also an image, also it's better if B or EIN in the snippet to be dense but I can't do so in Eigen

Eigen::SparseLU<Eigen::SparseMatrix<float>> Solver;
EA.makeCompressed();
Solver.compute(EA);
if (Solver.info() != Eigen::Success) std::cout << Solver.lastErrorMessage() << std::endl;
else std::cout << "Success !" << std::endl;
cv::SparseMat IN(MatTraverse(Image));
Eigen::SparseMatrix<float> EIN = SparseCV2Eigen(IN);
Eigen::SparseMatrix<float> OUT = Solver.solve(EIN);
Eigen::MatrixXf OUTM(OUT);
OUTM.resize(Image.cols,Image.rows);
cv::Mat CVOUT(OUTM.rows(), OUTM.cols(), CV_32F, OUTM.data());

Another, the same equation can be solved in Matlab using X = A\B in a much faster time

1
These kind of questions are explicitly off-topic here. Read point #4 from this help center article. - πάντα ῥεῖ
Can you show a minimal reproducible example along with your compiler flags? - Avi Ginsburg
Show what you tried and may be someone can help you make it work - fernando.reyes
Make sure you compiled with compiler optimization ON. Also, is the matrix symmetric? - ggael
@AbdarhmanTaha: I meant if you want to multiply something with X, e.g., ` X*y` you instead can calculate: luA.solve(B*y) (assuming luA is an LU-decomposition of A. - chtz

1 Answers

-2
votes

Try this one: http://arma.sourceforge.net/docs.html#operators

It has lots operators for matrix:

operators: + − * / % == != <= >= < > Overloaded operators for Mat, Col, Row and Cube classes

Meanings:

  • Addition of two objects −
    Subtraction of one object from another or negation of an object

/
Element-wise division of an object by another object or a scalar *
Matrix multiplication of two objects; not applicable to the Cube class unless multiplying a cube by a scalar

%
Schur product: element-wise multiplication of two objects

==
Element-wise equality evaluation of two objects; generates a matrix of type umat with entries that indicate whether at a given position the two elements from the two objects are equal (1) or not equal (0) !=
Element-wise non-equality evaluation of two objects

=
As for ==, but the check is for "greater than or equal to" <=
As for ==, but the check is for "less than or equal to"

As for ==, but the check is for "greater than" <
As for ==, but the check is for "less than"