-
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
01e2661
commit c83beef
Showing
3 changed files
with
96 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
#include "opt_to_str.h" | ||
namespace { | ||
using ConvFunction = std::function<std::string(boost::any)>; | ||
|
||
template <typename T> | ||
std::pair<std::type_index, ConvFunction> normal_conv_pair{ | ||
std::type_index(typeid(T)), | ||
[](boost::any value) { return std::to_string(boost::any_cast<T>(value)); } | ||
}; | ||
|
||
template <> | ||
std::pair<std::type_index, ConvFunction> normal_conv_pair<bool>{ | ||
std::type_index(typeid(bool)), | ||
[](boost::any value) { return boost::any_cast<bool>(value) ? "True" : "False"; } | ||
}; | ||
|
||
template <> | ||
std::pair<std::type_index, ConvFunction> normal_conv_pair<config::IndicesType>{ | ||
std::type_index(typeid(config::IndicesType)), | ||
[](boost::any value) { | ||
auto opt_value = (boost::any_cast<config::IndicesType>(value)); | ||
if (opt_value.size() == 0) { | ||
return std::string("[]"); | ||
} | ||
std::string str_value = "["; | ||
for (int i = 0; i < opt_value.size() - 1; i++) { | ||
str_value += std::to_string(opt_value.at(i)) + ", "; | ||
} | ||
str_value += std::to_string(opt_value.back()) + "]"; | ||
return str_value; | ||
} | ||
}; | ||
template <> | ||
std::pair<std::type_index, ConvFunction> normal_conv_pair<algos::metric::MetricAlgo>{ | ||
std::type_index(typeid(algos::metric::MetricAlgo)), | ||
[](boost::any value){ | ||
auto opt_value = boost::any_cast<algos::metric::MetricAlgo>(value); | ||
return opt_value._to_string(); | ||
} | ||
}; | ||
template <> | ||
std::pair<std::type_index, ConvFunction> normal_conv_pair<algos::metric::Metric>{ | ||
std::type_index(typeid(algos::metric::Metric)), | ||
[](boost::any value){ | ||
auto opt_value = boost::any_cast<algos::metric::Metric>(value); | ||
return opt_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>, | ||
normal_conv_pair<algos::metric::MetricAlgo>, | ||
normal_conv_pair<algos::metric::Metric> | ||
}; | ||
} // namespace | ||
|
||
namespace python_bindings{ | ||
std::string opt_to_str(std::type_index type, boost::any val) { | ||
return converters.at(type)(val); | ||
} | ||
} // namespace python_bindings |
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,24 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <type_traits> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "algorithms/algorithm.h" | ||
#include "algorithms/metric/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/tabular_data/input_table_type.h" | ||
#include "config/thread_number/type.h" | ||
#include "config/names.h" | ||
#include "model/types/types.h" | ||
|
||
namespace python_bindings{ | ||
std::string opt_to_str(std::type_index type, boost::any val); | ||
} // namespace python_bindings |
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