Skip to content

Commit

Permalink
Cleanup in Python bindings and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
BUYT-1 committed Jun 5, 2024
1 parent 4c15f0d commit 6d79e72
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 48 deletions.
3 changes: 2 additions & 1 deletion cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ class Algorithm(StrEnum):
Algorithm.naive_ucc_verifier),
Task.aucc_verification: TaskInfo([Algorithm.naive_aucc_verifier],
Algorithm.naive_aucc_verifier),
Task.gfd_verification: TaskInfo([Algorithm.naive_gfd_verifier, Algorithm.gfd_verifier, Algorithm.egfd_verifier],
Task.gfd_verification: TaskInfo([Algorithm.naive_gfd_verifier, Algorithm.gfd_verifier,
Algorithm.egfd_verifier],
Algorithm.naive_gfd_verifier),
}

Expand Down
4 changes: 2 additions & 2 deletions examples/comparison_pfd_vs_afd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def get_pfds():
pfds = set(get_pfds())
afds = set(get_afds())

print("pFDs \ AFDs =", stringify(pfds - afds))
print("AFDs \ pFDs =", stringify(afds - pfds))
print("pFDs \\ AFDs =", stringify(pfds - afds))
print("AFDs \\ pFDs =", stringify(afds - pfds))
print("AFDs ∩ pFDs =", stringify(afds & pfds))

print("1 - PerValue([DeviceId] -> Data) =", 0.1714285714)
Expand Down
22 changes: 11 additions & 11 deletions src/python_bindings/ac/bind_ac.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include "bind_ac.h"
#include "ac/bind_ac.h"

