Skip to content

Commit

Permalink
[py] binding of IntervalMatrix + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Jun 6, 2022
1 parent c0e13ef commit 044ba87
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
25 changes: 24 additions & 1 deletion doc/doc/manual/03-domains/01-dom-intervals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,36 @@ 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:

* | ``IntervalMatrix`` is also available.
| One can refer to the `documentation of IBEX <http://www.ibex-lib.org/doc/interval.html#matrices-and-array-of-matrices>`_ 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
Expand Down Expand Up @@ -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 <http://www.ibex-lib.org/doc/interval.html#set-membership-operations>`_). 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 <http://www.ibex-lib.org/doc/interval.html#set-membership-operations>`_). In the following table, if :math:`[x]` is an interval object, :math:`d` is a real value.

==================================== =======================================================
Code Meaning
Expand Down
16 changes: 16 additions & 0 deletions python/src/core/domains/interval/codac_py_IntervalMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
};
41 changes: 41 additions & 0 deletions src/core/arithmetic/codac_matrix_arithmetic.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
34 changes: 34 additions & 0 deletions src/core/arithmetic/codac_matrix_arithmetic.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 044ba87

Please sign in to comment.