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

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

commit 5298b014b5e7385191843415e101e9fb7ddc1664
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Wed Dec 21 15:30:55 2022 -0800

    added iterator, removed get_coreset()
---
 python/src/density_wrapper.cpp | 26 +++-----------------------
 python/tests/density_test.py   |  9 ++++++---
 2 files changed, 9 insertions(+), 26 deletions(-)

diff --git a/python/src/density_wrapper.cpp b/python/src/density_wrapper.cpp
index 6ae5a47..5db808f 100644
--- a/python/src/density_wrapper.cpp
+++ b/python/src/density_wrapper.cpp
@@ -17,33 +17,14 @@
  * under the License.
  */
 
-#include "density_sketch.hpp"
-
 #include <pybind11/pybind11.h>
 #include <pybind11/stl.h>
 #include <pybind11/numpy.h>
 #include <vector>
 
-namespace py = pybind11;
-
-namespace datasketches {
-
-namespace python {
-
-template<typename T>
-py::list density_sketch_get_coreset(const density_sketch<T>& sketch) {
-  py::list list(sketch.get_num_retained());
-  unsigned i = 0;
-  for (auto pair: sketch) {
-    list[i++] = py::make_tuple(pair.first, pair.second);
-  }
-  return list;
-}
-
-}
-}
+#include "density_sketch.hpp"
 
-namespace dspy = datasketches::python;
+namespace py = pybind11;
 
 template<typename T>
 void bind_density_sketch(py::module &m, const char* name) {
@@ -71,12 +52,11 @@ void bind_density_sketch(py::module &m, const char* name) {
         "Returns True if the sketch is in estimation mode, otherwise False")
     .def("get_estimate", &density_sketch<T>::get_estimate, py::arg("point"),
         "Returns an approximate density at the given point")
-    .def("get_coreset", &dspy::density_sketch_get_coreset<T>,
-        "Returns the retained samples with weights")
     .def("__str__", &density_sketch<T>::to_string, 
py::arg("print_levels")=false, py::arg("print_items")=false,
         "Produces a string summary of the sketch")
     .def("to_string", &density_sketch<T>::to_string, 
py::arg("print_levels")=false, py::arg("print_items")=false,
         "Produces a string summary of the sketch")
+    .def("__iter__", [](const density_sketch<T>& s){ return 
py::make_iterator(s.begin(), s.end()); })
     ;
 }
 
diff --git a/python/tests/density_test.py b/python/tests/density_test.py
index 82f5bad..eccb0aa 100644
--- a/python/tests/density_test.py
+++ b/python/tests/density_test.py
@@ -44,10 +44,13 @@ class densityTest(unittest.TestCase):
     self.assertLess(sketch.get_num_retained(), n)
     self.assertGreater(sketch.get_estimate([n - 1, n - 1, n - 1]), 0)
 
-    print(sketch.to_string())
+    print(sketch)
 
-    list = sketch.get_coreset()
-    self.assertEqual(len(list), sketch.get_num_retained())
+    for tuple in sketch:
+      vector = tuple[0]
+      weight = tuple[1]
+      self.assertEqual(len(vector), dim)
+      self.assertGreaterEqual(weight, 1) 
 
   def test_density_merge(self):
     sketch1 = density_doubles_sketch(10, 2)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to