{"action":"created","issue":{"url":"https://api.github.com/repos/libigl/libigl/issues/662","repository_url":"https://api.github.com/repos/libigl/libigl","labels_url":"https://api.github.com/repos/libigl/libigl/issues/662/labels{/name}","comments_url":"https://api.github.com/repos/libigl/libigl/issues/662/comments","events_url":"https://api.github.com/repos/libigl/libigl/issues/662/events","html_url":"https://github.com/libigl/libigl/issues/662","id":282515032,"number":662,"title":"Unable to create eigen MatrixXi from python list or numpy matrix in pyigl","user":{"login":"pilcru","id":2668286,"avatar_url":"https://avatars2.githubusercontent.com/u/2668286?v=4","gravatar_id":"","url":"https://api.github.com/users/pilcru","html_url":"https://github.com/pilcru","followers_url":"https://api.github.com/users/pilcru/followers","following_url":"https://api.github.com/users/pilcru/following{/other_user}","gists_url":"https://api.github.com/users/pilcru/gists{/gist_id}","starred_url":"https://api.github.com/users/pilcru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pilcru/subscriptions","organizations_url":"https://api.github.com/users/pilcru/orgs","repos_url":"https://api.github.com/users/pilcru/repos","events_url":"https://api.github.com/users/pilcru/events{/privacy}","received_events_url":"https://api.github.com/users/pilcru/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-12-15T18:48:50Z","updated_at":"2018-02-27T15:18:59Z","closed_at":null,"author_association":"NONE","body":"I have been having issues with using the python bindings to instantiate matrices of integers (pyigl.eigen.MatrixXi) from python lists or numpy matrices. For example, trying to run tutorial 405_AsRigidAsPossible.py gives:\r\n\r\n```\r\npython 405_AsRigidAsPossible.py \r\nTraceback (most recent call last):\r\n  File \"405_AsRigidAsPossible.py\", line 80, in <module>\r\n    b = igl.eigen.MatrixXi([[t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0]]).transpose()\r\nTypeError: __init__(): incompatible constructor arguments. The following argument types are supported:\r\n    1. pyigl.eigen.MatrixXi()\r\n    2. pyigl.eigen.MatrixXi(arg0: int, arg1: int)\r\n    3. pyigl.eigen.MatrixXi(arg0: int)\r\n    4. pyigl.eigen.MatrixXi(arg0: buffer)\r\n    5. pyigl.eigen.MatrixXi(arg0: std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)\r\n    6. pyigl.eigen.MatrixXi(arg0: std::vector<int, std::allocator<int> >)\r\n\r\nInvoked with: [[8, 17, 23, 26, 29, 40, 55, 56, 57, 61, 73, 79, 82, 90, 102, 104, 105, 108, 111, 112, 116, 124, 126, 128, 130, 148, 155, 174, 175, 176, 177, 179, 180, 181, 190, 192, 197, 198, 199, 209, 218, 224, 245, 247, 260, 262, 264, 272, 276, 277, 303, 319, 334, 339, 342, 354, 355, 369, 372, 374, 390, 391, 394, 407, 417, 421, 435, 467, 473, 474, 475, 478, 500]]\r\n```\r\n\r\nInstantiating with a numpy array of int also fails, with the message `Incompatible buffer format!`. I can still create an empty MatrixXi of a given size, and then assign to its elements.\r\n\r\nI've reproduced this on Windows (compiling with Visual Studio 2015 update 3, against python 3.5.4 and 2.7.12) and Linux (gcc 5.4.1, python 3.5.4), staying as close as I could to the [CMakeLists](../tree/master/python/CMakeLists.txt). This is all on a fresh checkout of master.\r\n\r\nI thought I was not compiling properly (first time using libigl) but it does not seem to be the issue. Is this maybe more of a pybind11+eigen issue that I should file there, or is the issue coming directly from the bindings defined in [py_vector.cpp](../tree/master/python/modules/py_vector.cpp)? Am I just doing something wrong?"},"comment":{"url":"https://api.github.com/repos/libigl/libigl/issues/comments/368912930","html_url":"https://github.com/libigl/libigl/issues/662#issuecomment-368912930","issue_url":"https://api.github.com/repos/libigl/libigl/issues/662","id":368912930,"user":{"login":"pilcru","id":2668286,"avatar_url":"https://avatars2.githubusercontent.com/u/2668286?v=4","gravatar_id":"","url":"https://api.github.com/users/pilcru","html_url":"https://github.com/pilcru","followers_url":"https://api.github.com/users/pilcru/followers","following_url":"https://api.github.com/users/pilcru/following{/other_user}","gists_url":"https://api.github.com/users/pilcru/gists{/gist_id}","starred_url":"https://api.github.com/users/pilcru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pilcru/subscriptions","organizations_url":"https://api.github.com/users/pilcru/orgs","repos_url":"https://api.github.com/users/pilcru/repos","events_url":"https://api.github.com/users/pilcru/events{/privacy}","received_events_url":"https://api.github.com/users/pilcru/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T15:18:59Z","updated_at":"2018-02-27T15:18:59Z","author_association":"NONE","body":"Hi, thanks for looking at this.\r\n\r\nActually, the only `dtype` that has worked for me on windows is the \"compatible C int\", `intc`, or `i` for short. `int32` is the default (so it is already using that when converting from a list), and it gets taken to a \"compatible Python int\" through the C interface, `int_` or `l`. I'm using [this page](https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.scalars.html#arrays-scalars-built-in) of the numpy docs for reference.\r\n\r\n`i` and `l` have the same length on most (all?) platforms, so they should be compatible, but [this line](https://github.com/libigl/libigl/blob/a630c8e27330c75767e40e821173878049b36458/python/modules/py_vector.cpp#L35) tests for format name rather than format size, so it fails.\r\n\r\nIt looks like pybind11 now recommends using their own [eigen bindings](http://pybind11.readthedocs.io/en/stable/advanced/cast/eigen.html) rather than [this](http://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html) which is what libigl's `py_vector.cpp` seems to be based on. Maybe that's something to check out? Or you've already found that it doesn't match your requirements? From the pybind11 doc:\r\n\r\n> For a much easier approach of binding Eigen types (although with some limitations), refer to the section on Eigen."}}
{"actor":{"display_login":"pilcru"}}