14 September 2020 at 16 h 10 min #17129jjcasmarParticipant
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 h 30 min #17171HugoKeymaster
17 September 2020 at 16 h 57 min #17172Damien MarchalParticipant
- SOFA Consortium
- CNRS/Defrost Team
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 1 h 28 min #17176jjcasmarParticipant
Thanks 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 h 12 min #17248Damien MarchalParticipant
- CNRS/Defrost Team
Small 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/1499
A 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.
- You must be logged in to reply to this topic.