- This topic has 4 replies, 3 voices, and was last updated 4 years, 2 months ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.
Home › Forum › SOFA › Programming with SOFA › [SOLVED] Use Eigen::SparseMatrix in SofaPython3
Tagged: 64_bits, Eigen, Linux_other, Plugin_other, SOFA_2006, SofaPython3
Hi,
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<>
Hi @jjcasmar
Thank you for your question.
@damien-marchaluniv-lille1-fr could you please bring us some light on this point ?
Best
Hugo
Hi 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.
Thanks for the answer. I guess I will wait until that is ready and code that part in C++ for now.
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.
Regards,
WARNING
The forum has been moved to GitHub Discussions.
Old topics and replies are kept here as an archive.