Skip to content

Commit

Permalink
Add GetPossibleOptions to Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
BUYT-1 committed Aug 15, 2023
1 parent 6d016bf commit 433bf6d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/core/algorithms/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,13 @@ std::type_index Algorithm::GetTypeIndex(std::string_view option_name) const {
return it->second->GetTypeIndex();
}

std::unordered_set<std::string_view> Algorithm::GetPossibleOptions() const {
std::unordered_set<std::string_view> possible_options;
for (const auto& [key, _] : possible_options_) {
possible_options.insert(key);
}
return possible_options;
}

} // namespace algos

2 changes: 2 additions & 0 deletions src/core/algorithms/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class Algorithm {
}

std::type_index GetTypeIndex(std::string_view option_name) const;

[[nodiscard]] std::unordered_set<std::string_view> GetPossibleOptions() const;
};

} // namespace algos
2 changes: 2 additions & 0 deletions src/python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ PYBIND11_MODULE(desbordante, module) {
"Load data after all options have been set by SetOption calls")
.def("get_needed_options", &PyAlgorithmBase::GetNeededOptions,
"Get names of options the algorithm needs")
.def("get_possible_options", &PyAlgorithmBase::GetPossibleOptions,
"Get names of options the algorithm may request")
.def("set_option", &PyAlgorithmBase::SetOption, "option_name"_a,
"option_value"_a = pybind11::none(), "Set option value")
.def("get_option_type", &PyAlgorithmBase::GetOptionType, "option_name"_a,
Expand Down
4 changes: 4 additions & 0 deletions src/python_bindings/py_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ std::unordered_set<std::string_view> PyAlgorithmBase::GetNeededOptions() const {
return algorithm_->GetNeededOptions();
}

std::unordered_set<std::string_view> PyAlgorithmBase::GetPossibleOptions() const {
return algorithm_->GetPossibleOptions();
}

py::tuple PyAlgorithmBase::GetOptionType(std::string_view option_name) const {
auto type_index = algorithm_->GetTypeIndex(option_name);
if (type_index == void_index)
Expand Down
2 changes: 2 additions & 0 deletions src/python_bindings/py_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class PyAlgorithmBase {

[[nodiscard]] std::unordered_set<std::string_view> GetNeededOptions() const;

[[nodiscard]] std::unordered_set<std::string_view> GetPossibleOptions() const;

[[nodiscard]] pybind11::tuple GetOptionType(std::string_view option_name) const;

// For pandas dataframes
Expand Down
6 changes: 4 additions & 2 deletions src/python_bindings/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import desbordante as desb

for name, type_ in getmembers(desb, isclass):
for algo_name, type_ in getmembers(desb, isclass):
if not (issubclass(type_, desb.FdAlgorithm)
and type_ is not desb.FdAlgorithm):
continue
algorithm = type_()
for option_name in algorithm.get_possible_options():
print(option_name, algorithm.get_option_type(option_name))
algorithm.load_data('WDC_satellites.csv', ',', False)
algorithm.execute()
print(name, algorithm.get_fds())
print(algo_name, algorithm.get_fds())

0 comments on commit 433bf6d

Please sign in to comment.