Skip to content

Commit f71856f

Browse files
authored
Add binding for modifying and adding entries to sparse matrices (#605)
1 parent 0a4696e commit f71856f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bindings/Sofa/src/SofaPython3/Sofa/Types/Binding_CompressedRowSparseMatrix.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ void bindCompressedRowSparseMatrixConstraint(pybind11::module& m)
5353

5454
crsmc.def_property_readonly("value", [](sofa::Data<MatrixDeriv>& self)
5555
{
56-
sofa::helper::ReadAccessor accessor(self);
56+
sofa::helper::WriteAccessor accessor(self);
57+
accessor.wref().compress();
5758
return toEigen(accessor.ref());
5859
});
5960

61+
crsmc.def("add", [](sofa::Data<MatrixDeriv>& self, sofa::Index row, sofa::Index col, const MatrixDeriv::Block value)
62+
{
63+
sofa::helper::WriteAccessor accessor(self);
64+
auto line = accessor->writeLine(row);
65+
line.addCol(col, value);
66+
});
67+
6068
PythonFactory::registerType(MatrixDeriv::Name(), [](sofa::core::BaseData* data) -> py::object {
6169
auto matrix = reinterpret_cast<sofa::Data<MatrixDeriv>*>(data);
6270
return py::cast(matrix);

0 commit comments

Comments
 (0)