eigenrcppeigen

Copy SimplicialLLT object in Eigen


I apologies in advance if this is an easy question but I am still learning Eigen.

I am creating two Eigen::SimplicialLLT objects

Eigen::SimplicialLLT <Eigen::SparseMatrix<double>> Omegachol1;
Eigen::SimplicialLLT <Eigen::SparseMatrix<double>> Omegachol2;
Omegachol1.compute(Omega1);
Omegachol2.compute(Omega2);

and next, I would need to use one of them for other calculations and therefore I need to assign a new SimplicialLLT object to one of them (reusing the initial object is of course possible but very tedious and the code would quickly become unreadable).

I tried something like

Eigen::SimplicialLLT <Eigen::SparseMatrix<double>> Omegachol = Omegachol1;

but it does not work.

Is there a way to copy SimplicialLLT object and reuse them?

Based on my understanding, this is not a duplicate of Re-use Eigen::SimplicialLLT's symbolic decomposition


Solution

  • These solvers objects are neither copyable nor movable. I suggest using a reference to the solver object:

    Eigen::SimplicialLLT <Eigen::SparseMatrix<double>> Omegachol1;
    Eigen::SimplicialLLT <Eigen::SparseMatrix<double>> Omegachol2;
    Omegachol1.compute(Omega1);
    Omegachol2.compute(Omega2);
    
    Eigen::SimplicialLLT <Eigen::SparseMatrix<double>> & Omegachol1_ref = Omegachol1
    

    EDIT: Apparently also for Eigen::SimplicialLLT the solve method is non-const, so you will need a non-const reference.