title: Armadillo: solve with sp_mat
body: <p>I'm writing a basic FEM program using Armadillo. I use <code>sp_mat</code> and <code>vec</code> as matrix and vector type. The problem is, that when I do <code>solve(X, b)</code> i get an error. Could it be that <code>solve</code> does not support <code>sp_mat</code>. Any alternatives except of using dense matrices? Below is the code, where the <code>sp_mat</code> doesn't compile. If I use the the commented line <code>mat A</code> instead it works fine.</p>
  
  <pre><code>    int N = 3;
  double h = 1./N;
  
  //mat A = zeros&lt;mat&gt;(N+1,N+1);
  sp_mat A(N+1,N+1); 
  for(int i=0;i&lt;=N;i++) {
      if(i&gt;0) {A(i,i-1)=-1.;}
      A(i,i)=2.;
      if(i&lt;N) {A(i,i+1)=-1.;}
  }
  A(N,N)=1;
  
  vec b = zeros(N+1);
  for(int i=0;i&lt;=N;i++) {
      b(i)=h; 
  }
  
  vec zeta = solve(A,b);
  cout &lt;&lt; zeta;
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>make all 
  Building file: ../src/FEM.cpp
  Invoking: GCC C++ Compiler
  g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/FEM.d" -MT"src/FEM.d" -o "src/FEM.o" "../src/FEM.cpp"
  ../src/FEM.cpp: In function ‘int main()’:
  ../src/FEM.cpp:37:22: error: no matching function for call to ‘solve(arma::sp_mat&amp;, arma::vec&amp;)’
    vec zeta = solve(A,b);
                        ^
  ../src/FEM.cpp:37:22: note: candidates are:
  In file included from /usr/include/armadillo:397:0,
                   from ../src/FEM.cpp:10:
  /usr/include/armadillo_bits/fn_solve.hpp:25:1: note: template&lt;class T1, class T2&gt; const arma::Glue&lt;T1, T2, arma::glue_solve&gt; arma::solve(const arma::Base&lt;typename T1::elem_type, T1&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T2&gt;&amp;, bool, const typename arma::arma_blas_type_only&lt;typename T1::elem_type&gt;::result*)
   solve
   ^
  /usr/include/armadillo_bits/fn_solve.hpp:25:1: note:   template argument deduction/substitution failed:
  ../src/FEM.cpp:37:22: note:   ‘arma::sp_mat {aka arma::SpMat&lt;double&gt;}’ is not derived from ‘const arma::Base&lt;typename T1::elem_type, T1&gt;’
    vec zeta = solve(A,b);
                        ^
  In file included from /usr/include/armadillo:397:0,
                   from ../src/FEM.cpp:10:
  /usr/include/armadillo_bits/fn_solve.hpp:44:1: note: template&lt;class T1, class T2&gt; const arma::Glue&lt;T1, T2, arma::glue_solve&gt; arma::solve(const arma::Base&lt;typename T1::elem_type, T1&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T2&gt;&amp;, const char*, const typename arma::arma_blas_type_only&lt;typename T1::elem_type&gt;::result*)
   solve
   ^
  /usr/include/armadillo_bits/fn_solve.hpp:44:1: note:   template argument deduction/substitution failed:
  ../src/FEM.cpp:37:22: note:   ‘arma::sp_mat {aka arma::SpMat&lt;double&gt;}’ is not derived from ‘const arma::Base&lt;typename T1::elem_type, T1&gt;’
    vec zeta = solve(A,b);
                        ^
  In file included from /usr/include/armadillo:397:0,
                   from ../src/FEM.cpp:10:
  /usr/include/armadillo_bits/fn_solve.hpp:67:1: note: template&lt;class T1, class T2&gt; const arma::Glue&lt;T1, T2, arma::glue_solve_tr&gt; arma::solve(const arma::Op&lt;T1, arma::op_trimat&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T2&gt;&amp;, bool, const typename arma::arma_blas_type_only&lt;typename T1::elem_type&gt;::result*)
   solve
   ^
  /usr/include/armadillo_bits/fn_solve.hpp:67:1: note:   template argument deduction/substitution failed:
  ../src/FEM.cpp:37:22: note:   ‘arma::sp_mat {aka arma::SpMat&lt;double&gt;}’ is not derived from ‘const arma::Op&lt;T1, arma::op_trimat&gt;’
    vec zeta = solve(A,b);
                        ^
  In file included from /usr/include/armadillo:397:0,
                   from ../src/FEM.cpp:10:
  /usr/include/armadillo_bits/fn_solve.hpp:87:1: note: template&lt;class T1, class T2&gt; const arma::Glue&lt;T1, T2, arma::glue_solve_tr&gt; arma::solve(const arma::Op&lt;T1, arma::op_trimat&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T2&gt;&amp;, const char*, const typename arma::arma_blas_type_only&lt;typename T1::elem_type&gt;::result*)
   solve
   ^
  /usr/include/armadillo_bits/fn_solve.hpp:87:1: note:   template argument deduction/substitution failed:
  ../src/FEM.cpp:37:22: note:   ‘arma::sp_mat {aka arma::SpMat&lt;double&gt;}’ is not derived from ‘const arma::Op&lt;T1, arma::op_trimat&gt;’
    vec zeta = solve(A,b);
                        ^
  In file included from /usr/include/armadillo:397:0,
                   from ../src/FEM.cpp:10:
  /usr/include/armadillo_bits/fn_solve.hpp:110:1: note: template&lt;class T1, class T2&gt; bool arma::solve(arma::Mat&lt;typename T1::elem_type&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T1&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T2&gt;&amp;, bool, const typename arma::arma_blas_type_only&lt;typename T1::elem_type&gt;::result*)
   solve
   ^
  /usr/include/armadillo_bits/fn_solve.hpp:110:1: note:   template argument deduction/substitution failed:
  ../src/FEM.cpp:37:22: note:   ‘arma::sp_mat {aka arma::SpMat&lt;double&gt;}’ is not derived from ‘arma::Mat&lt;typename T1::elem_type&gt;’
    vec zeta = solve(A,b);
                        ^
  In file included from /usr/include/armadillo:397:0,
                   from ../src/FEM.cpp:10:
  /usr/include/armadillo_bits/fn_solve.hpp:139:1: note: template&lt;class T1, class T2&gt; bool arma::solve(arma::Mat&lt;typename T1::elem_type&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T1&gt;&amp;, const arma::Base&lt;typename T1::elem_type, T2&gt;&amp;, const char*, const typename arma::arma_blas_type_only&lt;typename T1::elem_type&gt;::result*)
   solve
   ^
  /usr/include/armadillo_bits/fn_solve.hpp:139:1: note:   template argument deduction/substitution failed:
  ../src/FEM.cpp:37:22: note:   ‘arma::sp_mat {aka arma::SpMat&lt;double&gt;}’ is not derived from ‘arma::Mat&lt;typename T1::elem_type&gt;’
    vec zeta = solve(A,b);
                        ^
  make: *** [src/FEM.o] Error 1
  </code></pre>