From 2b30bf74694efd4dfd5a1bf06201ef3a72a8e347 Mon Sep 17 00:00:00 2001 From: Simon Rohou Date: Mon, 20 Jan 2025 18:29:44 +0100 Subject: [PATCH 1/3] [doc] updated manual (info dev) --- doc/manual/development/info_dev.rst | 27 +++++++++++++++++++++----- doc/manual/manual/installation/cpp.rst | 4 ++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/doc/manual/development/info_dev.rst b/doc/manual/development/info_dev.rst index 7fd6e3de..2a3c3267 100644 --- a/doc/manual/development/info_dev.rst +++ b/doc/manual/development/info_dev.rst @@ -35,7 +35,12 @@ If you simply want to use the latest Codac release in Python, you can download t 1. **Ensure the following prerequisites are met**: - - the prerequisites for the :ref:`C++ installation of Codac `. + - the prerequisites for the :ref:`C++ installation of Codac `. On Linux systems, you can simply: + + .. code-block:: bash + + sudo apt-get install -y g++ gcc cmake git flex bison + - a supported version of Python (>=3.6). - a recent `Doxygen `_ version (for instance, release 1.13.0 or newest). On Linux systems, latest releases are not available as Debian packages, so we advice to install Doxygen from the sources: @@ -60,13 +65,14 @@ If you simply want to use the latest Codac release in Python, you can download t .. code-block:: bash - git clone -b master https://github.com/lebarsfa/ibex-lib.git $HOME/ibex-lib + git clone https://github.com/lebarsfa/ibex-lib.git $HOME/ibex-lib + cd $HOME/ibex-lib You will need to compile both IBEX and Codac using the ``-fPIC`` options. This can be done with the following CMake configuration: .. code-block:: bash - cd $HOME/ibex-lib/build + mkdir build ; cd build cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_INSTALL_PREFIX=$HOME/ibex-lib/build_install -DCMAKE_BUILD_TYPE=Release .. make ; make install @@ -77,16 +83,27 @@ If you simply want to use the latest Codac release in Python, you can download t .. code-block:: bash git clone https://github.com/codac-team/codac $HOME/codac + cd $HOME/codac + + .. admonition:: Using Codac v2 simultaneously with Codac v1 + + In case you want to use the two versions of Codac in the same Python script, you will have to compile the binaries of Codac v2 under a different name in order to avoid ``import`` conflicts. Things are already prepared in the branch ``codac2_renamed``, you can therefore: + + .. code-block:: bash + + git checkout codac2_renamed + + Note that you will then have to ``import codac2`` instead of ``import codac`` in your Python scripts. In addition to the ``-fPIC`` options, you will have to configure ``WITH_PYTHON=ON``. Note that the ``git submodule`` commands will automatically get the `pybind11 `_ files required for the binding. .. code-block:: bash - cd $HOME/codac/build # Get automatically pybind11 and eigen submodules: git submodule init ; git submodule update # Configure CMake - cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_C_FLAGS="-fPIC" -DWITH_PYTHON=ON -DCMAKE_INSTALL_PREFIX=$HOME/codac/build_install -DCMAKE_PREFIX_PATH=$HOME/ibex-lib/build_install -DCMAKE_BUILD_TYPE=Release .. + mkdir build ; cd build + cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_C_FLAGS="-fPIC" -DWITH_PYTHON=ON -DCMAKE_INSTALL_PREFIX=$HOME/codac/build_install -DCMAKE_PREFIX_PATH="$HOME/ibex-lib/build_install;$HOME/doxygen/build_install" -DCMAKE_BUILD_TYPE=Release .. make ; make install 4. **Configure your Python environment**: diff --git a/doc/manual/manual/installation/cpp.rst b/doc/manual/manual/installation/cpp.rst index 374b445a..bfac3a8a 100644 --- a/doc/manual/manual/installation/cpp.rst +++ b/doc/manual/manual/installation/cpp.rst @@ -263,8 +263,8 @@ Troubleshooting ---------------- If you encounter issues during the installation process, consider the following: -- Ensure all prerequisites are installed and up to date. -- Check `the GitHub issues `_ page for known problems. +- ensure all prerequisites are installed and up to date. +- check `the GitHub issues `_ page for known problems. If you need further assistance, reach out to the library maintainers via the GitHub repository's issue tracker or email support at `simon.rohou [at] ensta.fr`. From 26beffe05dacf8e06f246924d9c6196d4c39906a Mon Sep 17 00:00:00 2001 From: Simon Rohou Date: Mon, 20 Jan 2025 19:17:30 +0100 Subject: [PATCH 2/3] [traj] updated eval methods --- examples/00_graphics/graphic_examples.py | 2 +- examples/04_explored_area/main.cpp | 2 +- examples/04_explored_area/main.py | 2 +- .../trajectory/codac2_py_AnalyticTraj.cpp | 14 ++++++ .../core/trajectory/codac2_py_SampledTraj.cpp | 38 ++++++++++++---- .../src/core/trajectory/codac2_py_TrajBase.h | 14 ------ .../domains/ellipsoid/codac2_Ellipsoid.cpp | 8 ++-- src/core/trajectory/codac2_SampledTraj.h | 45 +++++++++++++++++-- src/core/trajectory/codac2_TrajBase.h | 10 ++--- 9 files changed, 96 insertions(+), 39 deletions(-) diff --git a/examples/00_graphics/graphic_examples.py b/examples/00_graphics/graphic_examples.py index f6c8770e..f753ba5c 100644 --- a/examples/00_graphics/graphic_examples.py +++ b/examples/00_graphics/graphic_examples.py @@ -84,5 +84,5 @@ t=ScalarVar() # Fermat's spiral f1=AnalyticFunction([t], [a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)]) -traj3=AnalyticTrajectory(f1, [0,100]) +traj3=AnalyticTraj(f1, [0,100]) fig3.draw_trajectory(traj3, ColorMap.rainbow()) \ No newline at end of file diff --git a/examples/04_explored_area/main.cpp b/examples/04_explored_area/main.cpp index fb474e3f..739dd90a 100644 --- a/examples/04_explored_area/main.cpp +++ b/examples/04_explored_area/main.cpp @@ -19,7 +19,7 @@ int main() Interval tdomain(0,5); auto sampled_f = AnalyticTraj(f,tdomain).sampled(0.8); - sampled_f[6] = {0,-1}; // appending the position (0,-1) at t=6 + sampled_f.set(6., {0,-1}); // appending the position (0,-1) at t=6 VectorVar w(3); auto g = sampled_f.as_function(); diff --git a/examples/04_explored_area/main.py b/examples/04_explored_area/main.py index 7f0c1366..e0291553 100644 --- a/examples/04_explored_area/main.py +++ b/examples/04_explored_area/main.py @@ -15,7 +15,7 @@ tdomain = [0,5] sampled_f = AnalyticTraj(f,tdomain).sampled(0.8) -sampled_f[6] = [0,-1] # appending the position (0,-1) at t=6 +sampled_f.set(6, [0,-1]) # appending the position (0,-1) at t=6 w = VectorVar(3) g = sampled_f.as_function() diff --git a/python/src/core/trajectory/codac2_py_AnalyticTraj.cpp b/python/src/core/trajectory/codac2_py_AnalyticTraj.cpp index e3f0aa2b..9beb9cb6 100644 --- a/python/src/core/trajectory/codac2_py_AnalyticTraj.cpp +++ b/python/src/core/trajectory/codac2_py_AnalyticTraj.cpp @@ -36,6 +36,20 @@ void _export_AnalyticTraj(py::module& m, const string& class_name) ANALYTICTRAJ_OS_ANALYTICTRAJ_CONST_ANALYTICFUNCTION_O_REF_CONST_INTERVAL_REF, "f"_a, "tdomain"_a) + .def("__call__", [](const AnalyticTraj& x, double t) + { + return x(t); + }, + VIRTUAL_S_ANALYTICTRAJ_OS_OPERATORCALL_DOUBLE_CONST, + "t"_a) + + .def("__call__", [](const AnalyticTraj& x, const Interval& t) + { + return x(t); + }, + VIRTUAL_WRAPPER_S_DOMAIN_ANALYTICTRAJ_OS_OPERATORCALL_CONST_INTERVAL_REF_CONST, + "t"_a) + ; } diff --git a/python/src/core/trajectory/codac2_py_SampledTraj.cpp b/python/src/core/trajectory/codac2_py_SampledTraj.cpp index a1127e25..cd739142 100644 --- a/python/src/core/trajectory/codac2_py_SampledTraj.cpp +++ b/python/src/core/trajectory/codac2_py_SampledTraj.cpp @@ -50,6 +50,7 @@ py::class_> _export_SampledTraj(py::module& m, const string& clas else if constexpr(std::is_same_v) { exported_class + .def(py::init( [](const py::array_t& l_t, const py::array_t& l_x) { @@ -85,6 +86,18 @@ py::class_> _export_SampledTraj(py::module& m, const string& clas }), SAMPLEDTRAJ_T_SAMPLEDTRAJ_CONST_LIST_DOUBLE_REF_CONST_LIST_T_REF, "l_t"_a, "l_x"_a) + + .def("__getitem__", [](const SampledTraj& x, Index_type i) -> SampledTraj + { + matlab::test_integer(i); + return x[matlab::input_index(i)]; + }, py::return_value_policy::reference_internal) + + .def("subvector", [](const SampledTraj& x, Index_type i, Index_type j) -> SampledTraj + { + matlab::test_integer(i,j); + return x.subvector(matlab::input_index(i),matlab::input_index(j)); + }, py::return_value_policy::reference_internal) ; } @@ -104,17 +117,26 @@ py::class_> _export_SampledTraj(py::module& m, const string& clas SAMPLEDTRAJ_T_SAMPLEDTRAJ_T_SAMPLED_DOUBLE_BOOL_CONST, "dt"_a, "keep_original_values"_a) - .def("__getitem__", [](const SampledTraj& x, Index_type index) -> const T& + .def("__call__", [](const SampledTraj& x, double t) -> T { - matlab::test_integer(index); - return x.at(matlab::input_index(index)); - }, py::return_value_policy::reference_internal) + return x(t); + }, + VIRTUAL_T_SAMPLEDTRAJ_T_OPERATORCALL_DOUBLE_CONST, + "t"_a) + + .def("__call__", [](const SampledTraj& x, const Interval& t) -> typename Wrapper::Domain + { + return x(t); + }, + VIRTUAL_WRAPPER_T_DOMAIN_SAMPLEDTRAJ_T_OPERATORCALL_CONST_INTERVAL_REF_CONST, + "t"_a) - .def("__setitem__", [](SampledTraj& x, Index_type index, const T& a) + .def("set", [](SampledTraj& x, double ti, const T& xi) { - matlab::test_integer(index); - x[matlab::input_index(index)] = a; - }) + return x.set(ti,xi); + }, + VOID_SAMPLEDTRAJ_T_SET_DOUBLE_CONST_T_REF, + "ti"_a, "xi"_a) .def("__repr__", [](const SampledTraj& x) { std::ostringstream stream; diff --git a/python/src/core/trajectory/codac2_py_TrajBase.h b/python/src/core/trajectory/codac2_py_TrajBase.h index fa53eb64..7dac6b10 100644 --- a/python/src/core/trajectory/codac2_py_TrajBase.h +++ b/python/src/core/trajectory/codac2_py_TrajBase.h @@ -57,20 +57,6 @@ void export_TrajBase(py::class_& pyclass) }, VIRTUAL_WRAPPER_T_DOMAIN_TRAJBASE_T_CODOMAIN_CONST) - .def("__call__", [](const S& x, double t) - { - return x(t); - }, - VIRTUAL_T_TRAJBASE_T_OPERATORCALL_DOUBLE_CONST, - "t"_a) - - .def("__call__", [](const S& x, const Interval& t) - { - return x(t); - }, - VIRTUAL_WRAPPER_T_DOMAIN_TRAJBASE_T_OPERATORCALL_CONST_INTERVAL_REF_CONST, - "t"_a) - .def("nan_value", [](const S& x) { return x.nan_value(); diff --git a/src/core/domains/ellipsoid/codac2_Ellipsoid.cpp b/src/core/domains/ellipsoid/codac2_Ellipsoid.cpp index dccf52b6..420f1574 100644 --- a/src/core/domains/ellipsoid/codac2_Ellipsoid.cpp +++ b/src/core/domains/ellipsoid/codac2_Ellipsoid.cpp @@ -167,12 +167,10 @@ namespace codac2 { return e_res + elli_error; } - Matrix nonlinear_mapping_base(const Matrix &G, const Matrix &J, const IntervalMatrix &J_box, const Vector& trig, const Vector& q) { - - Index n = G.cols(); - + Matrix nonlinear_mapping_base(const Matrix &G, const Matrix &J, const IntervalMatrix &J_box, const Vector& trig, const Vector& q) + { assert(G.is_squared() && J.is_squared() && J_box.is_squared()); - assert(n == J.cols() && n == J_box.cols() && n == q.size()); + assert(G.cols() == J.cols() && G.cols() == J_box.cols() && G.cols() == q.size()); auto JG = J * G; // note: reliability may be lost here! auto G_ = G.template cast(); diff --git a/src/core/trajectory/codac2_SampledTraj.h b/src/core/trajectory/codac2_SampledTraj.h index 50f9aa6f..b8f93cac 100644 --- a/src/core/trajectory/codac2_SampledTraj.h +++ b/src/core/trajectory/codac2_SampledTraj.h @@ -12,6 +12,7 @@ #include #include "codac2_TrajBase.h" #include "codac2_analytic_variables.h" +#include "codac2_template_tools.h" namespace codac2 { @@ -31,7 +32,7 @@ namespace codac2 auto it_t = l_t.begin(); auto it_x = l_x.begin(); while(it_t != l_t.end()) { - (*this)[*(it_t)] = *(it_x); + this->set(*it_t,*it_x); it_t++; it_x++; } } @@ -90,8 +91,8 @@ namespace codac2 ++it; } - (*this)[new_tdomain.lb()] = y_lb; // clean truncation - (*this)[new_tdomain.ub()] = y_ub; + this->set(new_tdomain.lb(), y_lb); // clean truncation + this->set(new_tdomain.ub(), y_ub); } virtual typename Wrapper::Domain codomain() const @@ -138,6 +139,12 @@ namespace codac2 } } + void set(double t, const T& x) + { + assert(this->empty() || size_of(x) == this->size()); + std::map::operator[](t) = x; + } + virtual SampledTraj sampled(double dt) const { return sampled(dt, true); @@ -154,11 +161,41 @@ namespace codac2 { // Appending values from the initial map: for(const auto& [ti,xi] : *this) - straj[ti] = xi; + straj.set(ti, xi); } return straj; } + + template + requires std::is_same_v + SampledTraj operator[](Index i) const + { + assert_release(i >= 0 && i < size()); + std::map m; + for(const auto& [t,y] : *this) + { + assert(i < y.size()); + m[t] = y[i]; + } + + return { m }; + } + + template + requires std::is_same_v + SampledTraj subvector(Index i, Index j) const + { + assert_release(i >= 0 && i <= j && j < size()); + std::map m; + for(const auto& [t,y] : *this) + { + assert(j < y.size()); + m[t] = y.subvector(i,j); + } + + return { m }; + } }; template diff --git a/src/core/trajectory/codac2_TrajBase.h b/src/core/trajectory/codac2_TrajBase.h index 11eec618..b74220a1 100644 --- a/src/core/trajectory/codac2_TrajBase.h +++ b/src/core/trajectory/codac2_TrajBase.h @@ -55,8 +55,8 @@ namespace codac2 auto tdom = tdomain(); SampledTraj straj; for(double t = tdom.lb() ; t < tdom.ub() ; t+=dt) - straj[t] = (*this)(t); - straj[tdom.ub()] = (*this)(tdom.ub()); + straj.set(t, (*this)(t)); + straj.set(tdom.ub(), (*this)(tdom.ub())); return straj; } @@ -67,20 +67,20 @@ namespace codac2 SampledTraj p; double t = tdomain().lb(), last_t = t; - p[t] = y0; t += dt; + p.set(t, y0); t += dt; T y = y0; while(t < tdomain().ub()) { y += ((*this)(last_t)+(*this)(t))*dt/2.; - p[t] = y; + p.set(t, y); last_t = t; t += dt; } t = tdomain().ub(); y += ((*this)(last_t)+(*this)(t))*(t-last_t)/2.; - p[t] = y; + p.set(t, y); return p; } From acfb48aba1c069dd5c6265ff74afaac07b2309dd Mon Sep 17 00:00:00 2001 From: Simon Rohou Date: Mon, 20 Jan 2025 19:44:08 +0100 Subject: [PATCH 3/3] [proj] releasing assertion --- src/core/contractors/codac2_CtcProj.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/contractors/codac2_CtcProj.h b/src/core/contractors/codac2_CtcProj.h index 1515d10e..00dff8a3 100644 --- a/src/core/contractors/codac2_CtcProj.h +++ b/src/core/contractors/codac2_CtcProj.h @@ -35,7 +35,6 @@ namespace codac2 assert_release(*min_element(_xi.begin(),_xi.end()) >= 0); assert_release(*max_element(_xi.begin(),_xi.end()) < size_of(c)); assert_release(size_of(c) >= (Index)_xi.size() && "cannot compute a projection of a set into a superset"); - assert_release(y.is_bisectable()); assert_release(default_eps > 0.); }