特征稀疏LU解算器 < >我使用C++中的特征库求解稀疏线性方程组:AX= B,A是方稀疏矩阵,B是矩形稀疏矩阵。我有多个A矩阵的实例,每个实例都有多个右侧b。因此,我想将所有的A矩阵分解一次,并存储它们,然后对每个A和每个b进行求解 我尝试使用C++向量来存储所有的求解器。这是我编写的示例代码: vector<Eigen::SparseMatrix<double>> A; //fill in all A matrices vector<Eigen::SparseLU<Eigen::SparseMatrix<double>>> solver_A; Eigen::SparseLU<Eigen::SparseMatrix<double>> solver; for (int i=0;i<A.size();i++){ solver.analyzePattern(A[i]); solver.factorize(A[i]); solver_A.push_back(solver); } //Later, solver_A entries are to be used to solve for various right hand sides <pre>/usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘<b>void __gnu_cxx::new_allocator&lt;_Tp&gt;::construct(_Up*, _Args&amp;&amp; ...) [with _Up = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Args = {const Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;&amp;}; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’: <b>/usr/include/c++/7/bits/alloc_traits.h:475:4:</b> required from ‘<b>static void std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::construct(std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type&amp;, _Up*, _Args&amp;&amp; ...) [with _Up = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Args = {const Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;&amp;}; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:943:30:</b> required from ‘<b>void std::vector&lt;_Tp, _Alloc&gt;::push_back(const value_type&amp;) [with _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Alloc = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;; std::vector&lt;_Tp, _Alloc&gt;::value_type = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’ <b>header_files/coefficient_computations.cpp:476:51:</b> required from here <b>/usr/include/c++/7/ext/new_allocator.h:136:4:</b> <font color="#EF2929"><b>error: </b></font>‘Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;::SparseLU(const Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;&amp;) [with _MatrixType = Eigen::SparseMatrix&lt;double&gt;; _O<b>rderingType = Eigen::COLAMDOrdering&lt;int&gt;]</b>’ is private within this context { <font color="#EF2929"><b>::new((void *)__p) _Up(std::forward&lt;_Args&gt;(__args)...)</b></font>; } <font color="#EF2929"><b>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b></font> In file included from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13</b>, from <b>header_files/general_functions.hpp:17</b>, from <b>header_files/coefficient_computations.hpp:17</b>, from <b>header_files/coefficient_computations.cpp:2</b>: <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5:</b> <font color="#34E2E2"><b>note: </b></font>declared private here <font color="#34E2E2"><b>SparseLU</b></font> (const SparseLU&amp; ); <font color="#34E2E2"><b>^~~~~~~~</b></font> In file included from <b>/usr/include/c++/7/vector:62:0</b>, from <b>header_files/coefficient_computations.hpp:13</b>, from <b>header_files/coefficient_computations.cpp:2</b>: /usr/include/c++/7/bits/stl_construct.h: In instantiation of ‘<b>void std::_Construct(_T1*, _Args&amp;&amp; ...) [with _T1 = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Args = {Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;}]</b>’: <b>/usr/include/c++/7/bits/stl_uninitialized.h:83:18:</b> required from ‘<b>static _ForwardIterator std::__uninitialized_copy&lt;_TrivialValueTypes&gt;::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*&gt;; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; bool _TrivialValueTypes = false]</b>’ <b>/usr/include/c++/7/bits/stl_uninitialized.h:134:15:</b> required from ‘<b>_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*&gt;; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*]</b>’ <b>/usr/include/c++/7/bits/stl_uninitialized.h:289:37:</b> required from ‘<b>_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator&lt;_Tp&gt;&amp;) [with _InputIterator = std::move_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*&gt;; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’ <b>/usr/include/c++/7/bits/stl_uninitialized.h:311:2:</b> required from ‘<b>_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&amp;) [with _InputIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; _Allocator = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;]</b>’ <b>/usr/include/c++/7/bits/vector.tcc:426:6:</b> required from ‘<b>void std::vector&lt;_Tp, _Alloc&gt;::_M_realloc_insert(std::vector&lt;_Tp, _Alloc&gt;::iterator, _Args&amp;&amp; ...) [with _Args = {const Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;&amp;}; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Alloc = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;; std::vector&lt;_Tp, _Alloc&gt;::iterator = __gnu_cxx::__normal_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*, std::vector&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt; &gt;; typename std::_Vector_base&lt;_Tp, _Alloc&gt;::pointer = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:948:21:</b> required from ‘<b>void std::vector&lt;_Tp, _Alloc&gt;::push_back(const value_type&amp;) [with _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Alloc = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;; std::vector&lt;_Tp, _Alloc&gt;::value_type = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’ <b>header_files/coefficient_computations.cpp:476:51:</b> required from here <b>/usr/include/c++/7/bits/stl_construct.h:75:7:</b> <font color="#EF2929"><b>error: </b></font>‘Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;::SparseLU(const Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;&amp;) [with _MatrixType = Eigen::SparseMatrix&lt;double&gt;; _O<b>rderingType = Eigen::COLAMDOrdering&lt;int&gt;]</b>’ is private within this context { <font color="#EF2929"><b>::new(static_cast&lt;void*&gt;(__p)) _T1(std::forward&lt;_Args&gt;(__args)...)</b></font>; } <font color="#EF2929"><b>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b></font> In file included from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13</b>, from <b>header_files/general_functions.hpp:17</b>, from <b>header_files/coefficient_computations.hpp:17</b>, from <b>header_files/coefficient_computations.cpp:2</b>: <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5:</b> <font color="#34E2E2"><b>note: </b></font>declared private here <font color="#34E2E2"><b>SparseLU</b></font> (const SparseLU&amp; ); <font color="#34E2E2"><b>^~~~~~~~</b></font> </pre>

