Commit 3738bfdf authored by Ludovic Courtès's avatar Ludovic Courtès

core: 'compound_function' takes functions in its constructor arguments.

parent a293ccd2
......@@ -471,38 +471,53 @@ vec compound_function::parametersJacobian(const vec& x) const
return jac;
}
void compound_function::push_back(const ptr<nonlinear_function>& f, const arguments& f_args)
// Return the parameters of the composition of FUNCTIONS.
static const parameters
compound_parameters(const std::vector<ptr<nonlinear_function> >& functions)
{
// FIXME: Update to work with new 'parameters' class.
abort();
#if 0
// Update the input param
if(parametrization().input_parametrization() == params::UNKNOWN_INPUT)
{
setParametrization(f->parametrization().input_parametrization());
}
else if(parametrization().input_parametrization() != f->parametrization().input_parametrization())
{
setParametrization(params::CARTESIAN);
}
assert(functions.size() > 0);
// Update the output param
if(output_parametrization() == params::UNKNOWN_OUTPUT)
{
setParametrization(f->output_parametrization());
}
else if(output_parametrization() != f->output_parametrization())
{
std::cerr << "Creating a compound function with different output dimensions, this is not allowed" << std::endl;
throw;
}
parameters result = functions[0]->parametrization();
fs.push_back(f);
fs_args.push_back(f_args);
is_fixed.push_back(f_args.is_defined("fixed"));
#endif
for (auto f: functions)
{
auto input = f->parametrization().input_parametrization();
auto output = f->parametrization().output_parametrization();
if (result.input_parametrization() == params::UNKNOWN_INPUT)
result = alta::parameters(result.dimX(), result.dimY(),
input,
result.output_parametrization());
else if (result.input_parametrization() != input)
// Parametrization mismatch: fall back to Cartesian.
result = result.set_input(6, params::CARTESIAN);
if (result.output_parametrization() == params::UNKNOWN_OUTPUT)
result = alta::parameters(result.dimX(), result.dimY(),
result.input_parametrization(),
output);
else if (result.output_parametrization() != output)
abort();
}
return result;
}
compound_function::compound_function(const std::vector<ptr<nonlinear_function> >& functions,
const std::vector<arguments> args)
: nonlinear_function(compound_parameters(functions)),
fs(functions), fs_args(args)
{
assert(functions.size() == args.size());
is_fixed.resize(functions.size());
for (unsigned int x = 0; x < functions.size(); x++)
{
is_fixed[x] = args[x].is_defined("fixed");
}
}
nonlinear_function* compound_function::operator[](int i) const
{
#ifdef DEBUG
......
......@@ -214,6 +214,9 @@ class compound_function: public nonlinear_function
{
public: // methods
compound_function(const std::vector<ptr<nonlinear_function> >& functions,
const std::vector<arguments> args);
//Destructor
virtual ~compound_function();
......@@ -221,12 +224,6 @@ class compound_function: public nonlinear_function
virtual vec operator()(const vec& x) const;
virtual vec value(const vec& x) const;
//! Provide a vector like interface
//! This function allows to put a new nonlinear function \a f in the
//! compound object. This function will be processed for nonlinear
//! optimisation only if \a fixed equals true.
virtual void push_back(const ptr<nonlinear_function>& f, const arguments& f_args);
//! \brief Access to the i-th function of the compound
nonlinear_function* operator[](int i) const;
......@@ -304,6 +301,9 @@ class compound_function: public nonlinear_function
//! to the associated function will be done.
virtual void save_call(std::ostream& out, const arguments& args) const;
private:
compound_function() ALTA_DEPRECATED { abort(); }
protected:
std::vector<ptr<nonlinear_function>> fs;
std::vector<arguments> fs_args;
......
......@@ -270,11 +270,11 @@ function* plugins_manager::get_function(const arguments& args)
return NULL;
}
//! create a *compound* class to store multiple ! functions in it.
compound_function* compound = new compound_function();
//! For each args_vec element, create a function object and add ! it to the
//compound one.
std::vector<ptr<nonlinear_function> > functions(args_vec.size());
std::vector<arguments> function_args(args_vec.size());
for(unsigned int i=0; i<args_vec.size(); ++i)
{
std::string n("--func ");
......@@ -297,10 +297,15 @@ function* plugins_manager::get_function(const arguments& args)
}
else
{
compound->push_back(ptr<nonlinear_function>(nl_f), temp_args);
functions[i] = ptr<nonlinear_function>(nl_f);
function_args[i] = temp_args;
}
}
//! create a *compound* class to store multiple ! functions in it.
compound_function* compound = new compound_function(functions, function_args);
//! return the compound class
func = compound;
#ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment