diff --git a/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp b/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp index 15ea21109..daeec1c5f 100644 --- a/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp +++ b/python/src/core/domains/interval/codac_py_IntervalMatrix.cpp @@ -22,6 +22,7 @@ #include "ibex_Matrix.h" #include "codac_Interval.h" #include "codac_IntervalMatrix.h" +#include "codac_matrix_arithmetic.h" // Generated file from Doxygen XML (doxygen2docstring.py): // todo: #include "codac_py_IntervalMatrix_docs.h" @@ -85,12 +86,12 @@ void export_IntervalMatrix(py::module& m) // Some sanity checks... if(info.format != py::format_descriptor::format()) - throw std::runtime_error("Incompatible format: expected a double array"); + throw std::runtime_error("Incompatible format: expected a double array"); if(info.ndim != 2) - throw std::runtime_error("Incompatible buffer dimension"); + throw std::runtime_error("Incompatible buffer dimension"); - ibex::Matrix m((int)info.shape[0], (int)info.shape[1], static_cast(info.ptr)); + ibex::Matrix m((int)info.shape[0], (int)info.shape[1], static_cast(info.ptr)); return IntervalMatrix(m); })) @@ -134,5 +135,8 @@ void export_IntervalMatrix(py::module& m) .def( "__mul__", [](IntervalMatrix& m, const Interval& x) { return x*m; }) .def("shape", [] (IntervalMatrix& o) { return make_tuple(o.nb_rows(), o.nb_cols()); }) .def("__repr__", [](const IntervalMatrix& x) { ostringstream str; str << x; return str.str(); }) + + .def("__or__", [](const IntervalMatrix& x, const IntervalMatrix& y) { return x|y; }) + .def("__and__", [](const IntervalMatrix& x, const IntervalMatrix& y) { return x&y; }) ; }; \ No newline at end of file diff --git a/python/src/core/domains/interval/codac_py_IntervalVector.cpp b/python/src/core/domains/interval/codac_py_IntervalVector.cpp index 28d039d35..01b6ca28e 100644 --- a/python/src/core/domains/interval/codac_py_IntervalVector.cpp +++ b/python/src/core/domains/interval/codac_py_IntervalVector.cpp @@ -149,6 +149,28 @@ void export_IntervalVector(py::module& m) .def(py::init(&create_from_vector_of_intervals), "list"_a) //.def("__init__", &create_from_tuple, "list"_a) + .def(py::init([](py::array_t b) // create for instance an IntervalVector from a NumPy array + { + // Request a buffer descriptor from Python + py::buffer_info info = b.request(); + + // Some sanity checks... + if(info.format != py::format_descriptor::format()) + throw std::runtime_error("Incompatible format: expected a double array"); + + if(info.ndim == 1 || // e.g.: a=np.array([1,0,0]) + (info.ndim == 2 && (int)info.shape[1] == 1)) // e.g.: a=np.array([[1],[0],[0]]) + { + ibex::Vector m((int)info.shape[0], static_cast(info.ptr)); + return IntervalVector(m); + } + + else + throw std::runtime_error("Incompatible buffer dimension"); + + return IntervalVector(0); + })) + // Python vector methods .def("__len__", &IntervalVector::size) @@ -310,8 +332,8 @@ void export_IntervalVector(py::module& m) // bwd_mul overloading //bool (*bwd_mul_1) (const IntervalVector&, Interval&, IntervalVector&) = &ibex::bwd_mul; //bool (*bwd_mul_2) (const Interval&, IntervalVector&, IntervalVector&) = &ibex::bwd_mul; - m.def( "bwd_mul", (bool (*) (const IntervalVector&, Interval&, IntervalVector&)) &ibex::bwd_mul); - m.def( "bwd_mul", (bool (*) (const Interval&, IntervalVector&, IntervalVector&)) &ibex::bwd_mul); + m.def("bwd_mul", (bool (*) (const IntervalVector&, Interval&, IntervalVector&)) &ibex::bwd_mul); + m.def("bwd_mul", (bool (*) (const Interval&, IntervalVector&, IntervalVector&)) &ibex::bwd_mul); m.def("max", (IntervalVector(*) (const IntervalVector&, const IntervalVector&)) &max_IntevalVector); }; \ No newline at end of file diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a7729c813..8ddaba0b0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -18,6 +18,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/arithmetic/codac_traj_arithmetic.h ${CMAKE_CURRENT_SOURCE_DIR}/arithmetic/codac_traj_arithmetic_scalar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/arithmetic/codac_traj_arithmetic_vector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/arithmetic/codac_matrix_arithmetic.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/arithmetic/codac_matrix_arithmetic.h ${CMAKE_CURRENT_SOURCE_DIR}/graphics/codac_Figure.h ${CMAKE_CURRENT_SOURCE_DIR}/graphics/codac_Figure.cpp ${CMAKE_CURRENT_SOURCE_DIR}/graphics/vibes/vibes.h diff --git a/src/core/arithmetic/codac_tube_arithmetic.h b/src/core/arithmetic/codac_tube_arithmetic.h index 221e9697f..f80abd863 100644 --- a/src/core/arithmetic/codac_tube_arithmetic.h +++ b/src/core/arithmetic/codac_tube_arithmetic.h @@ -7,10 +7,7 @@ * \copyright Copyright 2021 Codac Team * \license This program is distributed under the terms of * the GNU Lesser General Public License (LGPL). - - * \param x - * \return Tube output - */ + */ #ifndef __CODAC_TUBE_ARITHMETIC_H__ #define __CODAC_TUBE_ARITHMETIC_H__