Skip to content

Commit

Permalink
Added checks for error being nan or inf. Re #7182.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jun 6, 2013
1 parent fe567e4 commit 3a18cc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/CurveFitting/src/FitMW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ namespace
double error = E[i];
double weight = 0.0;

if ( ! boost::math::isfinite(y) )
if ( ! boost::math::isfinite(y) ) // nan or inf data
{
if ( !m_ignoreInvalidData ) throw std::runtime_error("Infinte number or NaN found in input data.");
y = 0.0; // leaving inf or nan would break the fit
}
else if ( ! boost::math::isfinite( error ) ) // nan or inf error
{
if ( !m_ignoreInvalidData ) throw std::runtime_error("Infinte number or NaN found in input data.");
}
else if ( error <= 0 )
{
if ( !m_ignoreInvalidData ) weight = 1.0;
Expand Down
8 changes: 5 additions & 3 deletions Code/Mantid/Framework/CurveFitting/test/FitMWTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FitMWTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(covar->Double(1,2), 100.0);
TS_ASSERT(fabs(covar->Double(0,2)) < 100.0);
TS_ASSERT(fabs(covar->Double(0,2)) > 0.0);
TS_ASSERT_EQUALS(covar->Double(0,2), covar->Double(1,1));
TS_ASSERT_DELTA(covar->Double(0,2), covar->Double(1,1), 0.000001);

TS_ASSERT_DIFFERS( fun->getError(0), 0.0 );
TS_ASSERT_DIFFERS( fun->getError(1), 0.0 );
Expand Down Expand Up @@ -375,6 +375,8 @@ class FitMWTest : public CxxTest::TestSuite
ws->dataY(0)[3] = 1.0 / zero;
ws->dataY(0)[5] = log(-one);
ws->dataE(0)[7] = 0;
ws->dataE(0)[9] = 1.0 / zero;
ws->dataE(0)[11] = log(-one);

FunctionDomain_sptr domain;
IFunctionValues_sptr values;
Expand All @@ -393,7 +395,7 @@ class FitMWTest : public CxxTest::TestSuite
FunctionValues *val = dynamic_cast<FunctionValues*>(values.get());
for(size_t i = 0; i < val->size(); ++i)
{
if ( i == 3 || i == 5 || i == 7 )
if ( i == 3 || i == 5 || i == 7 || i == 9 || i == 11 )
{
TS_ASSERT_EQUALS( val->getFitWeight(i), 0.0 );
}
Expand Down Expand Up @@ -452,7 +454,7 @@ class FitMWTest : public CxxTest::TestSuite
API::MatrixWorkspace_sptr createTestWorkspace(const bool histogram)
{
MatrixWorkspace_sptr ws2(new WorkspaceTester);
ws2->initialize(2,10,10);
ws2->initialize(2,20,20);

for(size_t is = 0; is < ws2->getNumberHistograms(); ++is)
{
Expand Down

0 comments on commit 3a18cc7

Please sign in to comment.