Closed domire8 closed 2 years ago
This seems good then. Just a question about that:
map.set_parameter(sr.Parameter("stiffness", 1, sr.StateType.PARAMETER_INT))
What is going on here? Because the original parameter is a double so what is the type of the parameter once set. Sorry if that is something that is also in C++ and that I have missed.
What is going on here? Because the original parameter is a double so what is the type of the parameter once set. Sorry if that is something that is also in C++ and that I have missed.
Okay so in super().set_parameter
what happens is that:
void ParameterMap::set_parameter(const std::shared_ptr<ParameterInterface>& parameter) {
this->validate_and_set_parameter(parameter);
}
and what happens in validate and set parameter:
void
ParameterMap::validate_and_set_parameter(const std::shared_ptr<ParameterInterface>& parameter) {
this->parameters_[parameter->get_name()] = parameter;
}
And because its all parameter interface pointers, you can replace the type of parameter easily, hence it didnt complain when I set a double parameter as an int parameter. However, this is just the base class, of course the validate and set parameter of your derived class has to check that the parameter is valid. Because I didn't do that in my dummy class, i can replace a double with an int parameter but that wouldn't be possible anymore once you do proper parameter validation
Right yes I see. All good then.
This PR tweaks the pybindings such that @buschbapti can inherit from
ParameterMap
in python for the optimizers. The following code snippet shows how to do that:As you can see there is an intermediate step
parameter = sr.Parameter(param)
invalidate_and_set_parameter
because the the input type of validate and set parameters is actuallystd::shared_ptr<ParameterInterface>
and notParameterContainer
as we have in python. Therefore, you need to convert that shared ptr to the python parameter type. Afterwards everything works as expected. To facilitate that step, I added a new constructor in python such that you can create a new Parameter from a ParamterInterface pointer directly. I'm not sure if that makes sense and if thats allowed by good programming principles but apart from that everything seems to work out quite nicely!