Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python bindinds
Browse files Browse the repository at this point in the history
damien-masse committed Dec 20, 2024
1 parent e7d43bd commit 1ead3e5
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
matrices/codac2_py_arithmetic_mul.cpp
matrices/codac2_py_arithmetic_div.cpp
matrices/codac2_py_inversion.cpp
matrices/codac2_py_IntFullPivLU.cpp
matrices/codac2_py_Matrix.cpp
matrices/codac2_py_MatrixBase.h
matrices/codac2_py_MatrixBlock.h
2 changes: 2 additions & 0 deletions python/src/core/codac2_py_core.cpp
Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@ py::class_<Row> export_Row(py::module& m);
py::class_<Vector> export_Vector(py::module& m);
py::class_<Matrix> export_Matrix(py::module& m);
void export_Inversion(py::module& m);
void export_IntFullPivLU(py::module& m);

// paver
void export_pave(py::module& m);
@@ -163,6 +164,7 @@ PYBIND11_MODULE(_core, m)
export_EigenBlock<Row>(m, "RowBlock");
export_EigenBlock<Vector>(m, "VectorBlock");
export_Inversion(m);
export_IntFullPivLU(m);

// domains
export_BoolInterval(m);
57 changes: 57 additions & 0 deletions tests/core/matrices/codac2_tests_IntFullPivLU.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python

# Codac tests
# ----------------------------------------------------------------------------
# \date 2024
# \author Damien Massé
# \copyright Copyright 2024 Codac Team
# \license GNU Lesser General Public License (LGPL)


import unittest
from codac import *

class TestIntFullPivLU(unittest.TestCase):


# bindings not implemented
def tests_IntFullPivLU_1(self):
M = Matrix([
[ 1, -4, 3, 7 ],
[ 2, 1, -4, 6 ],
[ 5, 2, 1 , 9 ],
[ -1, 0, 3, 2 ]
])

LUdec = IntFullPivLU(M)
self.assertTrue(LUdec.isInjective()==BoolInterval.TRUE)
self.assertTrue(LUdec.isSurjective()==BoolInterval.TRUE)
self.assertTrue(LUdec.rank()==Interval(4))
self.assertTrue((LUdec.determinant()+602).mag()<=1e-10)
self.assertTrue((LUdec.ReconstructedMatrix()-M).norm().ub()<=1e-10)
I1 = LUdec.solve(IntervalMatrix.eye(4,4));
self.assertTrue((I1*M-Matrix.eye(4,4)).norm().ub()<1e-10)

def tests_IntFullPivLU_2(self):
M = Matrix([
[ 1, -4, 6, 7 ],
[ 2, 1, 3, 6 ],
[ 5, 2, 8 , 9 ],
[ -1, 0, -2, 2 ]
])

LUdec = IntFullPivLU(M)
self.assertTrue(LUdec.isInjective()==BoolInterval.UNKNOWN)
self.assertTrue(LUdec.isSurjective()==BoolInterval.UNKNOWN)
self.assertTrue(LUdec.rank()==Interval([3,4]))
self.assertTrue((LUdec.determinant()).mag()<=1e-10)
self.assertTrue((LUdec.ReconstructedMatrix()-M).norm().ub()<=1e-10)
K = LUdec.kernel()
self.assertTrue(K.cols()==1)
self.assertTrue((M*K).norm().ub()<1e-10)
Im = LUdec.image(M)
self.assertTrue(Im.cols()==3)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1ead3e5

Please sign in to comment.