diff --git a/examples/03_sivia/CMakeLists.txt b/examples/03_sivia/CMakeLists.txt index 3c62a678..314b49ff 100644 --- a/examples/03_sivia/CMakeLists.txt +++ b/examples/03_sivia/CMakeLists.txt @@ -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 @@ -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) \ No newline at end of file + target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex) \ No newline at end of file diff --git a/python/codac/core/__init__.py b/python/codac/core/__init__.py index 33f38f01..3ba61870 100644 --- a/python/codac/core/__init__.py +++ b/python/codac/core/__init__.py @@ -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: diff --git a/python/src/core/domains/interval/codac2_py_IntervalMatrix.cpp b/python/src/core/domains/interval/codac2_py_IntervalMatrix.cpp index 6575b6be..92c78bc9 100644 --- a/python/src/core/domains/interval/codac2_py_IntervalMatrix.cpp +++ b/python/src/core/domains/interval/codac2_py_IntervalMatrix.cpp @@ -13,17 +13,31 @@ #include #include #include +#include #include #include #include #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" @@ -54,18 +68,18 @@ py::class_ export_IntervalMatrix(py::module& m) matlab::test_integer(r,c); return std::make_unique(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(), "x"_a) .def(py::init(), - INTERVALMATRIXBASE_EIGENADDONS_MATRIX_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF, + MATRIX_ADDONS_INTERVALMATRIXBASE_MATRIX_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF, "x"_a) .def(py::init(), - 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(), @@ -112,7 +126,7 @@ py::class_ 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) diff --git a/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h b/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h index ef3821a7..b2b48f96 100644 --- a/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h +++ b/python/src/core/domains/interval/codac2_py_IntervalMatrixBase.h @@ -29,117 +29,117 @@ void export_IntervalMatrixBase(py::module& m, py::class_& 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) @@ -147,27 +147,27 @@ void export_IntervalMatrixBase(py::module& m, py::class_& pyclass) 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) ; diff --git a/python/src/core/domains/interval/codac2_py_IntervalVector.cpp b/python/src/core/domains/interval/codac2_py_IntervalVector.cpp index 30c199e1..b68c0d6e 100644 --- a/python/src/core/domains/interval/codac2_py_IntervalVector.cpp +++ b/python/src/core/domains/interval/codac2_py_IntervalVector.cpp @@ -16,14 +16,24 @@ #include #include "codac2_py_doc.h" -#include "codac2_py_MatrixBase_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_py_VectorBase_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_IntervalVector_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_py_IntervalVector_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_IntervalVector_docs.h" #include "codac2_py_VectorBase.h" #include "codac2_py_IntervalMatrixBase.h" @@ -47,27 +57,18 @@ py::class_ export_IntervalVector(py::module& m) matlab::test_integer(n); return std::make_unique(n); }), - INTERVALVECTOR_EIGENADDONS_MATRIX_INT, + MATRIX_ADDONS_INTERVALVECTOR_MATRIX_INT, "n"_a) - .def(py::init( - [](Index_type n, const Interval& x) - { - matlab::test_integer(n); - return std::make_unique((int)n,x); - }), - VECTORBASE_EIGENADDONS_MATRIX_INT_CONST_SCALAR_REF, - "n"_a, "x"_a) - .def(py::init(), "x"_a) .def(py::init(), - INTERVALMATRIXBASE_EIGENADDONS_MATRIX_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF, + MATRIX_ADDONS_INTERVALMATRIXBASE_MATRIX_CONST_MATRIX_DOUBLEROWSATCOMPILETIMECOLSATCOMPILETIME_REF, "x"_a) .def(py::init(), - 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( // this constructor must be the last one to be declared @@ -78,14 +79,14 @@ py::class_ export_IntervalVector(py::module& m) (*iv)[i] = v[i]; return iv; }), - INTERVALVECTOR_EIGENADDONS_MATRIX_CONST_INITIALIZER_LIST_INTERVAL_REF, + MATRIX_ADDONS_INTERVALVECTOR_MATRIX_CONST_INITIALIZER_LIST_INTERVAL_REF, "v"_a) .def("complementary", [](const IntervalVector& x) { return x.complementary(); }, - INTERVALVECTOR_EIGENADDONS_AUTO_COMPLEMENTARY_CONST) + MATRIXBASE_ADDONS_INTERVALVECTOR_AUTO_COMPLEMENTARY_CONST) .def("diff", [](const IntervalVector& x, const IntervalVector& y, bool compactness = true) { return x.diff(y,compactness); }, - INTERVALVECTOR_EIGENADDONS_LIST_MATRIX_INTERVALRC_DIFF_CONST_MATRIX_INTERVALRC_REF_BOOL_CONST, + MATRIXBASE_ADDONS_INTERVALVECTOR_LIST_MATRIX_INTERVALRC_DIFF_CONST_MATRIXBASE_OTHERDERIVED_REF_BOOL_CONST, "y"_a, "compactness"_a = true) .def_static("empty", [](Index_type n) @@ -93,7 +94,7 @@ py::class_ export_IntervalVector(py::module& m) matlab::test_integer(n); return IntervalVector::empty(n); }, - INTERVALVECTOR_EIGENADDONS_STATIC_AUTO_EMPTY_INDEX, + MATRIX_ADDONS_INTERVALVECTOR_STATIC_AUTO_EMPTY_INDEX, "n"_a) .def("__repr__", [](const IntervalVector& x) diff --git a/python/src/core/matrices/codac2_py_Matrix.cpp b/python/src/core/matrices/codac2_py_Matrix.cpp index 8a08b717..31ec6ce2 100644 --- a/python/src/core/matrices/codac2_py_Matrix.cpp +++ b/python/src/core/matrices/codac2_py_Matrix.cpp @@ -15,11 +15,24 @@ #include #include "codac2_py_doc.h" -#include "codac2_py_MatrixBase_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_py_Matrix_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_Matrix_docs.h" #include "codac2_py_MatrixBase.h" @@ -44,15 +57,6 @@ py::class_ export_Matrix(py::module& m) DOC_TO_BE_DEFINED, "r"_a, "c"_a) - .def(py::init( - [](Index_type r, Index_type c, double x) - { - matlab::test_integer(r,c); - return std::make_unique((int)r,(int)c,x); - }), - MATRIXBASE_EIGENADDONS_MATRIX_INT_INT_CONST_SCALAR_REF, - "r"_a, "c"_a, "x"_a) - .def(py::init(), DOC_TO_BE_DEFINED, "x"_a) diff --git a/python/src/core/matrices/codac2_py_MatrixBase.h b/python/src/core/matrices/codac2_py_MatrixBase.h index d29a1ee6..c396c1a7 100644 --- a/python/src/core/matrices/codac2_py_MatrixBase.h +++ b/python/src/core/matrices/codac2_py_MatrixBase.h @@ -57,13 +57,13 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) { return x.min_coeff(); }, - BASE_EIGENADDONS_SCALAR_MIN_COEFF_CONST) + MATRIXBASE_ADDONS_BASE_SCALAR_MIN_COEFF_CONST) .def("max_coeff", [](const S& x) { return x.max_coeff(); }, - BASE_EIGENADDONS_SCALAR_MAX_COEFF_CONST) + MATRIXBASE_ADDONS_BASE_SCALAR_MAX_COEFF_CONST) .def("norm", [](const S& x) { @@ -75,7 +75,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) { return x.squared_norm(); }, - BASE_EIGENADDONS_AUTO_SQUARED_NORM_CONST) + MATRIXBASE_ADDONS_BASE_AUTO_SQUARED_NORM_CONST) ; @@ -87,7 +87,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) { return x.is_squared(); }, - BASE_EIGENADDONS_BOOL_IS_SQUARED_CONST) + MATRIXBASE_ADDONS_BASE_BOOL_IS_SQUARED_CONST) .def("__getitem__", [](const S& x, const py::tuple& ij) -> const T& { @@ -99,7 +99,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) return x(matlab::input_index(i), matlab::input_index(j)); }, py::return_value_policy::reference_internal, - BASE_EIGENADDONS_CONST_SCALAR_REF_OPERATORCALL_INDEX_INDEX_CONST) + MATRIX_ADDONS_BASE_CONST_SCALAR_REF_OPERATORCALL_INDEX_INDEX_CONST) .def("__setitem__", [](S& x, const py::tuple& ij, const T& a) { @@ -111,7 +111,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) x(matlab::input_index(i), matlab::input_index(j)) = a; }, - BASE_EIGENADDONS_SCALAR_REF_OPERATORCALL_INDEX_INDEX) + MATRIX_ADDONS_BASE_SCALAR_REF_OPERATORCALL_INDEX_INDEX) ; } @@ -122,14 +122,14 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) { x.init(a); }, - BASE_EIGENADDONS_AUTO_REF_INIT_CONST_SCALAR_REF, + MATRIX_ADDONS_BASE_AUTO_REF_INIT_CONST_SCALAR_REF, "x"_a) .def("init", [](S& x, const S& a) { x.init(a); }, - BASE_EIGENADDONS_AUTO_REF_INIT_CONST_MATRIX_SCALARROWSATCOMPILETIMECOLSATCOMPILETIME_REF, + MATRIX_ADDONS_BASE_AUTO_REF_INIT_CONST_MATRIX_SCALARROWSATCOMPILETIMECOLSATCOMPILETIME_REF, "x"_a) .def("__repr__", [](const S& x) @@ -188,7 +188,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) matlab::test_integer(i,j); return x(matlab::input_index(i),matlab::input_index(j)); }, py::return_value_policy::reference_internal, - BASE_EIGENADDONS_SCALAR_REF_OPERATORCALL_INDEX_INDEX) + MATRIX_ADDONS_BASE_SCALAR_REF_OPERATORCALL_INDEX_INDEX) .def("resize", [](S& x, Index_type nb_rows, Index_type nb_cols) { @@ -203,7 +203,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) matlab::test_integer(nb_rows, nb_cols); x.resize_save_values(nb_rows, nb_cols); }, - MATRIXBASE_EIGENADDONS_VOID_RESIZE_SAVE_VALUES_INDEX_INDEX, + MATRIX_ADDONS_MATRIXBASE_VOID_RESIZE_SAVE_VALUES_INDEX_INDEX, "nb_rows"_a, "nb_cols"_a) .def_static("zeros", [](Index_type r, Index_type c) @@ -211,7 +211,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) matlab::test_integer(r,c); return S::zeros(r,c); }, - MATRIXBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_ZEROS_INDEX_INDEX, + MATRIX_ADDONS_MATRIXBASE_STATIC_MATRIX_SCALARRC_ZEROS_INDEX_INDEX, "r"_a, "c"_a) .def_static("ones", [](Index_type r, Index_type c) @@ -219,7 +219,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) matlab::test_integer(r,c); return S::ones(r,c); }, - MATRIXBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_ONES_INDEX_INDEX, + MATRIX_ADDONS_MATRIXBASE_STATIC_MATRIX_SCALARRC_ONES_INDEX_INDEX, "r"_a, "c"_a) .def_static("eye", [](Index_type r, Index_type c) @@ -227,7 +227,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) matlab::test_integer(r,c); return S::eye(r,c); }, - MATRIXBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_EYE_INDEX_INDEX, + MATRIX_ADDONS_MATRIXBASE_STATIC_MATRIX_SCALARRC_EYE_INDEX_INDEX, "r"_a, "c"_a) .def_static("random", [](Index_type r, Index_type c) @@ -235,7 +235,7 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) matlab::test_integer(r,c); return S::random(r,c); }, - MATRIXBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_RANDOM_INDEX_INDEX, + MATRIX_ADDONS_MATRIXBASE_STATIC_MATRIX_SCALARRC_RANDOM_INDEX_INDEX, "r"_a, "c"_a) ; @@ -243,5 +243,5 @@ void export_MatrixBase(py::module& m, py::class_& pyclass) //S abs(const MatrixBase& x) m.def("abs", [](const S& x) { return abs(x); }, - AUTO_ABS_CONST_EIGEN_MATRIX_SCALARROWSATCOMPILETIMECOLSATCOMPILETIME_REF); + AUTO_ABS_CONST_EIGEN_MATRIXBASE_OTHERDERIVED_REF); } \ No newline at end of file diff --git a/python/src/core/matrices/codac2_py_Vector.cpp b/python/src/core/matrices/codac2_py_Vector.cpp index d305e755..9bf3a1ea 100644 --- a/python/src/core/matrices/codac2_py_Vector.cpp +++ b/python/src/core/matrices/codac2_py_Vector.cpp @@ -15,13 +15,24 @@ #include #include "codac2_py_doc.h" -#include "codac2_py_MatrixBase_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_py_Vector_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_py_VectorBase_eigenaddons_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py) -#include "codac2_py_Vector_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_Vector_docs.h" #include "codac2_py_VectorBase.h" @@ -44,7 +55,7 @@ py::class_ export_Vector(py::module& m) matlab::test_integer(n); return std::make_unique(n); }), - VECTOR_EIGENADDONS_MATRIX_INT, + MATRIX_ADDONS_VECTOR_MATRIX_INT, "n"_a) .def(py::init(), @@ -58,20 +69,20 @@ py::class_ export_Vector(py::module& m) (*v)[i] = v_[i]; return v; }), - VECTOR_EIGENADDONS_MATRIX_INITIALIZER_LIST_DOUBLE, + MATRIX_ADDONS_VECTOR_MATRIX_INITIALIZER_LIST_DOUBLE, "v"_a) .def("min_coeff_index", [](const Vector& x) { return matlab::output_index(x.min_coeff_index()); }, - VECTOR_EIGENADDONS_INDEX_MIN_COEFF_INDEX_CONST) + MATRIXBASE_ADDONS_VECTOR_INDEX_MIN_COEFF_INDEX_CONST) .def("max_coeff_index", [](const Vector& x) { return matlab::output_index(x.max_coeff_index()); }, - VECTOR_EIGENADDONS_INDEX_MAX_COEFF_INDEX_CONST) + MATRIXBASE_ADDONS_VECTOR_INDEX_MAX_COEFF_INDEX_CONST) .def("__repr__", [](const Vector& x) { diff --git a/python/src/core/matrices/codac2_py_VectorBase.h b/python/src/core/matrices/codac2_py_VectorBase.h index edd06286..c3d5efb7 100644 --- a/python/src/core/matrices/codac2_py_VectorBase.h +++ b/python/src/core/matrices/codac2_py_VectorBase.h @@ -36,21 +36,21 @@ void export_VectorBase(py::module& m, py::class_& pyclass) matlab::test_integer(index); return x[matlab::input_index(index)]; }, py::return_value_policy::reference_internal, - VECTORBASE_EIGENADDONS_CONST_SCALAR_REF_OPERATORCOMPO_INDEX_CONST) + MATRIX_ADDONS_VECTORBASE_CONST_SCALAR_REF_OPERATORCOMPO_INDEX_CONST) .def("__setitem__", [](S& x, Index_type index, const T& a) { matlab::test_integer(index); x[matlab::input_index(index)] = a; }, - VECTORBASE_EIGENADDONS_SCALAR_REF_OPERATORCOMPO_INDEX) + MATRIX_ADDONS_VECTORBASE_SCALAR_REF_OPERATORCOMPO_INDEX) .def("subvector", [](const S& x, Index_type start_id, Index_type end_id) -> S { matlab::test_integer(start_id, end_id); return x.subvector(matlab::input_index(start_id), matlab::input_index(end_id)); }, - VECTORBASE_EIGENADDONS_AUTO_SUBVECTOR_INDEX_INDEX_CONST, + MATRIXBASE_ADDONS_VECTORBASE_AUTO_SUBVECTOR_INDEX_INDEX_CONST, "start_id"_a, "end_id"_a) .def("resize", [](S& x, Index_type n) @@ -66,7 +66,7 @@ void export_VectorBase(py::module& m, py::class_& pyclass) matlab::test_integer(n); x.resize_save_values(n); }, - VECTORBASE_EIGENADDONS_VOID_RESIZE_SAVE_VALUES_INDEX, + MATRIX_ADDONS_VECTORBASE_VOID_RESIZE_SAVE_VALUES_INDEX, "n"_a) .def("put", [](S& x, Index_type start_id, const S& x1) @@ -74,7 +74,7 @@ void export_VectorBase(py::module& m, py::class_& pyclass) matlab::test_integer(start_id); x.put(matlab::input_index(start_id), x1); }, - VECTORBASE_EIGENADDONS_VOID_PUT_INDEX_CONST_MATRIX_SCALARRC_REF, + MATRIX_ADDONS_VECTORBASE_VOID_PUT_INDEX_CONST_MATRIXBASE_OTHERDERIVED_REF, "start_id"_a, "x"_a) .def_static("zeros", [](Index_type n) @@ -82,7 +82,7 @@ void export_VectorBase(py::module& m, py::class_& pyclass) matlab::test_integer(n); return S::zeros(n); }, - VECTORBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_ZEROS_INDEX, + MATRIX_ADDONS_VECTORBASE_STATIC_MATRIX_SCALARRC_ZEROS_INDEX, "n"_a) .def_static("ones", [](Index_type n) @@ -90,7 +90,7 @@ void export_VectorBase(py::module& m, py::class_& pyclass) matlab::test_integer(n); return S::ones(n); }, - VECTORBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_ONES_INDEX, + MATRIX_ADDONS_VECTORBASE_STATIC_MATRIX_SCALARRC_ONES_INDEX, "n"_a) .def_static("random", [](Index_type n) @@ -98,7 +98,7 @@ void export_VectorBase(py::module& m, py::class_& pyclass) matlab::test_integer(n); return S::random(n); }, - VECTORBASE_EIGENADDONS_STATIC_MATRIX_SCALARRC_RANDOM_INDEX, + MATRIX_ADDONS_VECTORBASE_STATIC_MATRIX_SCALARRC_RANDOM_INDEX, "n"_a) .def("__repr__", [](const S& x) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 69ffe13d..56c2808d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -57,9 +57,6 @@ ${CMAKE_CURRENT_SOURCE_DIR}/domains/interval/codac2_IntervalMatrix.h ${CMAKE_CURRENT_SOURCE_DIR}/domains/interval/codac2_IntervalRow.h ${CMAKE_CURRENT_SOURCE_DIR}/domains/interval/codac2_IntervalVector.h - ${CMAKE_CURRENT_SOURCE_DIR}/domains/interval/eigen/codac2_IntervalMatrix_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/domains/interval/eigen/codac2_IntervalMatrixBase_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/domains/interval/eigen/codac2_IntervalVector_eigenaddons.h ${CMAKE_CURRENT_SOURCE_DIR}/domains/paving/codac2_Paving.cpp ${CMAKE_CURRENT_SOURCE_DIR}/domains/paving/codac2_Paving.h ${CMAKE_CURRENT_SOURCE_DIR}/domains/paving/codac2_PavingNode.h @@ -89,6 +86,26 @@ ${CMAKE_CURRENT_SOURCE_DIR}/geometry/codac2_geometry.h ${CMAKE_CURRENT_SOURCE_DIR}/geometry/codac2_Polygon.cpp ${CMAKE_CURRENT_SOURCE_DIR}/geometry/codac2_Polygon.h + + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Base.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_include.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrix.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrixBase.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalVector.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Matrix.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_MatrixBase.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Vector.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons/codac2_Matrix_addons_VectorBase.h + + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Base.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_include.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrix.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrixBase.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalVector.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Matrix.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_MatrixBase.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Vector.h + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_VectorBase.h ${CMAKE_CURRENT_SOURCE_DIR}/matrices/codac2_GaussJordan.cpp ${CMAKE_CURRENT_SOURCE_DIR}/matrices/codac2_GaussJordan.h @@ -96,13 +113,6 @@ ${CMAKE_CURRENT_SOURCE_DIR}/matrices/codac2_Matrix.h ${CMAKE_CURRENT_SOURCE_DIR}/matrices/codac2_Row.h ${CMAKE_CURRENT_SOURCE_DIR}/matrices/codac2_Vector.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_Base_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_eigenaddons_test.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_Matrix_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_MatrixBase_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_Vector_eigenaddons.h - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/codac2_VectorBase_eigenaddons.h ${CMAKE_CURRENT_SOURCE_DIR}/paver/codac2_pave.cpp ${CMAKE_CURRENT_SOURCE_DIR}/paver/codac2_pave.h @@ -172,7 +182,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/graphics/ipe ${CMAKE_CURRENT_SOURCE_DIR}/graphics/vibes ${CMAKE_CURRENT_SOURCE_DIR}/matrices - ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/Matrix_addons + ${CMAKE_CURRENT_SOURCE_DIR}/matrices/eigen/MatrixBase_addons ${CMAKE_CURRENT_SOURCE_DIR}/paver ${CMAKE_CURRENT_SOURCE_DIR}/proj ${CMAKE_CURRENT_SOURCE_DIR}/separators @@ -210,7 +221,7 @@ file(APPEND ${CODAC_CORE_MAIN_HEADER} "#pragma once\n\n") foreach(header_path ${CODAC_CORE_HDR}) get_filename_component(header_name ${header_path} NAME) - if(NOT header_name MATCHES "^.*eigenaddons.*$") + if(NOT header_name MATCHES "^.*_addons.*$") file(APPEND ${CODAC_CORE_MAIN_HEADER} "#include <${header_name}>\n") endif() endforeach() diff --git a/src/core/domains/interval/eigen/codac2_IntervalMatrixBase_eigenaddons.h b/src/core/domains/interval/eigen/codac2_IntervalMatrixBase_eigenaddons.h deleted file mode 100644 index aff0d8e3..00000000 --- a/src/core/domains/interval/eigen/codac2_IntervalMatrixBase_eigenaddons.h +++ /dev/null @@ -1,631 +0,0 @@ -/** - * \file codac2_IntervalMatrixBase_eigenaddons.h - * - * This class reuses some of the functions developed for ibex::IntervalMatrixBase. - * The original IBEX code is revised in modern C++ and adapted to the template - * structure proposed in Codac, based on the Eigen library. - * See ibex::IntervalMatrixBase (IBEX lib, author: Gilles Chabert) - * - * This file is included in the declaration of Eigen::MatrixBase, - * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. - * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html - * and the file codac2_matrices.h - * - * ---------------------------------------------------------------------------- - * \date 2024 - * \author Simon Rohou, Gilles Chabert - * \copyright Copyright 2023 Codac Team - * \license GNU Lesser General Public License (LGPL) - */ - -template - requires IsIntervalDomain -Matrix(const Matrix& x) - : Matrix(x.template cast()) -{ } - -template - requires IsIntervalDomain -Matrix(const Matrix& lb, const Matrix& ub) - : Matrix(lb) -{ - assert_release(lb.size() == ub.size()); - - for(Index i = 0 ; i < this->size() ; i++) - { - auto& lbi = *(this->data()+i); - const auto& ubi = *(ub.data()+i); - - if(lbi.lb() > ubi) - { - set_empty(); - break; - } - - else - lbi |= ubi; - } -} - -template - requires IsIntervalDomain -Matrix(int r, int c, const double bounds[][2]) - : Matrix(r,c) -{ - assert_release(r > 0 && c > 0); - - Index k = 0; - for(Index i = 0 ; i < this->rows() ; i++) - for(Index j = 0 ; j < this->cols() ; j++) - { - (*this)(i,j) = codac2::Interval(bounds[k][0],bounds[k][1]); - k++; - } - assert_release(k == this->size() && "incorrect array size"); -} - -template - requires IsIntervalDomain -Matrix(const MatrixBase& x) - : Matrix(x.eval().template cast()) -{ } - -template - requires IsIntervalDomain -inline bool operator==(const MatrixBase& x) const -{ - return operator==(x.eval().template cast()); -} - -template - requires IsIntervalDomain -inline double volume() const -{ - if(this->is_empty()) - return 0.; - - double v = 0.; - for(Index i = 0 ; i < this->size() ; i++) - { - if((this->data()+i)->is_unbounded()) return codac2::oo; - if((this->data()+i)->is_degenerated()) return 0.; - v += std::log((this->data()+i)->diam()); - } - return std::exp(v); -} - -#define degenerate_mat(op) \ - Matrix op(this->rows(),this->cols()); \ - \ - if(this->is_empty()) \ - op.init(std::numeric_limits::quiet_NaN()); \ - \ - else \ - { \ - for(Index i = 0 ; i < this->size() ; i++) \ - *(op.data()+i) = (this->data()+i)->op(); \ - } \ - \ - return op; \ - -template - requires IsIntervalDomain -inline auto lb() const -{ - degenerate_mat(lb); -} - -template - requires IsIntervalDomain -inline auto ub() const -{ - degenerate_mat(ub); -} - -template - requires IsIntervalDomain -inline auto mid() const -{ - degenerate_mat(mid); -} - -template - requires IsIntervalDomain -inline auto mag() const -{ - degenerate_mat(mag); -} - -template - requires IsIntervalDomain -inline auto mig() const -{ - degenerate_mat(mig); -} - -template - requires IsIntervalDomain -inline auto rand() const -{ - srand(time(NULL)); - degenerate_mat(rand); -} - -template - requires IsIntervalDomain -inline auto rad() const -{ - degenerate_mat(rad); -} - -template - requires IsIntervalDomain -inline auto diam() const -{ - degenerate_mat(diam); -} - -template - requires IsIntervalDomain -inline double min_diam() const -{ - return (this->data()+extr_diam_index(true))->diam(); -} - -template - requires IsIntervalDomain -inline double max_diam() const -{ - return (this->data()+extr_diam_index(false))->diam(); -} - -template - requires IsIntervalDomain -inline Index min_diam_index() const -{ - return extr_diam_index(true); -} - -template - requires IsIntervalDomain -inline Index max_diam_index() const -{ - return extr_diam_index(false); -} - -template - requires IsIntervalDomain -inline Index extr_diam_index(bool min) const -{ - // This code originates from the ibex-lib - // See: ibex_TemplateVector.h - // Author: Gilles Chabert - - double d = min ? codac2::oo : -1; // -1 to be sure that even a 0-diameter interval can be selected - int selected_index = -1; - bool unbounded = false; - assert_release(!this->is_empty() && "Diameter of an empty IntervalVector is undefined"); - - Index i; - - for(i = 0 ; i < this->size() ; i++) - { - if((this->data()+i)->is_unbounded()) - { - unbounded = true; - if(!min) break; - } - else - { - double w = (this->data()+i)->diam(); - if(min ? wd) - { - selected_index = i; - d = w; - } - } - } - - if(min && selected_index == -1) - { - assert(unbounded); - // the selected interval is the first one. - i = 0; - } - - // The unbounded intervals are not considered if we look for the minimal diameter - // and some bounded intervals have been found (selected_index!=-1) - if(unbounded && (!min || selected_index == -1)) - { - double pt = min ? -codac2::oo : codac2::oo; // keep the point less/most distant from +oo (we normalize if the lower bound is -oo) - selected_index = i; - - for(; i < this->size() ; i++) - { - if((this->data()+i)->lb() == -codac2::oo) - { - if((this->data()+i)->ub() == codac2::oo) - if(!min) - { - selected_index = i; - break; - } - - if((min && (-(this->data()+i)->ub() > pt)) || (!min && (-(this->data()+i)->ub() < pt))) - { - selected_index = i; - pt = -(this->data()+i)->ub(); - } - } - - else if((this->data()+i)->ub() == codac2::oo) - if((min && ((this->data()+i)->lb() > pt)) || (!min && ((this->data()+i)->lb() < pt))) - { - selected_index = i; - pt = (this->data()+i)->lb(); - } - } - } - - return selected_index; -} - -// to MatrixBase template -// to MatrixBase requires IsIntervalDomain -// to MatrixBase inline bool is_empty() const -// to MatrixBase { -// to MatrixBase for(Index i = 0 ; i < this->size() ; i++) -// to MatrixBase if((this->data()+i)->is_empty()) -// to MatrixBase return true; -// to MatrixBase return false; -// to MatrixBase } - -template - requires IsIntervalDomain -inline void set_empty() -{ - this->init(codac2::Interval::empty()); -} - -template - requires IsIntervalDomain -inline bool contains(const Matrix& x) const -{ - assert_release(x.size() == this->size()); - - if(this->is_empty()) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->contains(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool interior_contains(const Matrix& x) const -{ - assert_release(x.size() == this->size()); - - if(this->is_empty()) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->interior_contains(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_unbounded() const -{ - if(this->is_empty()) return false; - for(Index i = 0 ; i < this->size() ; i++) - if((this->data()+i)->is_unbounded()) - return true; - return false; -} - -template - requires IsIntervalDomain -inline bool is_degenerated() const -{ - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->is_degenerated()) - return false; - return true; -} - -template - requires IsIntervalDomain -inline bool is_flat() const -{ - if(this->is_empty()) return true; - for(Index i = 0 ; i < this->size() ; i++) - if((this->data()+i)->is_degenerated()) // don't use diam() because of roundoff - return true; - return false; -} - -template - requires IsIntervalDomain -inline bool intersects(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->intersects(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_disjoint(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return true; - - for(Index i = 0 ; i < this->size() ; i++) - if((this->data()+i)->is_disjoint(*(x.data()+i))) - return true; - - return false; -} - -template - requires IsIntervalDomain -inline bool overlaps(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->overlaps(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_subset(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return true; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->is_subset(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_strict_subset(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return true; - - if(!is_subset(x)) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if((this->data()+i)->is_strict_subset(*(x.data()+i))) - return true; - - return false; -} - -template - requires IsIntervalDomain -inline bool is_interior_subset(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return true; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->is_interior_subset(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_strict_interior_subset(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return true; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(this->data()+i)->is_strict_interior_subset(*(x.data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_superset(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if(!(x.data()+i)->is_subset(*(this->data()+i))) - return false; - - return true; -} - -template - requires IsIntervalDomain -inline bool is_strict_superset(const Matrix& x) const -{ - assert_release(this->size() == x.size()); - - if(this->is_empty()) - return false; - - if(!is_superset(x)) - return false; - - for(Index i = 0 ; i < this->size() ; i++) - if((x.data()+i)->is_strict_subset(*(this->data()+i))) - return true; - - return false; -} - -template - requires IsIntervalDomain -inline bool is_bisectable() const -{ - for(Index i = 0 ; i < this->size() ; i++) - if((this->data()+i)->is_bisectable()) - return true; - return false; -} - -template - requires IsIntervalDomain -inline auto& inflate(double r) -{ - assert_release(r >= 0.); - - for(Index i = 0 ; i < this->size() ; i++) - (this->data()+i)->inflate(r); - return *this; -} - -template - requires IsIntervalDomain -inline auto& inflate(const Matrix& r) -{ - assert_release(this->size() == r.size()); - assert_release(r.min_coeff() >= 0.); - - for(Index i = 0 ; i < this->size() ; i++) - (this->data()+i)->inflate(*(r.data()+i)); - return *this; -} - -template - requires IsIntervalDomain -inline auto& operator&=(const Matrix& x) -{ - assert_release(this->size() == x.size()); - - if constexpr(std::is_same_v) - { - if(x.is_empty()) - { - set_empty(); - return *this; - } - } - - for(Index i = 0 ; i < this->size() ; i++) - *(this->data()+i) &= *(x.data()+i); - return *this; -} - -template - requires IsIntervalDomain -inline auto& operator&=(const MatrixBase& x) -{ - assert_release(this->size() == x.size()); - - for(Index i = 0 ; i < this->rows() ; i++) - for(Index j = 0 ; j < this->cols() ; j++) - (*this)(i,j) &= x(i,j); - return *this; -} - -template - requires IsIntervalDomain -inline auto& operator|=(const Matrix& x) -{ - assert_release(this->size() == x.size()); - - if constexpr(std::is_same_v) - { - if(x.is_empty()) - return *this; - } - - for(Index i = 0 ; i < this->size() ; i++) - *(this->data()+i) |= *(x.data()+i); - return *this; -} - -template - requires IsIntervalDomain -inline auto operator&(const Matrix& x) const -{ - auto y = *this; - return y &= x; -} - -template - requires IsIntervalDomain -inline auto operator|(const Matrix& x) const -{ - auto y = *this; - return y |= x; -} - -template - requires IsIntervalDomain -inline static auto empty(Index r, Index c) -{ - assert_release(r >= 0 && c >= 0); - Matrix e(r,c); - return e.init(codac2::Interval::empty()); -} - -template - requires IsIntervalDomain -inline auto bisect(Index i, float ratio = 0.49) const -{ - assert_release(i >= 0 && i < this->size()); - assert_release((this->data()+i)->is_bisectable()); - assert_release(codac2::Interval(0,1).interior_contains(ratio)); - - auto p = std::make_pair(*this,*this); - auto pi = (this->data()+i)->bisect(ratio); - *(p.first.data()+i) = pi.first; - *(p.second.data()+i) = pi.second; - return p; -} - -template - requires IsIntervalDomain -inline auto bisect_largest(float ratio = 0.49) const -{ - return bisect(max_diam_index(), ratio); -} \ No newline at end of file diff --git a/src/core/domains/interval/eigen/codac2_IntervalMatrix_eigenaddons.h b/src/core/domains/interval/eigen/codac2_IntervalMatrix_eigenaddons.h deleted file mode 100644 index 1077dba3..00000000 --- a/src/core/domains/interval/eigen/codac2_IntervalMatrix_eigenaddons.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * \file codac2_IntervalMatrix_eigenaddons.h - * - * This file is included in the declaration of Eigen::MatrixBase, - * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. - * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html - * and the file codac2_matrices.h - * - * ---------------------------------------------------------------------------- - * \date 2024 - * \author Simon Rohou - * \copyright Copyright 2023 Codac Team - * \license GNU Lesser General Public License (LGPL) - */ - -//template -// requires (IsIntervalDomain && (!IsVectorOrRow) -// && (std::is_same_v,IV> && ...)) -//Matrix(const IV&... x) -// : Matrix(sizeof...(IV), std::get<0>(std::tie(x...)).size()) -//{ -// Index i = 0; -// ((this->row(i++) = x), ...); -// assert_release(i == rows() && "invalid input size"); -//} \ No newline at end of file diff --git a/src/core/matrices/codac2_matrices.h b/src/core/matrices/codac2_matrices.h index 1b3963df..5158b28c 100644 --- a/src/core/matrices/codac2_matrices.h +++ b/src/core/matrices/codac2_matrices.h @@ -32,8 +32,8 @@ namespace Eigen concept IsIntervalDomain = std::is_same_v; } -#define EIGEN_MATRIX_PLUGIN "codac2_eigenaddons.h" -#define EIGEN_MATRIXBASE_PLUGIN "codac2_eigenaddons_test.h" +#define EIGEN_MATRIXBASE_PLUGIN "codac2_MatrixBase_addons_include.h" +#define EIGEN_MATRIX_PLUGIN "codac2_Matrix_addons_include.h" #ifndef EIGEN_NO_DEBUG /* Disables Eigen's assertions if defined. @@ -94,18 +94,20 @@ namespace codac2 namespace codac2 { - template - inline auto abs(const Eigen::Matrix& x) + template + inline auto abs(const Eigen::MatrixBase& x) { - Eigen::Matrix a(x); - - for(int i = 0 ; i < x.size() ; i++) - { - if constexpr(std::is_same_v) - *(a.data()+i) = fabs(*(x.data()+i)); - else - *(a.data()+i) = abs(*(x.data()+i)); - } + using M = Eigen::MatrixBase; + Eigen::Matrix a(x); + + for(Index i = 0 ; i < x.rows() ; i++) + for(Index j = 0 ; j < x.cols() ; j++) + { + if constexpr(std::is_same_v) + a(i,j) = fabs(x(i,j)); + else + a(i,j) = abs(x(i,j)); + } return a; } diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Base.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Base.h new file mode 100644 index 00000000..ae49d330 --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Base.h @@ -0,0 +1,46 @@ +/** + * \file codac2_MatrixBase_addons_Base.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +inline bool is_squared() const +{ + return this->rows() == this->cols(); +} + +inline auto squared_norm() const +{ + return this->squaredNorm(); +} + +#define minmax_item(op) \ + Scalar m = (*this)(0,0); /* first element */ \ + for(Index i = 0 ; i < this->rows() ; i++) \ + for(Index j = 0 ; j < this->cols() ; j++) \ + { \ + if constexpr(std::is_same_v) \ + m = codac2::op(m,(*this)(i,j)); \ + else \ + m = std::op(m,(*this)(i,j)); \ + } \ + return m; \ + +inline Scalar min_coeff() const +{ + minmax_item(min); +} + +inline Scalar max_coeff() const +{ + minmax_item(max); +} \ No newline at end of file diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrix.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrix.h new file mode 100644 index 00000000..fba89179 --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrix.h @@ -0,0 +1,14 @@ +/** + * \file codac2_MatrixBase_addons_IntervalMatrix.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrixBase.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrixBase.h new file mode 100644 index 00000000..54993bd9 --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrixBase.h @@ -0,0 +1,338 @@ +/** + * \file codac2_MatrixBase_addons_IntervalMatrixBase.h + * + * This class reuses some of the functions developed for ibex::IntervalMatrixBase. + * The original IBEX code is revised in modern C++ and adapted to the template + * structure proposed in Codac, based on the Eigen library. + * See ibex::IntervalMatrixBase (IBEX lib, author: Gilles Chabert) + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou, Gilles Chabert + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +template + requires IsIntervalDomain +inline double volume() const +{ + if(this->is_empty()) + return 0.; + + double v = 0.; + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + { + if((*this)(i,j).is_unbounded()) return codac2::oo; + if((*this)(i,j).is_degenerated()) return 0.; + v += std::log((*this)(i,j).diam()); + } + return std::exp(v); +} + +inline bool is_empty() const +{ + for(Index i = 0 ; i < rows() ; i++) + for(Index j = 0 ; j < cols() ; j++) + if((*this)(i,j).is_empty()) + return true; + return false; +} + +#define degenerate_mat(op) \ + Matrix m(this->rows(),this->cols()); \ + \ + if(this->is_empty()) \ + m.init(std::numeric_limits::quiet_NaN()); \ + \ + else \ + { \ + for(Index i = 0 ; i < this->rows() ; i++) \ + for(Index j = 0 ; j < this->cols() ; j++) \ + m(i,j) = (*this)(i,j).op(); \ + } \ + \ + return m; \ + +template + requires IsIntervalDomain +inline auto lb() const +{ + degenerate_mat(lb); +} + +template + requires IsIntervalDomain +inline auto ub() const +{ + degenerate_mat(ub); +} + +template + requires IsIntervalDomain +inline auto mid() const +{ + degenerate_mat(mid); +} + +template + requires IsIntervalDomain +inline auto mag() const +{ + degenerate_mat(mag); +} + +template + requires IsIntervalDomain +inline auto mig() const +{ + degenerate_mat(mig); +} + +template + requires IsIntervalDomain +inline auto rand() const +{ + srand(time(NULL)); + degenerate_mat(rand); +} + +template + requires IsIntervalDomain +inline auto rad() const +{ + degenerate_mat(rad); +} + +template + requires IsIntervalDomain +inline auto diam() const +{ + degenerate_mat(diam); +} + +template +inline bool contains(const MatrixBase& x) const +{ + assert_release(x.size() == this->size()); + + if(this->is_empty()) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).contains(x(i,j))) + return false; + + return true; +} + +template +inline bool interior_contains(const MatrixBase& x) const +{ + assert_release(x.size() == this->size()); + + if(this->is_empty()) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).interior_contains(x(i,j))) + return false; + + return true; +} + +inline bool is_unbounded() const +{ + if(this->is_empty()) return false; + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if((*this)(i,j).is_unbounded()) + return true; + return false; +} + +inline bool is_degenerated() const +{ + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).is_degenerated()) + return false; + return true; +} + +inline bool is_flat() const +{ + if(this->is_empty()) return true; + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if((*this)(i,j).is_degenerated()) // don't use diam() because of roundoff + return true; + return false; +} + +template +inline bool intersects(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).intersects(x(i,j))) + return false; + + return true; +} + +template +inline bool is_disjoint(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return true; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if((*this)(i,j).is_disjoint(x(i,j))) + return true; + + return false; +} + +template +inline bool overlaps(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).overlaps(x(i,j))) + return false; + + return true; +} + +template +inline bool is_subset(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return true; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).is_subset(x(i,j))) + return false; + + return true; +} + +template +inline bool is_strict_subset(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return true; + + if(!is_subset(x)) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if((*this)(i,j).is_strict_subset(x(i,j))) + return true; + + return false; +} + +template +inline bool is_interior_subset(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return true; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).is_interior_subset(x(i,j))) + return false; + + return true; +} + +template +inline bool is_strict_interior_subset(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return true; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!(*this)(i,j).is_strict_interior_subset(x(i,j))) + return false; + + return true; +} + +template +inline bool is_superset(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(!x(i,j).is_subset((*this)(i,j))) + return false; + + return true; +} + +template +inline bool is_strict_superset(const MatrixBase& x) const +{ + assert_release(this->size() == x.size()); + + if(this->is_empty()) + return false; + + if(!is_superset(x)) + return false; + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if(x(i,j).is_strict_subset((*this)(i,j))) + return true; + + return false; +} + +inline bool is_bisectable() const +{ + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + if((*this)(i,j).is_bisectable()) + return true; + return false; +} \ No newline at end of file diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalVector.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalVector.h new file mode 100644 index 00000000..d9e85d62 --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalVector.h @@ -0,0 +1,89 @@ +/** + * \file codac2_MatrixBase_addons_IntervalVector.h + * + * This class reuses some of the functions developed for ibex::IntervalVector. + * The original IBEX code is revised in modern C++ and adapted to the template + * structure proposed in Codac, based on the Eigen library. + * See ibex::IntervalVector (IBEX lib, author: Gilles Chabert) + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou, Gilles Chabert + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +template + requires IsIntervalDomain && IsVectorOrRow +inline auto complementary() const +{ + return Matrix((int)this->size()).diff(*this); +} + +template + requires IsIntervalDomain && IsVectorOrRow +inline std::list> diff(const MatrixBase& y, bool compactness = true) const +{ + // This code originates from the ibex-lib + // See: ibex_TemplateVector.h + // Author: Gilles Chabert + // It has been revised with modern C++ and templated types + + const Index n = this->size(); + assert_release(y.size() == n); + + if(y == *this) + return { }; + + Matrix x = *this; + Matrix z = x & y; + + if(z.is_empty()) + { + if(x.is_empty()) return { }; + else return { x }; + } + + else + { + // Check if in one dimension y is flat and x not, + // in which case the diff returns also x directly + if(compactness) + for(Index i = 0 ; i < n ; i++) + if(z[i].is_degenerated() && !x[i].is_degenerated()) + { + if(x.is_empty()) return { }; + else return { x }; + } + } + + std::list> l; + + for(Index var = 0 ; var < n ; var++) + { + codac2::Interval c1, c2; + + for(const auto& ci : x[var].diff(y[var], compactness)) + { + assert(!ci.is_empty()); + + Matrix v(n); + for(Index i = 0 ; i < var ; i++) + v[i] = x[i]; + v[var] = ci; + for(Index i = var+1 ; i < n ; i++) + v[i] = x[i]; + if(!v.is_empty()) + l.push_back(v); + } + + x[var] = z[var]; + } + + return l; +} \ No newline at end of file diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Matrix.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Matrix.h new file mode 100644 index 00000000..247e837f --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Matrix.h @@ -0,0 +1,19 @@ +/** + * \file codac2_MatrixBase_addons_Matrix.h + * + * This class reuses some of the functions developed for ibex::Matrix. + * The original IBEX code is revised in modern C++ and adapted to the template + * structure proposed in Codac, based on the Eigen library. + * See ibex::Matrix (IBEX lib, author: Gilles Chabert) + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou, Gilles Chabert + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_MatrixBase.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_MatrixBase.h new file mode 100644 index 00000000..6c555930 --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_MatrixBase.h @@ -0,0 +1,14 @@ +/** + * \file codac2_MatrixBase_addons_MatrixBase.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Vector.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Vector.h new file mode 100644 index 00000000..22752f58 --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_Vector.h @@ -0,0 +1,34 @@ +/** + * \file codac2_MatrixBase_addons_Vector.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +template + requires (!IsIntervalDomain) && (IsVectorOrRow) +inline Index min_coeff_index() const +{ + Index r,c; + this->minCoeff(&r,&c); + assert(c == 0); + return r; +} + +template + requires (!IsIntervalDomain) && (IsVectorOrRow) +inline Index max_coeff_index() const +{ + Index r,c; + this->maxCoeff(&r,&c); + assert(c == 0); + return r; +} \ No newline at end of file diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_VectorBase.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_VectorBase.h new file mode 100644 index 00000000..fe1a470d --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_VectorBase.h @@ -0,0 +1,30 @@ +/** + * \file codac2_MatrixBase_addons_VectorBase.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +template + requires IsVectorOrRow +inline auto diag_matrix() const +{ + return this->asDiagonal().toDenseMatrix(); +} + +template + requires IsVectorOrRow +inline auto subvector(Index start_id, Index end_id) const +{ + assert_release(end_id >= 0 && start_id >= 0); + assert_release(end_id < this->size() && start_id <= end_id); + return this->segment(start_id,end_id-start_id+1); +} \ No newline at end of file diff --git a/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_include.h b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_include.h new file mode 100644 index 00000000..30a8cb4f --- /dev/null +++ b/src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_include.h @@ -0,0 +1,23 @@ +/** + * \file codac2_MatrixBase_addons_include.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include "codac2_MatrixBase_addons_Base.h" +#include "codac2_MatrixBase_addons_IntervalMatrix.h" +#include "codac2_MatrixBase_addons_IntervalMatrixBase.h" +#include "codac2_MatrixBase_addons_IntervalVector.h" +#include "codac2_MatrixBase_addons_Matrix.h" +#include "codac2_MatrixBase_addons_MatrixBase.h" +#include "codac2_MatrixBase_addons_Vector.h" +#include "codac2_MatrixBase_addons_VectorBase.h" \ No newline at end of file diff --git a/src/core/matrices/eigen/codac2_Base_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Base.h similarity index 77% rename from src/core/matrices/eigen/codac2_Base_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Base.h index d7af3d9b..8e94f720 100644 --- a/src/core/matrices/eigen/codac2_Base_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Base.h @@ -1,5 +1,5 @@ /** - * \file codac2_Base_eigenaddons.h + * \file codac2_Matrix_addons_Base.h * * This file is included in the declaration of Eigen::MatrixBase, * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. @@ -56,37 +56,11 @@ inline auto& init(const Matrix& x) / return *this; } -inline bool is_squared() const -{ - return this->rows() == this->cols(); -} - -inline auto squared_norm() const -{ - return this->squaredNorm(); -} - -#define minmax_item(op) \ - Scalar m = *(this->data()); /* first element */ \ - for(Index i = 1 ; i < this->size() ; i++) \ - { \ - if constexpr(std::is_same_v) \ - m = codac2::op(m,*(this->data()+i)); \ - else \ - m = std::op(m,*(this->data()+i)); \ - } \ - return m; \ - -inline Scalar min_coeff() const -{ - minmax_item(min); -} - -inline Scalar max_coeff() const -{ - minmax_item(max); -} - +// This operator should be related to Eigen::MatrixBase, +// for allowing a comparison between two matrix expressions. +// However, it is not possible to overwrite Eigen::MatrixBase::operator==. +// Therefore, only comparisons between Eigen::Matrix types is possible. +// This must be corrected... template inline bool operator==(const Matrix& x) const { diff --git a/src/core/matrices/eigen/codac2_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrix.h similarity index 55% rename from src/core/matrices/eigen/codac2_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrix.h index b2bec7db..059dfb19 100644 --- a/src/core/matrices/eigen/codac2_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrix.h @@ -1,5 +1,5 @@ /** - * \file codac2_eigenaddons.h + * \file codac2_Matrix_addons_IntervalMatrix.h * * This file is included in the declaration of Eigen::MatrixBase, * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. @@ -12,12 +12,3 @@ * \copyright Copyright 2023 Codac Team * \license GNU Lesser General Public License (LGPL) */ - -#include "codac2_Base_eigenaddons.h" -#include "codac2_MatrixBase_eigenaddons.h" -#include "codac2_Matrix_eigenaddons.h" -#include "codac2_VectorBase_eigenaddons.h" -#include "codac2_Vector_eigenaddons.h" -#include "codac2_IntervalMatrixBase_eigenaddons.h" -#include "codac2_IntervalMatrix_eigenaddons.h" -#include "codac2_IntervalVector_eigenaddons.h" \ No newline at end of file diff --git a/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrixBase.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrixBase.h new file mode 100644 index 00000000..d01e4f3b --- /dev/null +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalMatrixBase.h @@ -0,0 +1,300 @@ +/** + * \file codac2_Matrix_addons_IntervalMatrixBase.h + * + * This class reuses some of the functions developed for ibex::IntervalMatrixBase. + * The original IBEX code is revised in modern C++ and adapted to the template + * structure proposed in Codac, based on the Eigen library. + * See ibex::IntervalMatrixBase (IBEX lib, author: Gilles Chabert) + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou, Gilles Chabert + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +template + requires IsIntervalDomain +Matrix(const Matrix& x) + : Matrix(x.template cast()) +{ } + +template + requires IsIntervalDomain +Matrix(const Matrix& lb, const Matrix& ub) + : Matrix(lb) +{ + assert_release(lb.size() == ub.size()); + + for(Index i = 0 ; i < this->size() ; i++) + { + auto& lbi = *(this->data()+i); + const auto& ubi = *(ub.data()+i); + + if(lbi.lb() > ubi) + { + set_empty(); + break; + } + + else + lbi |= ubi; + } +} + +template + requires IsIntervalDomain +Matrix(int r, int c, const double bounds[][2]) + : Matrix(r,c) +{ + assert_release(r > 0 && c > 0); + + Index k = 0; + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + { + (*this)(i,j) = codac2::Interval(bounds[k][0],bounds[k][1]); + k++; + } + assert_release(k == this->size() && "incorrect array size"); +} + +template + requires IsIntervalDomain +Matrix(const MatrixBase& x) + : Matrix(x.eval().template cast()) +{ } + +template + requires IsIntervalDomain +inline bool operator==(const MatrixBase& x) const +{ + return operator==(x.eval().template cast()); +} + +template + requires IsIntervalDomain +inline double min_diam() const +{ + return (this->data()+extr_diam_index(true))->diam(); +} + +template + requires IsIntervalDomain +inline double max_diam() const +{ + return (this->data()+extr_diam_index(false))->diam(); +} + +template + requires IsIntervalDomain +inline Index min_diam_index() const +{ + return extr_diam_index(true); +} + +template + requires IsIntervalDomain +inline Index max_diam_index() const +{ + return extr_diam_index(false); +} + +template + requires IsIntervalDomain +inline Index extr_diam_index(bool min) const +{ + // This code originates from the ibex-lib + // See: ibex_TemplateVector.h + // Author: Gilles Chabert + + double d = min ? codac2::oo : -1; // -1 to be sure that even a 0-diameter interval can be selected + int selected_index = -1; + bool unbounded = false; + assert_release(!this->is_empty() && "Diameter of an empty IntervalVector is undefined"); + + Index i; + + for(i = 0 ; i < this->size() ; i++) + { + if((this->data()+i)->is_unbounded()) + { + unbounded = true; + if(!min) break; + } + else + { + double w = (this->data()+i)->diam(); + if(min ? wd) + { + selected_index = i; + d = w; + } + } + } + + if(min && selected_index == -1) + { + assert(unbounded); + // the selected interval is the first one. + i = 0; + } + + // The unbounded intervals are not considered if we look for the minimal diameter + // and some bounded intervals have been found (selected_index!=-1) + if(unbounded && (!min || selected_index == -1)) + { + double pt = min ? -codac2::oo : codac2::oo; // keep the point less/most distant from +oo (we normalize if the lower bound is -oo) + selected_index = i; + + for(; i < this->size() ; i++) + { + if((this->data()+i)->lb() == -codac2::oo) + { + if((this->data()+i)->ub() == codac2::oo) + if(!min) + { + selected_index = i; + break; + } + + if((min && (-(this->data()+i)->ub() > pt)) || (!min && (-(this->data()+i)->ub() < pt))) + { + selected_index = i; + pt = -(this->data()+i)->ub(); + } + } + + else if((this->data()+i)->ub() == codac2::oo) + if((min && ((this->data()+i)->lb() > pt)) || (!min && ((this->data()+i)->lb() < pt))) + { + selected_index = i; + pt = (this->data()+i)->lb(); + } + } + } + + return selected_index; +} + +template + requires IsIntervalDomain +inline void set_empty() +{ + this->init(codac2::Interval::empty()); +} + +template + requires IsIntervalDomain +inline auto& inflate(double r) +{ + assert_release(r >= 0.); + + for(Index i = 0 ; i < this->size() ; i++) + (this->data()+i)->inflate(r); + return *this; +} + +template + requires IsIntervalDomain +inline auto& inflate(const MatrixBase& r) +{ + assert_release(this->size() == r.size()); + assert_release(r.min_coeff() >= 0.); + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + (*this)(i,j).inflate(r(i,j)); + return *this; +} + +template + requires IsIntervalDomain +inline auto& operator&=(const MatrixBase& x) +{ + assert_release(this->size() == x.size()); + + if constexpr(std::is_same_v::Scalar,codac2::Interval>) + { + if(x.is_empty()) + { + set_empty(); + return *this; + } + } + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + (*this)(i,j) &= x(i,j); + return *this; +} + +template + requires IsIntervalDomain +inline auto& operator|=(const MatrixBase& x) +{ + assert_release(this->size() == x.size()); + + if constexpr(std::is_same_v::Scalar,codac2::Interval>) + { + if(x.is_empty()) + return *this; + } + + for(Index i = 0 ; i < this->rows() ; i++) + for(Index j = 0 ; j < this->cols() ; j++) + (*this)(i,j) |= x(i,j); + return *this; +} + +template + requires IsIntervalDomain +inline auto operator&(const MatrixBase& x) const +{ + auto y = *this; + return y &= x; +} + +template + requires IsIntervalDomain +inline auto operator|(const MatrixBase& x) const +{ + auto y = *this; + return y |= x; +} + +template + requires IsIntervalDomain +inline static auto empty(Index r, Index c) +{ + assert_release(r >= 0 && c >= 0); + Matrix e(r,c); + return e.init(codac2::Interval::empty()); +} + +template + requires IsIntervalDomain +inline auto bisect(Index i, float ratio = 0.49) const +{ + assert_release(i >= 0 && i < this->size()); + assert_release((this->data()+i)->is_bisectable()); + assert_release(codac2::Interval(0,1).interior_contains(ratio)); + + auto p = std::make_pair(*this,*this); + auto pi = (this->data()+i)->bisect(ratio); + *(p.first.data()+i) = pi.first; + *(p.second.data()+i) = pi.second; + return p; +} + +template + requires IsIntervalDomain +inline auto bisect_largest(float ratio = 0.49) const +{ + return bisect(max_diam_index(), ratio); +} \ No newline at end of file diff --git a/src/core/domains/interval/eigen/codac2_IntervalVector_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalVector.h similarity index 58% rename from src/core/domains/interval/eigen/codac2_IntervalVector_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalVector.h index 3da9e38c..1ff3fd2c 100644 --- a/src/core/domains/interval/eigen/codac2_IntervalVector_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_IntervalVector.h @@ -1,5 +1,5 @@ /** - * \file codac2_IntervalVector_eigenaddons.h + * \file codac2_Matrix_addons_IntervalVector.h * * This class reuses some of the functions developed for ibex::IntervalVector. * The original IBEX code is revised in modern C++ and adapted to the template @@ -84,23 +84,6 @@ Matrix(int n, const double bounds[][2]) assert_release(n > 0); } -//template -// requires IsIntervalDomain && IsVectorOrRow -//explicit Matrix(std::initializer_list> l) -// : Matrix( -// [&]() -> int { if constexpr(R == 1) return 1; else return l.size(); }(), -// [&]() -> int { if constexpr(C == 1) return 1; else return l.size(); }() -// ) -//{ -// assert_release(!std::empty(l)); -// Index i = 0; -// for(const auto& li : l) -// { -// assert_release(!std::empty(li)); -// (*this)[i++] = codac2::Interval(li); -// } -//} - template requires IsIntervalDomain && IsVectorOrRow inline static auto empty(Index n) @@ -110,74 +93,4 @@ inline static auto empty(Index n) return Matrix((int)n,codac2::Interval::empty()); else return Matrix((int)n,codac2::Interval::empty()); -} - -template - requires IsIntervalDomain && IsVectorOrRow -inline auto complementary() const -{ - return Matrix((int)this->size()).diff(*this); -} - -template - requires IsIntervalDomain && IsVectorOrRow -inline std::list> diff(const Matrix& y, bool compactness = true) const -{ - // This code originates from the ibex-lib - // See: ibex_TemplateVector.h - // Author: Gilles Chabert - // It has been revised with modern C++ and templated types - - const Index n = this->size(); - assert_release(y.size() == n); - - if(y == *this) - return { }; - - Matrix x = *this; - Matrix z = x & y; - - if(z.is_empty()) - { - if(x.is_empty()) return { }; - else return { x }; - } - - else - { - // Check if in one dimension y is flat and x not, - // in which case the diff returns also x directly - if(compactness) - for(Index i = 0 ; i < n ; i++) - if(z[i].is_degenerated() && !x[i].is_degenerated()) - { - if(x.is_empty()) return { }; - else return { x }; - } - } - - std::list> l; - - for(Index var = 0 ; var < n ; var++) - { - codac2::Interval c1, c2; - - for(const auto& ci : x[var].diff(y[var], compactness)) - { - assert(!ci.is_empty()); - - Matrix v(n); - for(Index i = 0 ; i < var ; i++) - v[i] = x[i]; - v[var] = ci; - for(Index i = var+1 ; i < n ; i++) - v[i] = x[i]; - if(!v.is_empty()) - l.push_back(v); - } - - x[var] = z[var]; - } - - return l; } \ No newline at end of file diff --git a/src/core/matrices/eigen/codac2_Matrix_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Matrix.h similarity index 95% rename from src/core/matrices/eigen/codac2_Matrix_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Matrix.h index 90c6ec54..f6d28008 100644 --- a/src/core/matrices/eigen/codac2_Matrix_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Matrix.h @@ -1,5 +1,5 @@ /** - * \file codac2_Matrix_eigenaddons.h + * \file codac2_Matrix_addons_Matrix.h * * This class reuses some of the functions developed for ibex::Matrix. * The original IBEX code is revised in modern C++ and adapted to the template diff --git a/src/core/matrices/eigen/codac2_MatrixBase_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_MatrixBase.h similarity index 98% rename from src/core/matrices/eigen/codac2_MatrixBase_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_MatrixBase.h index 7d68049d..a4c30c33 100644 --- a/src/core/matrices/eigen/codac2_MatrixBase_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_MatrixBase.h @@ -1,5 +1,5 @@ /** - * \file codac2_MatrixBase_eigenaddons.h + * \file codac2_Matrix_addons_MatrixBase.h * * This file is included in the declaration of Eigen::MatrixBase, * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. diff --git a/src/core/matrices/eigen/codac2_Vector_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Vector.h similarity index 75% rename from src/core/matrices/eigen/codac2_Vector_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Vector.h index 4ad8c346..a48b9ef9 100644 --- a/src/core/matrices/eigen/codac2_Vector_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_Vector.h @@ -1,5 +1,5 @@ /** - * \file codac2_Vector_eigenaddons.h + * \file codac2_Matrix_addons_Vector.h * * This file is included in the declaration of Eigen::MatrixBase, * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. @@ -49,24 +49,4 @@ explicit Matrix(int n, double values[]) ) { assert_release(n > 0); -} - -template - requires (!IsIntervalDomain) && (IsVectorOrRow) -inline Index min_coeff_index() const -{ - Index r,c; - this->minCoeff(&r,&c); - assert(c == 0); - return r; -} - -template - requires (!IsIntervalDomain) && (IsVectorOrRow) -inline Index max_coeff_index() const -{ - Index r,c; - this->maxCoeff(&r,&c); - assert(c == 0); - return r; } \ No newline at end of file diff --git a/src/core/matrices/eigen/codac2_VectorBase_eigenaddons.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_VectorBase.h similarity index 82% rename from src/core/matrices/eigen/codac2_VectorBase_eigenaddons.h rename to src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_VectorBase.h index 2f0aa75f..a3d41c5f 100644 --- a/src/core/matrices/eigen/codac2_VectorBase_eigenaddons.h +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_VectorBase.h @@ -1,5 +1,5 @@ /** - * \file codac2_VectorBase_eigenaddons.h + * \file codac2_Matrix_addons_VectorBase.h * * This file is included in the declaration of Eigen::MatrixBase, * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. @@ -25,13 +25,6 @@ explicit Matrix(int n, const Scalar& x) init(x); } -template - requires IsVectorOrRow -inline auto diag_matrix() const -{ - return this->asDiagonal().toDenseMatrix(); -} - template requires IsVectorOrRow inline Scalar& operator()(Index i) @@ -94,18 +87,9 @@ inline static Matrix random(Index n) return Matrix::Random(n); } -template - requires IsVectorOrRow -inline auto subvector(Index start_id, Index end_id) const -{ - assert_release(end_id >= 0 && start_id >= 0); - assert_release(end_id < this->size() && start_id <= end_id); - return this->segment(start_id,end_id-start_id+1); -} - -template - requires IsVectorOrRow -inline void put(Index start_id, const Matrix& x) +template + requires IsVectorOrRow && IsVectorOrRow::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> +inline void put(Index start_id, const MatrixBase& x) { assert_release(start_id >= 0 && start_id < this->size()); assert_release(start_id+x.size() <= this->size()); diff --git a/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_include.h b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_include.h new file mode 100644 index 00000000..2802ca6e --- /dev/null +++ b/src/core/matrices/eigen/Matrix_addons/codac2_Matrix_addons_include.h @@ -0,0 +1,23 @@ +/** + * \file codac2_Matrix_addons_include.h + * + * This file is included in the declaration of Eigen::MatrixBase, + * thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. + * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html + * and the file codac2_matrices.h + * + * ---------------------------------------------------------------------------- + * \date 2024 + * \author Simon Rohou + * \copyright Copyright 2023 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include "codac2_Matrix_addons_Base.h" +#include "codac2_Matrix_addons_IntervalMatrix.h" +#include "codac2_Matrix_addons_IntervalMatrixBase.h" +#include "codac2_Matrix_addons_IntervalVector.h" +#include "codac2_Matrix_addons_Matrix.h" +#include "codac2_Matrix_addons_MatrixBase.h" +#include "codac2_Matrix_addons_Vector.h" +#include "codac2_Matrix_addons_VectorBase.h" \ No newline at end of file diff --git a/src/core/matrices/eigen/codac2_eigenaddons_test.h b/src/core/matrices/eigen/codac2_eigenaddons_test.h deleted file mode 100644 index 1b431877..00000000 --- a/src/core/matrices/eigen/codac2_eigenaddons_test.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * \file codac2_eigenaddons.h - * - * This file is included in the declaration of Eigen::MatrixBase, - * thanks to the preprocessor token EIGEN_MATRIXBASE_PLUGIN. - * See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html - * and the file codac2_matrices.h - * - * ---------------------------------------------------------------------------- - * \date 2024 - * \author Simon Rohou - * \copyright Copyright 2023 Codac Team - * \license GNU Lesser General Public License (LGPL) - */ - - - -inline bool is_empty() const -{ - for(Index i = 0 ; i < rows() ; i++) - for(Index j = 0 ; j < cols() ; j++) - if((*this)(i,j).is_empty()) - return true; - return false; -} - - -#define degenerate_matt(op) \ - Matrix op(this->rows(),this->cols()); \ - \ - if(this->is_empty()) \ - op.init(std::numeric_limits::quiet_NaN()); \ - \ - else \ - { \ - for(Index i = 0 ; i < this->rows() ; i++) \ - for(Index j = 0 ; j < this->cols() ; j++) \ - op(i,j) = (*this)(i,j).mid(); \ - } \ - \ - return op; \ - -inline auto mid() const -{ - degenerate_matt(mid); -} \ No newline at end of file diff --git a/tests/core/domains/interval/codac2_tests_IntervalMatrix.cpp b/tests/core/domains/interval/codac2_tests_IntervalMatrix.cpp index f227ea11..2efde4cd 100644 --- a/tests/core/domains/interval/codac2_tests_IntervalMatrix.cpp +++ b/tests/core/domains/interval/codac2_tests_IntervalMatrix.cpp @@ -631,6 +631,35 @@ TEST_CASE("IntervalMatrix - mixing type") IntervalMatrix im_empty(m1,m2); CHECK(im_empty == IntervalMatrix::empty(2,2)); } + + { + IntervalMatrix m1 = IntervalMatrix::ones(3,3); + IntervalMatrix m2 = IntervalMatrix::zeros(3,3); + CHECK(m1.volume() == 0.); + CHECK(m2.volume() == 0.); + CHECK((m1+m2).volume() == 0.); + } + + { + IntervalMatrix m1 { + { {1,2},{2,3} }, + { {3,4},{4,5} } + }; + Matrix m2 { + { 1.5, 2.5 }, + { 3.5, 4.5 } + }; + + CHECK(m1.contains(m2)); + CHECK(m2.template cast().is_strict_subset(m1)); + + Matrix m3(2,2); + m3.init(m2+m2); + CHECK(m3 == Matrix({ + { 3, 5 }, + { 7, 9 } + })); + } } #if 0 diff --git a/tests/core/domains/interval/codac2_tests_IntervalVector.py b/tests/core/domains/interval/codac2_tests_IntervalVector.py index 740d4c35..66edc90b 100644 --- a/tests/core/domains/interval/codac2_tests_IntervalVector.py +++ b/tests/core/domains/interval/codac2_tests_IntervalVector.py @@ -50,7 +50,7 @@ def tests_intervalvector(self): x = IntervalVector(2) x[0] = Interval(0,1) x[1] = Interval(0,1) - self.assertTrue(x == IntervalVector(2,Interval(0,1))) + self.assertTrue(x == IntervalVector([[0,1],[0,1]])) self.assertTrue(x == IntervalVector(x)) #self.assertTrue(x == (IntervalVector(2)=x)) @@ -219,8 +219,8 @@ def tests_intervalvector(self): self.assertTrue(not IntervalVector([[0,1],[2,3],[4,5]]).is_flat()) self.assertTrue(IntervalVector.empty(3).is_flat()) - self.assertTrue(IntervalVector(1,Interval(0,0)).is_flat()) - self.assertTrue(not IntervalVector(1,Interval(0,1)).is_flat()) + self.assertTrue(IntervalVector([[0,0]]).is_flat()) + self.assertTrue(not IntervalVector([[0,1]]).is_flat()) self.assertTrue(IntervalVector([[0,1],[2,2],[3,4]]).is_flat()) self.assertTrue(IntervalVector([[0,1],[2,3],[4,4]]).is_flat()) self.assertTrue(not IntervalVector.empty(3).is_unbounded()) diff --git a/tests/core/functions/analytic/codac2_tests_AnalyticFunction.py b/tests/core/functions/analytic/codac2_tests_AnalyticFunction.py index ffefce83..2dc92337 100644 --- a/tests/core/functions/analytic/codac2_tests_AnalyticFunction.py +++ b/tests/core/functions/analytic/codac2_tests_AnalyticFunction.py @@ -96,7 +96,7 @@ def test_eval(f,*args): # .def("__rmul__", [](const ScalarVar& e1, const Interval& e2) self.assertTrue(test_eval(AnalyticFunction([x1], Interval(6.)*x1), 5.) == 30.) # .def("__mul__", [](const ScalarVar& e1, const VectorVar& e2) - self.assertTrue(test_eval(AnalyticFunction([v1,v2], v1[0]*v2), Vector([5.,10.]),IntervalVector(2,3.)) == Vector([15,15])) + self.assertTrue(test_eval(AnalyticFunction([v1,v2], v1[0]*v2), Vector([5.,10.]),IntervalVector([[3],[3]])) == Vector([15,15])) # .def("__mul__", [](const ScalarVar& e1, const IntervalVector& e2) self.assertTrue(test_eval(AnalyticFunction([x1], x1*IntervalVector([[-2,3],[0,1]])), 5.) == IntervalVector([[-10,15],[0,5]])) # .def("__truediv__", [](const ScalarVar& e1, const ScalarVar& e2)