diff --git a/src/scion/math/InterpolationTable/src/generateTables.hpp b/src/scion/math/InterpolationTable/src/generateTables.hpp index ba63dec..9b782e6 100644 --- a/src/scion/math/InterpolationTable/src/generateTables.hpp +++ b/src/scion/math/InterpolationTable/src/generateTables.hpp @@ -63,15 +63,19 @@ void generateTables() { } } - std::swap( xStart, xEnd ); - std::swap( yStart, yEnd ); - if ( *xStart > *std::prev( xStart ) ) { + // don't do this for the last region: valgrind will yell at you + if ( xEnd != this->x().end() ) { - --xStart; - --yStart; + std::swap( xStart, xEnd ); + std::swap( yStart, yEnd ); + if ( *xStart > *std::prev( xStart ) ) { + + --xStart; + --yStart; + } } } this->linearised_ = linearised; - this->tables_ = tables; + this->tables_ = std::move( tables ); } diff --git a/src/scion/math/InterpolationTable/src/processBoundaries.hpp b/src/scion/math/InterpolationTable/src/processBoundaries.hpp index db7f928..45cc543 100644 --- a/src/scion/math/InterpolationTable/src/processBoundaries.hpp +++ b/src/scion/math/InterpolationTable/src/processBoundaries.hpp @@ -120,11 +120,17 @@ processBoundaries( std::vector< X >&& x, std::vector< Y >&& y, throw std::exception(); } } - if ( *std::next( xIter ) == *xIter ) { - Log::error( "An x value can only be repeated a maximum of two times" ); - Log::info( "x = {} is present at least three times", *xIter ); - throw std::exception(); + // make sure we do not go beyond the end of the x grid: valgrind will yell at you + auto next = std::next( xIter ); + if ( next < x.end() ) { + + if ( *std::next( xIter ) == *xIter ) { + + Log::error( "An x value can only be repeated a maximum of two times" ); + Log::info( "x = {} is present at least three times", *xIter ); + throw std::exception(); + } } xIter = std::adjacent_find( xIter, x.end() ); } diff --git a/src/scion/math/InterpolationTableFunction/src/generateTables.hpp b/src/scion/math/InterpolationTableFunction/src/generateTables.hpp index d54d8a2..1bd45a7 100644 --- a/src/scion/math/InterpolationTableFunction/src/generateTables.hpp +++ b/src/scion/math/InterpolationTableFunction/src/generateTables.hpp @@ -66,14 +66,18 @@ void generateTables() { } } - std::swap( xStart, xEnd ); - std::swap( fStart, fEnd ); - if ( *xStart > *std::prev( xStart ) ) { + // don't do this for the last region: valgrind will yell at you + if ( xEnd != this->x().end() ) { - --xStart; - --fStart; + std::swap( xStart, xEnd ); + std::swap( fStart, fEnd ); + if ( *xStart > *std::prev( xStart ) ) { + + --xStart; + --fStart; + } } } - this->tables_ = tables; + this->tables_ = std::move( tables ); } diff --git a/src/scion/math/InterpolationTableFunction/src/processBoundaries.hpp b/src/scion/math/InterpolationTableFunction/src/processBoundaries.hpp index edda734..5f60209 100644 --- a/src/scion/math/InterpolationTableFunction/src/processBoundaries.hpp +++ b/src/scion/math/InterpolationTableFunction/src/processBoundaries.hpp @@ -105,11 +105,17 @@ processBoundaries( std::vector< X >&& x, std::vector< F >&& f, Log::error( "A jump in the x grid cannot occur at the end of the x grid" ); throw std::exception(); } - if ( *std::next( xIter ) == *xIter ) { - Log::error( "An x value can only be repeated a maximum of two times" ); - Log::info( "x = {} is present at least three times", *xIter ); - throw std::exception(); + // make sure we do not go beyond the end of the x grid: valgrind will yell at you + auto next = std::next( xIter ); + if ( next < x.end() ) { + + if ( *std::next( xIter ) == *xIter ) { + + Log::error( "An x value can only be repeated a maximum of two times" ); + Log::info( "x = {} is present at least three times", *xIter ); + throw std::exception(); + } } xIter = std::adjacent_find( xIter, x.end() ); }