Home › Forum › SOFA › Programming with SOFA › [SOLVED] Use Eigen::SparseMatrix in SofaPython3
Tagged: 64_bits, Eigen, Linux_other, Plugin_other, SOFA_2006, SofaPython3
- This topic has 4 replies, 3 voices, and was last updated 5 years ago by
Damien Marchal.
-
AuthorPosts
-
14 September 2020 at 16:10 #17129
jjcasmar
BlockedHi,
I want to use Eigen::SparseMatrix in SofaPython3 and provide it as a scipy csr sparse matrix but SOFA fails to convert it with the following error:
[ERROR] [SofaPython3::SceneLoader] RuntimeError: Trying to set the value of the data C, but the later hasn't register it's DataTypeInfo (see sofa/defaulttype/DataTypeInfo.h for more details)
I have looked into the file, but its a pretty long file and difficult to get what I should do to support a new Data type.
afaik pybind11, which is used for SofaPython3 already provides suport for converting to/from scipy.sparse.csc/csr_matrix to Eigen::SparseMatrix<>
17 September 2020 at 16:30 #17171Hugo
KeymasterHi @jjcasmar
Thank you for your question.
@damien-marchaluniv-lille1-fr could you please bring us some light on this point ?Best
Hugo
17 September 2020 at 16:57 #17172Damien Marchal
BlockedHi all,
There is no support for sparse matrices in the binding yet (lack of time more than technical difficulty). As you pointed out, pybind11 has the proper machinery for that.
The problem is that, to detect the BaseData you want to store in is really holding a Data<Eigen::Sparse> we rely on the AbstractTypeInfo mechanism… which requires to declare an AbstractTypeInfo describing a Data<Eigen::Sparse>. With this done, in
void PythonFactory::fromPython(BaseData* d, const py::object& o) in PythonFactory.cpp it will be possible to detect when a data is Eigen::Sparse and call the proper pybind11 conversion from scipy.The dual function toPython should also be implemented to expose in a copyless way matrices to python.
18 September 2020 at 01:28 #17176jjcasmar
BlockedThanks for the answer. I guess I will wait until that is ready and code that part in C++ for now.
1 October 2020 at 22:12 #17248Damien Marchal
BlockedSmall news about that topic…
Yinoussa (from Defrost) made this week a preliminary pull request to Sofa. The aim of this PR is to able to manipulate Eigen matrices in sofa Data field.
It is there: https://github.com/sofa-framework/sofa/pull/1499A second work should coom soon to expose Eigen matrices in Python. One difficulty we have with Eigen matrices is that we havnt found out yet how to write in the Eigen matrices from python without copying everything, but readonly matrices is working now.
Regards,
-
AuthorPosts
- You must be logged in to reply to this topic.