Skip to content

Commit

Permalink
updated search
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertolazzi committed Feb 28, 2024
1 parent a2f4ed4 commit 72f907c
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ docs_build/xml-matlab
docs_build/sphinx/_doxygen
toolbox/lib/cmake-build-debug
toolbox/cmake-build-debug

/Xcode
4 changes: 2 additions & 2 deletions src/SplineConstant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ namespace Splines {
//! Evalute spline value at `x`
real_type
ConstantSpline::eval( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return m_Y[res.first];
}

Expand Down
16 changes: 8 additions & 8 deletions src/SplineCubicBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ namespace Splines {

real_type
CubicSplineBase::eval( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_eval( res.first, res.second );
}

Expand All @@ -160,8 +160,8 @@ namespace Splines {

real_type
CubicSplineBase::D( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_D( res.first, res.second );
}

Expand All @@ -184,8 +184,8 @@ namespace Splines {

real_type
CubicSplineBase::DD( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_DD( res.first, res.second );
}

Expand All @@ -208,8 +208,8 @@ namespace Splines {

real_type
CubicSplineBase::DDD( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_DDD( res.first, res.second );
}

Expand Down
8 changes: 4 additions & 4 deletions src/SplineLinear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace Splines {

real_type
LinearSpline::eval( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_eval( res.first, res.second );
}

Expand All @@ -64,8 +64,8 @@ namespace Splines {
if ( m_curve_can_extend && m_curve_extended_constant ) {
if ( x <= m_X[0] || x >= m_X[m_npts-1] ) return 0;
}
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_D( res.first, res.second );
}

Expand Down
24 changes: 12 additions & 12 deletions src/SplineQuinticBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ namespace Splines {

real_type
QuinticSplineBase::eval( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_eval( res.first, res.second );
}

Expand All @@ -130,8 +130,8 @@ namespace Splines {

real_type
QuinticSplineBase::D( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_D( res.first, res.second );
}

Expand All @@ -155,8 +155,8 @@ namespace Splines {

real_type
QuinticSplineBase::DD( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_DD( res.first, res.second );
}

Expand All @@ -180,8 +180,8 @@ namespace Splines {

real_type
QuinticSplineBase::DDD( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_DDD( res.first, res.second );
}

Expand All @@ -205,8 +205,8 @@ namespace Splines {

real_type
QuinticSplineBase::DDDD( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_DDDD( res.first, res.second );
}

Expand All @@ -230,8 +230,8 @@ namespace Splines {

real_type
QuinticSplineBase::DDDDD( real_type x ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
return this->id_DDDDD( res.first, res.second );
}

Expand Down
10 changes: 6 additions & 4 deletions src/SplineSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ namespace Splines {
size_t U{ data.size() };
size_t L{ 0 };
while ( U-L > 1 ) {
size_t pos{ (L+U)>>1 };
std::string const & id_pos = data[pos].first;
size_t pos{ (L+U)>>1 }; // se L=U+1 --> (L+U)/2 ==> L
std::string const & id_pos{ data[pos].first };
if ( id_pos < id ) L = pos; else U = pos;
}
if ( data[L].first == id ) return data[L].second;
if ( data[U].first == id ) return data[U].second;
if ( U < data.size() )
if ( data[U].first == id )
return data[U].second;
return -1; // non trovato
}

Expand All @@ -61,7 +63,7 @@ namespace Splines {
size_t pos{ data.size() };
data.push_back(DATA_TYPE(id,position));
while ( pos > 0 ) {
size_t pos1 = pos-1;
size_t pos1{pos-1};
data[pos].first = data[pos1].first;
data[pos].second = data[pos1].second;
if ( data[pos1].first < id ) break;
Expand Down
4 changes: 2 additions & 2 deletions src/SplineSetGC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ namespace Splines {
real_type x;
intersect( indep, zeta, x );
for ( integer pos{0}; pos < m_header_to_position.n_elem(); ++pos ) {
BinarySearch::DATA_TYPE const & D = m_header_to_position.get_elem( pos );
BinarySearch::DATA_TYPE const & D{ m_header_to_position.get_elem( pos ) };
vals[D.first] = m_splines[size_t(D.second)]->eval(x);
}
}
Expand All @@ -367,7 +367,7 @@ namespace Splines {

// preallocation
for ( integer pos{0}; pos < m_header_to_position.n_elem(); ++pos ) {
BinarySearch::DATA_TYPE const & D = m_header_to_position.get_elem( pos );
BinarySearch::DATA_TYPE const & D{ m_header_to_position.get_elem( pos ) };
vals[D.first].set_vec_real(unsigned(npts));
}

Expand Down
39 changes: 19 additions & 20 deletions src/SplineVec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace Splines {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void
SplineVec::search( real_type x, std::pair<integer,real_type> & res ) const {
SplineVec::search( std::pair<integer,real_type> & res ) const {
UTILS_ASSERT( m_npts > 0, "in SplineVec[{}]::search(...), npts == 0!", m_name );
#ifdef SPLINES_USE_THREADS
bool ok{true};
Expand All @@ -69,13 +69,12 @@ namespace Splines {
Utils::search_interval(
m_npts,
m_X,
x,
res.second,
last_interval,
m_curve_is_closed,
m_curve_can_extend
);
res.first = last_interval;
res.second = x;
res.first = last_interval;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -286,8 +285,8 @@ namespace Splines {

real_type
SplineVec::eval( real_type x, integer j ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base[4];
integer i{res.first};
Hermite3( res.second-m_X[i], m_X[i+1]-m_X[i], base );
Expand All @@ -301,8 +300,8 @@ namespace Splines {

real_type
SplineVec::D( real_type x, integer j ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base_D[4];
integer i{res.first};
Hermite3_D( res.second-m_X[i], m_X[i+1]-m_X[i], base_D );
Expand All @@ -316,8 +315,8 @@ namespace Splines {

real_type
SplineVec::DD( real_type x, integer j ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base_DD[4];
integer i{res.first};
Hermite3_DD( res.second-m_X[i], m_X[i+1]-m_X[i], base_DD );
Expand All @@ -331,8 +330,8 @@ namespace Splines {

real_type
SplineVec::DDD( real_type x, integer j ) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base_DDD[4];
integer i{res.first};
Hermite3_DDD( res.second-m_X[i], m_X[i+1]-m_X[i], base_DDD );
Expand All @@ -350,8 +349,8 @@ namespace Splines {
real_type vals[],
integer inc
) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base[4];
integer i{res.first};
Hermite3( res.second-m_X[i], m_X[i+1]-m_X[i], base );
Expand All @@ -371,8 +370,8 @@ namespace Splines {
real_type vals[],
integer inc
) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base_D[4];
integer i{res.first};
Hermite3_D( res.second-m_X[i], m_X[i+1]-m_X[i], base_D );
Expand All @@ -392,8 +391,8 @@ namespace Splines {
real_type vals[],
integer inc
) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base_DD[4];
integer i{res.first};
Hermite3_DD( res.second-m_X[i], m_X[i+1]-m_X[i], base_DD );
Expand All @@ -413,8 +412,8 @@ namespace Splines {
real_type vals[],
integer inc
) const {
std::pair<integer,real_type> res;
this->search( x, res );
std::pair<integer,real_type> res(0,x);
this->search( res );
real_type base_DDD[4];
integer i{res.first};
Hermite3_DDD( res.second-m_X[i], m_X[i+1]-m_X[i], base_DDD );
Expand Down
7 changes: 3 additions & 4 deletions src/Splines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ namespace Splines {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void
Spline::search( real_type x, std::pair<integer,real_type> & res ) const {
Spline::search( std::pair<integer,real_type> & res ) const {
UTILS_ASSERT( m_npts > 0, "in Spline[{}]::search(...), npts == 0!", m_name );
#ifdef SPLINES_USE_THREADS
bool ok{true};
Expand All @@ -250,13 +250,12 @@ namespace Splines {
Utils::search_interval(
m_npts,
m_X,
x,
res.second,
last_interval,
m_curve_is_closed,
m_curve_can_extend
);
res.first = last_interval;
res.second = x;
res.first = last_interval;
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/Splines.hh
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ namespace Splines {
//!
//! Find interval containing `x` using binary search.
//!
void search( real_type x, std::pair<integer,real_type> & res ) const;
void search( std::pair<integer,real_type> & res ) const;

//!
//! \name Open/Close
Expand Down
2 changes: 1 addition & 1 deletion src/Splines/SplineVec.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace Splines {
//!
//! Search the segment containing `x`
//!
void search( real_type x, std::pair<integer,real_type> & res ) const;
void search( std::pair<integer,real_type> & res ) const;

//!
//! Spline name usd in the constructor
Expand Down

0 comments on commit 72f907c

Please sign in to comment.