特征稀疏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<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</b>’: <b>/usr/include/c++/7/bits/alloc_traits.h:475:4:</b> required from ‘<b>static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:943:30:</b> required from ‘<b>void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::value_type = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</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<_MatrixType, _OrderingType>::SparseLU(const Eigen::SparseLU<_MatrixType, _OrderingType>&) [with _MatrixType = Eigen::SparseMatrix<double>; _O<b>rderingType = Eigen::COLAMDOrdering<int>]</b>’ is private within this context { <font color="#EF2929"><b>::new((void *)__p) _Up(std::forward<_Args>(__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& ); <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&& ...) [with _T1 = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >}]</b>’: <b>/usr/include/c++/7/bits/stl_uninitialized.h:83:18:</b> required from ‘<b>static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; 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<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*]</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<_Tp>&) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</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&) [with _InputIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _Allocator = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >]</b>’ <b>/usr/include/c++/7/bits/vector.tcc:426:6:</b> required from ‘<b>void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*, std::vector<Eigen::SparseLU<Eigen::SparseMatrix<double> > > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Eigen::SparseLU<Eigen::SparseMatrix<double> >*]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:948:21:</b> required from ‘<b>void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::value_type = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</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<_MatrixType, _OrderingType>::SparseLU(const Eigen::SparseLU<_MatrixType, _OrderingType>&) [with _MatrixType = Eigen::SparseMatrix<double>; _O<b>rderingType = Eigen::COLAMDOrdering<int>]</b>’ is private within this context { <font color="#EF2929"><b>::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__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& ); <font color="#34E2E2"><b>^~~~~~~~</b></font> </pre>
如果注释了行“solver\u A.push\u back(solver)”,则编译成功。请提供任何帮助以解决此问题或使用其他解决方案。特征稀疏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<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</b>’: <b>/usr/include/c++/7/bits/alloc_traits.h:475:4:</b> required from ‘<b>static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:943:30:</b> required from ‘<b>void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::value_type = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</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<_MatrixType, _OrderingType>::SparseLU(const Eigen::SparseLU<_MatrixType, _OrderingType>&) [with _MatrixType = Eigen::SparseMatrix<double>; _O<b>rderingType = Eigen::COLAMDOrdering<int>]</b>’ is private within this context { <font color="#EF2929"><b>::new((void *)__p) _Up(std::forward<_Args>(__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& ); <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&& ...) [with _T1 = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >}]</b>’: <b>/usr/include/c++/7/bits/stl_uninitialized.h:83:18:</b> required from ‘<b>static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; 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<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*]</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<_Tp>&) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</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&) [with _InputIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _Allocator = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >]</b>’ <b>/usr/include/c++/7/bits/vector.tcc:426:6:</b> required from ‘<b>void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*, std::vector<Eigen::SparseLU<Eigen::SparseMatrix<double> > > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Eigen::SparseLU<Eigen::SparseMatrix<double> >*]</b>’ <b>/usr/include/c++/7/bits/stl_vector.h:948:21:</b> required from ‘<b>void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::value_type = Eigen::SparseLU<Eigen::SparseMatrix<double> >]</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<_MatrixType, _OrderingType>::SparseLU(const Eigen::SparseLU<_MatrixType, _OrderingType>&) [with _MatrixType = Eigen::SparseMatrix<double>; _O<b>rderingType = Eigen::COLAMDOrdering<int>]</b>’ is private within this context { <font color="#EF2929"><b>::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__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& ); <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
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]);
}