Skip to content

Commit

Permalink
Re #9682. Changed behavior of interpolation with one value
Browse files Browse the repository at this point in the history
In the previous commit, I fixed the problem caused by having only one value in the interpolation table by return 0. On second thought, it makes more sense to assume a "constant interpolation" and return the one stored y-value for any x.
  • Loading branch information
Michael Wedel committed Jun 30, 2014
1 parent 167c634 commit 2e62762
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Code/Mantid/Framework/Kernel/src/Interpolation.cpp
Expand Up @@ -60,11 +60,16 @@ namespace Kernel
{
size_t N = m_x.size();

if ( N < 2 )
if ( N == 0 )
{
g_log.error() << "Need at least two values for interpolation. Return interpolation value zero.";
g_log.error() << "Need at least one value for interpolation. Return interpolation value zero.";
return 0.0;
}

if ( N == 1 )
{
return m_y[0];
}

// check first if at is within the limits of interpolation interval

Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/Framework/Kernel/test/InterpolationTest.h
Expand Up @@ -201,9 +201,11 @@ class InterpolationTest : public CxxTest::TestSuite
interpolationOne.addPoint(200, 2.0);

for(size_t i = 0; i < m_tableXValues.size(); ++i) {
// When there are only one or two values in the interpolation, it returns 0.0
// When there are zero values in the interpolation, it returns 0.0
checkValue(interpolationZero, m_tableXValues[i], 0.0, "zero interpolation values");
checkValue(interpolationOne, m_tableXValues[i], 0.0, "one interpolation value");

// With one value, it returns this one value for any x.
checkValue(interpolationOne, m_tableXValues[i], 2.0, "one interpolation value");
}
}

Expand Down

0 comments on commit 2e62762

Please sign in to comment.