-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SymGEigsShiftSolver available soon? #113
Comments
|
Can I use SymGEigsShiftSolver now without waiting 1.0.0? I saw SymGEigsShiftSolver.cpp but this is just testing by include'ing SymGEigsShiftSolver.h. I can't find that file to include in my project. Can you help me with that please? |
|
Yeah I did it. Properly set all the paths etc. However, it doesn't compile; here is the first of many errors coming from SymGEigsShiftInvertOp.h: line31: using Scalar = typename OpType::Scalar; //error: 'Scalar' : symbol cannot be used in a using-declaration Is it a C++11 issue? I'm using the old C++ in my Visual Studio 2010. Any idea how I can get it run there, or is this a different problem? |
Yeah, you need a modern compiler such as GCC and Clang, or Visual Studio 2015, according to this document. |
You can use this self-contained example to test the compiler: #include <Eigen/Core>
#include <iostream>
#include <Spectra/SymGEigsShiftSolver.h>
#include <Spectra/MatOp/SymShiftInvert.h>
#include <Spectra/MatOp/DenseSymMatProd.h>
using namespace Spectra;
// Generate data for testing
void gen_dense_data(int n, Eigen::MatrixXd& A, Eigen::MatrixXd& B)
{
// Eigen solver only uses the lower triangle of A,
// so we don't need to make A symmetric here
A = Eigen::MatrixXd::Random(n, n);
B = A.transpose() * A;
// To make sure B is positive definite
B.diagonal() += Eigen::VectorXd::Random(n).cwiseAbs();
}
int main()
{
std::srand(123);
// Eigen solver only uses the lower triangle
Eigen::MatrixXd A, B;
gen_dense_data(100, A, B);
int k = 10;
int m = 20;
double sigma = 1.2345;
using OpType = SymShiftInvert<double, Eigen::Dense, Eigen::Dense>;
using BOpType = DenseSymMatProd<double>;
OpType op(A, B);
BOpType Bop(B);
SymGEigsShiftSolver<OpType, BOpType, GEigsMode::ShiftInvert> eigs(op, Bop, k, m, sigma);
eigs.init();
eigs.compute(SortRule::LargestMagn, 100);
std::cout << eigs.eigenvalues() << std::endl;
return 0;
} |
Makes sense but there's a problem: I tried to use clang++ -std=c++11 which is good for these new C++11 Spectra code but it fails to compile my whole project written in the old C++, e.g., it errors about Mesh::computeHeatKernelSignature() syntax and many others. I expect some back-compatibility but apparently it's not the case. So, do you recommend a solution, or do you have another SymGEigsShiftSolver compatible with the old C++? That's all I need. |
C++11 should be mostly back-compatible, and will eventually be the standard for future code. If the code does not compile with Clang then very likely there is something not following the standard. I suggest looking at those errors more carefully to see what happens. |
Also, is it simply because you changed the compiler? |
Yes, simply because I changed the compiler. My code that is including your old Spectra release (without SymGEigsShiftSolver) compiles perfectly with: g++ -O3 *.cpp -o output -w When I include your new Spectra (C++11), I had to use (on the same machine): clang++ -std=c++11 -stdlib=libc++ -Weverything main.cpp -o output -w -O3 Do you have any comment on this compiler error? Thanks. |
It looks like a linking problem, see the discussion here. Some things you can check:
|
Thanks for the link; it is very related. As suggested there, I've replaced clang++ with g++, CC, clang, and gcc but still get the same error. I'm on macOS BigSur. Do you know another compiler or any other trick? |
To better debug, I suggest doing the following:
|
OK will do that. I also want to ask an algebra question that still concerns SymGEigsShiftSolver: Eigenvectors of a real symmetric matrix, like Laplacian, are already orthonormal: standard eigenvalue problem works: L v = lambda v. My question is, what does it mean for eigenvectors to be orthonormal w.r.t. a matrix? What's the benefit of that? Any geometric intuition is highly appreciated. |
My understanding is the following: |
Here's how I see it (Attention: Mathematicians please look away): In short: It is so that it is useful. How lucky we are! :-) |
Hey, I tried using SymGEigsShiftSolver on a positive semidefinite matrix A (Av=Bv) with a B which is diagonal and positive, with sigma offset -1e-6 to make it invertible. Unfortunately it didn't converge. Thanks a lot! |
@stigersh Can you provide an example matrix to reproduce the problem? |
Sorry didn't see the response.. Thank you for replying! |
For sparse symmetric 10Kx10K A and B (B is diagonal), generalized problem is solved for the 15 smallest eigenvalues via
I've a feeling that it'll run faster via SymGEigsShiftSolver but I couldn't see it in the current release spectra-0.8.1.tar.gz. So, am I right that SymGEigsShiftSolver (with sigma = -1e-6) will be faster/better (for the small eigenvalues that I need)? And when will it be released so I can use it (saw test/SymGEigsShift.cpp but can't adapt it as SymGEigsShiftSolver not in the current release)?
The text was updated successfully, but these errors were encountered: