Skip to content

Commit

Permalink
Merge pull request #141 from SimonRohou/codac2_eigen
Browse files Browse the repository at this point in the history
Codac2 eigen: updated Eigen extensions
  • Loading branch information
SimonRohou authored Nov 26, 2024
2 parents 71566a2 + b084c0d commit 353dd82
Show file tree
Hide file tree
Showing 35 changed files with 1,183 additions and 1,050 deletions.
11 changes: 1 addition & 10 deletions examples/03_sivia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
ibex_init_common() # IBEX should have installed this function
message(STATUS "Found IBEX version ${IBEX_VERSION}")

# Adding Eigen3

# In case you installed Eigen3 in a local directory, you need
# to specify its path with the CMAKE_PREFIX_PATH option, e.g.
# set(CMAKE_PREFIX_PATH "~/eigen/build_install")

find_package(Eigen3 3.4 REQUIRED NO_MODULE)
message(STATUS "Found Eigen3 version ${Eigen3_VERSION}")

# Adding Codac

# In case you installed Codac in a local directory, you need
Expand All @@ -46,4 +37,4 @@
add_executable(${PROJECT_NAME} main.cpp)
target_compile_options(${PROJECT_NAME} PUBLIC ${CODAC_CXX_FLAGS})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CODAC_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex Eigen3::Eigen)
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex)
2 changes: 1 addition & 1 deletion python/codac/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def cart_prod(*args):
if mode != -1 and mode != 0:
codac_error("cart_prod: invalid input arguments, was expecting a " + mode_str[mode] + ", got a scalar domain")
mode = 0
lst.append(IntervalVector(1,Interval(arg)))
lst.append(IntervalVector([Interval(arg)]))

elif isinstance(arg, (list,Vector,IntervalVector)):
if mode != -1 and mode != 0:
Expand Down
32 changes: 23 additions & 9 deletions python/src/core/domains/interval/codac2_py_IntervalMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,31 @@
#include <pybind11/operators.h>
#include <pybind11/stl.h>
#include <codac2_Row.h>
#include <codac2_Matrix.h>
#include <codac2_IntervalRow.h>
#include <codac2_IntervalVector.h>
#include <codac2_IntervalMatrix.h>

#include "codac2_py_doc.h"
#include "codac2_py_MatrixBase_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_IntervalMatrixBase_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_IntervalMatrix_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_Base_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_eigenaddons_test_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#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_matrices_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py)
#include "codac2_py_IntervalMatrix_docs.h"

#include "codac2_py_IntervalMatrixBase.h"

Expand Down Expand Up @@ -54,18 +68,18 @@ py::class_<IntervalMatrix> export_IntervalMatrix(py::module& m)
matlab::test_integer(r,c);
return std::make_unique<IntervalMatrix>(r,c,x);
}),
MATRIXBASE_EIGENADDONS_MATRIX_INT_INT_CONST_SCALAR_REF,
MATRIX_ADDONS_MATRIXBASE_MATRIX_INT_INT_CONST_SCALAR_REF,
"r"_a, "c"_a, "x"_a)

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

.def(py::init<const Matrix&>(),
INTERVALMATRIXBASE_EIGENADDONS_MATRIX_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF,
MATRIX_ADDONS_INTERVALMATRIXBASE_MATRIX_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF,
"x"_a)

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

.def(py::init<const Row&>(),
Expand Down Expand Up @@ -112,7 +126,7 @@ py::class_<IntervalMatrix> export_IntervalMatrix(py::module& m)
matlab::test_integer(r,c);
return IntervalMatrix::empty(r,c);
},
INTERVALMATRIXBASE_EIGENADDONS_STATIC_AUTO_EMPTY_INDEX_INDEX,
MATRIX_ADDONS_INTERVALMATRIXBASE_STATIC_AUTO_EMPTY_INDEX_INDEX,
"r"_a, "c"_a)

.def("__repr__", [](const IntervalMatrix& x)
Expand Down
114 changes: 57 additions & 57 deletions python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,145 +29,145 @@ void export_IntervalMatrixBase(py::module& m, py::class_<S>& pyclass)
pyclass

.def("volume", &S::volume,
INTERVALMATRIXBASE_EIGENADDONS_DOUBLE_VOLUME_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_DOUBLE_VOLUME_CONST)

.def("is_empty", &S::is_empty,
EIGENADDONS_TEST_BOOL_IS_EMPTY_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_EMPTY_CONST)

.def("set_empty", &S::set_empty,
INTERVALMATRIXBASE_EIGENADDONS_VOID_SET_EMPTY)
MATRIX_ADDONS_INTERVALMATRIXBASE_VOID_SET_EMPTY)

.def("lb", [](const S& x) { return x.lb(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_LB_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_LB_CONST)

.def("ub", [](const S& x) { return x.ub(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_UB_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_UB_CONST)

.def("mid", [](const S& x) { return x.mid(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_MID_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_MID_CONST)

.def("mag", [](const S& x) { return x.mag(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_MAG_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_MAG_CONST)

.def("mig", [](const S& x) { return x.mig(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_MIG_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_MIG_CONST)

.def("rand", [](const S& x) { return x.rand(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_RAND_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_RAND_CONST)

.def("rad", [](const S& x) { return x.rad(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_RAD_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_RAD_CONST)

.def("diam", [](const S& x) { return x.diam(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_DIAM_CONST)
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_AUTO_DIAM_CONST)

.def("min_diam", [](const S& x) { return x.min_diam(); },
INTERVALMATRIXBASE_EIGENADDONS_DOUBLE_MIN_DIAM_CONST)
MATRIX_ADDONS_INTERVALMATRIXBASE_DOUBLE_MIN_DIAM_CONST)

.def("max_diam", [](const S& x) { return x.max_diam(); },
INTERVALMATRIXBASE_EIGENADDONS_DOUBLE_MAX_DIAM_CONST)
MATRIX_ADDONS_INTERVALMATRIXBASE_DOUBLE_MAX_DIAM_CONST)

.def("min_diam_index", [](const S& x)
{
return matlab::output_index(x.min_diam_index());
},
INTERVALMATRIXBASE_EIGENADDONS_INDEX_MIN_DIAM_INDEX_CONST)
MATRIX_ADDONS_INTERVALMATRIXBASE_INDEX_MIN_DIAM_INDEX_CONST)

.def("max_diam_index", [](const S& x)
{
return matlab::output_index(x.max_diam_index());
},
INTERVALMATRIXBASE_EIGENADDONS_INDEX_MAX_DIAM_INDEX_CONST)
MATRIX_ADDONS_INTERVALMATRIXBASE_INDEX_MAX_DIAM_INDEX_CONST)

.def("extr_diam_index", [](const S& x, bool min)
{
return matlab::output_index(x.extr_diam_index(min));
},
INTERVALMATRIXBASE_EIGENADDONS_INDEX_EXTR_DIAM_INDEX_BOOL_CONST,
MATRIX_ADDONS_INTERVALMATRIXBASE_INDEX_EXTR_DIAM_INDEX_BOOL_CONST,
"min"_a)

.def("__contains__", &S::contains,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_CONTAINS_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("__contains__", [](const S& x, const V& y) { return x.contains(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_CONTAINS_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("contains", &S::contains,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_CONTAINS_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("contains", [](const S& x, const V& y) { return x.contains(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_CONTAINS_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("interior_contains", &S::interior_contains,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_INTERIOR_CONTAINS_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("interior_contains", [](const S& x, const V& y) { return x.interior_contains(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_INTERIOR_CONTAINS_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_unbounded", &S::is_unbounded,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_UNBOUNDED_CONST)
.def("is_unbounded", [](const S& x) { return x.is_unbounded(); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_UNBOUNDED_CONST)

.def("is_degenerated", &S::is_degenerated,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_DEGENERATED_CONST)
.def("is_degenerated", [](const S& x) { return x.is_degenerated(); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_DEGENERATED_CONST)

.def("is_flat", &S::is_flat,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_FLAT_CONST)
.def("is_flat", [](const S& x) { return x.is_flat(); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_FLAT_CONST)

.def("intersects", &S::intersects,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_INTERSECTS_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("intersects", [](const S& x, const S& y) { return x.intersects(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_INTERSECTS_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_disjoint", &S::is_disjoint,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_DISJOINT_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_disjoint", [](const S& x, const S& y) { return x.is_disjoint(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_DISJOINT_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("overlaps", &S::overlaps,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_OVERLAPS_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("overlaps", [](const S& x, const S& y) { return x.overlaps(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_OVERLAPS_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_subset", &S::is_subset,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_SUBSET_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_subset", [](const S& x, const S& y) { return x.is_subset(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_SUBSET_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_strict_subset", &S::is_strict_subset,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_STRICT_SUBSET_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_strict_subset", [](const S& x, const S& y) { return x.is_strict_subset(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_STRICT_SUBSET_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_interior_subset", &S::is_interior_subset,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_INTERIOR_SUBSET_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_interior_subset", [](const S& x, const S& y) { return x.is_interior_subset(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_INTERIOR_SUBSET_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_strict_interior_subset", &S::is_strict_interior_subset,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_STRICT_INTERIOR_SUBSET_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_strict_interior_subset", [](const S& x, const S& y) { return x.is_strict_interior_subset(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_STRICT_INTERIOR_SUBSET_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_superset", &S::is_superset,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_SUPERSET_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_superset", [](const S& x, const S& y) { return x.is_superset(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_SUPERSET_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_strict_superset", &S::is_strict_superset,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_STRICT_SUPERSET_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST)
.def("is_strict_superset", [](const S& x, const S& y) { return x.is_strict_superset(y); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_STRICT_SUPERSET_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST)

.def("is_bisectable", &S::is_bisectable,
INTERVALMATRIXBASE_EIGENADDONS_BOOL_IS_BISECTABLE_CONST)
.def("is_bisectable", [](const S& x) { return x.is_bisectable(); },
MATRIXBASE_ADDONS_INTERVALMATRIXBASE_BOOL_IS_BISECTABLE_CONST)

.def("inflate", (S&(S::*)(double))&S::inflate,
INTERVALMATRIXBASE_EIGENADDONS_AUTO_REF_INFLATE_DOUBLE,
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_REF_INFLATE_DOUBLE,
"r"_a)

.def("inflate", (S&(S::*)(const V&))&S::inflate,
INTERVALMATRIXBASE_EIGENADDONS_AUTO_REF_INFLATE_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF,
.def("inflate", [](S& x, const V& r) { return x.inflate(r); },
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_REF_INFLATE_CONST_MATRIXBASE_OTHERDERIVED_REF,
"r"_a)

.def("bisect", [](const S& x, Index_type i, double ratio)
{
matlab::test_integer(i);
return x.bisect(matlab::input_index(i),ratio);
},
INTERVALMATRIXBASE_EIGENADDONS_AUTO_BISECT_INDEX_FLOAT_CONST,
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_BISECT_INDEX_FLOAT_CONST,
"i"_a, "ratio"_a = 0.49)

.def("bisect_largest", [](const S& x, double ratio = 0.49) { return x.bisect_largest(); },
INTERVALMATRIXBASE_EIGENADDONS_AUTO_BISECT_LARGEST_FLOAT_CONST,
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_BISECT_LARGEST_FLOAT_CONST,
"ratio"_a = 0.49)

.def(py::self &= py::self,
INTERVALMATRIXBASE_EIGENADDONS_AUTO_REF_OPERATORANDEQ_CONST_MATRIX_U_ROWSATCOMPILETIMECOLSATCOMPILETIME_REF
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_REF_OPERATORANDEQ_CONST_MATRIXBASE_OTHERDERIVED_REF
"x"_a)

.def(py::self |= py::self,
INTERVALMATRIXBASE_EIGENADDONS_AUTO_REF_OPERATOROREQ_CONST_MATRIX_U_ROWSATCOMPILETIMECOLSATCOMPILETIME_REF
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_REF_OPERATOROREQ_CONST_MATRIXBASE_OTHERDERIVED_REF
"x"_a)

.def(py::self & py::self,
INTERVALMATRIXBASE_EIGENADDONS_AUTO_OPERATORAND_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_OPERATORAND_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST
"x"_a)

.def(py::self | py::self,
INTERVALMATRIXBASE_EIGENADDONS_AUTO_OPERATOROR_CONST_MATRIX_INTERVALROWSATCOMPILETIMECOLSATCOMPILETIME_REF_CONST,
MATRIX_ADDONS_INTERVALMATRIXBASE_AUTO_OPERATOROR_CONST_MATRIXBASE_OTHERDERIVED_REF_CONST,
"x"_a)
;

Expand Down
Loading

0 comments on commit 353dd82

Please sign in to comment.