-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb3f7d7
commit e4d9b33
Showing
8 changed files
with
308 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "opt_to_py.h" | ||
namespace { | ||
namespace py = pybind11; | ||
using ConvFunction = std::function<py::object(boost::any)>; | ||
|
||
template <typename T> | ||
std::pair<std::type_index, ConvFunction> normal_conv_pair{ | ||
std::type_index(typeid(T)), | ||
[](boost::any value) { return py::cast(boost::any_cast<T>(value)); }}; | ||
|
||
template <typename T> | ||
std::pair<std::type_index, ConvFunction> enum_conv_pair{ | ||
std::type_index(typeid(T)), | ||
[](boost::any value) { return py::cast(boost::any_cast<T>(value)._to_string()); }}; | ||
const std::unordered_map<std::type_index, ConvFunction> converters{ | ||
normal_conv_pair<int>, | ||
normal_conv_pair<double>, | ||
normal_conv_pair<long double>, | ||
normal_conv_pair<unsigned int>, | ||
normal_conv_pair<bool>, | ||
normal_conv_pair<config::ThreadNumType>, | ||
normal_conv_pair<config::MaxLhsType>, | ||
normal_conv_pair<config::ErrorType>, | ||
normal_conv_pair<config::IndicesType>, | ||
enum_conv_pair<algos::metric::MetricAlgo>, | ||
enum_conv_pair<algos::metric::Metric>, | ||
enum_conv_pair<algos::InputFormat>}; | ||
} // namespace | ||
|
||
namespace python_bindings { | ||
py::object opt_to_py(std::type_index type, boost::any val) { | ||
return converters.at(type)(val); | ||
} | ||
} // namespace python_bindings |
11 changes: 3 additions & 8 deletions
11
src/python_bindings/opt_to_str.h → src/python_bindings/opt_to_py.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <type_traits> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include <boost/any.hpp> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "algorithms/algorithm.h" | ||
#include "algorithms/metric/enums.h" | ||
#include "association_rules/ar_algorithm_enums.h" | ||
#include "config/equal_nulls/type.h" | ||
#include "config/error/type.h" | ||
#include "config/indices/type.h" | ||
#include "config/max_lhs/type.h" | ||
#include "config/names.h" | ||
#include "config/tabular_data/input_table_type.h" | ||
#include "config/thread_number/type.h" | ||
#include "model/types/types.h" | ||
|
||
namespace python_bindings { | ||
namespace py = pybind11; | ||
py::object opt_to_str(std::type_index type, boost::any val); | ||
pybind11::object opt_to_py(std::type_index type, boost::any val); | ||
} // namespace python_bindings |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.