diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.cpp index 62b337fd4..71777420c 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.cpp @@ -53,10 +53,18 @@ void bindCompressedRowSparseMatrixConstraint(pybind11::module& m) crsmc.def_property_readonly("value", [](sofa::Data& self) { - sofa::helper::ReadAccessor accessor(self); + sofa::helper::WriteAccessor accessor(self); + accessor.wref().compress(); return toEigen(accessor.ref()); }); + crsmc.def("add", [](sofa::Data& self, sofa::Index row, sofa::Index col, const MatrixDeriv::Block value) + { + sofa::helper::WriteAccessor accessor(self); + auto line = accessor->writeLine(row); + line.addCol(col, value); + }); + PythonFactory::registerType(MatrixDeriv::Name(), [](sofa::core::BaseData* data) -> py::object { auto matrix = reinterpret_cast*>(data); return py::cast(matrix);