#include <cstddef>
#include <string>
#include <utility>
#include <vector>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -7,9 +12,7 @@
#include "algorithms/algebraic_constraints/mining_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindAc(py::module_& main_module) {
Expand All @@ -27,7 +30,7 @@ void BindAc(py::module_& main_module) {
std::vector<std::pair<pybind11::float_, pybind11::float_>> res;
res.reserve(ranges.ranges.size() / 2);
assert(ranges.ranges.size() % 2 == 0);
for (size_t i = 0; i < ranges.ranges.size(); i += 2) {
for (std::size_t i = 0; i < ranges.ranges.size(); i += 2) {
// TODO: change this once a proper conversion mechanism from
// `model::INumericType` is implemented
std::string l_endpoint =
Expand All @@ -42,12 +45,9 @@ void BindAc(py::module_& main_module) {
BindPrimitiveNoBase<ACAlgorithm>(ac_module, "AcAlgorithm")
.def("get_ac_ranges", &ACAlgorithm::GetRangesCollections,
py::return_value_policy::reference_internal)
.def(
"get_ac_exceptions",
[](ACAlgorithm& algo) {
algo.CollectACExceptions();
return algo.GetACExceptions();
},
py::return_value_policy::reference_internal);
.def("get_ac_exceptions", [](ACAlgorithm& algo) {
algo.CollectACExceptions();
return algo.GetACExceptions();
});
}
} // namespace python_bindings
4 changes: 1 addition & 3 deletions src/python_bindings/ar/bind_ar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bind_ar.h"
#include "ar/bind_ar.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -7,9 +7,7 @@
#include "algorithms/association_rules/mining_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindAr(py::module_& main_module) {
Expand Down
3 changes: 2 additions & 1 deletion src/python_bindings/bind_main_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include "py_util/opt_to_py.h"
#include "py_util/py_to_any.h"

namespace {
namespace py = pybind11;

namespace {
using algos::Algorithm;
auto const kVoidIndex = std::type_index{typeid(void)};

Expand Down
4 changes: 1 addition & 3 deletions src/python_bindings/dd/bind_split.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bind_split.h"
#include "dd/bind_split.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -7,9 +7,7 @@
#include "algorithms/dd/mining_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindSplit(py::module_& main_module) {
Expand Down
8 changes: 6 additions & 2 deletions src/python_bindings/fd/bind_fd.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "bind_fd.h"
#include "fd/bind_fd.h"

#include <cstddef>
#include <initializer_list>
#include <vector>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -10,9 +14,9 @@
#include "py_util/bind_primitive.h"
#include "util/bitset_utils.h"

namespace {
namespace py = pybind11;

namespace {
template <typename ElementType>
py::tuple VectorToTuple(std::vector<ElementType> vec) {
std::size_t const size = vec.size();
Expand Down
6 changes: 3 additions & 3 deletions src/python_bindings/fd/bind_fd_verification.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bind_fd_verification.h"
#include "fd/bind_fd_verification.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -8,9 +8,7 @@
#include "algorithms/fd/verification_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindFdVerification(pybind11::module_& main_module) {
Expand All @@ -30,6 +28,8 @@ void BindFdVerification(pybind11::module_& main_module) {
.def("get_num_error_rows", &FDVerifier::GetNumErrorRows)
.def("get_highlights", &FDVerifier::GetHighlights);

// Create AFD verification module alias. We currently consider FD verification and AFD
// verification to be the same.
main_module.attr("afd_verification") = fd_verification_module;
}
} // namespace python_bindings
2 changes: 0 additions & 2 deletions src/python_bindings/gfd/bind_gfd_verification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include "algorithms/gfd/verification_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindGfdVerification(pybind11::module_& main_module) {
Expand Down
4 changes: 1 addition & 3 deletions src/python_bindings/mfd/bind_mfd_verification.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bind_mfd_verification.h"
#include "mfd/bind_mfd_verification.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -7,9 +7,7 @@
#include "algorithms/metric/verification_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindMfdVerification(py::module_& main_module) {
Expand Down
2 changes: 1 addition & 1 deletion src/python_bindings/od/bind_od.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bind_od.h"
#include "od/bind_od.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand Down
4 changes: 4 additions & 0 deletions src/python_bindings/py_util/bind_primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <array>
#include <cstddef>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>

#include <pybind11/pybind11.h>

Expand Down
5 changes: 4 additions & 1 deletion src/python_bindings/py_util/create_dataframe_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "create_dataframe_reader.h"
#include "py_util/create_dataframe_reader.h"

#include <Python.h>
#include <pybind11/pybind11.h>

#include "config/exceptions.h"
#include "py_util/dataframe_reader.h"
Expand Down
2 changes: 2 additions & 0 deletions src/python_bindings/py_util/create_dataframe_reader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

#include <pybind11/pybind11.h>

#include "config/tabular_data/input_table_type.h"
Expand Down
3 changes: 2 additions & 1 deletion src/python_bindings/py_util/dataframe_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "dataframe_reader.h"
#include "py_util/dataframe_reader.h"

#include <cstddef>
#include <string>
#include <utility>
#include <vector>
Expand Down
5 changes: 5 additions & 0 deletions src/python_bindings/py_util/dataframe_reader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

#include <cstddef>
#include <functional>
#include <string>
#include <vector>

#include <pybind11/pybind11.h>

#include "model/table/idataset_stream.h"
Expand Down
3 changes: 2 additions & 1 deletion src/python_bindings/py_util/get_py_type.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "get_py_type.h"
#include "py_util/get_py_type.h"

#include <functional>
#include <typeinfo>
#include <unordered_map>
#include <vector>

#include <Python.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl/filesystem.h>

#include "algorithms/cfd/enums.h"
Expand Down
9 changes: 7 additions & 2 deletions src/python_bindings/py_util/opt_to_py.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "opt_to_py.h"
#include "py_util/opt_to_py.h"

#include <functional>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <utility>

#include <boost/any.hpp>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "algorithms/metric/enums.h"
Expand All @@ -14,8 +18,9 @@
#include "config/max_lhs/type.h"
#include "config/thread_number/type.h"

namespace {
namespace py = pybind11;

namespace {
using ConvFunction = std::function<py::object(boost::any)>;

template <typename T>
Expand Down
11 changes: 9 additions & 2 deletions src/python_bindings/py_util/py_to_any.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "py_util/py_to_any.h"

#include <functional>
#include <memory>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

#include <boost/any.hpp>
#include <easylogging++.h>
Expand All @@ -19,9 +26,9 @@
#include "py_util/create_dataframe_reader.h"
#include "util/enum_to_available_values.h"

namespace {

namespace py = pybind11;

namespace {
using ConvFunc = std::function<boost::any(std::string_view, py::handle)>;

template <typename T>
Expand Down
3 changes: 3 additions & 0 deletions src/python_bindings/py_util/py_to_any.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <string_view>
#include <typeindex>

#include <boost/any.hpp>
#include <pybind11/pybind11.h>

Expand Down
11 changes: 8 additions & 3 deletions src/python_bindings/statistics/bind_statistics.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#include "bind_statistics.h"
#include "statistics/bind_statistics.h"

#include <cassert>
#include <cstddef>

#include <Python.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "algorithms/statistics/data_stats.h"
#include "algorithms/statistics/statistic.h"
#include "model/types/builtin.h"
#include "model/types/type.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace PYBIND11_NAMESPACE {
namespace detail {
Expand Down
4 changes: 1 addition & 3 deletions src/python_bindings/ucc/bind_ucc.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bind_ucc.h"
#include "ucc/bind_ucc.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand All @@ -9,10 +9,8 @@
#include "py_util/bind_primitive.h"
#include "util/bitset_utils.h"

namespace {
namespace py = pybind11;
using model::UCC;
} // namespace

namespace python_bindings {
void BindUcc(py::module_& main_module) {
Expand Down
6 changes: 3 additions & 3 deletions src/python_bindings/ucc/bind_ucc_verification.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include "bind_ucc_verification.h"
#include "ucc/bind_ucc_verification.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "algorithms/ucc/verification_algorithms.h"
#include "py_util/bind_primitive.h"

namespace {
namespace py = pybind11;
} // namespace

namespace python_bindings {
void BindUccVerification(pybind11::module_& main_module) {
Expand All @@ -22,6 +20,8 @@ void BindUccVerification(pybind11::module_& main_module) {
.def("get_num_rows_violating_ucc", &UCCVerifier::GetNumRowsViolatingUCC)
.def("get_clusters_violating_ucc", &UCCVerifier::GetClustersViolatingUCC)
.def("get_error", &UCCVerifier::GetError);
// Create AUCC verification module alias. We currently consider UCC verification and AUCC
// verification to be the same.
main_module.attr("aucc_verification") = ucc_verification_module;
}
} // namespace python_bindings

0 comments on commit 6d79e72

Please sign in to comment.