Skip to content

Commit

Permalink
Merge pull request #131 from damien-masse/codac2_dev
Browse files Browse the repository at this point in the history
Codac2 dev add mignitude and magnitude for Interval (element, Vector, Matrice)
  • Loading branch information
SimonRohou authored Nov 6, 2024
2 parents 1b40e95 + 21a61f1 commit 99d866f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
8 changes: 7 additions & 1 deletion python/src/core/domains/interval/codac2_py_Interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ py::class_<Interval> export_Interval(py::module& m)
.def("mid", &Interval::mid,
DOUBLE_INTERVAL_MID_CONST)

.def("mag", &Interval::mag,
DOUBLE_INTERVAL_MAG_CONST)

.def("mig", &Interval::mig,
DOUBLE_INTERVAL_MIG_CONST)

.def("rand", &Interval::rand,
DOUBLE_INTERVAL_RAND_CONST)

Expand Down Expand Up @@ -266,4 +272,4 @@ py::class_<Interval> export_Interval(py::module& m)
"x"_a);

return exported_interval_class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ void export_IntervalMatrixBase(py::module& m, py::class_<S>& pyclass)
.def("mid", &S::mid,
V_INTERVALMATRIXBASE_SVROWSCOLS_MID_CONST)

.def("mig", &S::mig,
V_INTERVALMATRIXBASE_SVROWSCOLS_MIG_CONST)

.def("mag", &S::mag,
V_INTERVALMATRIXBASE_SVROWSCOLS_MAG_CONST)

.def("rand", &S::rand,
V_INTERVALMATRIXBASE_SVROWSCOLS_RAND_CONST)

Expand Down Expand Up @@ -166,4 +172,4 @@ void export_IntervalMatrixBase(py::module& m, py::class_<S>& pyclass)
;

py::implicitly_convertible<V,S>();
}
}
4 changes: 3 additions & 1 deletion src/core/domains/codac2_Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace codac2
virtual V lb() const = 0;
virtual V ub() const = 0;
virtual V mid() const = 0;
virtual V mag() const = 0;
virtual V mig() const = 0;
virtual V rad() const = 0;
virtual V diam() const = 0;
virtual double volume() const = 0;
Expand All @@ -56,4 +58,4 @@ namespace codac2
virtual bool is_strict_superset(const T& x) const = 0;
};

}
}
12 changes: 11 additions & 1 deletion src/core/domains/interval/codac2_Interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ namespace codac2
return ibex::Interval::mid();
}

double Interval::mag() const
{
return ibex::Interval::mag();
}

double Interval::mig() const
{
return ibex::Interval::mig();
}

double Interval::rand() const
{
if(is_empty())
Expand Down Expand Up @@ -378,4 +388,4 @@ namespace codac2
return Interval(x);
}

} // namespace codac
} // namespace codac
21 changes: 20 additions & 1 deletion src/core/domains/interval/codac2_Interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ namespace codac2
*/
double mid() const;

/**
* \brief Returns the magnitude of this
* i.e. max(|lower bound|, |upper bound|).
*
* \return the magnitude of the interval
*/
double mag() const;

/**
* \brief Returns the mignitude of this
*
* +(lower bound) if lower_bound > 0
* -(upper bound) if upper_bound < 0
* 0 otherwise.
*
* \return the mignitude of the interval
*/
double mig() const;

/**
* \brief Returns a random value inside the interval
*
Expand Down Expand Up @@ -659,4 +678,4 @@ namespace codac2
{
return ibex::next_float(x);
}
}
}
12 changes: 11 additions & 1 deletion src/core/domains/interval/codac2_IntervalMatrixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ namespace codac2
degenerate_mat(mid);
}

V mag() const
{
degenerate_mat(mag);
}

V mig() const
{
degenerate_mat(mig);
}

V rand() const
{
srand(time(NULL));
Expand Down Expand Up @@ -504,4 +514,4 @@ namespace codac2
return bisect(max_diam_index(), ratio);
}
};
}
}

0 comments on commit 99d866f

Please sign in to comment.