You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2021/10/12 22:14:30 UTC

[datasketches-cpp] 02/02: adjusted python wrapper

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch no_sstream_in_to_string
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit df9188d0a3961da98f13b5faa34ae38311294b94
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Oct 12 15:14:22 2021 -0700

    adjusted python wrapper
---
 python/src/cpc_wrapper.cpp   |  1 -
 python/src/fi_wrapper.cpp    | 10 +++++++---
 python/src/kll_wrapper.cpp   | 10 +++++++---
 python/src/req_wrapper.cpp   | 10 +++++++---
 python/src/theta_wrapper.cpp |  1 -
 python/src/vo_wrapper.cpp    | 10 +++++++---
 6 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/python/src/cpc_wrapper.cpp b/python/src/cpc_wrapper.cpp
index deae7f6..1a9ccd8 100644
--- a/python/src/cpc_wrapper.cpp
+++ b/python/src/cpc_wrapper.cpp
@@ -17,7 +17,6 @@
  * under the License.
  */
 
-#include <sstream>
 #include <pybind11/pybind11.h>
 
 #include "cpc_sketch.hpp"
diff --git a/python/src/fi_wrapper.cpp b/python/src/fi_wrapper.cpp
index c4066b7..2ea4ee7 100644
--- a/python/src/fi_wrapper.cpp
+++ b/python/src/fi_wrapper.cpp
@@ -20,7 +20,6 @@
 #include "frequent_items_sketch.hpp"
 
 #include <pybind11/pybind11.h>
-#include <sstream>
 
 namespace py = pybind11;
 
@@ -64,6 +63,11 @@ py::list fi_sketch_get_frequent_items(const frequent_items_sketch<T>& sk,
   return list;
 }
 
+template<typename T>
+std::string fi_sketch_to_string(const frequent_items_sketch<T>& sk, bool print_items) {
+  return sk.to_string(print_items);
+}
+
 }
 }
 
@@ -75,9 +79,9 @@ void bind_fi_sketch(py::module &m, const char* name) {
 
   py::class_<frequent_items_sketch<T>>(m, name)
     .def(py::init<uint8_t>(), py::arg("lg_max_k"))
-    .def("__str__", &frequent_items_sketch<T>::to_string, py::arg("print_items")=false,
+    .def("__str__", &dspy::fi_sketch_to_string<T>, py::arg("print_items")=false,
          "Produces a string summary of the sketch")
-    .def("to_string", &frequent_items_sketch<T>::to_string, py::arg("print_items")=false,
+    .def("to_string", &dspy::fi_sketch_to_string<T>, py::arg("print_items")=false,
          "Produces a string summary of the sketch")
     .def("update", (void (frequent_items_sketch<T>::*)(const T&, uint64_t)) &frequent_items_sketch<T>::update, py::arg("item"), py::arg("weight")=1,
          "Updates the sketch with the given string and, optionally, a weight")
diff --git a/python/src/kll_wrapper.cpp b/python/src/kll_wrapper.cpp
index 48004b9..7cf8c03 100644
--- a/python/src/kll_wrapper.cpp
+++ b/python/src/kll_wrapper.cpp
@@ -22,7 +22,6 @@
 #include <pybind11/pybind11.h>
 #include <pybind11/stl.h>
 #include <pybind11/numpy.h>
-#include <sstream>
 #include <vector>
 
 namespace py = pybind11;
@@ -106,6 +105,11 @@ void kll_sketch_update(kll_sketch<T>& sk, py::array_t<T, py::array::c_style | py
   }
 }
 
+template<typename T>
+std::string kll_sketch_to_string(const kll_sketch<T>& sk, bool print_levels, bool print_items) {
+  return sk.to_string(print_levels, print_items);
+}
+
 }
 }
 
@@ -124,9 +128,9 @@ void bind_kll_sketch(py::module &m, const char* name) {
          "Updates the sketch with the values in the given array")
     .def("merge", (void (kll_sketch<T>::*)(const kll_sketch<T>&)) &kll_sketch<T>::merge, py::arg("sketch"),
          "Merges the provided sketch into the this one")
