我正在研究一个数字代码,并希望评估该代码用例的稀疏和密集矩阵-LU分解(以及以后的分解)如何不同。Eigens密集分解对象可以是可复制的,并且可以使用boost :: variant缓存这些对象,以在以后获得更大的灵活性。
我想用稀疏解算器实现相同的目标,但是这样做有困难。下面的最小示例应说明我的方法。
问题是,为什么稀疏求解器不可复制?我可以只编写自己的复制操作,还是确定格式不正确。我该如何解决这个问题?
谢谢 :)
/// -------------------------------- DENSE APPROACH, WORKS -------------------------------
using CacheType = boost::variant<Eigen::FullPivLU<Eigen::MatrixXd>,
Eigen::PartialPivLU<Eigen::MatrixXd>>;
// visit the variant, and solve with the correct decomposition
struct DenseVisitor : boost::static_visitor<Eigen::MatrixXd> {
DenseVisitor(Eigen::MatrixXd const& r) : rhs{r} {}
template <class Decomposition>
Eigen::MatrixXd operator()(Decomposition const& d) const
{
Eigen::MatrixXd res = d.solve(rhs);
return res;
}
private:
Eigen::MatrixXd const& rhs; // reference to rhs, since () will take only one argument
};
// part of a class, having a cachetype as …
Run Code Online (Sandbox Code Playgroud)