title: error: no matching function for call to ‘pybind11::buffer_info::buffer_info
body: <p>I'm trying to wrap a c++ function that uses Armadillo library using <code>pybind11</code> and <code>cppimport</code>. But when I try to do something simple like matrix multiplication I get the following error.</p>
  
  <pre><code>error: no matching function for call to ‘pybind11::buffer_info::buffer_info(double*, long unsigned int, std::__cxx11::string, int, &lt;brace-enclosed initializer list&gt;, &lt;brace-enclosed initializer list&gt;)’
        );
        ^
      In file included from /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/pytypes.h:13:0,
                       from /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/cast.h:13,
                       from /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/attr.h:13,
                       from /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/pybind11.h:43,
                       from /home/muah/Music/cpp2py/.rendered.code.cpp:3:
      /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/buffer_info.h:83:5: note: candidate: pybind11::buffer_info::buffer_info(pybind11::buffer_info::private_ctr_tag, void*, pybind11::ssize_t, const string&amp;, pybind11::ssize_t, pybind11::detail::any_container&lt;long int&gt;&amp;&amp;, pybind11::detail::any_container&lt;long int&gt;&amp;&amp;)
           buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &amp;format, ssize_t ndim,
           ^~~~~~~~~~~
      /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/buffer_info.h:83:5: note:   candidate expects 7 arguments, 6 provided
      /home/muah/anaconda3/envs/ising/include/python3.6m/pybind11/buffer_info.h:59:5: note: candidate: pybind11::buffer_info::buffer_info(pybind11::buffer_info&amp;&amp;)
           buffer_info(buffer_info &amp;&amp;other) {
  </code></pre>
  
  <p>This is the code for conversions between armadillo mat to numpy vice versa. </p>
  
  <pre><code>#pragma once
  #include &lt;armadillo&gt;
  #include &lt;pybind11/pybind11.h&gt;
  #include &lt;pybind11/numpy.h&gt;
  
  namespace py=pybind11;
  
  typedef py::array_t&lt;double, py::array::f_style | py::array::forcecast&gt; pyarr_d;
  
  inline
  arma::mat py_to_mat(pyarr_d&amp; pmat)
  {
      py::buffer_info info = pmat.request();
      arma::mat amat;
      if(info.ndim == 1) {
          amat = arma::mat(reinterpret_cast&lt;double*&gt;(info.ptr),info.shape[0],1);
      } else {
          amat = arma::mat(reinterpret_cast&lt;double*&gt;(info.ptr),info.shape[0],info.shape[1]);
      }
      return amat;
  }
  
  
  inline
  py::array_t&lt;double&gt; mat_to_py(arma::mat &amp;mat)
  {
      py::buffer_info buffer(
          mat.memptr(),
          sizeof(double),
          py::format_descriptor&lt;double&gt;::format(),
          2,
          { mat.n_rows, mat.n_cols },
          { sizeof(double), sizeof(double) * mat.n_rows }
      );
      return py::array_t&lt;double&gt;(buffer);
  }
  </code></pre>
  
  <p>This is the c++ function:</p>
  
  <pre><code>&lt;%
  cfg['compiler_args'] = ['-std=c++11', '-larmadillo']
  setup_pybind11(cfg)
  %&gt;
  
  #include &lt;pybind11/pybind11.h&gt;
  #include &lt;pybind11/numpy.h&gt;
  #include &lt;armadillo&gt;
  #include "py2arma.hpp"  
  
  namespace py = pybind11;
  
  
  py::array matrix_mul(pyarr_d a, pyarr_d b) 
  {
      arma::mat A = py_to_mat(a);
      arma::mat B = py_to_mat(b);
      arma::mat C = A * B;
      return mat_to_py(C);
  }
  
  
  PYBIND11_PLUGIN(code) 
  {
      py::module m("code", "lala");
      m.def("matrix_mul",(py::array(*)(pyarr_d,pyarr_d))&amp;matrix_mul);
      return m.ptr();
  }
  </code></pre>
  
  <p>This is the python function:</p>
  
  <pre><code>import cppimport
  import numpy as np
  
  code = cppimport.imp("code")
  
  if __name__ == '__main__':
      xs = np.random.rand(3,3)
      ys = np.random.rand(3,1)
  
      py_mul = np.dot(xs, ys)
      cpp_mul = code.matrix_mul(xs, ys)
      print(py_mul)
      print(cpp_mul)
  </code></pre>
  
  <p>This link contains the full stack-trace: <a href="https://pastebin.com/XuKyQDMQ" rel="nofollow noreferrer">https://pastebin.com/XuKyQDMQ</a></p>
  
  <p>I don't understand what this error means. How to fix this, am I doing the conversions correctly ? </p>
  
  <p>EDIT: To fix the problems, add py::detail::any_container before matrix shape and strides part of buffer_info. And change the type of <code>mat_to_py</code> function from <code>py::array</code> to <code>pyarr_d</code>.</p>
  
  <p>This fixes all the issues with the code. </p>