Skip to content

Commit

Permalink
Merge branch 'codac2_ellipsoids' into codac2_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Jan 19, 2025
2 parents 005bd03 + ef4db0f commit 90d48ff
Show file tree
Hide file tree
Showing 26 changed files with 1,729 additions and 11 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/unixmatrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:
fail-fast: false
matrix:
cfg:
- { os: windows-2022, shell: cmd, arch: x64, bitness: 64, runtime: vc17, cmake_params: '-G "Visual Studio 17" -T v143 -A x64', cmake_flags: ' /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', desc: 'Windows Visual Studio 2022 x64' }
- { os: windows-2022, shell: cmd, arch: x86, bitness: 32, runtime: vc17, cmake_params: '-G "Visual Studio 17" -T v143 -A Win32', cmake_flags: ' /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', choco_flags: '--x86', desc: 'Windows Visual Studio 2022 x86' }
- { os: windows-2022, shell: cmd, arch: x64, bitness: 64, runtime: vc17, cmake_params: '-G "Visual Studio 17" -T v143 -A x64', cmake_flags: ' /MP4 /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', desc: 'Windows Visual Studio 2022 x64' }
- { os: windows-2022, shell: cmd, arch: x86, bitness: 32, runtime: vc17, cmake_params: '-G "Visual Studio 17" -T v143 -A Win32', cmake_flags: ' /MP4 /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', choco_flags: '--x86', desc: 'Windows Visual Studio 2022 x86' }
# Problems related to C++20?
#- { os: windows-2022, shell: cmd, arch: x64, bitness: 64, runtime: vc16, cmake_params: '-G "Visual Studio 17" -T v142 -A x64', cmake_flags: ' /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', desc: 'Windows Visual Studio 2019 x64' }
#- { os: windows-2022, shell: cmd, arch: x86, bitness: 32, runtime: vc16, cmake_params: '-G "Visual Studio 17" -T v142 -A Win32', cmake_flags: ' /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', choco_flags: '--x86', desc: 'Windows Visual Studio 2019 x86' }
#- { os: windows-2019, shell: cmd, arch: x64, bitness: 64, runtime: vc15, cmake_params: '-G "Visual Studio 16" -T v141 -A x64', cmake_flags: ' /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', desc: 'Windows Visual Studio 2017 x64' }
#- { os: windows-2019, shell: cmd, arch: x86, bitness: 32, runtime: vc15, cmake_params: '-G "Visual Studio 16" -T v141 -A Win32', cmake_flags: ' /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', choco_flags: '--x86', desc: 'Windows Visual Studio 2017 x86' }
#- { os: windows-2022, shell: cmd, arch: x64, bitness: 64, runtime: vc16, cmake_params: '-G "Visual Studio 17" -T v142 -A x64', cmake_flags: ' /MP4 /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', desc: 'Windows Visual Studio 2019 x64' }
#- { os: windows-2022, shell: cmd, arch: x86, bitness: 32, runtime: vc16, cmake_params: '-G "Visual Studio 17" -T v142 -A Win32', cmake_flags: ' /MP4 /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', choco_flags: '--x86', desc: 'Windows Visual Studio 2019 x86' }
#- { os: windows-2019, shell: cmd, arch: x64, bitness: 64, runtime: vc15, cmake_params: '-G "Visual Studio 16" -T v141 -A x64', cmake_flags: ' /MP4 /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', desc: 'Windows Visual Studio 2017 x64' }
#- { os: windows-2019, shell: cmd, arch: x86, bitness: 32, runtime: vc15, cmake_params: '-G "Visual Studio 16" -T v141 -A Win32', cmake_flags: ' /MP4 /wd4267 /wd4244 /wd4305 /wd4996', test_config: 'Release/', choco_flags: '--x86', desc: 'Windows Visual Studio 2017 x86' }
- { os: windows-2022, shell: cmd, arch: x64, bitness: 64, runtime: mingw13, cmake_params: '-G "MinGW Makefiles"', cmake_flags: '-fPIC', desc: 'Windows MinGW 13.2.0 x64' }
- { os: windows-2022, shell: cmd, arch: x86, bitness: 32, runtime: mingw13, cmake_params: '-G "MinGW Makefiles"', cmake_flags: '-fPIC', choco_flags: '--x86', desc: 'Windows MinGW 13.2.0 x86' }
- { os: windows-2022, shell: cmd, arch: x64, bitness: 64, runtime: mingw12, cmake_params: '-G "MinGW Makefiles"', cmake_flags: '-fPIC', desc: 'Windows MinGW 12.2.0 x64' }
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
echo export BASHMINGWPATH=/c/ProgramData/mingw64/mingw${{ matrix.cfg.bitness }}/bin>>%USERPROFILE%\.bashrc
if: (matrix.cfg.runtime=='mingw13')
- run: |
#choco install -y -r --no-progress eigen --version=3.4.0.20240224 ${{ matrix.cfg.choco_flags }}
rem choco install -y -r --no-progress eigen --version=3.4.0.20240224 ${{ matrix.cfg.choco_flags }}
wget https://github.com/lebarsfa/ibex-lib/releases/download/ibex-2.8.9.20241117/ibex.2.8.9.20241117.nupkg --no-check-certificate -nv
choco install -y -r --no-progress --ignore-dependencies -s . ibex --version=2.8.9.20241117 ${{ matrix.cfg.choco_flags }} --params "'/url:https://github.com/lebarsfa/ibex-lib/releases/download/ibex-2.8.9.20241117/ibex_${{ matrix.cfg.arch }}_${{ matrix.cfg.runtime }}.zip'"
del /f /q ibex.2.8.9.20241117.nupkg
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vcmatrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
del /f /q ibex.2.8.9.20241117.nupkg
- run: |
mkdir build ; cd build
cmake -E env CXXFLAGS=" /wd4267 /wd4244 /wd4305 /wd4996" CFLAGS=" /wd4267 /wd4244 /wd4305 /wd4996" cmake ${{ matrix.cfg.cmake_params }} -D CMAKE_INSTALL_PREFIX="../codac" -D BUILD_TESTS=ON -D WITH_CAPD=OFF -D WITH_PYTHON=ON ..
cmake -E env CXXFLAGS=" /MP4 /wd4267 /wd4244 /wd4305 /wd4996" CFLAGS=" /MP4 /wd4267 /wd4244 /wd4305 /wd4996" cmake ${{ matrix.cfg.cmake_params }} -D CMAKE_INSTALL_PREFIX="../codac" -D BUILD_TESTS=ON -D WITH_CAPD=OFF -D WITH_PYTHON=ON ..
cmake --build . -j 4 --config Release --target install
cmake --build . --config Release --target pip_package ; cp `ls *.whl` ../`ls *.whl | sed "s/py3-none-any/cp${{ matrix.cfg.py_v_maj }}${{ matrix.cfg.py_v_min }}-cp${{ matrix.cfg.py_v_maj }}${{ matrix.cfg.py_v_min }}${{ matrix.cfg.cpcfg }}/"`
cd ..
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Temporary attempts to fix errors similar to:
# _ number of sections exceeded object file format limit.
# _ out of memory allocating XXX bytes.
# _ string table overflow.
# _ .obj: file too big.
if(MSVC)
add_compile_options(/bigobj)
elseif(MINGW)
add_compile_options(-Wa,-mbig-obj)
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
add_compile_options(-g0)
endif()
endif()

