Skip to content

Commit

Permalink
Merge pull request #137 from SimonRohou/codac2_eigen
Browse files Browse the repository at this point in the history
Codac2 eigen: revised matrix types (using EIGEN_MATRIX_PLUGIN)
  • Loading branch information
SimonRohou authored Nov 21, 2024
2 parents 7689f45 + 5921d4c commit 8810533
Show file tree
Hide file tree
Showing 158 changed files with 2,810 additions and 3,453 deletions.
2 changes: 1 addition & 1 deletion doc/api/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = ../src/core/graphics/vibes/
EXCLUDE = ../src/graphics/3rd/vibes/

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
2 changes: 1 addition & 1 deletion examples/02_centered_form/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
2*x[2]*cos(x[2]*x[0])-sin(x[2]*x[1])
))

ctc = CtcInverse(f, [[0],[0]])
ctc = CtcInverse(f, [0,0])
graphics.draw_while_paving([[0,2],[2,4],[0,10]], ctc, 0.004)
2 changes: 1 addition & 1 deletion examples/02_centered_form/main_evans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main()
2*x[0]*x[1]+2*exp(-x[0]*x[2])*(x[1]*cos(x[1]*x[2])-x[0]*sin(x[1]*x[2]))-exp(-x[0]*x[3])*sin(x[1]*x[3])
));

CtcInverse_<IntervalVector> ctc(f, {{0.},{0.}});
CtcInverse_<IntervalVector> ctc(f, {0.,0.});
IntervalVector x0({{-10,10},{0,20},{1,1},{2,2}});

shared_ptr<Figure2D> g = make_shared<Figure2D>("Evans", GraphicOutput::VIBES);
Expand Down
12 changes: 7 additions & 5 deletions examples/02_centered_form/main_parabolas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ int main()
);

AnalyticFunction h({a}, fa(a[0],a[1])-fb(a[2],a[3]));
CtcInverse_<IntervalVector> ctc(h, {{0.},{0.},{0.}});
CtcInverse_<IntervalVector> ctc(h, {0.,0.,0.});

// to be restored...
/*IntervalVector x0({{0,1},{0,1},{0,1},{0,1}});
Paver p(x0);
IntervalVector x0({{0,1},{0,1},{0,1},{0,1}});
draw_while_paving(x0, ctc, 0.001);

/*
// to be restored...
Figure2D g("(u1,v1)", GraphicOutput::VIBES);
g.set_axes(axis(0,x0[0]), axis(1,x0[1]));
g.set_window_properties({100,100},{600,600});
Expand All @@ -42,5 +43,6 @@ int main()
l_34.push_back(fb.eval_centered(li[2],li[3]));
}
export_to_ObjectFileFormat(l_12, "output_u1v1.off");
export_to_ObjectFileFormat(l_34, "output_u2v2.off");*/
export_to_ObjectFileFormat(l_34, "output_u2v2.off");
*/
}
2 changes: 1 addition & 1 deletion examples/02_centered_form/main_parabolas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
IntervalVector([[2],[0],[0.55]]),IntervalVector([[2],[1],[-0.45]]),IntervalVector([[2],[2],[0.55]]))
)

ctc = CtcInverse(h, [[0],[0],[0]])
ctc = CtcInverse(h, [0,0,0])
draw_while_paving([[0,1],[0,1],[0,1],[0,1]], ctc, 0.001)
8 changes: 5 additions & 3 deletions python/src/codac2_py_matlab.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

#pragma once

#include <codac2_Index.h>

#define FOR_MATLAB false

namespace codac2
{
#if FOR_MATLAB
using size_t_type = double;
using Index_type = double;
using int_type = double;
#else
using size_t_type = size_t;
using Index_type = Index;
using int_type = int;
#endif

Expand All @@ -40,7 +42,7 @@ namespace codac2
}

