Skip to content

Commit

Permalink
Merge branch 'codac2_dev' of github.com:codac-team/codac into codac2_…
Browse files Browse the repository at this point in the history
…eigen
  • Loading branch information
SimonRohou committed Nov 28, 2024
2 parents 30e74a0 + 9a05925 commit a9f4939
Show file tree
Hide file tree
Showing 26 changed files with 987 additions and 129 deletions.
2 changes: 1 addition & 1 deletion 3rd/eigen
Submodule eigen updated 1 files
+11 −2 Eigen/src/Core/IO.h
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
endif()

if(MSVC)
#add_compile_options(/W4 /WX) # temporarily removed because of multiple "the following warning is treated as an error" with WS
add_compile_options(/W4)
else()
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
Expand Down
2 changes: 2 additions & 0 deletions python/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
domains/interval/codac2_py_Interval_operations.cpp
domains/interval/codac2_py_IntervalMatrix.cpp
domains/interval/codac2_py_IntervalMatrixBase.h
domains/interval/codac2_py_IntervalRow.cpp
domains/interval/codac2_py_IntervalVector.cpp
domains/interval/codac2_py_IntervalVector_templ.h
domains/paving/codac2_py_Paving.cpp
domains/paving/codac2_py_PavingNode.cpp
domains/paving/codac2_py_Subpaving.cpp
Expand Down
2 changes: 1 addition & 1 deletion python/src/core/codac2_py_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ PYBIND11_MODULE(_core, m)
export_BoolInterval(m);
auto py_Interval = export_Interval(m);
export_Interval_operations(m, py_Interval);
py::class_<IntervalRow> exported_intervalrow_class(m, "IntervalRow", DOC_TO_BE_DEFINED);
auto py_IR = export_IntervalRow(m);
auto py_IV = export_IntervalVector(m);
auto py_IM = export_IntervalMatrix(m);
auto py_IB = export_EigenBlock<IntervalMatrix>(m, "IntervalMatrixBlock");
Expand Down
16 changes: 8 additions & 8 deletions python/src/core/domains/interval/codac2_py_IntervalMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,10 @@ py::class_<IntervalMatrix> export_IntervalMatrix(py::module& m)
DOC_TO_BE_DEFINED,
"x"_a)

.def(py::init<const IntervalRow&>(),
DOC_TO_BE_DEFINED,
"x"_a)

.def(py::init<const Vector&>(),
DOC_TO_BE_DEFINED,
"x"_a)

.def(py::init<const IntervalVector&>(),
DOC_TO_BE_DEFINED,
"x"_a)

.def(py::init<const Eigen::Block<Matrix>&>(),
DOC_TO_BE_DEFINED,
"x"_a)
Expand All @@ -110,6 +102,14 @@ py::class_<IntervalMatrix> export_IntervalMatrix(py::module& m)
}),
DOC_TO_BE_DEFINED,
"v"_a)

.def(py::init<const IntervalRow&>(),
DOC_TO_BE_DEFINED,
"x"_a)

.def(py::init<const IntervalVector&>(),
DOC_TO_BE_DEFINED,
"x"_a)

