Skip to content

Commit

Permalink
Refs #11672. Added fix and another test
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed May 1, 2015
1 parent 114d749 commit c68375b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ class MANTID_API_DLL IFunction {

friend class ParameterTie;
friend class CompositeFunction;
friend class FunctionParameterDecorator;

/// Flag to hint that the function is being used in parallel computations
bool m_isParallel;
Expand Down
18 changes: 16 additions & 2 deletions Code/Mantid/Framework/API/src/FunctionParameterDecorator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MantidAPI/FunctionParameterDecorator.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidAPI/ParameterReference.h"

namespace Mantid {
namespace API {
Expand Down Expand Up @@ -172,7 +174,15 @@ size_t FunctionParameterDecorator::getParameterIndex(
const ParameterReference &ref) const {
throwIfNoFunctionSet();

return m_wrappedFunction->getParameterIndex(ref);
if(boost::dynamic_pointer_cast<CompositeFunction>(m_wrappedFunction)) {
return m_wrappedFunction->getParameterIndex(ref);
}

if(ref.getFunction() == this && ref.getIndex() < nParams()) {
return ref.getIndex();
}

return nParams();
}

size_t FunctionParameterDecorator::nAttributes() const {
Expand Down Expand Up @@ -289,7 +299,11 @@ void FunctionParameterDecorator::declareParameter(
}

/// Does nothing.
void FunctionParameterDecorator::addTie(ParameterTie *tie) { UNUSED_ARG(tie); }
void FunctionParameterDecorator::addTie(ParameterTie *tie) {
throwIfNoFunctionSet();

m_wrappedFunction->addTie(tie);
}

/**
* @brief Function that is called before the decorated function is set
Expand Down
24 changes: 22 additions & 2 deletions Code/Mantid/Framework/API/test/FunctionParameterDecoratorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ class FunctionParameterDecoratorTest : public CxxTest::TestSuite {
}

void testTiesInComposite() {
FunctionParameterDecorator_sptr fn1 =
FunctionParameterDecorator_sptr fn =
getFunctionParameterDecoratorGaussian();

CompositeFunction_sptr composite = boost::make_shared<CompositeFunction>();
composite->addFunction(fn1);
composite->addFunction(fn);

TS_ASSERT_THROWS_NOTHING(composite->addTies("f0.Height=2.0*f0.Sigma"));

Expand All @@ -301,6 +301,26 @@ class FunctionParameterDecoratorTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(composite->getParameter("f0.Height"), 6.0);
}

void testTiesInWrappedComposite() {
FunctionParameterDecorator_sptr outer =
boost::make_shared<TestableFunctionParameterDecorator>();
outer->setDecoratedFunction("CompositeFunction");

FunctionParameterDecorator_sptr fn =
getFunctionParameterDecoratorGaussian();

CompositeFunction_sptr composite =
boost::dynamic_pointer_cast<CompositeFunction>(
outer->getDecoratedFunction());
composite->addFunction(fn);

TS_ASSERT_THROWS_NOTHING(outer->addTies("f0.Height=2.0*f0.Sigma"));

outer->setParameter("f0.Sigma", 3.0);
outer->applyTies();
TS_ASSERT_EQUALS(outer->getParameter("f0.Height"), 6.0);
}

void testParameterNames() {
FunctionParameterDecorator_sptr fn =
getFunctionParameterDecoratorGaussian();
Expand Down

0 comments on commit c68375b

Please sign in to comment.