You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble getting the following example to work (although the first two examples in the README work fine for me). Very new to C++ so could be a bug or I could be missing something obvious.
#include<Eigen/Core>
#include<Spectra/SymEigsSolver.h>
#include<iostream>usingnamespaceSpectra;// M = diag(1, 2, ..., 10)classMyDiagonalTen
{
public:using Scalar = double; // A typedef named "Scalar" is requiredintrows() { return10; }
intcols() { return10; }
// y_out = M * x_invoidperform_op(constdouble *x_in, double *y_out) const
{
for (int i = 0; i < rows(); i++)
{
y_out[i] = x_in[i] * (i + 1);
}
}
};
intmain()
{
MyDiagonalTen op;
SymEigsSolver<MyDiagonalTen> eigs(op, 3, 6);
eigs.init();
eigs.compute(SortRule::LargestAlge);
if (eigs.info() == CompInfo::Successful)
{
Eigen::VectorXd evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n"
<< evalues << std::endl;
}
return0;
}
I see:
g++ tmp.cpp -o tmp && "/dabox/hayes/spectra/examples/"tmp
tmp.cpp: In member function ‘void MyDiagonalTen::perform_op(const double*, double*) const’:
tmp.cpp:17:34: error: passing ‘const MyDiagonalTen’ as ‘this’ argument discards qualifiers [-fpermissive]
17 | for (int i = 0; i < rows(); i++)
| ^
tmp.cpp:12:9: note: in call to ‘int MyDiagonalTen::rows()’
12 | int rows() { return 10; }
| ^~~~
In file included from /usr/local/include/Spectra/SymEigsBase.h:22,
from /usr/local/include/Spectra/SymEigsSolver.h:12,
from tmp.cpp:2:
/usr/local/include/Spectra/MatOp/internal/ArnoldiOp.h: In instantiation of ‘Spectra::ArnoldiOp<Scalar, OpType, Spectra::IdentityBOp>::Index Spectra::ArnoldiOp<Scalar, OpType, Spectra::IdentityBOp>::rows() const [with Scalar = double; OpType = MyDiagonalTen; Spectra::ArnoldiOp<Scalar, OpType, Spectra::IdentityBOp>::Index = long int]’:
/usr/local/include/Spectra/LinAlg/Arnoldi.h:119:59: required from ‘Spectra::Arnoldi<Scalar, ArnoldiOpType>::Arnoldi(ArnoldiOpType&&, Spectra::Arnoldi<Scalar, ArnoldiOpType>::Index) [with Scalar = double; ArnoldiOpType = Spectra::ArnoldiOp<double, MyDiagonalTen, Spectra::IdentityBOp>; Spectra::Arnoldi<Scalar, ArnoldiOpType>::Index = long int]’
/usr/local/include/Spectra/LinAlg/Lanczos.h:52:62: required from ‘Spectra::Lanczos<Scalar, ArnoldiOpType>::Lanczos(T&&, Spectra::Lanczos<Scalar, ArnoldiOpType>::Index) [with T = Spectra::ArnoldiOp<double, MyDiagonalTen, Spectra::IdentityBOp>; Scalar = double; ArnoldiOpType = Spectra::ArnoldiOp<double, MyDiagonalTen, Spectra::IdentityBOp>; Spectra::Lanczos<Scalar, ArnoldiOpType>::Index = long int]’
/usr/local/include/Spectra/SymEigsBase.h:237:37: required from ‘Spectra::SymEigsBase<OpType, BOpType>::SymEigsBase(OpType&, const BOpType&, Spectra::SymEigsBase<OpType, BOpType>::Index, Spectra::SymEigsBase<OpType, BOpType>::Index) [with OpType = MyDiagonalTen; BOpType = Spectra::IdentityBOp; Spectra::SymEigsBase<OpType, BOpType>::Index = long int]’
/usr/local/include/Spectra/SymEigsSolver.h:158:69: required from ‘Spectra::SymEigsSolver<OpType>::SymEigsSolver(OpType&, Spectra::SymEigsSolver<OpType>::Index, Spectra::SymEigsSolver<OpType>::Index) [with OpType = MyDiagonalTen; Spectra::SymEigsSolver<OpType>::Index = long int]’
tmp.cpp:27:47: required from here
/usr/local/include/Spectra/MatOp/internal/ArnoldiOp.h:120:50: error: passing ‘const MyDiagonalTen’ as ‘this’ argument discards qualifiers [-fpermissive]
120 | inline Index rows() const { return m_op.rows(); }
| ^
tmp.cpp:12:9: note: in call to ‘int MyDiagonalTen::rows()’
12 | int rows() { return 10; }
| ^~~~
[Done] exited with code=1 in 2.437 seconds
The text was updated successfully, but these errors were encountered:
alexpghayes
changed the title
Custom matrix op errors
error: passing ‘const MyDiagonalTen’ as ‘this’ argument discards qualifiers
Mar 2, 2022
I'm having trouble getting the following example to work (although the first two examples in the README work fine for me). Very new to C++ so could be a bug or I could be missing something obvious.
I see:
The text was updated successfully, but these errors were encountered: