From a870f0eead586dcc8316844768364a7570cb21a9 Mon Sep 17 00:00:00 2001 From: Simon Rohou Date: Fri, 17 Apr 2026 14:50:38 +0200 Subject: [PATCH 1/2] [py] added ** and ^ operators for Interval and SlicedTube --- python/src/codac2_py_deprecated.h | 20 ++++++++++++++ .../domains/interval/codac2_py_Interval.cpp | 27 +++++++++++++++++++ .../tube/codac2_py_SlicedTube_operations.cpp | 20 ++++++++++++++ .../analytic/codac2_py_AnalyticExprWrapper.h | 18 +++++-------- .../analytic/codac2_py_analytic_variables.cpp | 1 + 5 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 python/src/codac2_py_deprecated.h diff --git a/python/src/codac2_py_deprecated.h b/python/src/codac2_py_deprecated.h new file mode 100644 index 000000000..5d7c946ff --- /dev/null +++ b/python/src/codac2_py_deprecated.h @@ -0,0 +1,20 @@ +/** + * \file + * Codac binding (core) + * ---------------------------------------------------------------------------- + * \date 2026 + * \author Simon Rohou + * \copyright Copyright 2026 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#pragma once + +#include + +inline void deprecated_xor() +{ + std::cout + << "Operator '^' is intentionally disabled in Codac. Use pow(x,y), sqr(x), or '**' instead." + << std::endl; +} \ No newline at end of file diff --git a/python/src/core/domains/interval/codac2_py_Interval.cpp b/python/src/core/domains/interval/codac2_py_Interval.cpp index 09f9c8a0e..145e9ad4c 100644 --- a/python/src/core/domains/interval/codac2_py_Interval.cpp +++ b/python/src/core/domains/interval/codac2_py_Interval.cpp @@ -13,9 +13,12 @@ #include #include #include +#include #include "codac2_py_Interval_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): #include "codac2_py_Interval_impl_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): +#include "codac2_py_Interval_operations_impl_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): #include "codac2_py_matlab.h" +#include "codac2_py_deprecated.h" using namespace std; using namespace codac2; @@ -262,6 +265,30 @@ py::class_ export_Interval(py::module& m) INTERVAL_REF_INTERVAL_OPERATORDIVEQ_CONST_INTERVAL_REF, "x"_a) + .def("__xor__", [](const Interval& x1, int x2) { deprecated_xor(); return codac2::pow(x1,x2); }, + INTERVAL_POW_CONST_INTERVAL_REF_INT, + "n"_a) + + .def("__xor__", [](const Interval& x1, double x2) { deprecated_xor(); return codac2::pow(x1,x2); }, + INTERVAL_POW_CONST_INTERVAL_REF_DOUBLE, + "n"_a) + + .def("__xor__", [](const Interval& x1, const Interval& x2) { deprecated_xor(); return codac2::pow(x1,x2); }, + INTERVAL_POW_CONST_INTERVAL_REF_CONST_INTERVAL_REF, + "n"_a) + + .def("__pow__", (Interval(*)(const Interval&,int)) &codac2::pow, + INTERVAL_POW_CONST_INTERVAL_REF_INT, + "n"_a) + + .def("__pow__", (Interval(*)(const Interval&,double)) &codac2::pow, + INTERVAL_POW_CONST_INTERVAL_REF_DOUBLE, + "n"_a) + + .def("__pow__", (Interval(*)(const Interval&,const Interval&)) &codac2::pow, + INTERVAL_POW_CONST_INTERVAL_REF_CONST_INTERVAL_REF, + "n"_a) + .def_static("empty", &Interval::empty, STATIC_INTERVAL_INTERVAL_EMPTY) diff --git a/python/src/core/domains/tube/codac2_py_SlicedTube_operations.cpp b/python/src/core/domains/tube/codac2_py_SlicedTube_operations.cpp index b760e42da..bb037bd37 100644 --- a/python/src/core/domains/tube/codac2_py_SlicedTube_operations.cpp +++ b/python/src/core/domains/tube/codac2_py_SlicedTube_operations.cpp @@ -15,6 +15,7 @@ #include #include "codac2_py_matlab.h" #include "codac2_py_SlicedTube_operations_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) +#include "codac2_py_deprecated.h" using namespace codac2; namespace py = pybind11; @@ -401,4 +402,23 @@ void export_SlicedTube_operations( py::is_operator()); bind_scalar_slicedtube_functions(m); + + py_SlicedTube_Interval + + .def("__xor__", [](const SlicedTube& x1, int x2) { deprecated_xor(); return codac2::pow(x1,x2); }, + SLICEDTUBE_INTERVAL_POW_CONST_SLICEDTUBE_INTERVAL_REF_INT, + "n"_a) + + .def("__xor__", [](const SlicedTube& x1, const Interval& x2) { deprecated_xor(); return codac2::pow(x1,x2); }, + SLICEDTUBE_INTERVAL_POW_CONST_SLICEDTUBE_INTERVAL_REF_CONST_INTERVAL_REF, + "n"_a) + + .def("__pow__", (SlicedTube (*)(const SlicedTube&,int)) &codac2::pow, + SLICEDTUBE_INTERVAL_POW_CONST_SLICEDTUBE_INTERVAL_REF_INT, + "n"_a) + + .def("__pow__", (SlicedTube (*)(const SlicedTube&,const Interval&)) &codac2::pow, + SLICEDTUBE_INTERVAL_POW_CONST_SLICEDTUBE_INTERVAL_REF_CONST_INTERVAL_REF, + "n"_a) + ; } diff --git a/python/src/core/functions/analytic/codac2_py_AnalyticExprWrapper.h b/python/src/core/functions/analytic/codac2_py_AnalyticExprWrapper.h index c45b07e50..652e398ef 100644 --- a/python/src/core/functions/analytic/codac2_py_AnalyticExprWrapper.h +++ b/python/src/core/functions/analytic/codac2_py_AnalyticExprWrapper.h @@ -16,24 +16,18 @@ #include #include "codac2_AnalyticExprWrapper.h" #include "codac2_py_matlab.h" -#include "codac2_arith_add.h" -#include "codac2_arith_sub.h" -#include "codac2_arith_mul.h" -#include "codac2_arith_div.h" +#include +#include +#include +#include +#include +#include "codac2_py_deprecated.h" #include "codac2_py_AnalyticExprWrapper_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_pow.h" using namespace codac2; namespace py = pybind11; using namespace pybind11::literals; -inline void deprecated_xor() -{ - std::cout - << "Operator '^' is intentionally disabled in Codac. Use pow(x,y), sqr(x), or '**' instead." - << std::endl; -} - inline void export_ScalarExpr(py::module& m) { py::class_ diff --git a/python/src/core/functions/analytic/codac2_py_analytic_variables.cpp b/python/src/core/functions/analytic/codac2_py_analytic_variables.cpp index f497c15c5..ff5ef04ef 100644 --- a/python/src/core/functions/analytic/codac2_py_analytic_variables.cpp +++ b/python/src/core/functions/analytic/codac2_py_analytic_variables.cpp @@ -16,6 +16,7 @@ #include "codac2_py_analytic_variables_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): #include "codac2_py_AnalyticExprWrapper.h" #include "codac2_py_matlab.h" +#include "codac2_py_deprecated.h" using namespace codac2; namespace py = pybind11; From 62f60cecfa836dc5a16b4c30780305dadc8ea7bb Mon Sep 17 00:00:00 2001 From: Simon Rohou Date: Fri, 17 Apr 2026 14:50:54 +0200 Subject: [PATCH 2/2] [matlab] corrected compilation error --- .../interval/codac2_py_IntervalMatrixBase.h | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h b/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h index 84059ee33..a5e4c7a24 100644 --- a/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h +++ b/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h @@ -72,56 +72,49 @@ void export_IntervalMatrixBase(py::module& m, py::class_& pyclass) .def("min_rad", [](const S& x, const std::vector& among_indices) { - return x.min_rad( - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices)); + return x.min_rad(matlab::convert_indices(among_indices)); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_DOUBLE_MIN_RAD_CONST_VECTOR_INDEX_REF_CONST, "among_indices"_a=std::vector()) .def("max_rad", [](const S& x, const std::vector& among_indices) { - return x.max_rad( - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices)); + return x.max_rad(matlab::convert_indices(among_indices)); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_DOUBLE_MAX_RAD_CONST_VECTOR_INDEX_REF_CONST, "among_indices"_a=std::vector()) .def("min_diam", [](const S& x, const std::vector& among_indices) { - return x.min_diam( - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices)); + return x.min_diam(matlab::convert_indices(among_indices)); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_DOUBLE_MIN_DIAM_CONST_VECTOR_INDEX_REF_CONST, "among_indices"_a=std::vector()) .def("max_diam", [](const S& x, const std::vector& among_indices) { - return x.max_diam( - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices)); + return x.max_diam(matlab::convert_indices(among_indices)); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_DOUBLE_MAX_DIAM_CONST_VECTOR_INDEX_REF_CONST, "among_indices"_a=std::vector()) .def("min_diam_index", [](const S& x, const std::vector& among_indices) { - return matlab::output_index(x.min_diam_index( - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices))); + return matlab::output_index(x.min_diam_index(matlab::convert_indices(among_indices))); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_INDEX_MIN_DIAM_INDEX_CONST_VECTOR_INDEX_REF_CONST, "among_indices"_a=std::vector()) .def("max_diam_index", [](const S& x, const std::vector& among_indices) { - return matlab::output_index(x.max_diam_index( - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices))); + return matlab::output_index(x.max_diam_index(matlab::convert_indices(among_indices))); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_INDEX_MAX_DIAM_INDEX_CONST_VECTOR_INDEX_REF_CONST, "among_indices"_a=std::vector()) .def("extr_diam_index", [](const S& x, bool min, const std::vector& among_indices) { - return matlab::output_index(x.extr_diam_index(min, - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices))); + return matlab::output_index(x.extr_diam_index(min,matlab::convert_indices(among_indices))); }, MATRIXBASE_ADDONS_INTERVALMATRIXBASE_INDEX_EXTR_DIAM_INDEX_BOOL_CONST_VECTOR_INDEX_REF_CONST, "min"_a, "among_indices"_a=std::vector()) @@ -196,8 +189,7 @@ void export_IntervalMatrixBase(py::module& m, py::class_& pyclass) .def("bisect_largest", [](const S& x, double ratio, const std::vector& among_indices) { - return x.bisect_largest(ratio, - among_indices.empty() ? among_indices : matlab::convert_indices(among_indices)); + return x.bisect_largest(ratio,matlab::convert_indices(among_indices)); }, MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_BISECT_LARGEST_DOUBLE_CONST_VECTOR_INDEX_REF_CONST, "ratio"_a = 0.49, "among_indices"_a=std::vector())