template<typename I>
size_t input_index(const I& x)
Index input_index(const I& x)
{
if constexpr(FOR_MATLAB)
return x-1;
Expand Down
2 changes: 1 addition & 1 deletion python/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
matrices/codac2_py_arithmetic_div.cpp
matrices/codac2_py_Matrix.cpp
matrices/codac2_py_MatrixBase.h
matrices/codac2_py_MatrixBaseBlock.h
matrices/codac2_py_MatrixBlock.h
matrices/codac2_py_Vector.cpp
matrices/codac2_py_VectorBase.h

Expand Down
4 changes: 2 additions & 2 deletions python/src/core/actions/codac2_py_OctaSym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void export_OctaSym(py::module& m)
{
vector<int> v(l.size());

size_t i = 0;
Index i = 0;
for(const auto& li : l)
{
matlab::test_integer(li);
Expand All @@ -57,7 +57,7 @@ void export_OctaSym(py::module& m)
.def(py::self != py::self)

.def("__call__", [](const OctaSym& a, const IntervalVector& x) { return a(x); },
INTERVALVECTOR_OCTASYM_OPERATORCALL_CONST_INTERVALVECTOR_REF_CONST,
MAT_TMINUSONE1_OCTASYM_OPERATORCALL_CONST_MAT_TMINUSONE1_REF_CONST,
"x"_a)

.def("__call__", [](const OctaSym& a, const pyCtcIntervalVector& c) { return CtcAction(c.copy(),a); },
Expand Down
26 changes: 18 additions & 8 deletions python/src/core/codac2_py_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include <codac2_Interval.h>
#include <codac2_AnalyticFunction.h>
#include <codac2_analytic_values.h>
#include <codac2_Row.h>
#include <codac2_IntervalRow.h>
#include "codac2_py_AnalyticFunction.h"
#include "codac2_py_CtcInverse.h"
#include "codac2_py_CtcInverseNotIn.h"
#include "codac2_py_SepInverse.h"
#include "codac2_py_MatrixBaseBlock.h"
#include "codac2_py_MatrixBlock.h"

using namespace codac2;
namespace py = pybind11;
Expand Down Expand Up @@ -52,6 +54,7 @@ void export_linear_ctc(py::module& m);
void export_BoolInterval(py::module& m);
py::class_<Interval> export_Interval(py::module& m);
void export_Interval_operations(py::module& m, py::class_<Interval>& py_Interval);
py::class_<IntervalRow> export_IntervalRow(py::module& m);
py::class_<IntervalVector> export_IntervalVector(py::module& m);
py::class_<IntervalMatrix> export_IntervalMatrix(py::module& m);
void export_Paving(py::module& m);
Expand All @@ -73,19 +76,20 @@ void export_Polygon(py::module& m);
void export_arithmetic_add(py::module& m,
py::class_<Vector>& py_V, py::class_<IntervalVector>& py_IV,
py::class_<Matrix>& py_M, py::class_<IntervalMatrix>& py_IM,
py::class_<MatrixBaseBlock<Matrix::EigenType&,double>>& py_B, py::class_<MatrixBaseBlock<IntervalMatrix::EigenType&,Interval>>& py_IB);
py::class_<Eigen::Block<Matrix>>& py_B, py::class_<Eigen::Block<IntervalMatrix>>& py_IB);
void export_arithmetic_sub(py::module& m,
py::class_<Vector>& py_V, py::class_<IntervalVector>& py_IV,
py::class_<Matrix>& py_M, py::class_<IntervalMatrix>& py_IM,
py::class_<MatrixBaseBlock<Matrix::EigenType&,double>>& py_B, py::class_<MatrixBaseBlock<IntervalMatrix::EigenType&,Interval>>& py_IB);
py::class_<Eigen::Block<Matrix>>& py_B, py::class_<Eigen::Block<IntervalMatrix>>& py_IB);
void export_arithmetic_mul(py::module& m,
py::class_<Vector>& py_V, py::class_<IntervalVector>& py_IV,
py::class_<Matrix>& py_M, py::class_<IntervalMatrix>& py_IM,
py::class_<MatrixBaseBlock<Matrix::EigenType&,double>>& py_B, py::class_<MatrixBaseBlock<IntervalMatrix::EigenType&,Interval>>& py_IB);
py::class_<Eigen::Block<Matrix>>& py_B, py::class_<Eigen::Block<IntervalMatrix>>& py_IB);
void export_arithmetic_div(py::module& m,
py::class_<Vector>& py_V, py::class_<IntervalVector>& py_IV,
py::class_<Matrix>& py_M, py::class_<IntervalMatrix>& py_IM,
py::class_<MatrixBaseBlock<Matrix::EigenType&,double>>& py_B, py::class_<MatrixBaseBlock<IntervalMatrix::EigenType&,Interval>>& py_IB);
py::class_<Eigen::Block<Matrix>>& py_B, py::class_<Eigen::Block<IntervalMatrix>>& py_IB);
py::class_<Row> export_Row(py::module& m);
py::class_<Vector> export_Vector(py::module& m);
py::class_<Matrix> export_Matrix(py::module& m);

