datasketches 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/NOTICE +1 -1
- data/README.md +0 -2
- data/ext/datasketches/cpc_wrapper.cpp +3 -3
- data/ext/datasketches/kll_wrapper.cpp +0 -10
- data/lib/datasketches/version.rb +1 -1
- data/lib/datasketches.rb +1 -1
- data/vendor/datasketches-cpp/CMakeLists.txt +23 -20
- data/vendor/datasketches-cpp/CODE_OF_CONDUCT.md +3 -0
- data/vendor/datasketches-cpp/CONTRIBUTING.md +50 -0
- data/vendor/datasketches-cpp/Doxyfile +2827 -0
- data/vendor/datasketches-cpp/LICENSE +0 -76
- data/vendor/datasketches-cpp/README.md +1 -3
- data/vendor/datasketches-cpp/common/CMakeLists.txt +12 -11
- data/vendor/datasketches-cpp/common/include/MurmurHash3.h +25 -27
- data/vendor/datasketches-cpp/common/include/common_defs.hpp +15 -10
- data/vendor/datasketches-cpp/common/include/count_zeros.hpp +11 -2
- data/vendor/datasketches-cpp/common/include/kolmogorov_smirnov.hpp +9 -6
- data/vendor/datasketches-cpp/common/include/memory_operations.hpp +5 -4
- data/vendor/datasketches-cpp/common/include/optional.hpp +148 -0
- data/vendor/datasketches-cpp/common/include/quantiles_sorted_view.hpp +95 -2
- data/vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp +1 -1
- data/vendor/datasketches-cpp/common/include/serde.hpp +69 -20
- data/vendor/datasketches-cpp/common/test/CMakeLists.txt +2 -2
- data/vendor/datasketches-cpp/common/test/integration_test.cpp +6 -0
- data/vendor/datasketches-cpp/common/test/optional_test.cpp +85 -0
- data/vendor/datasketches-cpp/common/test/test_allocator.hpp +14 -14
- data/vendor/datasketches-cpp/{python/src/__init__.py → count/CMakeLists.txt} +25 -1
- data/vendor/datasketches-cpp/count/include/count_min.hpp +405 -0
- data/vendor/datasketches-cpp/count/include/count_min_impl.hpp +497 -0
- data/vendor/datasketches-cpp/{MANIFEST.in → count/test/CMakeLists.txt} +23 -20
- data/vendor/datasketches-cpp/count/test/count_min_allocation_test.cpp +155 -0
- data/vendor/datasketches-cpp/count/test/count_min_test.cpp +303 -0
- data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +14 -20
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +7 -4
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +17 -17
- data/vendor/datasketches-cpp/cpc/include/cpc_confidence.hpp +3 -3
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +40 -40
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +14 -11
- data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +35 -11
- data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +8 -8
- data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +16 -8
- data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +3 -2
- data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +5 -5
- data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +20 -7
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_deserialize_from_java_test.cpp +60 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_serialize_for_java.cpp +38 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +4 -29
- data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +4 -4
- data/vendor/datasketches-cpp/{tox.ini → density/CMakeLists.txt} +24 -8
- data/vendor/datasketches-cpp/density/include/density_sketch.hpp +256 -0
- data/vendor/datasketches-cpp/density/include/density_sketch_impl.hpp +543 -0
- data/vendor/datasketches-cpp/{python/datasketches/__init__.py → density/test/CMakeLists.txt} +15 -3
- data/vendor/datasketches-cpp/density/test/density_sketch_test.cpp +244 -0
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +21 -9
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +6 -4
- data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +9 -3
- data/vendor/datasketches-cpp/fi/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_deserialize_from_java_test.cpp +95 -0
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_serialize_for_java.cpp +83 -0
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +3 -42
- data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/CouponList.hpp +3 -1
- data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +19 -11
- data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +2 -5
- data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +19 -7
- data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +98 -42
- data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +2 -0
- data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +94 -61
- data/vendor/datasketches-cpp/hll/include/HllArray.hpp +20 -8
- data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +4 -4
- data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +3 -1
- data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +3 -21
- data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +8 -0
- data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +14 -18
- data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +8 -2
- data/vendor/datasketches-cpp/hll/include/hll.hpp +79 -65
- data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +7 -1
- data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +0 -68
- data/vendor/datasketches-cpp/hll/test/hll_sketch_deserialize_from_java_test.cpp +69 -0
- data/vendor/datasketches-cpp/hll/test/hll_sketch_serialize_for_java.cpp +52 -0
- data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -1
- data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +2 -2
- data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +79 -53
- data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +61 -132
- data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/kll/test/kll_sketch_deserialize_from_java_test.cpp +103 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_serialize_for_java.cpp +62 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +5 -40
- data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +76 -54
- data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +66 -136
- data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_deserialize_from_java_test.cpp +84 -0
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_serialize_for_java.cpp +52 -0
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +15 -39
- data/vendor/datasketches-cpp/req/include/req_common.hpp +7 -3
- data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +2 -4
- data/vendor/datasketches-cpp/req/include/req_sketch.hpp +105 -26
- data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +50 -111
- data/vendor/datasketches-cpp/req/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/req/test/req_sketch_deserialize_from_java_test.cpp +55 -0
- data/vendor/datasketches-cpp/{tuple/include/array_of_doubles_intersection_impl.hpp → req/test/req_sketch_serialize_for_java.cpp} +12 -7
- data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +3 -89
- data/vendor/datasketches-cpp/sampling/CMakeLists.txt +4 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sample.hpp +210 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sample_impl.hpp +535 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sketch.hpp +281 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sketch_impl.hpp +531 -0
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +89 -32
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +33 -19
- data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +13 -10
- data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +23 -19
- data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +55 -8
- data/vendor/datasketches-cpp/sampling/test/ebpps_allocation_test.cpp +96 -0
- data/vendor/datasketches-cpp/sampling/test/ebpps_sample_test.cpp +137 -0
- data/vendor/datasketches-cpp/sampling/test/ebpps_sketch_test.cpp +266 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_deserialize_from_java_test.cpp +81 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_serialize_for_java.cpp +54 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +33 -51
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp +50 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_serialize_for_java.cpp +56 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +0 -20
- data/vendor/datasketches-cpp/theta/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/theta/include/bit_packing.hpp +6279 -0
- data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_sampled_sets.hpp +1 -0
- data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_theta_sketched_sets.hpp +7 -6
- data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +14 -8
- data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +60 -46
- data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +20 -5
- data/vendor/datasketches-cpp/theta/include/theta_constants.hpp +10 -4
- data/vendor/datasketches-cpp/theta/include/theta_helpers.hpp +3 -1
- data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +13 -5
- data/vendor/datasketches-cpp/theta/include/theta_intersection_base_impl.hpp +5 -5
- data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +3 -3
- data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity.hpp +2 -1
- data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity_base.hpp +1 -0
- data/vendor/datasketches-cpp/theta/include/theta_set_difference_base_impl.hpp +1 -1
- data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +180 -33
- data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +430 -130
- data/vendor/datasketches-cpp/theta/include/theta_union.hpp +17 -10
- data/vendor/datasketches-cpp/theta/include/theta_union_base_impl.hpp +10 -10
- data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +3 -3
- data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +21 -6
- data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +13 -3
- data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +15 -1
- data/vendor/datasketches-cpp/theta/test/bit_packing_test.cpp +80 -0
- data/vendor/datasketches-cpp/theta/test/theta_sketch_deserialize_from_java_test.cpp +57 -0
- data/vendor/datasketches-cpp/theta/test/theta_sketch_serialize_for_java.cpp +61 -0
- data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +39 -188
- data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +25 -0
- data/vendor/datasketches-cpp/tuple/CMakeLists.txt +8 -7
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch.hpp +19 -144
- data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b.hpp → array_tuple_a_not_b.hpp} +24 -16
- data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b_impl.hpp → array_tuple_a_not_b_impl.hpp} +4 -4
- data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection.hpp +65 -0
- data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection_impl.hpp +31 -0
- data/vendor/datasketches-cpp/tuple/include/array_tuple_sketch.hpp +237 -0
- data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_sketch_impl.hpp → array_tuple_sketch_impl.hpp} +40 -41
- data/vendor/datasketches-cpp/tuple/include/array_tuple_union.hpp +81 -0
- data/vendor/datasketches-cpp/tuple/include/array_tuple_union_impl.hpp +43 -0
- data/vendor/datasketches-cpp/tuple/include/tuple_a_not_b.hpp +11 -2
- data/vendor/datasketches-cpp/tuple/include/tuple_intersection.hpp +17 -10
- data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +2 -1
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +95 -32
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +2 -1
- data/vendor/datasketches-cpp/tuple/include/tuple_union.hpp +19 -11
- data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +16 -1
- data/vendor/datasketches-cpp/tuple/test/aod_sketch_deserialize_from_java_test.cpp +76 -0
- data/vendor/datasketches-cpp/tuple/test/aod_sketch_serialize_for_java.cpp +62 -0
- data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +5 -129
- data/vendor/datasketches-cpp/tuple/test/engagement_test.cpp +85 -89
- data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +3 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_deserialize_from_java_test.cpp +47 -0
- data/vendor/datasketches-cpp/{python/src/datasketches.cpp → tuple/test/tuple_sketch_serialize_for_java.cpp} +16 -30
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +1 -1
- data/vendor/datasketches-cpp/version.cfg.in +1 -1
- metadata +61 -79
- data/vendor/datasketches-cpp/fi/test/items_sketch_string_from_java.sk +0 -0
- data/vendor/datasketches-cpp/fi/test/items_sketch_string_utf8_from_java.sk +0 -0
- data/vendor/datasketches-cpp/fi/test/longs_sketch_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/array6_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/compact_array4_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/compact_set_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/list_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/updatable_array4_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/updatable_set_from_java.sk +0 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_from_java.sk +0 -0
- data/vendor/datasketches-cpp/pyproject.toml +0 -23
- data/vendor/datasketches-cpp/python/CMakeLists.txt +0 -81
- data/vendor/datasketches-cpp/python/README.md +0 -85
- data/vendor/datasketches-cpp/python/datasketches/PySerDe.py +0 -104
- data/vendor/datasketches-cpp/python/include/py_serde.hpp +0 -113
- data/vendor/datasketches-cpp/python/jupyter/CPCSketch.ipynb +0 -345
- data/vendor/datasketches-cpp/python/jupyter/FrequentItemsSketch.ipynb +0 -354
- data/vendor/datasketches-cpp/python/jupyter/HLLSketch.ipynb +0 -346
- data/vendor/datasketches-cpp/python/jupyter/KLLSketch.ipynb +0 -463
- data/vendor/datasketches-cpp/python/jupyter/ThetaSketchNotebook.ipynb +0 -403
- data/vendor/datasketches-cpp/python/pybind11Path.cmd +0 -21
- data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +0 -90
- data/vendor/datasketches-cpp/python/src/fi_wrapper.cpp +0 -128
- data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +0 -134
- data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +0 -210
- data/vendor/datasketches-cpp/python/src/ks_wrapper.cpp +0 -68
- data/vendor/datasketches-cpp/python/src/py_serde.cpp +0 -111
- data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +0 -204
- data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +0 -215
- data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +0 -172
- data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +0 -490
- data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +0 -173
- data/vendor/datasketches-cpp/python/tests/__init__.py +0 -16
- data/vendor/datasketches-cpp/python/tests/cpc_test.py +0 -64
- data/vendor/datasketches-cpp/python/tests/fi_test.py +0 -110
- data/vendor/datasketches-cpp/python/tests/hll_test.py +0 -130
- data/vendor/datasketches-cpp/python/tests/kll_test.py +0 -125
- data/vendor/datasketches-cpp/python/tests/quantiles_test.py +0 -126
- data/vendor/datasketches-cpp/python/tests/req_test.py +0 -126
- data/vendor/datasketches-cpp/python/tests/theta_test.py +0 -146
- data/vendor/datasketches-cpp/python/tests/vector_of_kll_test.py +0 -148
- data/vendor/datasketches-cpp/python/tests/vo_test.py +0 -125
- data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
- data/vendor/datasketches-cpp/sampling/test/binaries_from_java.txt +0 -67
- data/vendor/datasketches-cpp/sampling/test/varopt_sketch_long_sampling.sk +0 -0
- data/vendor/datasketches-cpp/sampling/test/varopt_sketch_string_exact.sk +0 -0
- data/vendor/datasketches-cpp/sampling/test/varopt_union_double_sampling.sk +0 -0
- data/vendor/datasketches-cpp/setup.py +0 -110
- data/vendor/datasketches-cpp/theta/test/theta_compact_empty_from_java.sk +0 -0
- data/vendor/datasketches-cpp/theta/test/theta_compact_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/theta/test/theta_compact_exact_from_java.sk +0 -0
- data/vendor/datasketches-cpp/theta/test/theta_compact_single_item_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_intersection.hpp +0 -52
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union.hpp +0 -81
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union_impl.hpp +0 -43
- data/vendor/datasketches-cpp/tuple/test/aod_1_compact_empty_from_java.sk +0 -1
- data/vendor/datasketches-cpp/tuple/test/aod_1_compact_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/aod_1_compact_non_empty_no_entries_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/aod_2_compact_exact_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/aod_3_compact_empty_from_java.sk +0 -1
@@ -1,204 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
-
* or more contributor license agreements. See the NOTICE file
|
4
|
-
* distributed with this work for additional information
|
5
|
-
* regarding copyright ownership. The ASF licenses this file
|
6
|
-
* to you under the Apache License, Version 2.0 (the
|
7
|
-
* "License"); you may not use this file except in compliance
|
8
|
-
* with the License. You may obtain a copy of the License at
|
9
|
-
*
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
*
|
12
|
-
* Unless required by applicable law or agreed to in writing,
|
13
|
-
* software distributed under the License is distributed on an
|
14
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
-
* KIND, either express or implied. See the License for the
|
16
|
-
* specific language governing permissions and limitations
|
17
|
-
* under the License.
|
18
|
-
*/
|
19
|
-
|
20
|
-
#include "quantiles_sketch.hpp"
|
21
|
-
|
22
|
-
#include <pybind11/pybind11.h>
|
23
|
-
#include <pybind11/stl.h>
|
24
|
-
#include <pybind11/numpy.h>
|
25
|
-
#include <vector>
|
26
|
-
|
27
|
-
namespace py = pybind11;
|
28
|
-
|
29
|
-
namespace datasketches {
|
30
|
-
|
31
|
-
namespace python {
|
32
|
-
|
33
|
-
template<typename T>
|
34
|
-
quantiles_sketch<T> quantiles_sketch_deserialize(py::bytes sk_bytes) {
|
35
|
-
std::string sk_str = sk_bytes; // implicit cast
|
36
|
-
return quantiles_sketch<T>::deserialize(sk_str.c_str(), sk_str.length());
|
37
|
-
}
|
38
|
-
|
39
|
-
template<typename T>
|
40
|
-
py::object quantiles_sketch_serialize(const quantiles_sketch<T>& sk) {
|
41
|
-
auto ser_result = sk.serialize();
|
42
|
-
return py::bytes((char*)ser_result.data(), ser_result.size());
|
43
|
-
}
|
44
|
-
|
45
|
-
// maybe possible to disambiguate the static vs method rank error calls, but
|
46
|
-
// this is easier for now
|
47
|
-
template<typename T>
|
48
|
-
double quantiles_sketch_generic_normalized_rank_error(uint16_t k, bool pmf) {
|
49
|
-
return quantiles_sketch<T>::get_normalized_rank_error(k, pmf);
|
50
|
-
}
|
51
|
-
|
52
|
-
template<typename T>
|
53
|
-
py::list quantiles_sketch_get_quantiles(const quantiles_sketch<T>& sk,
|
54
|
-
std::vector<double>& ranks,
|
55
|
-
bool inclusive) {
|
56
|
-
size_t n_quantiles = ranks.size();
|
57
|
-
auto result = sk.get_quantiles(ranks.data(), static_cast<uint32_t>(n_quantiles), inclusive);
|
58
|
-
// returning as std::vector<> would copy values to a list anyway
|
59
|
-
py::list list(n_quantiles);
|
60
|
-
for (size_t i = 0; i < n_quantiles; ++i) {
|
61
|
-
list[i] = result[i];
|
62
|
-
}
|
63
|
-
return list;
|
64
|
-
}
|
65
|
-
|
66
|
-
template<typename T>
|
67
|
-
py::list quantiles_sketch_get_pmf(const quantiles_sketch<T>& sk,
|
68
|
-
std::vector<T>& split_points,
|
69
|
-
bool inclusive) {
|
70
|
-
size_t n_points = split_points.size();
|
71
|
-
auto result = sk.get_PMF(split_points.data(), n_points, inclusive);
|
72
|
-
py::list list(n_points + 1);
|
73
|
-
for (size_t i = 0; i <= n_points; ++i) {
|
74
|
-
list[i] = result[i];
|
75
|
-
}
|
76
|
-
return list;
|
77
|
-
}
|
78
|
-
|
79
|
-
template<typename T>
|
80
|
-
py::list quantiles_sketch_get_cdf(const quantiles_sketch<T>& sk,
|
81
|
-
std::vector<T>& split_points,
|
82
|
-
bool inclusive) {
|
83
|
-
size_t n_points = split_points.size();
|
84
|
-
auto result = sk.get_CDF(split_points.data(), n_points, inclusive);
|
85
|
-
py::list list(n_points + 1);
|
86
|
-
for (size_t i = 0; i <= n_points; ++i) {
|
87
|
-
list[i] = result[i];
|
88
|
-
}
|
89
|
-
return list;
|
90
|
-
}
|
91
|
-
|
92
|
-
template<typename T>
|
93
|
-
void quantiles_sketch_update(quantiles_sketch<T>& sk, py::array_t<T, py::array::c_style | py::array::forcecast> items) {
|
94
|
-
if (items.ndim() != 1) {
|
95
|
-
throw std::invalid_argument("input data must have only one dimension. Found: "
|
96
|
-
+ std::to_string(items.ndim()));
|
97
|
-
}
|
98
|
-
|
99
|
-
auto data = items.template unchecked<1>();
|
100
|
-
for (uint32_t i = 0; i < data.size(); ++i) {
|
101
|
-
sk.update(data(i));
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
}
|
106
|
-
}
|
107
|
-
|
108
|
-
namespace dspy = datasketches::python;
|
109
|
-
|
110
|
-
template<typename T>
|
111
|
-
void bind_quantiles_sketch(py::module &m, const char* name) {
|
112
|
-
using namespace datasketches;
|
113
|
-
|
114
|
-
py::class_<quantiles_sketch<T>>(m, name)
|
115
|
-
.def(py::init<uint16_t>(), py::arg("k")=quantiles_constants::DEFAULT_K)
|
116
|
-
.def(py::init<const quantiles_sketch<T>&>())
|
117
|
-
.def("update", (void (quantiles_sketch<T>::*)(const T&)) &quantiles_sketch<T>::update, py::arg("item"),
|
118
|
-
"Updates the sketch with the given value")
|
119
|
-
.def("update", &dspy::quantiles_sketch_update<T>, py::arg("array"),
|
120
|
-
"Updates the sketch with the values in the given array")
|
121
|
-
.def("merge", (void (quantiles_sketch<T>::*)(const quantiles_sketch<T>&)) &quantiles_sketch<T>::merge, py::arg("sketch"),
|
122
|
-
"Merges the provided sketch into the this one")
|
123
|
-
.def("__str__", &quantiles_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
|
124
|
-
"Produces a string summary of the sketch")
|
125
|
-
.def("to_string", &quantiles_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
|
126
|
-
"Produces a string summary of the sketch")
|
127
|
-
.def("is_empty", &quantiles_sketch<T>::is_empty,
|
128
|
-
"Returns True if the sketch is empty, otherwise False")
|
129
|
-
.def("get_k", &quantiles_sketch<T>::get_k,
|
130
|
-
"Returns the configured parameter k")
|
131
|
-
.def("get_n", &quantiles_sketch<T>::get_n,
|
132
|
-
"Returns the length of the input stream")
|
133
|
-
.def("get_num_retained", &quantiles_sketch<T>::get_num_retained,
|
134
|
-
"Returns the number of retained items (samples) in the sketch")
|
135
|
-
.def("is_estimation_mode", &quantiles_sketch<T>::is_estimation_mode,
|
136
|
-
"Returns True if the sketch is in estimation mode, otherwise False")
|
137
|
-
.def("get_min_value", &quantiles_sketch<T>::get_min_item,
|
138
|
-
"Returns the minimum value from the stream. If empty, quantiles_floats_sketch returns nan; quantiles_ints_sketch throws a RuntimeError")
|
139
|
-
.def("get_max_value", &quantiles_sketch<T>::get_max_item,
|
140
|
-
"Returns the maximum value from the stream. If empty, quantiles_floats_sketch returns nan; quantiles_ints_sketch throws a RuntimeError")
|
141
|
-
.def("get_quantile", &quantiles_sketch<T>::get_quantile, py::arg("rank"), py::arg("inclusive")=false,
|
142
|
-
"Returns an approximation to the data value "
|
143
|
-
"associated with the given rank in a hypothetical sorted "
|
144
|
-
"version of the input stream so far.\n"
|
145
|
-
"For quantiles_floats_sketch: if the sketch is empty this returns nan. "
|
146
|
-
"For quantiles_ints_sketch: if the sketch is empty this throws a RuntimeError.")
|
147
|
-
.def("get_quantiles", &dspy::quantiles_sketch_get_quantiles<T>, py::arg("ranks"), py::arg("inclusive")=false,
|
148
|
-
"This returns an array that could have been generated by using get_quantile() for each "
|
149
|
-
"normalized rank separately.\n"
|
150
|
-
"If the sketch is empty this returns an empty vector.\n"
|
151
|
-
"Deprecated. Will be removed in the next major version. Use get_quantile() instead.")
|
152
|
-
.def("get_rank", &quantiles_sketch<T>::get_rank, py::arg("value"), py::arg("inclusive")=false,
|
153
|
-
"Returns an approximation to the normalized rank of the given value from 0 to 1, inclusive.\n"
|
154
|
-
"The resulting approximation has a probabilistic guarantee that can be obtained from the "
|
155
|
-
"get_normalized_rank_error(False) function.\n"
|
156
|
-
"With the parameter inclusive=true the weight of the given value is included into the rank."
|
157
|
-
"Otherwise the rank equals the sum of the weights of values less than the given value.\n"
|
158
|
-
"If the sketch is empty this returns nan.")
|
159
|
-
.def("get_pmf", &dspy::quantiles_sketch_get_pmf<T>, py::arg("split_points"), py::arg("inclusive")=false,
|
160
|
-
"Returns an approximation to the Probability Mass Function (PMF) of the input stream "
|
161
|
-
"given a set of split points (values).\n"
|
162
|
-
"The resulting approximations have a probabilistic guarantee that can be obtained from the "
|
163
|
-
"get_normalized_rank_error(True) function.\n"
|
164
|
-
"If the sketch is empty this returns an empty vector.\n"
|
165
|
-
"split_points is an array of m unique, monotonically increasing float values "
|
166
|
-
"that divide the real number line into m+1 consecutive disjoint intervals.\n"
|
167
|
-
"The definition of an 'interval' is inclusive of the left split point (or minimum value) and "
|
168
|
-
"exclusive of the right split point, with the exception that the last interval will include "
|
169
|
-
"the maximum value.\n"
|
170
|
-
"It is not necessary to include either the min or max values in these split points.")
|
171
|
-
.def("get_cdf", &dspy::quantiles_sketch_get_cdf<T>, py::arg("split_points"), py::arg("inclusive")=false,
|
172
|
-
"Returns an approximation to the Cumulative Distribution Function (CDF), which is the "
|
173
|
-
"cumulative analog of the PMF, of the input stream given a set of split points (values).\n"
|
174
|
-
"The resulting approximations have a probabilistic guarantee that can be obtained from the "
|
175
|
-
"get_normalized_rank_error(True) function.\n"
|
176
|
-
"If the sketch is empty this returns an empty vector.\n"
|
177
|
-
"split_points is an array of m unique, monotonically increasing float values "
|
178
|
-
"that divide the real number line into m+1 consecutive disjoint intervals.\n"
|
179
|
-
"The definition of an 'interval' is inclusive of the left split point (or minimum value) and "
|
180
|
-
"exclusive of the right split point, with the exception that the last interval will include "
|
181
|
-
"the maximum value.\n"
|
182
|
-
"It is not necessary to include either the min or max values in these split points.")
|
183
|
-
.def("normalized_rank_error", (double (quantiles_sketch<T>::*)(bool) const) &quantiles_sketch<T>::get_normalized_rank_error,
|
184
|
-
py::arg("as_pmf"),
|
185
|
-
"Gets the normalized rank error for this sketch.\n"
|
186
|
-
"If pmf is True, returns the 'double-sided' normalized rank error for the get_PMF() function.\n"
|
187
|
-
"Otherwise, it is the 'single-sided' normalized rank error for all the other queries.\n"
|
188
|
-
"Constants were derived as the best fit to 99 percentile empirically measured max error in thousands of trials")
|
189
|
-
.def_static("get_normalized_rank_error", &dspy::quantiles_sketch_generic_normalized_rank_error<T>,
|
190
|
-
py::arg("k"), py::arg("as_pmf"),
|
191
|
-
"Gets the normalized rank error given parameters k and the pmf flag.\n"
|
192
|
-
"If pmf is True, returns the 'double-sided' normalized rank error for the get_PMF() function.\n"
|
193
|
-
"Otherwise, it is the 'single-sided' normalized rank error for all the other queries.\n"
|
194
|
-
"Constants were derived as the best fit to 99 percentile empirically measured max error in thousands of trials")
|
195
|
-
.def("serialize", &dspy::quantiles_sketch_serialize<T>, "Serializes the sketch into a bytes object")
|
196
|
-
.def_static("deserialize", &dspy::quantiles_sketch_deserialize<T>, "Deserializes the sketch from a bytes object")
|
197
|
-
;
|
198
|
-
}
|
199
|
-
|
200
|
-
void init_quantiles(py::module &m) {
|
201
|
-
bind_quantiles_sketch<int>(m, "quantiles_ints_sketch");
|
202
|
-
bind_quantiles_sketch<float>(m, "quantiles_floats_sketch");
|
203
|
-
bind_quantiles_sketch<double>(m, "quantiles_doubles_sketch");
|
204
|
-
}
|
@@ -1,215 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
-
* or more contributor license agreements. See the NOTICE file
|
4
|
-
* distributed with this work for additional information
|
5
|
-
* regarding copyright ownership. The ASF licenses this file
|
6
|
-
* to you under the Apache License, Version 2.0 (the
|
7
|
-
* "License"); you may not use this file except in compliance
|
8
|
-
* with the License. You may obtain a copy of the License at
|
9
|
-
*
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
*
|
12
|
-
* Unless required by applicable law or agreed to in writing,
|
13
|
-
* software distributed under the License is distributed on an
|
14
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
-
* KIND, either express or implied. See the License for the
|
16
|
-
* specific language governing permissions and limitations
|
17
|
-
* under the License.
|
18
|
-
*/
|
19
|
-
|
20
|
-
#include "req_sketch.hpp"
|
21
|
-
|
22
|
-
#include <pybind11/pybind11.h>
|
23
|
-
#include <pybind11/stl.h>
|
24
|
-
#include <pybind11/numpy.h>
|
25
|
-
#include <sstream>
|
26
|
-
#include <vector>
|
27
|
-
#include <stdexcept>
|
28
|
-
|
29
|
-
namespace py = pybind11;
|
30
|
-
|
31
|
-
namespace datasketches {
|
32
|
-
|
33
|
-
namespace python {
|
34
|
-
|
35
|
-
template<typename T>
|
36
|
-
req_sketch<T> req_sketch_deserialize(py::bytes sk_bytes) {
|
37
|
-
std::string sk_str = sk_bytes; // implicit cast
|
38
|
-
return req_sketch<T>::deserialize(sk_str.c_str(), sk_str.length());
|
39
|
-
}
|
40
|
-
|
41
|
-
template<typename T>
|
42
|
-
py::object req_sketch_serialize(const req_sketch<T>& sk) {
|
43
|
-
auto ser_result = sk.serialize();
|
44
|
-
return py::bytes((char*)ser_result.data(), ser_result.size());
|
45
|
-
}
|
46
|
-
|
47
|
-
// maybe possible to disambiguate the static vs method rank error calls, but
|
48
|
-
// this is easier for now
|
49
|
-
template<typename T>
|
50
|
-
double req_sketch_generic_normalized_rank_error(uint16_t k, bool pmf) {
|
51
|
-
return req_sketch<T>::get_normalized_rank_error(k, pmf);
|
52
|
-
}
|
53
|
-
|
54
|
-
template<typename T>
|
55
|
-
py::list req_sketch_get_quantiles(const req_sketch<T>& sk,
|
56
|
-
std::vector<double>& ranks,
|
57
|
-
bool inclusive) {
|
58
|
-
size_t n_quantiles = ranks.size();
|
59
|
-
auto result = sk.get_quantiles(ranks.data(), n_quantiles, inclusive);
|
60
|
-
// returning as std::vector<> would copy values to a list anyway
|
61
|
-
py::list list(n_quantiles);
|
62
|
-
for (size_t i = 0; i < n_quantiles; ++i) {
|
63
|
-
list[i] = result[i];
|
64
|
-
}
|
65
|
-
return list;
|
66
|
-
}
|
67
|
-
|
68
|
-
template<typename T>
|
69
|
-
py::list req_sketch_get_pmf(const req_sketch<T>& sk,
|
70
|
-
std::vector<T>& split_points,
|
71
|
-
bool inclusive) {
|
72
|
-
size_t n_points = split_points.size();
|
73
|
-
auto result = sk.get_PMF(split_points.data(), n_points, inclusive);
|
74
|
-
py::list list(n_points + 1);
|
75
|
-
for (size_t i = 0; i <= n_points; ++i) {
|
76
|
-
list[i] = result[i];
|
77
|
-
}
|
78
|
-
return list;
|
79
|
-
}
|
80
|
-
|
81
|
-
template<typename T>
|
82
|
-
py::list req_sketch_get_cdf(const req_sketch<T>& sk,
|
83
|
-
std::vector<T>& split_points,
|
84
|
-
bool inclusive) {
|
85
|
-
size_t n_points = split_points.size();
|
86
|
-
auto result = sk.get_CDF(split_points.data(), n_points, inclusive);
|
87
|
-
py::list list(n_points + 1);
|
88
|
-
for (size_t i = 0; i <= n_points; ++i) {
|
89
|
-
list[i] = result[i];
|
90
|
-
}
|
91
|
-
return list;
|
92
|
-
}
|
93
|
-
|
94
|
-
template<typename T>
|
95
|
-
void req_sketch_update(req_sketch<T>& sk, py::array_t<T, py::array::c_style | py::array::forcecast> items) {
|
96
|
-
if (items.ndim() != 1) {
|
97
|
-
throw std::invalid_argument("input data must have only one dimension. Found: "
|
98
|
-
+ std::to_string(items.ndim()));
|
99
|
-
}
|
100
|
-
|
101
|
-
auto data = items.template unchecked<1>();
|
102
|
-
for (uint32_t i = 0; i < data.size(); ++i) {
|
103
|
-
sk.update(data(i));
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
namespace dspy = datasketches::python;
|
111
|
-
|
112
|
-
template<typename T>
|
113
|
-
void bind_req_sketch(py::module &m, const char* name) {
|
114
|
-
using namespace datasketches;
|
115
|
-
|
116
|
-
py::class_<req_sketch<T>>(m, name)
|
117
|
-
.def(py::init<uint16_t, bool>(), py::arg("k")=12, py::arg("is_hra")=true)
|
118
|
-
.def(py::init<const req_sketch<T>&>())
|
119
|
-
.def("update", (void (req_sketch<T>::*)(const T&)) &req_sketch<T>::update, py::arg("item"),
|
120
|
-
"Updates the sketch with the given value")
|
121
|
-
.def("update", &dspy::req_sketch_update<T>, py::arg("array"),
|
122
|
-
"Updates the sketch with the values in the given array")
|
123
|
-
.def("merge", (void (req_sketch<T>::*)(const req_sketch<T>&)) &req_sketch<T>::merge, py::arg("sketch"),
|
124
|
-
"Merges the provided sketch into the this one")
|
125
|
-
.def("__str__", &req_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
|
126
|
-
"Produces a string summary of the sketch")
|
127
|
-
.def("to_string", &req_sketch<T>::to_string, py::arg("print_levels")=false, py::arg("print_items")=false,
|
128
|
-
"Produces a string summary of the sketch")
|
129
|
-
.def("is_hra", &req_sketch<T>::is_HRA,
|
130
|
-
"Returns True if the sketch is in High Rank Accuracy mode, otherwise False")
|
131
|
-
.def("is_empty", &req_sketch<T>::is_empty,
|
132
|
-
"Returns True if the sketch is empty, otherwise False")
|
133
|
-
.def("get_k", &req_sketch<T>::get_k,
|
134
|
-
"Returns the configured parameter k")
|
135
|
-
.def("get_n", &req_sketch<T>::get_n,
|
136
|
-
"Returns the length of the input stream")
|
137
|
-
.def("get_num_retained", &req_sketch<T>::get_num_retained,
|
138
|
-
"Returns the number of retained items (samples) in the sketch")
|
139
|
-
.def("is_estimation_mode", &req_sketch<T>::is_estimation_mode,
|
140
|
-
"Returns True if the sketch is in estimation mode, otherwise False")
|
141
|
-
.def("get_min_value", &req_sketch<T>::get_min_item,
|
142
|
-
"Returns the minimum value from the stream. If empty, req_floats_sketch returns nan; req_ints_sketch throws a RuntimeError")
|
143
|
-
.def("get_max_value", &req_sketch<T>::get_max_item,
|
144
|
-
"Returns the maximum value from the stream. If empty, req_floats_sketch returns nan; req_ints_sketch throws a RuntimeError")
|
145
|
-
.def("get_quantile", &req_sketch<T>::get_quantile, py::arg("rank"), py::arg("inclusive")=false,
|
146
|
-
"Returns an approximation to the data value "
|
147
|
-
"associated with the given normalized rank in a hypothetical sorted "
|
148
|
-
"version of the input stream so far.\n"
|
149
|
-
"For req_floats_sketch: if the sketch is empty this returns nan. "
|
150
|
-
"For req_ints_sketch: if the sketch is empty this throws a RuntimeError.")
|
151
|
-
.def("get_quantiles", &dspy::req_sketch_get_quantiles<T>, py::arg("ranks"), py::arg("inclusive")=false,
|
152
|
-
"This returns an array that could have been generated by using get_quantile() for each "
|
153
|
-
"normalized rank separately.\n"
|
154
|
-
"If the sketch is empty this returns an empty vector.\n"
|
155
|
-
"Deprecated. Will be removed in the next major version. Use get_quantile() instead.")
|
156
|
-
.def("get_rank", &req_sketch<T>::get_rank, py::arg("value"), py::arg("inclusive")=false,
|
157
|
-
"Returns an approximation to the normalized rank of the given value from 0 to 1, inclusive.\n"
|
158
|
-
"The resulting approximation has a probabilistic guarantee that can be obtained from the "
|
159
|
-
"get_normalized_rank_error(False) function.\n"
|
160
|
-
"With the parameter inclusive=true the weight of the given value is included into the rank."
|
161
|
-
"Otherwise the rank equals the sum of the weights of values less than the given value.\n"
|
162
|
-
"If the sketch is empty this returns nan.")
|
163
|
-
.def("get_pmf", &dspy::req_sketch_get_pmf<T>, py::arg("split_points"), py::arg("inclusive")=false,
|
164
|
-
"Returns an approximation to the Probability Mass Function (PMF) of the input stream "
|
165
|
-
"given a set of split points (values).\n"
|
166
|
-
"The resulting approximations have a probabilistic guarantee that can be obtained from the "
|
167
|
-
"get_normalized_rank_error(True) function.\n"
|
168
|
-
"If the sketch is empty this returns an empty vector.\n"
|
169
|
-
"split_points is an array of m unique, monotonically increasing float values "
|
170
|
-
"that divide the real number line into m+1 consecutive disjoint intervals.\n"
|
171
|
-
"If the parameter inclusive=false, the definition of an 'interval' is inclusive of the left split point (or minimum value) and "
|
172
|
-
"exclusive of the right split point, with the exception that the last interval will include "
|
173
|
-
"the maximum value.\n"
|
174
|
-
"If the parameter inclusive=true, the definition of an 'interval' is exclusive of the left split point (or minimum value) and "
|
175
|
-
"inclusive of the right split point.\n"
|
176
|
-
"It is not necessary to include either the min or max values in these split points.")
|
177
|
-
.def("get_cdf", &dspy::req_sketch_get_cdf<T>, py::arg("split_points"), py::arg("inclusive")=false,
|
178
|
-
"Returns an approximation to the Cumulative Distribution Function (CDF), which is the "
|
179
|
-
"cumulative analog of the PMF, of the input stream given a set of split points (values).\n"
|
180
|
-
"The resulting approximations have a probabilistic guarantee that can be obtained from the "
|
181
|
-
"get_normalized_rank_error(True) function.\n"
|
182
|
-
"If the sketch is empty this returns an empty vector.\n"
|
183
|
-
"split_points is an array of m unique, monotonically increasing float values "
|
184
|
-
"that divide the real number line into m+1 consecutive disjoint intervals.\n"
|
185
|
-
"If the parameter inclusive=false, the definition of an 'interval' is inclusive of the left split point (or minimum value) and "
|
186
|
-
"exclusive of the right split point, with the exception that the last interval will include "
|
187
|
-
"the maximum value.\n"
|
188
|
-
"If the parameter inclusive=true, the definition of an 'interval' is exclusive of the left split point (or minimum value) and "
|
189
|
-
"inclusive of the right split point.\n"
|
190
|
-
"It is not necessary to include either the min or max values in these split points.")
|
191
|
-
.def("get_rank_lower_bound", &req_sketch<T>::get_rank_lower_bound, py::arg("rank"), py::arg("num_std_dev"),
|
192
|
-
"Returns an approximate lower bound on the given normalized rank.\n"
|
193
|
-
"Normalized rank must be a value between 0.0 and 1.0 (inclusive); "
|
194
|
-
"the number of standard deviations must be 1, 2, or 3.")
|
195
|
-
.def("get_rank_upper_bound", &req_sketch<T>::get_rank_upper_bound, py::arg("rank"), py::arg("num_std_dev"),
|
196
|
-
"Returns an approximate upper bound on the given normalized rank.\n"
|
197
|
-
"Normalized rank must be a value between 0.0 and 1.0 (inclusive); "
|
198
|
-
"the number of standard deviations must be 1, 2, or 3.")
|
199
|
-
.def_static("get_RSE", &req_sketch<T>::get_RSE,
|
200
|
-
py::arg("k"), py::arg("rank"), py::arg("is_hra"), py::arg("n"),
|
201
|
-
"Returns an a priori estimate of relative standard error (RSE, expressed as a number in [0,1]). "
|
202
|
-
"Derived from Lemma 12 in http://arxiv.org/abs/2004.01668v2, but the constant factors have been "
|
203
|
-
"modified based on empirical measurements, for a given value of parameter k.\n"
|
204
|
-
"Normalized rank must be a value between 0.0 and 1.0 (inclusive). If is_hra is True, uses high "
|
205
|
-
"rank accuracy mode, else low rank accuracy. N is an estimate of the total number of points "
|
206
|
-
"provided to the sketch.")
|
207
|
-
.def("serialize", &dspy::req_sketch_serialize<T>, "Serializes the sketch into a bytes object")
|
208
|
-
.def_static("deserialize", &dspy::req_sketch_deserialize<T>, "Deserializes the sketch from a bytes object")
|
209
|
-
;
|
210
|
-
}
|
211
|
-
|
212
|
-
void init_req(py::module &m) {
|
213
|
-
bind_req_sketch<int>(m, "req_ints_sketch");
|
214
|
-
bind_req_sketch<float>(m, "req_floats_sketch");
|
215
|
-
}
|
@@ -1,172 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
-
* or more contributor license agreements. See the NOTICE file
|
4
|
-
* distributed with this work for additional information
|
5
|
-
* regarding copyright ownership. The ASF licenses this file
|
6
|
-
* to you under the Apache License, Version 2.0 (the
|
7
|
-
* "License"); you may not use this file except in compliance
|
8
|
-
* with the License. You may obtain a copy of the License at
|
9
|
-
*
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
*
|
12
|
-
* Unless required by applicable law or agreed to in writing,
|
13
|
-
* software distributed under the License is distributed on an
|
14
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
-
* KIND, either express or implied. See the License for the
|
16
|
-
* specific language governing permissions and limitations
|
17
|
-
* under the License.
|
18
|
-
*/
|
19
|
-
|
20
|
-
#include <sstream>
|
21
|
-
#include <pybind11/pybind11.h>
|
22
|
-
#include <pybind11/stl.h>
|
23
|
-
|
24
|
-
#include "theta_sketch.hpp"
|
25
|
-
#include "theta_union.hpp"
|
26
|
-
#include "theta_intersection.hpp"
|
27
|
-
#include "theta_a_not_b.hpp"
|
28
|
-
#include "theta_jaccard_similarity.hpp"
|
29
|
-
#include "common_defs.hpp"
|
30
|
-
|
31
|
-
|
32
|
-
namespace py = pybind11;
|
33
|
-
|
34
|
-
namespace datasketches {
|
35
|
-
namespace python {
|
36
|
-
|
37
|
-
update_theta_sketch update_theta_sketch_factory(uint8_t lg_k, double p, uint64_t seed) {
|
38
|
-
update_theta_sketch::builder builder;
|
39
|
-
builder.set_lg_k(lg_k);
|
40
|
-
builder.set_p(p);
|
41
|
-
builder.set_seed(seed);
|
42
|
-
return builder.build();
|
43
|
-
}
|
44
|
-
|
45
|
-
theta_union theta_union_factory(uint8_t lg_k, double p, uint64_t seed) {
|
46
|
-
theta_union::builder builder;
|
47
|
-
builder.set_lg_k(lg_k);
|
48
|
-
builder.set_p(p);
|
49
|
-
builder.set_seed(seed);
|
50
|
-
return builder.build();
|
51
|
-
}
|
52
|
-
|
53
|
-
uint16_t theta_sketch_get_seed_hash(const theta_sketch& sk) {
|
54
|
-
return sk.get_seed_hash();
|
55
|
-
}
|
56
|
-
|
57
|
-
py::object compact_theta_sketch_serialize(const compact_theta_sketch& sk) {
|
58
|
-
auto serResult = sk.serialize();
|
59
|
-
return py::bytes((char*)serResult.data(), serResult.size());
|
60
|
-
}
|
61
|
-
|
62
|
-
compact_theta_sketch compact_theta_sketch_deserialize(py::bytes skBytes, uint64_t seed) {
|
63
|
-
std::string skStr = skBytes; // implicit cast
|
64
|
-
return compact_theta_sketch::deserialize(skStr.c_str(), skStr.length(), seed);
|
65
|
-
}
|
66
|
-
|
67
|
-
py::list theta_jaccard_sim_computation(const theta_sketch& sketch_a, const theta_sketch& sketch_b, uint64_t seed) {
|
68
|
-
return py::cast(theta_jaccard_similarity::jaccard(sketch_a, sketch_b, seed));
|
69
|
-
}
|
70
|
-
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
namespace dspy = datasketches::python;
|
75
|
-
|
76
|
-
void init_theta(py::module &m) {
|
77
|
-
using namespace datasketches;
|
78
|
-
|
79
|
-
py::class_<theta_sketch>(m, "theta_sketch")
|
80
|
-
.def("__str__", &theta_sketch::to_string, py::arg("print_items")=false,
|
81
|
-
"Produces a string summary of the sketch")
|
82
|
-
.def("to_string", &theta_sketch::to_string, py::arg("print_items")=false,
|
83
|
-
"Produces a string summary of the sketch")
|
84
|
-
.def("is_empty", &theta_sketch::is_empty,
|
85
|
-
"Returns True if the sketch is empty, otherwise False")
|
86
|
-
.def("get_estimate", &theta_sketch::get_estimate,
|
87
|
-
"Estimate of the distinct count of the input stream")
|
88
|
-
.def("get_upper_bound", &theta_sketch::get_upper_bound, py::arg("num_std_devs"),
|
89
|
-
"Returns an approximate upper bound on the estimate at standard deviations in {1, 2, 3}")
|
90
|
-
.def("get_lower_bound", &theta_sketch::get_lower_bound, py::arg("num_std_devs"),
|
91
|
-
"Returns an approximate lower bound on the estimate at standard deviations in {1, 2, 3}")
|
92
|
-
.def("is_estimation_mode", &theta_sketch::is_estimation_mode,
|
93
|
-
"Returns True if sketch is in estimation mode, otherwise False")
|
94
|
-
.def("get_theta", &theta_sketch::get_theta,
|
95
|
-
"Returns theta (effective sampling rate) as a fraction from 0 to 1")
|
96
|
-
.def("get_num_retained", &theta_sketch::get_num_retained,
|
97
|
-
"Retunrs the number of items currently in the sketch")
|
98
|
-
.def("get_seed_hash", &dspy::theta_sketch_get_seed_hash,
|
99
|
-
"Returns a hash of the seed used in the sketch")
|
100
|
-
.def("is_ordered", &theta_sketch::is_ordered,
|
101
|
-
"Returns True if the sketch entries are sorted, otherwise False")
|
102
|
-
;
|
103
|
-
|
104
|
-
py::class_<update_theta_sketch, theta_sketch>(m, "update_theta_sketch")
|
105
|
-
.def(py::init(&dspy::update_theta_sketch_factory),
|
106
|
-
py::arg("lg_k")=theta_constants::DEFAULT_LG_K, py::arg("p")=1.0, py::arg("seed")=DEFAULT_SEED)
|
107
|
-
.def(py::init<const update_theta_sketch&>())
|
108
|
-
.def("update", (void (update_theta_sketch::*)(int64_t)) &update_theta_sketch::update, py::arg("datum"),
|
109
|
-
"Updates the sketch with the given integral value")
|
110
|
-
.def("update", (void (update_theta_sketch::*)(double)) &update_theta_sketch::update, py::arg("datum"),
|
111
|
-
"Updates the sketch with the given floating point value")
|
112
|
-
.def("update", (void (update_theta_sketch::*)(const std::string&)) &update_theta_sketch::update, py::arg("datum"),
|
113
|
-
"Updates the sketch with the given string")
|
114
|
-
.def("compact", &update_theta_sketch::compact, py::arg("ordered")=true,
|
115
|
-
"Returns a compacted form of the sketch, optionally sorting it")
|
116
|
-
;
|
117
|
-
|
118
|
-
py::class_<compact_theta_sketch, theta_sketch>(m, "compact_theta_sketch")
|
119
|
-
.def(py::init<const compact_theta_sketch&>())
|
120
|
-
.def(py::init<const theta_sketch&, bool>())
|
121
|
-
.def("serialize", &dspy::compact_theta_sketch_serialize,
|
122
|
-
"Serializes the sketch into a bytes object")
|
123
|
-
.def_static("deserialize", &dspy::compact_theta_sketch_deserialize,
|
124
|
-
py::arg("bytes"), py::arg("seed")=DEFAULT_SEED,
|
125
|
-
"Reads a bytes object and returns the corresponding compact_theta_sketch")
|
126
|
-
;
|
127
|
-
|
128
|
-
py::class_<theta_union>(m, "theta_union")
|
129
|
-
.def(py::init(&dspy::theta_union_factory),
|
130
|
-
py::arg("lg_k")=theta_constants::DEFAULT_LG_K, py::arg("p")=1.0, py::arg("seed")=DEFAULT_SEED)
|
131
|
-
.def("update", &theta_union::update<const theta_sketch&>, py::arg("sketch"),
|
132
|
-
"Updates the union with the given sketch")
|
133
|
-
.def("get_result", &theta_union::get_result, py::arg("ordered")=true,
|
134
|
-
"Returns the sketch corresponding to the union result")
|
135
|
-
;
|
136
|
-
|
137
|
-
py::class_<theta_intersection>(m, "theta_intersection")
|
138
|
-
.def(py::init<uint64_t>(), py::arg("seed")=DEFAULT_SEED)
|
139
|
-
.def(py::init<const theta_intersection&>())
|
140
|
-
.def("update", &theta_intersection::update<const theta_sketch&>, py::arg("sketch"),
|
141
|
-
"Intersections the provided sketch with the current intersection state")
|
142
|
-
.def("get_result", &theta_intersection::get_result, py::arg("ordered")=true,
|
143
|
-
"Returns the sketch corresponding to the intersection result")
|
144
|
-
.def("has_result", &theta_intersection::has_result,
|
145
|
-
"Returns True if the intersection has a valid result, otherwise False")
|
146
|
-
;
|
147
|
-
|
148
|
-
py::class_<theta_a_not_b>(m, "theta_a_not_b")
|
149
|
-
.def(py::init<uint64_t>(), py::arg("seed")=DEFAULT_SEED)
|
150
|
-
.def("compute", &theta_a_not_b::compute<const theta_sketch&, const theta_sketch&>, py::arg("a"), py::arg("b"), py::arg("ordered")=true,
|
151
|
-
"Returns a sketch with the reuslt of appying the A-not-B operation on the given inputs")
|
152
|
-
;
|
153
|
-
|
154
|
-
py::class_<theta_jaccard_similarity>(m, "theta_jaccard_similarity")
|
155
|
-
.def_static("jaccard", &dspy::theta_jaccard_sim_computation,
|
156
|
-
py::arg("sketch_a"), py::arg("sketch_b"), py::arg("seed")=DEFAULT_SEED,
|
157
|
-
"Returns a list with {lower_bound, estimate, upper_bound} of the Jaccard similarity between sketches")
|
158
|
-
.def_static("exactly_equal", &theta_jaccard_similarity::exactly_equal<const theta_sketch&, const theta_sketch&>,
|
159
|
-
py::arg("sketch_a"), py::arg("sketch_b"), py::arg("seed")=DEFAULT_SEED,
|
160
|
-
"Returns True if sketch_a and sketch_b are equivalent, otherwise False")
|
161
|
-
.def_static("similarity_test", &theta_jaccard_similarity::similarity_test<const theta_sketch&, const theta_sketch&>,
|
162
|
-
py::arg("actual"), py::arg("expected"), py::arg("threshold"), py::arg("seed")=DEFAULT_SEED,
|
163
|
-
"Tests similarity of an actual sketch against an expected sketch. Computers the lower bound of the Jaccard "
|
164
|
-
"index J_{LB} of the actual and expected sketches. If J_{LB} >= threshold, then the sketches are considered "
|
165
|
-
"to be similar sith a confidence of 97.7% and returns True, otherwise False.")
|
166
|
-
.def_static("dissimilarity_test", &theta_jaccard_similarity::dissimilarity_test<const theta_sketch&, const theta_sketch&>,
|
167
|
-
py::arg("actual"), py::arg("expected"), py::arg("threshold"), py::arg("seed")=DEFAULT_SEED,
|
168
|
-
"Tests dissimilarity of an actual sketch against an expected sketch. Computers the lower bound of the Jaccard "
|
169
|
-
"index J_{UB} of the actual and expected sketches. If J_{UB} <= threshold, then the sketches are considered "
|
170
|
-
"to be dissimilar sith a confidence of 97.7% and returns True, otherwise False.")
|
171
|
-
;
|
172
|
-
}
|