Skip to content

Commit

Permalink
[core] input2index -> time_to_index
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Jun 11, 2020
1 parent 8850672 commit 962c219
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions python/src/core/dynamics/tube/tubex_py_Tube.cpp
Expand Up @@ -126,8 +126,8 @@ void export_Tube(py::module& m)
TUBE_CONSTINTERVAL_SLICE_TDOMAIN_INT,
"slice_id"_a)

.def("input2index", &Tube::input2index,
TUBE_INT_INPUT2INDEX_DOUBLE,
.def("time_to_index", &Tube::time_to_index,
TUBE_INT_TIME_TO_INDEX_DOUBLE,
"t"_a)

.def("index", &Tube::index,
Expand Down
4 changes: 2 additions & 2 deletions python/src/core/dynamics/tube/tubex_py_TubeVector.cpp
Expand Up @@ -120,8 +120,8 @@ void export_TubeVector(py::module& m)
.def("nb_slices", &TubeVector::nb_slices,
TUBEVECTOR_INT_NB_SLICES)

.def("input2index", &TubeVector::input2index,
TUBEVECTOR_INT_INPUT2INDEX_DOUBLE,
.def("time_to_index", &TubeVector::time_to_index,
TUBEVECTOR_INT_TIME_TO_INDEX_DOUBLE,
"t"_a)

.def("sample", (void (TubeVector::*)(double))&TubeVector::sample,
Expand Down
8 changes: 4 additions & 4 deletions src/core/dynamics/tube/tubex_Tube.cpp
Expand Up @@ -353,7 +353,7 @@ namespace tubex
assert(tdomain().contains(t));

if(m_synthesis_tree != NULL) // fast evaluation
return m_synthesis_tree->slice(m_synthesis_tree->input2index(t));
return m_synthesis_tree->slice(m_synthesis_tree->time_to_index(t));

else
{
Expand Down Expand Up @@ -449,12 +449,12 @@ namespace tubex
return slice(slice_id)->tdomain();
}

int Tube::input2index(double t) const
int Tube::time_to_index(double t) const
{
assert(tdomain().contains(t));

if(m_synthesis_tree != NULL) // fast evaluation
return m_synthesis_tree->input2index(t);
return m_synthesis_tree->time_to_index(t);

else
{
Expand Down Expand Up @@ -1022,7 +1022,7 @@ namespace tubex
sample(t.lb());
sample(t.ub());

for(Slice *s = slice(input2index(t.lb())) ;
for(Slice *s = slice(time_to_index(t.lb())) ;
s != NULL && !(t & s->tdomain()).is_degenerated() ;
s = s->next_slice())
s->set(y);
Expand Down
2 changes: 1 addition & 1 deletion src/core/dynamics/tube/tubex_Tube.h
Expand Up @@ -336,7 +336,7 @@ namespace tubex
* \param t the temporal key (double, must belong to the Tube's tdomain)
* \return an integer
*/
int input2index(double t) const;
int time_to_index(double t) const;

/**
* \brief Returns the Slice index related to the Slice pointer
Expand Down
12 changes: 6 additions & 6 deletions src/core/dynamics/tube/tubex_TubeTreeSynthesis.cpp
Expand Up @@ -150,7 +150,7 @@ namespace tubex
const pair<Interval,Interval> TubeTreeSynthesis::eval(const Interval& t)
{
if(t.is_degenerated()) // faster to perform the evaluation over the related slice
return slice(input2index(t.lb()))->eval(t);
return slice(time_to_index(t.lb()))->eval(t);

Interval inter = m_tdomain & t;

Expand Down Expand Up @@ -188,7 +188,7 @@ namespace tubex
}
}

int TubeTreeSynthesis::input2index(double t) const
int TubeTreeSynthesis::time_to_index(double t) const
{
assert(tdomain().contains(t));

Expand All @@ -199,10 +199,10 @@ namespace tubex
return 0;

if(t < m_first_subtree->tdomain().ub())
return m_first_subtree->input2index(t);
return m_first_subtree->time_to_index(t);

else
return m_second_subtree->input2index(t) + m_first_subtree->nb_slices();
return m_second_subtree->time_to_index(t) + m_first_subtree->nb_slices();
}

Slice* TubeTreeSynthesis::slice(int slice_id)
Expand Down Expand Up @@ -363,8 +363,8 @@ namespace tubex
if(m_integrals_update_needed)
root()->update_integrals();

int index_lb = m_tube_ref->input2index(t.lb());
int index_ub = m_tube_ref->input2index(t.ub());
int index_lb = m_tube_ref->time_to_index(t.lb());
int index_ub = m_tube_ref->time_to_index(t.ub());

Interval integral_lb = Interval::EMPTY_SET;
Interval integral_ub = Interval::EMPTY_SET;
Expand Down
2 changes: 1 addition & 1 deletion src/core/dynamics/tube/tubex_TubeTreeSynthesis.h
Expand Up @@ -30,7 +30,7 @@ namespace tubex
const std::pair<ibex::Interval,ibex::Interval> codomain_bounds();
const std::pair<ibex::Interval,ibex::Interval> eval(const ibex::Interval& t = ibex::Interval::ALL_REALS);

int input2index(double t) const;
int time_to_index(double t) const;
Slice* slice(int slice_id);
const Slice* slice(int slice_id) const;

Expand Down
4 changes: 2 additions & 2 deletions src/core/dynamics/tube/tubex_TubeVector.cpp
Expand Up @@ -255,10 +255,10 @@ namespace tubex
return n;
}

int TubeVector::input2index(double t) const
int TubeVector::time_to_index(double t) const
{
assert(tdomain().contains(t));
int index = (*this)[0].input2index(t);
int index = (*this)[0].time_to_index(t);
for(int i = 1 ; i < size() ; i++)
assert((*this)[0].nb_slices() == (*this)[i].nb_slices() && "all components do not have the same number of slices");
return index;
Expand Down
2 changes: 1 addition & 1 deletion src/core/dynamics/tube/tubex_TubeVector.h
Expand Up @@ -267,7 +267,7 @@ namespace tubex
* \param t the temporal key (double, must belong to the TubeVector's tdomain)
* \return an integer
*/
int input2index(double t) const;
int time_to_index(double t) const;

/**
* \brief Samples this tube at \f$t\f$
Expand Down
42 changes: 21 additions & 21 deletions tests/core/tests_slices_structure.cpp
Expand Up @@ -28,20 +28,20 @@ TEST_CASE("operator=")
}
}

TEST_CASE("input2index")
TEST_CASE("time_to_index")
{
SECTION("input2index")
SECTION("time_to_index")
{
Tube tube = tube_test_1();
CHECK(tube.input2index(0.0) == 0);
CHECK(tube.input2index(0.1) == 0);
CHECK(tube.input2index(0.5) == 0);
CHECK(tube.input2index(0.6) == 0);
CHECK(tube.input2index(0.9) == 0);
CHECK(tube.input2index(ibex::previous_float(1.0)) == 0);
CHECK(tube.input2index(1.0) == 1);
CHECK(tube.input2index(46.0) == 45);
CHECK(tube.input2index(tube.tdomain().ub()) == 45);
CHECK(tube.time_to_index(0.0) == 0);
CHECK(tube.time_to_index(0.1) == 0);
CHECK(tube.time_to_index(0.5) == 0);
CHECK(tube.time_to_index(0.6) == 0);
CHECK(tube.time_to_index(0.9) == 0);
CHECK(tube.time_to_index(ibex::previous_float(1.0)) == 0);
CHECK(tube.time_to_index(1.0) == 1);
CHECK(tube.time_to_index(46.0) == 45);
CHECK(tube.time_to_index(tube.tdomain().ub()) == 45);
CHECK(tube.nb_slices() == 46);
}

Expand Down Expand Up @@ -165,24 +165,24 @@ TEST_CASE("Tube slices structure")
CHECK(tube(6.) == Interval(-1.,0.)); // gate
}

SECTION("input2index and reverse operation")
SECTION("time_to_index and reverse operation")
{
Tube tube(Interval(0.,1.), Interval(-1.,1.));
tube.sample(0.6);
tube.sample(0.7);
tube.sample(0.62);
tube.sample(0.1);

// input2index
// time_to_index
CHECK(tube.nb_slices() == 5);
// todo: find a way to catch assert abort: CHECK_THROWS(tube.input2index(-0.1));
CHECK(tube.input2index(0.) == 0);
CHECK(tube.input2index(0.01) == 0);
CHECK(tube.input2index(0.6) == 2);
CHECK(tube.input2index(0.61) == 2);
CHECK(tube.input2index(0.62) == 3);
CHECK(tube.input2index(1.0) == 4);
// todo: find a way to catch assert abort: CHECK_THROWS(tube.input2index(1.01));
// todo: find a way to catch assert abort: CHECK_THROWS(tube.time_to_index(-0.1));
CHECK(tube.time_to_index(0.) == 0);
CHECK(tube.time_to_index(0.01) == 0);
CHECK(tube.time_to_index(0.6) == 2);
CHECK(tube.time_to_index(0.61) == 2);
CHECK(tube.time_to_index(0.62) == 3);
CHECK(tube.time_to_index(1.0) == 4);
// todo: find a way to catch assert abort: CHECK_THROWS(tube.time_to_index(1.01));
}

SECTION("Getting slices")
Expand Down

0 comments on commit 962c219

Please sign in to comment.