.def_static("empty", [](Index_type r, Index_type c)
{
Expand Down
51 changes: 51 additions & 0 deletions python/src/core/domains/interval/codac2_py_IntervalRow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Interval Python binding
* Originated from the former pyIbex library (Benoît Desrochers)
* ----------------------------------------------------------------------------
* \date 2024
* \author Benoît Desrochers, Simon Rohou, Fabrice Le Bars
* \copyright Copyright 2024 Codac Team
* \license GNU Lesser General Public License (LGPL)
*/

#include <sstream>
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/stl.h>
#include <codac2_Row.h>
#include <codac2_IntervalRow.h>
#include <codac2_IntervalMatrix.h>

#include "codac2_py_doc.h"
#include "codac2_py_Matrix_addons_Base_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
//#include "codac2_py_Matrix_addons_IntervalMatrix_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_Matrix_addons_IntervalMatrixBase_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_Matrix_addons_IntervalVector_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
//#include "codac2_py_Matrix_addons_Matrix_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_Matrix_addons_MatrixBase_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_Matrix_addons_Vector_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_Matrix_addons_VectorBase_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_MatrixBase_addons_Base_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
//#include "codac2_py_MatrixBase_addons_IntervalMatrix_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_MatrixBase_addons_IntervalMatrixBase_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_MatrixBase_addons_IntervalVector_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
//#include "codac2_py_MatrixBase_addons_Matrix_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
//#include "codac2_py_MatrixBase_addons_MatrixBase_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_MatrixBase_addons_Vector_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_MatrixBase_addons_VectorBase_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_matrices_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_IntervalVector_docs.h"

#include "codac2_py_IntervalVector_templ.h"

using namespace std;
using namespace codac2;
namespace py = pybind11;
using namespace pybind11::literals;

py::class_<IntervalRow> export_IntervalRow(py::module& m)
{
py::class_<IntervalRow> exported_intervalrow_class(m, "IntervalRow", DOC_TO_BE_DEFINED);
export_IntervalVector_<IntervalRow,Row>(m, exported_intervalrow_class);
return exported_intervalrow_class;
}
81 changes: 2 additions & 79 deletions python/src/core/domains/interval/codac2_py_IntervalVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
#include "codac2_py_matrices_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_IntervalVector_docs.h"

#include "codac2_py_VectorBase.h"
#include "codac2_py_IntervalMatrixBase.h"
#include "codac2_py_IntervalVector_templ.h"

using namespace std;
using namespace codac2;
Expand All @@ -46,82 +45,6 @@ using namespace pybind11::literals;
py::class_<IntervalVector> export_IntervalVector(py::module& m)
{
py::class_<IntervalVector> exported_intervalvector_class(m, "IntervalVector", DOC_TO_BE_DEFINED);
export_IntervalMatrixBase<IntervalVector,Vector,true>(m, exported_intervalvector_class);
export_VectorBase<IntervalVector,IntervalMatrix,Interval>(m, exported_intervalvector_class);

exported_intervalvector_class

.def(py::init(
[](Index_type n)
{
matlab::test_integer(n);
return std::make_unique<IntervalVector>(n);
}),
DOC_TO_BE_DEFINED,
"n"_a)

.def(py::init<const IntervalVector&>(),
"x"_a)

.def(py::init<const Vector&>(),
"x"_a)

.def(py::init<const Vector&,const Vector&>(),
MATRIX_ADDONS_INTERVALMATRIXBASE_MATRIX_CONST_MATRIX_DOUBLERC_REF_CONST_MATRIX_DOUBLERC_REF,
"lb"_a, "ub"_a)

.def(py::init( // this constructor must be the last one to be declared
[](const std::vector<Interval>& v)
{
auto iv = std::make_unique<IntervalVector>(v.size());
for(size_t i = 0 ; i < v.size() ; i++)
(*iv)[i] = v[i];
return iv;
}),
MATRIX_ADDONS_INTERVALVECTOR_MATRIX_CONST_INITIALIZER_LIST_INTERVAL_REF,
"v"_a)

.def("complementary", [](const IntervalVector& x) { return x.complementary(); },
MATRIXBASE_ADDONS_INTERVALVECTOR_AUTO_COMPLEMENTARY_CONST)

.def("diff", [](const IntervalVector& x, const IntervalVector& y, bool compactness = true) { return x.diff(y,compactness); },
MATRIXBASE_ADDONS_INTERVALVECTOR_LIST_MATRIX_INTERVALRC_DIFF_CONST_MATRIXBASE_OTHERDERIVED_REF_BOOL_CONST,
"y"_a, "compactness"_a = true)

.def_static("empty", [](Index_type n)
{
matlab::test_integer(n);
return IntervalVector::empty(n);
},
MATRIX_ADDONS_INTERVALVECTOR_STATIC_AUTO_EMPTY_INDEX,
"n"_a)

.def("__repr__", [](const IntervalVector& x)
{
std::ostringstream s;
s << x;
return string(s.str());
},
OSTREAM_REF_OPERATOROUT_OSTREAM_REF_CONST_INTERVALVECTOR_REF)

;

py::implicitly_convertible<py::list,IntervalVector>();
py::implicitly_convertible<Vector,IntervalVector>();

m.def("cart_prod_boxes", [](const std::list<IntervalVector>& l)
{
IntervalVector c = *l.begin();
for(auto it = std::next(l.cbegin()); it != l.cend(); it++)
c = cart_prod(c,*it);
return c;
},
INTERVALVECTOR_CART_PROD_CONST_X_REF_VARIADIC);
// The variadic version of this function is defined in __init__.py file

m.def("hull", [](const std::list<IntervalVector>& l) { return hull(l); },
AUTO_HULL_CONST_LIST_EIGEN_MATRIX_SCALARROWSATCOMPILETIMECOLSATCOMPILETIME_REF,
"l"_a);

export_IntervalVector_<IntervalVector,Vector>(m, exported_intervalvector_class);
return exported_intervalvector_class;
}
111 changes: 111 additions & 0 deletions python/src/core/domains/interval/codac2_py_IntervalVector_templ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* IV_templ binding
* ----------------------------------------------------------------------------
* \date 2024
* \author Simon Rohou
* \copyright Copyright 2024 Codac Team
* \license GNU Lesser General Public License (LGPL)
*/

#pragma once

#include <sstream>
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/stl.h>

#include <codac2_IntervalVector.h>

#include "codac2_py_MatrixBase.h"
#include "codac2_py_IntervalMatrixBase.h"
#include "codac2_py_VectorBase.h"

using namespace std;
using namespace codac2;
namespace py = pybind11;
using namespace pybind11::literals;


template<typename IV,typename V>
void export_IntervalVector_(py::module& m, py::class_<IV>& pyclass)
{
export_IntervalMatrixBase<IV,V,true>(m, pyclass);
export_VectorBase<IV,IntervalMatrix,Interval>(m, pyclass);

pyclass

.def(py::init(
[](Index_type n)
{
matlab::test_integer(n);
return std::make_unique<IV>(n);
}),
DOC_TO_BE_DEFINED,
"n"_a)

.def(py::init<const IV&>(),
"x"_a)

.def(py::init<const V&>(),
"x"_a)

.def(py::init<const V&,const V&>(),
MATRIX_ADDONS_INTERVALMATRIXBASE_MATRIX_CONST_MATRIX_DOUBLERC_REF_CONST_MATRIX_DOUBLERC_REF,
"lb"_a, "ub"_a)

.def(py::init( // this constructor must be the last one to be declared
[](const std::vector<Interval>& v)
{
auto iv = std::make_unique<IV>(v.size());
for(size_t i = 0 ; i < v.size() ; i++)
(*iv)[i] = v[i];
return iv;
}),
MATRIX_ADDONS_INTERVALVECTOR_MATRIX_CONST_INITIALIZER_LIST_INTERVAL_REF,
"v"_a)

.def("complementary", [](const IV& x) { return x.complementary(); },
MATRIXBASE_ADDONS_INTERVALVECTOR_AUTO_COMPLEMENTARY_CONST)

.def("diff", [](const IV& x, const IV& y, bool compactness = true) { return x.diff(y,compactness); },
MATRIXBASE_ADDONS_INTERVALVECTOR_LIST_MATRIX_INTERVALRC_DIFF_CONST_MATRIXBASE_OTHERDERIVED_REF_BOOL_CONST,
"y"_a, "compactness"_a = true)

.def_static("empty", [](Index_type n)
{
matlab::test_integer(n);
return IV::empty(n);
},
MATRIX_ADDONS_INTERVALVECTOR_STATIC_AUTO_EMPTY_INDEX,
"n"_a)

.def("__repr__", [](const IV& x)
{
std::ostringstream s;
s << x;
return string(s.str());
},
OSTREAM_REF_OPERATOROUT_OSTREAM_REF_CONST_INTERVALVECTOR_REF)

;

py::implicitly_convertible<py::list,IV>();
py::implicitly_convertible<V,IV>();

if constexpr(std::is_same_v<IntervalVector,IV>)
{
m.def("cart_prod_boxes", [](const std::list<IV>& l)
{
IV c = *l.begin();
for(auto it = std::next(l.cbegin()); it != l.cend(); it++)
c = cart_prod(c,*it);
return c;
},
INTERVALVECTOR_CART_PROD_CONST_X_REF_VARIADIC);
// The variadic version of this function is defined in __init__.py file
}

m.def("hull", [](const std::list<IV>& l) { return hull(l); },
AUTO_HULL_CONST_LIST_EIGEN_MATRIX_SCALARROWSATCOMPILETIMECOLSATCOMPILETIME_REF,
"l"_a);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void export_AnalyticFunction(py::module& m, const std::string& export_name)
.def("__repr__", [](const AnalyticFunction<T>& f) {
std::ostringstream stream;
stream << f;
return string(stream.str());
return std::string(stream.str());
},
OSTREAM_REF_OPERATOROUT_OSTREAM_REF_CONST_ANALYTICFUNCTION_T_REF)
;
Expand Down
Loading

0 comments on commit a9f4939

Please sign in to comment.