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 2022/01/26 01:08:02 UTC

[datasketches-cpp] branch quantile_sketch_sorted_view updated (59b2924 -> 26c89ad)

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

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


    from 59b2924  implicit conversion
     new a9c8d07  adjusted python wrapper
     new 26c89ad  include cmath for std::isnan

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 kll/include/kll_sketch.hpp |  1 +
 python/src/kll_wrapper.cpp | 29 +++++++++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

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


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

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a9c8d075510fbba7e181792dc40f10487d13014c
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jan 25 17:03:53 2022 -0800

    adjusted python wrapper
---
 python/src/kll_wrapper.cpp | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/python/src/kll_wrapper.cpp b/python/src/kll_wrapper.cpp
index ab12818..3362c1d 100644
--- a/python/src/kll_wrapper.cpp
+++ b/python/src/kll_wrapper.cpp
@@ -59,10 +59,23 @@ double kll_sketch_get_rank(const kll_sketch<T>& sk, const T& item, bool inclusiv
 }
 
 template<typename T>
+T kll_sketch_get_quantile(const kll_sketch<T>& sk,
+                          double rank,
+                          bool inclusive) {
+  if (inclusive)
+    return T(sk.template get_quantile<true>(rank));
+  else
+    return T(sk.template get_quantile<false>(rank));
+}
+
+template<typename T>
 py::list kll_sketch_get_quantiles(const kll_sketch<T>& sk,
-                                  std::vector<double>& fractions) {
+                                  std::vector<double>& fractions,
+                                  bool inclusive) {
   size_t nQuantiles = fractions.size();
-  auto result = sk.get_quantiles(&fractions[0], nQuantiles);
+  auto result = inclusive ?
+      sk.template get_quantiles<true>(fractions.data(), nQuantiles)
+    : sk.template get_quantiles<false>(fractions.data(), nQuantiles);
 
   // returning as std::vector<> would copy values to a list anyway
   py::list list(nQuantiles);
@@ -79,8 +92,8 @@ py::list kll_sketch_get_pmf(const kll_sketch<T>& sk,
                             bool inclusive) {
   size_t nPoints = split_points.size();
   auto result = inclusive ?
-      sk.template get_PMF<true>(&split_points[0], nPoints)
-    : sk.template get_PMF<false>(&split_points[0], nPoints);
+      sk.template get_PMF<true>(split_points.data(), nPoints)
+    : sk.template get_PMF<false>(split_points.data(), nPoints);
 
   py::list list(nPoints + 1);
   for (size_t i = 0; i <= nPoints; ++i) {
@@ -96,8 +109,8 @@ py::list kll_sketch_get_cdf(const kll_sketch<T>& sk,
                             bool inclusive) {
   size_t nPoints = split_points.size();
   auto result = inclusive ?
-      sk.template get_CDF<true>(&split_points[0], nPoints)
-    : sk.template get_CDF<false>(&split_points[0], nPoints);
+      sk.template get_CDF<true>(split_points.data(), nPoints)
+    : sk.template get_CDF<false>(split_points.data(), nPoints);
 
   py::list list(nPoints + 1);
   for (size_t i = 0; i <= nPoints; ++i) {
@@ -156,7 +169,7 @@ void bind_kll_sketch(py::module &m, const char* name) {
          "Returns the minimum value from the stream. If empty, kll_floats_sketch retursn nan; kll_ints_sketch throws a RuntimeError")
     .def("get_max_value", &kll_sketch<T>::get_max_value,
          "Returns the maximum value from the stream. If empty, kll_floats_sketch retursn nan; kll_ints_sketch throws a RuntimeError")
-    .def("get_quantile", &kll_sketch<T>::get_quantile, py::arg("fraction"),
+    .def("get_quantile", &dspy::kll_sketch_get_quantile<T>, py::arg("fraction"), py::arg("inclusive")=false,
          "Returns an approximation to the value of the data item "
          "that would be preceded by the given fraction of a hypothetical sorted "
          "version of the input stream so far.\n"
@@ -165,7 +178,7 @@ void bind_kll_sketch(py::module &m, const char* name) {
          "sketch. Instead use get_quantiles(), which pays the overhead only once.\n"
          "For kll_floats_sketch: if the sketch is empty this returns nan. "
          "For kll_ints_sketch: if the sketch is empty this throws a RuntimeError.")
-    .def("get_quantiles", &dspy::kll_sketch_get_quantiles<T>, py::arg("fractions"),
+    .def("get_quantiles", &dspy::kll_sketch_get_quantiles<T>, py::arg("fractions"), py::arg("inclusive")=false,
          "This is a more efficient multiple-query version of get_quantile().\n"
          "This returns an array that could have been generated by using get_quantile() for each "
          "fractional rank separately, but would be very inefficient. "

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


[datasketches-cpp] 02/02: include cmath for std::isnan

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 26c89adb832c439313a3e1bcea9f7e0f92faacbd
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jan 25 17:04:18 2022 -0800

    include cmath for std::isnan
---
 kll/include/kll_sketch.hpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kll/include/kll_sketch.hpp b/kll/include/kll_sketch.hpp
index c0e0712..312ff9a 100644
--- a/kll/include/kll_sketch.hpp
+++ b/kll/include/kll_sketch.hpp
@@ -23,6 +23,7 @@
 #include <functional>
 #include <memory>
 #include <vector>
+#include <cmath>
 
 #include "quantile_sketch_sorted_view.hpp"
 #include "common_defs.hpp"

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