Skip to content

Commit

Permalink
Fix bug with byndings for Mind algorithm
Browse files Browse the repository at this point in the history
When loading data, it was not possible to obtain a type index for
the options that the `Spider` uses, since these options are not in
the possible options of the `Mind` algorithm.
  • Loading branch information
vs9h committed Dec 3, 2024
1 parent 9e045c9 commit 40b5b8a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/algorithms/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ bool Algorithm::SetExternalOption([[maybe_unused]] std::string_view option_name,
return false;
}

std::type_index Algorithm::GetExternalTypeIndex(std::string_view) const {
return typeid(void);
}

void Algorithm::AddSpecificNeededOptions(
[[maybe_unused]] std::unordered_set<std::string_view>& previous_options) const {}

Expand Down Expand Up @@ -125,7 +129,9 @@ std::unordered_set<std::string_view> Algorithm::GetNeededOptions() const {

std::type_index Algorithm::GetTypeIndex(std::string_view option_name) const {
auto it = possible_options_.find(option_name);
if (it == possible_options_.end()) return typeid(void);
if (it == possible_options_.end()) {
return GetExternalTypeIndex(option_name);
}
return it->second->GetTypeIndex();
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/algorithms/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class Algorithm {
// Overload this if you want to work with options outside of
// possible_options_ map. Useful for pipelines.
virtual bool SetExternalOption(std::string_view option_name, boost::any const& value);

// Override this function if your algorithm uses options outside possible_options_.
// For example, when you need to resolve the type index of one of the algorithms inside the
// pipeline.
virtual std::type_index GetExternalTypeIndex(std::string_view) const;

virtual void AddSpecificNeededOptions(
std::unordered_set<std::string_view>& previous_options) const;
void ExecutePrepare();
Expand Down
4 changes: 4 additions & 0 deletions src/core/algorithms/ind/mind/mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ bool Mind::SetExternalOption(std::string_view option_name, boost::any const& val
return false;
}

std::type_index Mind::GetExternalTypeIndex(std::string_view option_name) const {
return auind_algo_->GetTypeIndex(option_name);
};

void Mind::LoadINDAlgorithmDataInternal() {
timings_.load = util::TimedInvoke(&Algorithm::LoadData, auind_algo_);
}
Expand Down
1 change: 1 addition & 0 deletions src/core/algorithms/ind/mind/mind.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Mind final : public INDAlgorithm {
void AddSpecificNeededOptions(
std::unordered_set<std::string_view>& previous_options) const override;
bool SetExternalOption(std::string_view option_name, boost::any const& value) override;
std::type_index GetExternalTypeIndex(std::string_view option_name) const override;

void LoadINDAlgorithmDataInternal() override;

Expand Down

0 comments on commit 40b5b8a

Please sign in to comment.