Expand Down Expand Up @@ -147,17 +151,23 @@ PYBIND11_MODULE(_core, m)
export_linear_ctc(m);

// matrices
auto py_M = export_Matrix(m);
py::class_<Row> exported_row_class(m, "Row", DOC_TO_BE_DEFINED);
auto py_V = export_Vector(m);
auto py_B = export_MatrixBaseBlock<Matrix,double>(m, "MatrixBaseBlock_Matrix_double");
auto py_M = export_Matrix(m);
auto py_B = export_EigenBlock<Matrix>(m, "MatrixBlock");
export_EigenBlock<Row>(m, "RowBlock");
export_EigenBlock<Vector>(m, "VectorBlock");

// domains
export_BoolInterval(m);
auto py_Interval = export_Interval(m);
export_Interval_operations(m, py_Interval);
py::class_<IntervalRow> exported_intervalrow_class(m, "IntervalRow", DOC_TO_BE_DEFINED);
auto py_IV = export_IntervalVector(m);
auto py_IM = export_IntervalMatrix(m);
auto py_IB = export_MatrixBaseBlock<IntervalMatrix,Interval>(m, "MatrixBaseBlock_IntervalMatrix_Interval");
auto py_IB = export_EigenBlock<IntervalMatrix>(m, "IntervalMatrixBlock");
export_EigenBlock<IntervalRow>(m, "IntervalRowBlock");
export_EigenBlock<IntervalVector>(m, "IntervalVectorBlock");

export_arithmetic_add(m, py_V, py_IV, py_M, py_IM, py_B, py_IB);
export_arithmetic_sub(m, py_V, py_IV, py_M, py_IM, py_B, py_IB);
Expand Down
6 changes: 3 additions & 3 deletions python/src/core/contractors/codac2_py_Ctc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ py::class_<CtcBase<IntervalVector>,pyCtcIntervalVector> export_CtcIntervalVector
py::class_<CtcBase<IntervalVector>,pyCtcIntervalVector> py_ctc_iv(m, "CtcIntervalVector"/*, py_ctc*/);
py_ctc_iv

.def(py::init<size_t>(),
CTCBASE_X_CTCBASE_SIZET)
.def(py::init<Index>(),
CTCBASE_X_CTCBASE_INDEX)

.def("size", &CtcBase<IntervalVector>::size,
SIZET_CTCBASE_X_SIZE_CONST)
INDEX_CTCBASE_X_SIZE_CONST)