特征稀疏LU解算器 < >我使用C++中的特征库求解稀疏线性方程组:AX= B,A是方稀疏矩阵,B是矩形稀疏矩阵。我有多个A矩阵的实例,每个实例都有多个右侧b。因此,我想将所有的A矩阵分解一次,并存储它们,然后对每个A和每个b进行求解 我尝试使用C++向量来存储所有的求解器。这是我编写的示例代码: vector<Eigen::SparseMatrix<double>> A; //fill in all A matrices vector<Eigen::SparseLU<Eigen::SparseMatrix<double>>> solver_A; Eigen::SparseLU<Eigen::SparseMatrix<double>> solver; for (int i=0;i<A.size();i++){ solver.analyzePattern(A[i]); solver.factorize(A[i]); solver_A.push_back(solver); } //Later, solver_A entries are to be used to solve for various right hand sides <pre>/usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘<b>void __gnu_cxx::new_allocator&lt;_Tp&gt;::construct(_Up*, _Args&amp;&amp; ...) [with _Up = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Args = {const Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;&amp;}; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’: <b>/usr/include/c++/7/bits/alloc_traits.h:475:4:</b> required from ‘<b>static void std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::construct(std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type&amp;, _Up*, _Args&amp;&amp; ...) [with _Up = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Args = {const Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;&amp;}; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:943:30:</b> required from ‘<b>void std::vector&lt;_Tp, _Alloc&gt;::push_back(const value_type&amp;) [with _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Alloc = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;; std::vector&lt;_Tp, _Alloc&gt;::value_type = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’ <b>header_files/coefficient_computations.cpp:476:51:</b> required from here <b>/usr/include/c++/7/ext/new_allocator.h:136:4:</b> <font color="#EF2929"><b>error: </b></font>‘Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;::SparseLU(const Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;&amp;) [with _MatrixType = Eigen::SparseMatrix&lt;double&gt;; _O<b>rderingType = Eigen::COLAMDOrdering&lt;int&gt;]</b>’ is private within this context { <font color="#EF2929"><b>::new((void *)__p) _Up(std::forward&lt;_Args&gt;(__args)...)</b></font>; } <font color="#EF2929"><b>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b></font> In file included from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13</b>, from <b>header_files/general_functions.hpp:17</b>, from <b>header_files/coefficient_computations.hpp:17</b>, from <b>header_files/coefficient_computations.cpp:2</b>: <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5:</b> <font color="#34E2E2"><b>note: </b></font>declared private here <font color="#34E2E2"><b>SparseLU</b></font> (const SparseLU&amp; ); <font color="#34E2E2"><b>^~~~~~~~</b></font> In file included from <b>/usr/include/c++/7/vector:62:0</b>, from <b>header_files/coefficient_computations.hpp:13</b>, from <b>header_files/coefficient_computations.cpp:2</b>: /usr/include/c++/7/bits/stl_construct.h: In instantiation of ‘<b>void std::_Construct(_T1*, _Args&amp;&amp; ...) [with _T1 = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Args = {Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;}]</b>’: <b>/usr/include/c++/7/bits/stl_uninitialized.h:83:18:</b> required from ‘<b>static _ForwardIterator std::__uninitialized_copy&lt;_TrivialValueTypes&gt;::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*&gt;; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; bool _TrivialValueTypes = false]</b>’ <b>/usr/include/c++/7/bits/stl_uninitialized.h:134:15:</b> required from ‘<b>_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*&gt;; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*]</b>’ <b>/usr/include/c++/7/bits/stl_uninitialized.h:289:37:</b> required from ‘<b>_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator&lt;_Tp&gt;&amp;) [with _InputIterator = std::move_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*&gt;; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’ <b>/usr/include/c++/7/bits/stl_uninitialized.h:311:2:</b> required from ‘<b>_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&amp;) [with _InputIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; _ForwardIterator = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*; _Allocator = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;]</b>’ <b>/usr/include/c++/7/bits/vector.tcc:426:6:</b> required from ‘<b>void std::vector&lt;_Tp, _Alloc&gt;::_M_realloc_insert(std::vector&lt;_Tp, _Alloc&gt;::iterator, _Args&amp;&amp; ...) [with _Args = {const Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double, 0, int&gt;, Eigen::COLAMDOrdering&lt;int&gt; &gt;&amp;}; _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Alloc = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;; std::vector&lt;_Tp, _Alloc&gt;::iterator = __gnu_cxx::__normal_iterator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*, std::vector&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt; &gt;; typename std::_Vector_base&lt;_Tp, _Alloc&gt;::pointer = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;*]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:948:21:</b> required from ‘<b>void std::vector&lt;_Tp, _Alloc&gt;::push_back(const value_type&amp;) [with _Tp = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;; _Alloc = std::allocator&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt; &gt;; std::vector&lt;_Tp, _Alloc&gt;::value_type = Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt; &gt;]</b>’ <b>header_files/coefficient_computations.cpp:476:51:</b> required from here <b>/usr/include/c++/7/bits/stl_construct.h:75:7:</b> <font color="#EF2929"><b>error: </b></font>‘Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;::SparseLU(const Eigen::SparseLU&lt;_MatrixType, _OrderingType&gt;&amp;) [with _MatrixType = Eigen::SparseMatrix&lt;double&gt;; _O<b>rderingType = Eigen::COLAMDOrdering&lt;int&gt;]</b>’ is private within this context { <font color="#EF2929"><b>::new(static_cast&lt;void*&gt;(__p)) _T1(std::forward&lt;_Args&gt;(__args)...)</b></font>; } <font color="#EF2929"><b>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b></font> In file included from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31</b>, from <b>../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13</b>, from <b>header_files/general_functions.hpp:17</b>, from <b>header_files/coefficient_computations.hpp:17</b>, from <b>header_files/coefficient_computations.cpp:2</b>: <b>../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5:</b> <font color="#34E2E2"><b>note: </b></font>declared private here <font color="#34E2E2"><b>SparseLU</b></font> (const SparseLU&amp; ); <font color="#34E2E2"><b>^~~~~~~~</b></font> </pre>,c++,c++17,eigen,C++,C++17,Eigen,如果注释了行“solver\u A.push\u back(solver)”,则编译成功。请提供任何帮助以解决此问题或使用其他解决方案。vector::push_back要求向量元素可以复制或移动SparseLU两者都不是,因为它有一个私有副本构造函数(): 你可以通过多种方式解决这个问题。例如,通过构造具有适当大小的解算器向量,使其不需要动态增长(): 向量A; 向量解算器_A(A.size()); 对于(int i=0;i private: // Disable copy construct

如果注释了行“solver\u A.push\u back(solver)”,则编译成功。请提供任何帮助以解决此问题或使用其他解决方案。

vector::push_back
要求向量元素可以复制或移动
SparseLU
两者都不是,因为它有一个私有副本构造函数():

你可以通过多种方式解决这个问题。例如,通过构造具有适当大小的解算器向量,使其不需要动态增长():

向量A;
向量解算器_A(A.size());
对于(int i=0;i
private:
// Disable copy constructor 
 SparseLU (const SparseLU& );
vector<Eigen::SparseMatrix<double>> A;

vector<Eigen::SparseLU<Eigen::SparseMatrix<double>>> solver_A(A.size());

for (int i=0;i<A.size();i++) {
  solver_A[i].analyzePattern(A[i]); 
  solver_A[i].factorize(A[i]);
  }