title: Eigen Sparse LU solver
body: <p>I am using the Eigen library in C++ for solving sparse linear equations: Ax=b where, A is a square sparse matrix and b is a rectangular sparse matrix. I have multiple instances of the A matrices and each one has multiple right hand sides b. Hence, I want to factorize all the A matrices once and store them followed by solution for each A with each b.</p>
  
  <p>I tried to use the C++ vector for storing all the solvers. This is a sample code I have written:</p>
  
  <pre><code>vector&lt;Eigen::SparseMatrix&lt;double&gt;&gt; A;
  //fill in all A matrices
  
  vector&lt;Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt;&gt;&gt; solver_A;
  
  Eigen::SparseLU&lt;Eigen::SparseMatrix&lt;double&gt;&gt; solver;
  
  for (int i=0;i&lt;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
  </code></pre>
  
  <p>I am using 3.3.7 version of Eigen and compiling in linux with gcc compiler and c++17 standard. I am getting the following compilation error due to the <code>solver_A.push_back(solver)</code> line:</p>
  
  <pre><code>&lt;pre&gt;/usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘&lt;b&gt;void __gnu_cxx::new_allocator&amp;lt;_Tp&amp;gt;::construct(_Up*, _Args&amp;amp;&amp;amp; ...) [with _Up = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; _Args = {const Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double, 0, int&amp;gt;, Eigen::COLAMDOrdering&amp;lt;int&amp;gt; &amp;gt;&amp;amp;}; _Tp = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;]&lt;/b&gt;’:
  &lt;b&gt;/usr/include/c++/7/bits/alloc_traits.h:475:4:&lt;/b&gt;   required from ‘&lt;b&gt;static void std::allocator_traits&amp;lt;std::allocator&amp;lt;_CharT&amp;gt; &amp;gt;::construct(std::allocator_traits&amp;lt;std::allocator&amp;lt;_CharT&amp;gt; &amp;gt;::allocator_type&amp;amp;, _Up*, _Args&amp;amp;&amp;amp; ...) [with _Up = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; _Args = {const Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double, 0, int&amp;gt;, Eigen::COLAMDOrdering&amp;lt;int&amp;gt; &amp;gt;&amp;amp;}; _Tp = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; std::allocator_traits&amp;lt;std::allocator&amp;lt;_CharT&amp;gt; &amp;gt;::allocator_type = std::allocator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt; &amp;gt;]&lt;/b&gt;’
  &lt;b&gt;/usr/include/c++/7/bits/stl_vector.h:943:30:&lt;/b&gt;   required from ‘&lt;b&gt;void std::vector&amp;lt;_Tp, _Alloc&amp;gt;::push_back(const value_type&amp;amp;) [with _Tp = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; _Alloc = std::allocator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt; &amp;gt;; std::vector&amp;lt;_Tp, _Alloc&amp;gt;::value_type = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;]&lt;/b&gt;’
  &lt;b&gt;header_files/coefficient_computations.cpp:476:51:&lt;/b&gt;   required from here
  &lt;b&gt;/usr/include/c++/7/ext/new_allocator.h:136:4:&lt;/b&gt; &lt;font color="#EF2929"&gt;&lt;b&gt;error: &lt;/b&gt;&lt;/font&gt;‘Eigen::SparseLU&amp;lt;_MatrixType, _OrderingType&amp;gt;::SparseLU(const Eigen::SparseLU&amp;lt;_MatrixType, _OrderingType&amp;gt;&amp;amp;) [with _MatrixType = Eigen::SparseMatrix&amp;lt;double&amp;gt;; _O&lt;b&gt;rderingType = Eigen::COLAMDOrdering&amp;lt;int&amp;gt;]&lt;/b&gt;’ is private within this context
    { &lt;font color="#EF2929"&gt;&lt;b&gt;::new((void *)__p) _Up(std::forward&amp;lt;_Args&amp;gt;(__args)...)&lt;/b&gt;&lt;/font&gt;; }
      &lt;font color="#EF2929"&gt;&lt;b&gt;^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/b&gt;&lt;/font&gt;
  In file included from &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0&lt;/b&gt;,
                   from &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31&lt;/b&gt;,
                   from &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13&lt;/b&gt;,
                   from &lt;b&gt;header_files/general_functions.hpp:17&lt;/b&gt;,
                   from &lt;b&gt;header_files/coefficient_computations.hpp:17&lt;/b&gt;,
                   from &lt;b&gt;header_files/coefficient_computations.cpp:2&lt;/b&gt;:
  &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5:&lt;/b&gt; &lt;font color="#34E2E2"&gt;&lt;b&gt;note: &lt;/b&gt;&lt;/font&gt;declared private here
       &lt;font color="#34E2E2"&gt;&lt;b&gt;SparseLU&lt;/b&gt;&lt;/font&gt; (const SparseLU&amp;amp; );
       &lt;font color="#34E2E2"&gt;&lt;b&gt;^~~~~~~~&lt;/b&gt;&lt;/font&gt;
  In file included from &lt;b&gt;/usr/include/c++/7/vector:62:0&lt;/b&gt;,
                   from &lt;b&gt;header_files/coefficient_computations.hpp:13&lt;/b&gt;,
                   from &lt;b&gt;header_files/coefficient_computations.cpp:2&lt;/b&gt;:
  /usr/include/c++/7/bits/stl_construct.h: In instantiation of ‘&lt;b&gt;void std::_Construct(_T1*, _Args&amp;amp;&amp;amp; ...) [with _T1 = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; _Args = {Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double, 0, int&amp;gt;, Eigen::COLAMDOrdering&amp;lt;int&amp;gt; &amp;gt;}]&lt;/b&gt;’:
  &lt;b&gt;/usr/include/c++/7/bits/stl_uninitialized.h:83:18:&lt;/b&gt;   required from ‘&lt;b&gt;static _ForwardIterator std::__uninitialized_copy&amp;lt;_TrivialValueTypes&amp;gt;::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*&amp;gt;; _ForwardIterator = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*; bool _TrivialValueTypes = false]&lt;/b&gt;’
  &lt;b&gt;/usr/include/c++/7/bits/stl_uninitialized.h:134:15:&lt;/b&gt;   required from ‘&lt;b&gt;_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*&amp;gt;; _ForwardIterator = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*]&lt;/b&gt;’
  &lt;b&gt;/usr/include/c++/7/bits/stl_uninitialized.h:289:37:&lt;/b&gt;   required from ‘&lt;b&gt;_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator&amp;lt;_Tp&amp;gt;&amp;amp;) [with _InputIterator = std::move_iterator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*&amp;gt;; _ForwardIterator = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*; _Tp = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;]&lt;/b&gt;’
  &lt;b&gt;/usr/include/c++/7/bits/stl_uninitialized.h:311:2:&lt;/b&gt;   required from ‘&lt;b&gt;_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&amp;amp;) [with _InputIterator = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*; _ForwardIterator = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*; _Allocator = std::allocator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt; &amp;gt;]&lt;/b&gt;’
  &lt;b&gt;/usr/include/c++/7/bits/vector.tcc:426:6:&lt;/b&gt;   required from ‘&lt;b&gt;void std::vector&amp;lt;_Tp, _Alloc&amp;gt;::_M_realloc_insert(std::vector&amp;lt;_Tp, _Alloc&amp;gt;::iterator, _Args&amp;amp;&amp;amp; ...) [with _Args = {const Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double, 0, int&amp;gt;, Eigen::COLAMDOrdering&amp;lt;int&amp;gt; &amp;gt;&amp;amp;}; _Tp = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; _Alloc = std::allocator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt; &amp;gt;; std::vector&amp;lt;_Tp, _Alloc&amp;gt;::iterator = __gnu_cxx::__normal_iterator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*, std::vector&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt; &amp;gt; &amp;gt;; typename std::_Vector_base&amp;lt;_Tp, _Alloc&amp;gt;::pointer = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;*]&lt;/b&gt;’
  &lt;b&gt;/usr/include/c++/7/bits/stl_vector.h:948:21:&lt;/b&gt;   required from ‘&lt;b&gt;void std::vector&amp;lt;_Tp, _Alloc&amp;gt;::push_back(const value_type&amp;amp;) [with _Tp = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;; _Alloc = std::allocator&amp;lt;Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt; &amp;gt;; std::vector&amp;lt;_Tp, _Alloc&amp;gt;::value_type = Eigen::SparseLU&amp;lt;Eigen::SparseMatrix&amp;lt;double&amp;gt; &amp;gt;]&lt;/b&gt;’
  &lt;b&gt;header_files/coefficient_computations.cpp:476:51:&lt;/b&gt;   required from here
  &lt;b&gt;/usr/include/c++/7/bits/stl_construct.h:75:7:&lt;/b&gt; &lt;font color="#EF2929"&gt;&lt;b&gt;error: &lt;/b&gt;&lt;/font&gt;‘Eigen::SparseLU&amp;lt;_MatrixType, _OrderingType&amp;gt;::SparseLU(const Eigen::SparseLU&amp;lt;_MatrixType, _OrderingType&amp;gt;&amp;amp;) [with _MatrixType = Eigen::SparseMatrix&amp;lt;double&amp;gt;; _O&lt;b&gt;rderingType = Eigen::COLAMDOrdering&amp;lt;int&amp;gt;]&lt;/b&gt;’ is private within this context
       { &lt;font color="#EF2929"&gt;&lt;b&gt;::new(static_cast&amp;lt;void*&amp;gt;(__p)) _T1(std::forward&amp;lt;_Args&amp;gt;(__args)...)&lt;/b&gt;&lt;/font&gt;; }
         &lt;font color="#EF2929"&gt;&lt;b&gt;^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/b&gt;&lt;/font&gt;
  In file included from &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0&lt;/b&gt;,
                   from &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31&lt;/b&gt;,
                   from &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13&lt;/b&gt;,
                   from &lt;b&gt;header_files/general_functions.hpp:17&lt;/b&gt;,
                   from &lt;b&gt;header_files/coefficient_computations.hpp:17&lt;/b&gt;,
                   from &lt;b&gt;header_files/coefficient_computations.cpp:2&lt;/b&gt;:
  &lt;b&gt;../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5:&lt;/b&gt; &lt;font color="#34E2E2"&gt;&lt;b&gt;note: &lt;/b&gt;&lt;/font&gt;declared private here
       &lt;font color="#34E2E2"&gt;&lt;b&gt;SparseLU&lt;/b&gt;&lt;/font&gt; (const SparseLU&amp;amp; );
       &lt;font color="#34E2E2"&gt;&lt;b&gt;^~~~~~~~&lt;/b&gt;&lt;/font&gt;
  &lt;/pre&gt;
  </code></pre>
  
  <p>The compilation is successful if the line "solver_A.push_back(solver)" is commented. Any help is appreciated either to fix this issue or with alternate solution.</p>