Skip to content

Commit

Permalink
Re #4158. Writing FunctionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 2, 2012
1 parent a5af579 commit a58c45e
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 178 deletions.
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ParamFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class MANTID_API_DLL ParamFunction : public virtual IFunction

/// Number of active (in terms of fitting) parameters
virtual size_t nActive()const{return m_indexMap.size();}
/// Value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual double activeParameter(size_t i)const;
/// Set new value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual void setActiveParameter(size_t i, double value);
/// Returns the name of active parameter i
virtual std::string nameOfActive(size_t i)const;
/// Returns the name of active parameter i
Expand Down
22 changes: 11 additions & 11 deletions Code/Mantid/Framework/API/src/IFunction1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ namespace API

Kernel::Logger& IFunction1D::g_log = Kernel::Logger::get("IFunction1D");

/** Base class implementation of derivative IFunction1D throws error. This is to check if such a function is provided
by derivative class. In the derived classes this method must return the derivatives of the resuduals function
(defined in void Fit1D::function(const double*, double*, const double*, const double*, const double*, const int&))
with respect to the fit parameters. If this method is not reimplemented the derivative free simplex minimization
algorithm is used.
*/
void IFunction1D::functionDeriv1D(Jacobian*, const double*, const size_t)
{
throw Kernel::Exception::NotImplementedError("No derivative IFunction1D provided");
}

namespace
{
/**
Expand Down Expand Up @@ -91,6 +80,17 @@ void IFunction1D::functionDeriv(const FunctionDomain& domain, Jacobian& jacobian
functionDeriv1D(&jacobian,(*d1d)[0],d1d->size());
}

/** Base class implementation of derivative IFunction1D throws error. This is to check if such a function is provided
by derivative class. In the derived classes this method must return the derivatives of the resuduals function
(defined in void Fit1D::function(const double*, double*, const double*, const double*, const double*, const int&))
with respect to the fit parameters. If this method is not reimplemented the derivative free simplex minimization
algorithm is used.
*/
void IFunction1D::functionDeriv1D(Jacobian*, const double*, const size_t)
{
throw Kernel::Exception::NotImplementedError("No derivative IFunction1D provided");
}

/**
* Creates a workspace containing values calculated with this function. It takes a workspace and ws index
* of a spectrum which this function may have been fitted to. The output contains the original spectrum
Expand Down
22 changes: 21 additions & 1 deletion Code/Mantid/Framework/API/src/ParamFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ void ParamFunction::declareParameter(const std::string& name,double initValue, c
m_explicitlySet.push_back(false);
}

/**
* Returns the value of an active parameter.
* @param i :: The index of an active parameter
* @return the value of the active parameter
*/
double ParamFunction::activeParameter(size_t i)const
{
return m_parameters[indexOfActive(i)];
}

/**
* Sets the value of an active parameter.
* @param i :: The index of an active parameter
* @param value :: A new value.
*/
void ParamFunction::setActiveParameter(size_t i, double value)
{
m_parameters[indexOfActive(i)] = value;
}

/**
* Returns the name of an active parameter.
* @param i :: The index of an active parameter
Expand All @@ -247,7 +267,7 @@ std::string ParamFunction::nameOfActive(size_t i)const
*/
std::string ParamFunction::descriptionOfActive(size_t i)const
{
return m_parameterDescriptions[indexOfActive(static_cast<int>(i))];
return m_parameterDescriptions[indexOfActive(i)];
}

/**
Expand Down

0 comments on commit a58c45e

Please sign in to comment.