-    .def("__str__", &kll_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
+    .def("__str__", &dspy::kll_sketch_to_string<T>, py::arg("print_levels")=false, py::arg("print_items")=false,
          "Produces a string summary of the sketch")
-    .def("to_string", &kll_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
+    .def("to_string", &dspy::kll_sketch_to_string<T>, py::arg("print_levels")=false, py::arg("print_items")=false,
          "Produces a string summary of the sketch")
     .def("is_empty", &kll_sketch<T>::is_empty,
          "Returns True if the sketch is empty, otherwise False")
diff --git a/python/src/req_wrapper.cpp b/python/src/req_wrapper.cpp
index 9ef0b87..fbffe10 100644
--- a/python/src/req_wrapper.cpp
+++ b/python/src/req_wrapper.cpp
@@ -22,7 +22,6 @@
 #include <pybind11/pybind11.h>
 #include <pybind11/stl.h>
 #include <pybind11/numpy.h>
-#include <sstream>
 #include <vector>
 
 namespace py = pybind11;
@@ -135,6 +134,11 @@ void req_sketch_update(req_sketch<T>& sk, py::array_t<T, py::array::c_style | py
   }
 }
 
+template<typename T>
+std::string req_sketch_to_string(const req_sketch<T>& sk, bool print_levels, bool print_items) {
+  return sk.to_string(print_levels, print_items);
+}
+
 }
 }
 
@@ -153,9 +157,9 @@ void bind_req_sketch(py::module &m, const char* name) {
          "Updates the sketch with the values in the given array")
     .def("merge", (void (req_sketch<T>::*)(const req_sketch<T>&)) &req_sketch<T>::merge, py::arg("sketch"),
          "Merges the provided sketch into the this one")
-    .def("__str__", &req_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
+    .def("__str__", &dspy::req_sketch_to_string<T>, py::arg("print_levels")=false, py::arg("print_items")=false,
          "Produces a string summary of the sketch")
-    .def("to_string", &req_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
+    .def("to_string", &dspy::req_sketch_to_string<T>, py::arg("print_levels")=false, py::arg("print_items")=false,
          "Produces a string summary of the sketch")
     .def("is_hra", &req_sketch<T>::is_HRA,
          "Returns True if the sketch is in High Rank Accuracy mode, otherwise False")
diff --git a/python/src/theta_wrapper.cpp b/python/src/theta_wrapper.cpp
index 86a2406..a3a3536 100644
--- a/python/src/theta_wrapper.cpp
+++ b/python/src/theta_wrapper.cpp
@@ -17,7 +17,6 @@
  * under the License.
  */
 
-#include <sstream>
 #include <pybind11/pybind11.h>
 #include <pybind11/stl.h>
 
diff --git a/python/src/vo_wrapper.cpp b/python/src/vo_wrapper.cpp
index a8eb0f5..2e10ca0 100644
--- a/python/src/vo_wrapper.cpp
+++ b/python/src/vo_wrapper.cpp
@@ -22,7 +22,6 @@
 
 #include <pybind11/pybind11.h>
 #include <pybind11/functional.h>
-#include <sstream>
 
 namespace py = pybind11;
 
@@ -72,6 +71,11 @@ std::string vo_sketch_to_string(const var_opt_sketch<T>& sk, bool print_items) {
   }
 }
 
+template<typename T>
+std::string vo_union_to_string(const var_opt_union<T>& u) {
+  return u.to_string();
+}
+
 }
 }
 
@@ -116,9 +120,9 @@ void bind_vo_union(py::module &m, const char* name) {
 
   py::class_<var_opt_union<T>>(m, name)
     .def(py::init<uint32_t>(), py::arg("max_k"))
-    .def("__str__", &var_opt_union<T>::to_string,
+    .def("__str__", &dspy::vo_union_to_string<T>,
          "Produces a string summary of the sketch")
-    .def("to_string", &var_opt_union<T>::to_string,
+    .def("to_string", &dspy::vo_union_to_string<T>,
          "Produces a string summary of the sketch")
     .def("update", (void (var_opt_union<T>::*)(const var_opt_sketch<T>& sk)) &var_opt_union<T>::update, py::arg("sketch"),
          "Updates the union with the given sketch")

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org