@@ -45,32 +45,8 @@ template <typename T> bool check_id_na(T const& obj) {
4545} // namespace detail
4646
4747namespace independence {
48- struct UpdateCompProperties {
49- bool has_any_elements{false }; // whether the component has any elements in the update data
50- bool ids_all_na{false }; // whether all ids are all NA
51- bool ids_part_na{false }; // whether some ids are NA but some are not
52- bool dense{false }; // whether the component is dense
53- bool uniform{false }; // whether the component is uniform
54- bool is_columnar{false }; // whether the component is columnar
55- bool update_ids_match{false }; // whether the ids match
56- Idx elements_ps_in_update{utils::invalid_index}; // count of elements for this component per scenario in update
57- Idx elements_in_base{utils::invalid_index}; // count of elements for this component per scenario in input
58-
59- constexpr bool no_id () const { return !has_any_elements || ids_all_na; }
60- constexpr bool qualify_for_optional_id () const {
61- return update_ids_match && ids_all_na && uniform && elements_ps_in_update == elements_in_base;
62- }
63- constexpr bool provided_ids_valid () const {
64- return is_empty_component () || (update_ids_match && !(ids_all_na || ids_part_na));
65- }
66- constexpr bool is_empty_component () const { return !has_any_elements; }
67- constexpr bool is_independent () const { return qualify_for_optional_id () || provided_ids_valid (); }
68- constexpr Idx get_n_elements () const {
69- assert (uniform || elements_ps_in_update == utils::invalid_index);
7048
71- return qualify_for_optional_id () ? elements_ps_in_update : na_Idx;
72- }
73- };
49+ using UpdateCompProperties = utils::UpdateCompProperties;
7450
7551template <typename CompType> void process_buffer_span (auto const & all_spans, UpdateCompProperties& properties) {
7652 properties.ids_all_na = std::ranges::all_of (all_spans, [](auto const & vec) {
@@ -127,9 +103,6 @@ UpdateCompProperties check_component_independence(ConstDataset const& update_dat
127103 return properties;
128104}
129105
130- template <class ... ComponentTypes>
131- using UpdateIndependence = std::array<UpdateCompProperties, utils::n_types<ComponentTypes...>>;
132-
133106inline void validate_update_data_independence (UpdateCompProperties const & comp, std::string const & comp_name) {
134107 if (comp.is_empty_component ()) {
135108 return ; // empty dataset is still supported
@@ -150,10 +123,10 @@ inline void validate_update_data_independence(UpdateCompProperties const& comp,
150123 }
151124}
152125
153- template <class ... ComponentTypes, class ComponentContainer >
154- UpdateIndependence<ComponentTypes...> check_update_independence (MainModelState<ComponentContainer> const & state,
155- ConstDataset const & update_data) {
156- return utils::run_functor_with_all_types_return_array<ComponentTypes...> (
126+ template <typename MainModelType >
127+ typename MainModelType::UpdateIndependence
128+ check_update_independence ( typename MainModelType::MainModelState const & state, ConstDataset const & update_data) {
129+ return MainModelType::run_functor_with_all_component_types_return_array (
157130 [&state, &update_data]<typename CompType>() {
158131 auto const n_component = state.components .template size <CompType>();
159132 return check_component_independence<CompType>(update_data, n_component);
@@ -214,22 +187,22 @@ std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContainer> con
214187}
215188} // namespace detail
216189
217- template <class ... ComponentTypes, class ComponentContainer >
218- utils ::SequenceIdx<ComponentTypes...>
219- get_all_sequence_idx_map (MainModelState<ComponentContainer> const & state, ConstDataset const & update_data,
220- Idx scenario_idx, utils ::ComponentFlags<ComponentTypes...> const & components_to_store,
221- independence ::UpdateIndependence<ComponentTypes...> const & independence, bool cached) {
222- return utils::run_functor_with_all_types_return_array<ComponentTypes...> (
190+ template <class MainModelType >
191+ typename MainModelType ::SequenceIdx
192+ get_all_sequence_idx_map (typename MainModelType:: MainModelState const & state, ConstDataset const & update_data,
193+ Idx scenario_idx, typename MainModelType ::ComponentFlags const & components_to_store,
194+ typename MainModelType ::UpdateIndependence const & independence, bool cached) {
195+ return MainModelType::run_functor_with_all_component_types_return_array (
223196 [&state, &update_data, scenario_idx, &components_to_store, &independence, cached]<typename CompType>() {
224197 auto const component_properties =
225- std::get<utils:: index_of_component<CompType, ComponentTypes... >>(independence);
198+ std::get<MainModelType:: template index_of_component<CompType>>(independence);
226199 // The sequence for the independent components is cached (true). For the remaining components, the sequence
227200 // cannot be cached (false), so the independence flags are inverted to not return an empty sequence when
228201 // this is the case.
229202
230203 if (bool const component_independence = cached != component_properties.is_independent ();
231204 !component_independence ||
232- !std::get<utils:: index_of_component<CompType, ComponentTypes... >>(components_to_store)) {
205+ !std::get<MainModelType:: template index_of_component<CompType>>(components_to_store)) {
233206 return std::vector<Idx2D>{};
234207 }
235208 independence::validate_update_data_independence (component_properties, CompType::name);
0 commit comments