# # Check that the compiler supports c++20
# include(CheckCXXCompilerFlag)
# check_cxx_compiler_flag("-std=c++2a" COMPILER_SUPPORTS_CXX20)
Expand Down
44 changes: 44 additions & 0 deletions examples/ellipsoid_dev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ==================================================================
# codac / ellipsoid example - cmake configuration file
# ==================================================================

cmake_minimum_required(VERSION 3.0.2)
project(ellipsoid_dev LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Adding IBEX

# In case you installed IBEX in a local directory, you need
# to specify its path with the CMAKE_PREFIX_PATH option.
# set(CMAKE_PREFIX_PATH "~/ibex-lib/build_install")

find_package(IBEX REQUIRED)
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
# to specify its path with the CMAKE_PREFIX_PATH option.
set(CMAKE_PREFIX_PATH "~/Documents/Code_these/codac/build_install")

find_package(CODAC REQUIRED)
message(STATUS "Found Codac version ${CODAC_VERSION}")

# Compilation

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)
123 changes: 123 additions & 0 deletions examples/ellipsoid_dev/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <codac>

using namespace std;
using namespace codac2;

int main() {
// ----------------------------------------------------------
// ellipsoid projections
// ----------------------------------------------------------

Vector mu4({1., 0., 0.});
Matrix G4({{1., 0.5, 0.},
{0.5, 2., 0.2},
{0., 0.2, 3.}});
Ellipsoid e4(mu4, G4);

Matrix G5 = 0.7 * G4;
Ellipsoid e5(mu4, G5);

Matrix G6({{2., 0., 0.5},
{0., 1., 0.2},
{0., 0.2, 3.}});
Ellipsoid e6(mu4, G6);

Figure2D fig2("Projected ellipsoid xy", GraphicOutput::VIBES);
Figure2D fig3("Projected ellipsoid yz", GraphicOutput::VIBES);
Figure2D fig4("Projected ellipsoid xz", GraphicOutput::VIBES);

fig2.set_window_properties({700, 100}, {500, 500});
fig3.set_window_properties({1200, 100}, {500, 500});
fig4.set_window_properties({0, 100}, {500, 500});

fig2.set_axes(axis(0, {-3, 3}), axis(1, {-3, 3}));
fig3.set_axes(axis(1, {-3, 3}), axis(2, {-3, 3}));
fig4.set_axes(axis(0, {-3, 3}), axis(2, {-3, 3}));

fig2.draw_ellipsoid(e4, {Color::blue(), Color::blue(0.3)});
fig3.draw_ellipsoid(e4, {Color::blue(), Color::blue(0.3)});
fig4.draw_ellipsoid(e4, {Color::blue(), Color::blue(0.3)});

fig2.draw_ellipsoid(e5, {Color::red(), Color::red(0.3)});
fig3.draw_ellipsoid(e5, {Color::red(), Color::red(0.3)});
fig4.draw_ellipsoid(e5, {Color::red(), Color::red(0.3)});

fig2.draw_ellipsoid(e6, {Color::green(), Color::green(0.3)});
fig3.draw_ellipsoid(e6, {Color::green(), Color::green(0.3)});
fig4.draw_ellipsoid(e6, {Color::green(), Color::green(0.3)});

// ----------------------------------------------------------
// inclusion tests
// ----------------------------------------------------------

cout << "\nInclusion test e5 in e4: " << e5.is_concentric_subset(e4) << endl;

cout << "Inclusion test e4 in e5: " << e4.is_concentric_subset(e5) << endl;

cout << "Inclusion test e4 in e6: " << e6.is_concentric_subset(e4) << endl;

cout << "Inclusion test e5 in e6: " << e5.is_concentric_subset(e6) << endl;

// ----------------------------------------------------------
// test the non inclusion (e4 in e6)
// ----------------------------------------------------------

// step 1 identify the direction of non inclusion
Eigen::MatrixXd X = e4.G;
Eigen::MatrixXd Y = e6.G;
Eigen::MatrixXd Y_inv = Y.inverse();
Eigen::MatrixXd D = Eigen::MatrixXd::Identity(3,3)- X.transpose()*Y_inv.transpose()*Y_inv*X;
cout << "D = " << D << endl;

Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es(D);
Eigen::VectorXd eigenvalues = es.eigenvalues();

Eigen::VectorXd v;
double min_eigenvalue = MAXFLOAT;
for (int i = 0; i < eigenvalues.size(); i++){
if (eigenvalues(i) < min_eigenvalue){
min_eigenvalue = eigenvalues(i);
v = es.eigenvectors().col(i); // the vector associated to the smallest eigenvalue
}
}
cout << " the min eigenvalue of D is " << min_eigenvalue << endl;
cout << " the vector associated to the min eigenvalue is " << v << endl;

// select the less included point and draw it on the figures
Eigen::VectorXd x = e4.mu+e4.G*v;
cout << "the point " << x << " is the less included point" << endl;
fig2.draw_point(x, {Color::black()});
fig3.draw_point(x, {Color::black()});
fig4.draw_point(x, {Color::black()});

// IntervalVector x6(x);
// x6.inflate(0.001);
// fig2.draw_box(x6, {Color::black(), Color::black()});

// now let us prove by intervals that x is out of e6
// by proving (x-mu6).T@G6^(-T)@G6^(-1)@(x-mu6) > 1

IntervalVector w(x);
w -= IntervalVector(e6.mu);

IntervalMatrix Q(Y_inv);
Q = Q.transpose()*Q;

IntervalMatrix res = w.transpose()*Q*w;
cout << "the result of the inclusion test is " << res << endl;

if(res(0,0).lb() > 1.) {
cout << "the point is out of the ellipsoid" << endl;
cout << "the non inclusion is guaranteed" << endl;
}

// can we also prove that x is in e4? -> we should take the point not on the boundary or
// have guaranteed operations previously
Eigen::MatrixXd X_inv = X.inverse();
IntervalMatrix Qx(X_inv);
Qx = Qx.transpose()*Qx;

IntervalMatrix res2 = w.transpose()*Qx*w;
cout << "the result of the inclusion test in e4 is " << res2 << endl;

}
44 changes: 44 additions & 0 deletions examples/ellipsoid_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ==================================================================
# codac / ellipsoid example - cmake configuration file
# ==================================================================

cmake_minimum_required(VERSION 3.0.2)
project(codac_example LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Adding IBEX

# In case you installed IBEX in a local directory, you need
# to specify its path with the CMAKE_PREFIX_PATH option.
# set(CMAKE_PREFIX_PATH "~/ibex-lib/build_install")

find_package(IBEX REQUIRED)
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
# to specify its path with the CMAKE_PREFIX_PATH option.
set(CMAKE_PREFIX_PATH "~/Documents/Code_these/codac/build_install")

find_package(CODAC REQUIRED)
message(STATUS "Found Codac version ${CODAC_VERSION}")

# Compilation

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)
Loading

0 comments on commit 90d48ff

Please sign in to comment.