diff --git a/doc/doc/manual/03-domains/01-dom-intervals.rst b/doc/doc/manual/03-domains/01-dom-intervals.rst index 335a8089f..10d9dc541 100644 --- a/doc/doc/manual/03-domains/01-dom-intervals.rst +++ b/doc/doc/manual/03-domains/01-dom-intervals.rst @@ -156,6 +156,15 @@ Intervals, boxes and interval matrices IntervalVector c = cart_prod(a,b); // c: ([0, 1] ; [2, 3] ; [4, 5] ; [6, 7]) + .. note:: + + With Python, one can use NumPy arrays for building degenerated ``IntervalVector`` objects such as: + + .. code:: py + + x = IntervalVector(np.array([1,0,0])) # [1,1]×[0,0]×[0,0] + y = IntervalVector(np.array([[1],[0],[0]])) # [1,1]×[0,0]×[0,0] + .. _sec-manual-intervals-matrices: @@ -163,6 +172,20 @@ Intervals, boxes and interval matrices | One can refer to the `documentation of IBEX `_ for more information. + .. note:: + + With Python, one can use NumPy matrices for building degenerated ``IntervalMatrix`` objects such as: + + .. code:: py + + x = IntervalMatrix(np.eye(3,2)) + + # Produces: + # + # ((<1, 1> ; <0, 0>) + # (<0, 0> ; <1, 1>) + # (<0, 0> ; <0, 0>)) + .. _sec-manual-intervals-empty-set: The empty set @@ -204,7 +227,7 @@ For boxes (interval vectors), we have to specify their dimension even in case of Set operations -------------- -Set operations are available for ``Interval`` and ``IntervalVector`` objects (see the `official reference `_). In the following table, if :math:`[x]` is an interval object, :math:`d` is a real value. +Set operations are available for ``Interval``, ``IntervalVector`` and ``IntervalMatrix`` objects (see the `official reference `_). In the following table, if :math:`[x]` is an interval object, :math:`d` is a real value. ==================================== ======================================================= Code Meaning diff --git a/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp b/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp index daeec1c5f..0552b8747 100644 --- a/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp +++ b/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp @@ -138,5 +138,21 @@ void export_IntervalMatrix(py::module& m) .def("__or__", [](const IntervalMatrix& x, const IntervalMatrix& y) { return x|y; }) .def("__and__", [](const IntervalMatrix& x, const IntervalMatrix& y) { return x&y; }) + + .def("inflate", &IntervalMatrix::inflate, "r"_a) + .def("is_unbounded", &IntervalMatrix::is_unbounded) + .def("is_subset", &IntervalMatrix::is_subset, "x"_a) + .def("is_strict_subset", &IntervalMatrix::is_strict_subset, "x"_a) + .def("is_interior_subset", &IntervalMatrix::is_interior_subset, "x"_a) + .def("is_strict_interior_subset", &IntervalMatrix::is_strict_interior_subset, "x"_a) + .def("is_superset", &IntervalMatrix::is_superset, "x"_a) + .def("is_strict_superset", &IntervalMatrix::is_strict_superset, "x"_a) + .def("contains", &IntervalMatrix::contains, "x"_a) + .def("__contains__", &IntervalMatrix::contains, "x"_a) + .def("interior_contains", &IntervalMatrix::interior_contains, "x"_a) + .def("intersects", &IntervalMatrix::intersects, "x"_a) + .def("overlaps", &IntervalMatrix::overlaps, "x"_a) + .def("is_disjoint", &IntervalMatrix::is_disjoint,"x"_a) + .def("is_zero", &IntervalMatrix::is_zero) ; }; \ No newline at end of file diff --git a/src/core/arithmetic/codac_matrix_arithmetic.cpp b/src/core/arithmetic/codac_matrix_arithmetic.cpp new file mode 100644 index 000000000..779828cde --- /dev/null +++ b/src/core/arithmetic/codac_matrix_arithmetic.cpp @@ -0,0 +1,41 @@ +/** + * Arithmetic operations on matrices + * ---------------------------------------------------------------------------- + * \date 2022 + * \author Simon Rohou + * \copyright Copyright 2022 Codac Team + * \license This program is distributed under the terms of + * the GNU Lesser General Public License (LGPL). + */ + +#include "codac_matrix_arithmetic.h" + +using namespace std; +using namespace ibex; + +namespace codac +{ + const IntervalMatrix operator&(const IntervalMatrix& m1, const IntervalMatrix& m2) + { + assert(m1.nb_cols() == m2.nb_cols() && m1.nb_rows() == m2.nb_rows()); + IntervalMatrix m3(m1); + + for(int i = 0; i < m1.nb_rows(); i++) + for(int j = 0; j < m2.nb_cols(); j++) + m3[i][j] &= m2[i][j]; + + return m3; + } + + const IntervalMatrix operator|(const IntervalMatrix& m1, const IntervalMatrix& m2) + { + assert(m1.nb_cols() == m2.nb_cols() && m1.nb_rows() == m2.nb_rows()); + IntervalMatrix m3(m1); + + for(int i = 0; i < m1.nb_rows(); i++) + for(int j = 0; j < m2.nb_cols(); j++) + m3[i][j] |= m2[i][j]; + + return m3; + } +} \ No newline at end of file diff --git a/src/core/arithmetic/codac_matrix_arithmetic.h b/src/core/arithmetic/codac_matrix_arithmetic.h new file mode 100644 index 000000000..7abe2d5b9 --- /dev/null +++ b/src/core/arithmetic/codac_matrix_arithmetic.h @@ -0,0 +1,34 @@ +/** + * \file + * Arithmetic operations on matrices + * ---------------------------------------------------------------------------- + * \date 2022 + * \author Simon Rohou + * \copyright Copyright 2022 Codac Team + * \license This program is distributed under the terms of + * the GNU Lesser General Public License (LGPL). + */ + +#ifndef __CODAC_MATRIX_ARITHMETIC_H__ +#define __CODAC_MATRIX_ARITHMETIC_H__ + +#include "codac_IntervalMatrix.h" + +namespace codac +{ + /** \brief \f$[\mathbf{X}]\sqcup[\mathbf{Y}]\f$ + * \param x + * \param y + * \return IntervalMatrix output + */ + const IntervalMatrix operator|(const IntervalMatrix& x, const IntervalMatrix& y); + + /** \brief \f$[\mathbf{X}]\cap[\mathbf{Y}]\f$ + * \param x + * \param y + * \return IntervalMatrix output + */ + const IntervalMatrix operator&(const IntervalMatrix& x, const IntervalMatrix& y); +} + +#endif \ No newline at end of file