bpp-phyl3  3.0.0
Parametrizable.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include <Bpp/Exceptions.h>
10 
11 
12 using namespace std;
13 
14 namespace bpp
15 {
16 std::unordered_map<std::string, std::shared_ptr<ConfiguredParameter>>
17 createParameterMap (Context& c, const ParameterAliasable& parametrizable)
18 {
19  const auto& parameters = parametrizable.getIndependentParameters ();
20  const auto nbParameters = parameters.size ();
21  std::unordered_map<std::string, std::shared_ptr<ConfiguredParameter>> map;
22  for (std::size_t i = 0; i < nbParameters; ++i)
23  {
24  const auto& param = parameters[i];
25  auto value = NumericMutable<double>::create (c, param.getValue ());
26  map.emplace (param.getName (),
27  ConfiguredParameter::create (c, {std::move(value)}, param));
28  }
29  return map;
30 }
31 
32 std::unordered_map<std::string, std::shared_ptr<ConfiguredParameter>>
33 createParameterMap (Context& c, const Parametrizable& parametrizable)
34 {
35  const auto& parameters = parametrizable.getParameters ();
36  const auto nbParameters = parameters.size ();
37  std::unordered_map<std::string, std::shared_ptr<ConfiguredParameter>> map;
38  for (std::size_t i = 0; i < nbParameters; ++i)
39  {
40  const auto& param = parameters[i];
41  auto value = NumericMutable<double>::create (c, param.getValue ());
42  map.emplace (param.getName (),
43  ConfiguredParameter::create (c, {std::move(value)}, param));
44  }
45  return map;
46 }
47 
49  const std::function<NodeRef (const std::string&)>& parameter)
50 {
51  const auto& parameters = parametrizable.getParameters ();
52  const auto nbParameters = parameters.size ();
53  NodeRefVec deps (nbParameters);
54  for (std::size_t i = 0; i < nbParameters; ++i)
55  {
56  auto dep = parameter(parameters[i].getName ());
57  if (!dep)
58  {
59  throw Exception ("createDependencyVector (Parametrizable): parameter not found: " + parameters[i].getName ());
60  }
61  deps[i] = std::move (dep);
62  }
63  return deps;
64 }
65 
67  const std::function<NodeRef (const std::string&)>& parameter)
68 {
69  const auto& parameters = parametrizable.getIndependentParameters ();
70  const auto nbParameters = parameters.size ();
71  NodeRefVec deps (nbParameters);
72  for (std::size_t i = 0; i < nbParameters; ++i)
73  {
74  auto dep = parameter(parameters[i].getName ());
75  if (!dep)
76  {
77  throw Exception ("createDependencyVector (Parametrizable): parameter not found: " + parameters[i].getName ());
78  }
79  deps[i] = std::move (dep);
80  }
81  return deps;
82 }
83 } // namespace bpp
Context for dataflow node construction.
Definition: DataFlow.h:527
r = variable_value.
virtual const ParameterList & getIndependentParameters() const=0
size_t size() const
virtual const ParameterList & getParameters() const=0
Defines the basic types of data flow nodes.
std::unordered_map< std::string, std::shared_ptr< ConfiguredParameter > > createParameterMap(Context &c, const Parametrizable &parametrizable)
NodeRefVec createDependencyVector(const ParameterAliasable &parametrizable, const std::function< NodeRef(const std::string &)> &parameter)
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
Definition: DataFlow.h:81
std::shared_ptr< Node_DF > NodeRef
Definition: DataFlow.h:78