Skip to content

Commit

Permalink
Re #4158. Added domain and values tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 2, 2012
1 parent a58c45e commit c7ce196
Show file tree
Hide file tree
Showing 20 changed files with 830 additions and 734 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ set ( TEST_FILES
test/FilePropertyTest.h
test/FrameworkManagerTest.h
test/FunctionPropertyTest.h
test/FunctionDomainTest.h
test/FunctionFactoryTest.h
test/FunctionTest.h
test/FunctionValuesTest.h
test/IEventListTest.h
test/IFunction1DTest.h
test/IFunctionMDTest.h
Expand Down
78 changes: 0 additions & 78 deletions Code/Mantid/Framework/API/inc/MantidAPI/CompositeFunctionMW.h

This file was deleted.

4 changes: 3 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/FunctionDomain1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class MANTID_API_DLL FunctionDomain1D: public FunctionDomain
virtual size_t size() const {return m_X.size();}
/// Get an x value.
/// @param i :: Index
const double* operator[](size_t i) const {return &m_X.at(i);}
double operator[](size_t i) const {return m_X.at(i);}
/// Get a pointer to i-th value
const double* getPointerAt(size_t i) const {return &m_X.at(i);}
protected:
std::vector<double> m_X; ///< vector of function arguments
};
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/FunctionValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class MANTID_API_DLL FunctionValues
/// set a fitting weight
void setFitWeight(size_t i,double value);
void setFitWeights(const std::vector<double>& values);
/// get a fitting weight
void setFitWeights(const double& value);
/// get a fitting weight
double getFitWeight(size_t i) const;
protected:
void setDataSize();
std::vector<double> m_calculated; ///< buffer for calculated values
std::vector<double> m_data; ///< buffer for fit data
std::vector<double> m_weights; ///< buffer for fitting weights (reciprocal errors)
Expand Down
2 changes: 0 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/IFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ class MANTID_API_DLL IFunction
virtual std::string name()const = 0;
/// Writes itself into a string
virtual std::string asString()const;
/// The string operator
virtual operator std::string()const{return asString();}
/// Set the workspace.
/// @param ws :: Shared pointer to a workspace
virtual void setWorkspace(boost::shared_ptr<const Workspace> ws) {}
Expand Down
170 changes: 0 additions & 170 deletions Code/Mantid/Framework/API/src/CompositeFunctionMW.cpp

This file was deleted.

12 changes: 3 additions & 9 deletions Code/Mantid/Framework/API/src/FunctionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ namespace Mantid
*/
IFunction* FunctionFactoryImpl::createInitialized(const std::string& input) const
{
//std::vector<std::string> ops;
//ops.push_back(";");
//ops.push_back(",");
//ops.push_back("=");
//ops.push_back("== < > <= >=");

Expression expr;
try
{
Expand Down Expand Up @@ -170,7 +164,7 @@ namespace Mantid
}
else if (term.terms()[0].name() == "name")
{
cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunction"));
if (!cfun) inputError(expr.str());
}
else
Expand All @@ -191,7 +185,7 @@ namespace Mantid
}
else if (firstTerm->terms()[0].name() == "name")
{
cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunction"));
if (!cfun) inputError(expr.str());
}
else
Expand All @@ -202,7 +196,7 @@ namespace Mantid
}
else if (term.name() == ";")
{
cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunction"));
if (!cfun) inputError(expr.str());
}
else
Expand Down
29 changes: 15 additions & 14 deletions Code/Mantid/Framework/API/src/FunctionValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace API
{
if (m_data.size() != m_calculated.size())
{
setDataSize();
m_data.resize(m_calculated.size());
}
m_data[i] = value;
}
Expand Down Expand Up @@ -107,9 +107,9 @@ namespace API
*/
void FunctionValues::setFitWeight(size_t i,double value)
{
if (m_data.size() != m_calculated.size())
if (m_weights.size() != m_calculated.size())
{
setDataSize();
m_weights.resize(m_calculated.size());
}
m_weights[i] = value;
}
Expand All @@ -127,27 +127,28 @@ namespace API
m_weights.assign(values.begin(),values.end());
}

/**
* Set all weights to the same value.
* @param value :: The value to set.
*/
void FunctionValues::setFitWeights(const double& value)
{
m_weights.resize(m_calculated.size(),value);
}


/**
* Get a fitting weight.
* @param i :: Index
*/
double FunctionValues::getFitWeight(size_t i) const
{
if (m_data.size() != m_calculated.size())
if (m_weights.size() != m_calculated.size())
{
throw std::runtime_error("Fitting data was not set");
throw std::runtime_error("Fitting weights was not set");
}
return m_weights[i];
}

/**
* Resize the fitting data and weight buffers to match the size of the calculated buffer.
*/
void FunctionValues::setDataSize()
{
m_data.resize(m_calculated.size());
m_weights.resize(m_calculated.size());
}

} // namespace API
} // namespace Mantid

0 comments on commit c7ce196

Please sign in to comment.