.def("copy", [](const CtcBase<IntervalVector>& c)
{
Expand Down
2 changes: 1 addition & 1 deletion python/src/core/contractors/codac2_py_Ctc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class pyCtcIntervalVector : public CtcBase<IntervalVector>
{
public:

pyCtcIntervalVector(size_t_type n)
pyCtcIntervalVector(Index_type n)
: CtcBase<IntervalVector>(n)
{
matlab::test_integer(n);
Expand Down
4 changes: 2 additions & 2 deletions python/src/core/contractors/codac2_py_CtcEmpty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void export_CtcEmpty(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInte
py::class_<CtcEmpty> exported(m, "CtcEmpty", pyctc, CTCEMPTY_MAIN);
exported

.def(py::init<size_t>(),
CTCEMPTY_CTCEMPTY_SIZET
.def(py::init<Index>(),
CTCEMPTY_CTCEMPTY_INDEX
"n"_a)

.def(CONTRACT_BOX_METHOD(CtcEmpty,
Expand Down
4 changes: 2 additions & 2 deletions python/src/core/contractors/codac2_py_CtcIdentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void export_CtcIdentity(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcI
py::class_<CtcIdentity> exported(m, "CtcIdentity", pyctc, CTCIDENTITY_MAIN);
exported

.def(py::init<size_t>(),
CTCIDENTITY_CTCIDENTITY_SIZET
.def(py::init<Index>(),
CTCIDENTITY_CTCIDENTITY_INDEX
"n"_a)

.def(CONTRACT_BOX_METHOD(CtcIdentity,
Expand Down
4 changes: 2 additions & 2 deletions python/src/core/contractors/codac2_py_CtcInter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void export_CtcInter(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInte
py::class_<CtcInter<IntervalVector>> exported(m, "CtcInter", pyctc, CTCINTER_MAIN);
exported

.def(py::init<size_t>(),
CTCINTER_X_CTCINTER_SIZET,
.def(py::init<Index>(),
CTCINTER_X_CTCINTER_INDEX,
"n"_a)

.def(py::init(
Expand Down
12 changes: 6 additions & 6 deletions python/src/core/contractors/codac2_py_CtcProj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ void export_CtcProj(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInter
exported

.def(py::init(
[](const CtcBase<IntervalVector>& c, std::vector<size_t_type> proj_indices, double default_eps)
[](const CtcBase<IntervalVector>& c, std::vector<Index_type> proj_indices, double default_eps)
{
std::transform(std::begin(proj_indices),std::end(proj_indices),std::begin(proj_indices),
[](size_t_type x)
[](Index_type x)
{
matlab::test_integer(x);
return matlab::input_index(x);
});

return std::make_unique<CtcProj>(c.copy(), proj_indices, default_eps);
}),
CTCPROJ_CTCPROJ_CONST_C_REF_CONST_VECTOR_SIZET_REF_DOUBLE,
CTCPROJ_CTCPROJ_CONST_C_REF_CONST_VECTOR_INDEX_REF_DOUBLE,
"c"_a, "proj_indices"_a, "default_eps"_a=0.01)

.def(py::init(
[](const CtcBase<IntervalVector>& c, std::vector<size_t_type> proj_indices, const IntervalVector& y, double default_eps)
[](const CtcBase<IntervalVector>& c, std::vector<Index_type> proj_indices, const IntervalVector& y, double default_eps)
{
std::transform(std::begin(proj_indices),std::end(proj_indices),std::begin(proj_indices),
[](size_t_type x)
[](Index_type x)
{
matlab::test_integer(x);
return matlab::input_index(x);
});

return std::make_unique<CtcProj>(c.copy(), proj_indices, y, default_eps);
}),
CTCPROJ_CTCPROJ_CONST_C_REF_CONST_VECTOR_SIZET_REF_CONST_INTERVALVECTOR_REF_DOUBLE,
CTCPROJ_CTCPROJ_CONST_C_REF_CONST_VECTOR_INDEX_REF_CONST_INTERVALVECTOR_REF_DOUBLE,
"c"_a, "proj_indices"_a, "y"_a, "default_eps"_a=0.01)

.def("contract", (void(CtcProj::*)(IntervalVector&,double) const) &CtcProj::contract,
Expand Down
4 changes: 2 additions & 2 deletions python/src/core/contractors/codac2_py_CtcUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void export_CtcUnion(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInte
py::class_<CtcUnion<IntervalVector>> exported(m, "CtcUnion", pyctc, CTCUNION_MAIN);
exported

.def(py::init<size_t>(),
CTCUNION_X_CTCUNION_SIZET,
.def(py::init<Index>(),
CTCUNION_X_CTCUNION_INDEX,
"n"_a)

.def(py::init(
Expand Down
8 changes: 4 additions & 4 deletions python/src/core/contractors/codac2_py_directed_ctc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ void export_directed_ctc(py::module& m)

py::class_<ComponentOp>(m, "ComponentOp")

.def_static("fwd", (Interval(*)(const IntervalVector&,size_t)) &ComponentOp::fwd,
STATIC_INTERVAL_COMPONENTOP_FWD_CONST_INTERVALVECTOR_REF_SIZET,
.def_static("fwd", (Interval(*)(const IntervalVector&,Index)) &ComponentOp::fwd,
STATIC_INTERVAL_COMPONENTOP_FWD_CONST_INTERVALVECTOR_REF_INDEX,
"x1"_a, "i"_a)
.def_static("bwd", (void(*)(const Interval&,IntervalVector&,size_t)) &ComponentOp::bwd,
STATIC_VOID_COMPONENTOP_BWD_CONST_INTERVAL_REF_INTERVALVECTOR_REF_SIZET,
.def_static("bwd", (void(*)(const Interval&,IntervalVector&,Index)) &ComponentOp::bwd,
STATIC_VOID_COMPONENTOP_BWD_CONST_INTERVAL_REF_INTERVALVECTOR_REF_INDEX,
"y"_a, "x1"_a, "i"_a)

;
Expand Down
2 changes: 1 addition & 1 deletion python/src/core/domains/interval/codac2_py_Interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ py::class_<Interval> export_Interval(py::module& m)
DOUBLE_INTERVAL_VOLUME_CONST)

.def("size", &Interval::size,
SIZET_INTERVAL_SIZE_CONST)
INDEX_INTERVAL_SIZE_CONST)

.def("set_empty", &Interval::set_empty,
VOID_INTERVAL_SET_EMPTY)
Expand Down
Loading

0 comments on commit 8810533

Please sign in to comment.