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
@@ -32,10 +32,10 @@ namespace datasketches {
|
|
32
32
|
static const double RELATIVE_ERROR_FOR_LG_K_11 = 0.02;
|
33
33
|
|
34
34
|
TEST_CASE("cpc sketch: lg k limits", "[cpc_sketch]") {
|
35
|
-
cpc_sketch s1(
|
36
|
-
cpc_sketch s2(
|
37
|
-
REQUIRE_THROWS_AS(cpc_sketch(
|
38
|
-
REQUIRE_THROWS_AS(cpc_sketch(
|
35
|
+
cpc_sketch s1(cpc_constants::MIN_LG_K); // this should work
|
36
|
+
cpc_sketch s2(cpc_constants::MAX_LG_K); // this should work
|
37
|
+
REQUIRE_THROWS_AS(cpc_sketch(cpc_constants::MIN_LG_K - 1), std::invalid_argument);
|
38
|
+
REQUIRE_THROWS_AS(cpc_sketch(cpc_constants::MAX_LG_K + 1), std::invalid_argument);
|
39
39
|
}
|
40
40
|
|
41
41
|
TEST_CASE("cpc sketch: empty", "[cpc_sketch]") {
|
@@ -88,9 +88,6 @@ TEST_CASE("cpc sketch: serialize deserialize empty", "[cpc_sketch]") {
|
|
88
88
|
REQUIRE(deserialized.is_empty() == sketch.is_empty());
|
89
89
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
90
90
|
REQUIRE(deserialized.validate());
|
91
|
-
|
92
|
-
std::ofstream os("cpc-empty.bin");
|
93
|
-
sketch.serialize(os);
|
94
91
|
}
|
95
92
|
|
96
93
|
TEST_CASE("cpc sketch: serialize deserialize sparse", "[cpc_sketch]") {
|
@@ -108,9 +105,6 @@ TEST_CASE("cpc sketch: serialize deserialize sparse", "[cpc_sketch]") {
|
|
108
105
|
for (int i = 0; i < n; i++) deserialized.update(i);
|
109
106
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
110
107
|
REQUIRE(deserialized.validate());
|
111
|
-
|
112
|
-
std::ofstream os("cpc-sparse.bin");
|
113
|
-
sketch.serialize(os);
|
114
108
|
}
|
115
109
|
|
116
110
|
TEST_CASE("cpc sketch: serialize deserialize hybrid", "[cpc_sketch]") {
|
@@ -128,9 +122,6 @@ TEST_CASE("cpc sketch: serialize deserialize hybrid", "[cpc_sketch]") {
|
|
128
122
|
for (int i = 0; i < n; i++) deserialized.update(i);
|
129
123
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
130
124
|
REQUIRE(deserialized.validate());
|
131
|
-
|
132
|
-
std::ofstream os("cpc-hybrid.bin");
|
133
|
-
sketch.serialize(os);
|
134
125
|
}
|
135
126
|
|
136
127
|
TEST_CASE("cpc sketch: serialize deserialize pinned", "[cpc_sketch]") {
|
@@ -148,9 +139,6 @@ TEST_CASE("cpc sketch: serialize deserialize pinned", "[cpc_sketch]") {
|
|
148
139
|
for (int i = 0; i < n; i++) deserialized.update(i);
|
149
140
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
150
141
|
REQUIRE(deserialized.validate());
|
151
|
-
|
152
|
-
std::ofstream os("cpc-pinned.bin");
|
153
|
-
sketch.serialize(os);
|
154
142
|
}
|
155
143
|
|
156
144
|
TEST_CASE("cpc sketch: serialize deserialize sliding", "[cpc_sketch]") {
|
@@ -168,9 +156,6 @@ TEST_CASE("cpc sketch: serialize deserialize sliding", "[cpc_sketch]") {
|
|
168
156
|
for (int i = 0; i < n; i++) deserialized.update(i);
|
169
157
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
170
158
|
REQUIRE(deserialized.validate());
|
171
|
-
|
172
|
-
std::ofstream os("cpc-sliding.bin");
|
173
|
-
sketch.serialize(os);
|
174
159
|
}
|
175
160
|
|
176
161
|
TEST_CASE("cpc sketch: serializing deserialize sliding large", "[cpc_sketch]") {
|
@@ -188,9 +173,6 @@ TEST_CASE("cpc sketch: serializing deserialize sliding large", "[cpc_sketch]") {
|
|
188
173
|
for (int i = 0; i < n; i++) deserialized.update(i);
|
189
174
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
190
175
|
REQUIRE(deserialized.validate());
|
191
|
-
|
192
|
-
std::ofstream os("cpc-sliding-large.bin");
|
193
|
-
sketch.serialize(os);
|
194
176
|
}
|
195
177
|
|
196
178
|
TEST_CASE("cpc sketch: serialize deserialize empty, bytes", "[cpc_sketch]") {
|
@@ -201,9 +183,6 @@ TEST_CASE("cpc sketch: serialize deserialize empty, bytes", "[cpc_sketch]") {
|
|
201
183
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
202
184
|
REQUIRE(deserialized.validate());
|
203
185
|
REQUIRE_THROWS_AS(cpc_sketch::deserialize(bytes.data(), bytes.size() - 1), std::out_of_range);
|
204
|
-
|
205
|
-
std::ofstream os("cpc-empty.bin");
|
206
|
-
sketch.serialize(os);
|
207
186
|
}
|
208
187
|
|
209
188
|
TEST_CASE("cpc sketch: serialize deserialize sparse, bytes", "[cpc_sketch]") {
|
@@ -261,8 +240,6 @@ TEST_CASE("cpc sketch: serialize deserialize pinned, bytes", "[cpc_sketch]") {
|
|
261
240
|
for (int i = 0; i < n; i++) deserialized.update(i);
|
262
241
|
REQUIRE(deserialized.get_estimate() == sketch.get_estimate());
|
263
242
|
REQUIRE(deserialized.validate());
|
264
|
-
|
265
|
-
std::cout << sketch.to_string();
|
266
243
|
}
|
267
244
|
|
268
245
|
TEST_CASE("cpc sketch: serialize deserialize sliding, bytes", "[cpc_sketch]") {
|
@@ -380,8 +357,6 @@ TEST_CASE("cpc sketch: update int equivalence", "[cpc_sketch]") {
|
|
380
357
|
sketch.update((uint8_t) -1);
|
381
358
|
sketch.update((int8_t) -1);
|
382
359
|
REQUIRE(sketch.get_estimate() == Approx(1).margin(RELATIVE_ERROR_FOR_LG_K_11));
|
383
|
-
std::ofstream os("cpc-negative-one.bin"); // to compare with Java
|
384
|
-
sketch.serialize(os);
|
385
360
|
}
|
386
361
|
|
387
362
|
TEST_CASE("cpc sketch: update float equivalence", "[cpc_sketch]") {
|
@@ -28,10 +28,10 @@ namespace datasketches {
|
|
28
28
|
static const double RELATIVE_ERROR_FOR_LG_K_11 = 0.02;
|
29
29
|
|
30
30
|
TEST_CASE("cpc union: lg k limits", "[cpc_union]") {
|
31
|
-
cpc_union u1(
|
32
|
-
cpc_union u2(
|
33
|
-
REQUIRE_THROWS_AS(cpc_union(
|
34
|
-
REQUIRE_THROWS_AS(cpc_union(
|
31
|
+
cpc_union u1(cpc_constants::MIN_LG_K); // this should work
|
32
|
+
cpc_union u2(cpc_constants::MAX_LG_K); // this should work
|
33
|
+
REQUIRE_THROWS_AS(cpc_union(cpc_constants::MIN_LG_K - 1), std::invalid_argument);
|
34
|
+
REQUIRE_THROWS_AS(cpc_union(cpc_constants::MAX_LG_K + 1), std::invalid_argument);
|
35
35
|
}
|
36
36
|
|
37
37
|
TEST_CASE("cpc union: empty", "[cpc_union]") {
|
@@ -15,12 +15,28 @@
|
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
17
|
|
18
|
-
|
19
|
-
envlist = py3
|
20
|
-
isolated_build = true
|
18
|
+
add_library(density INTERFACE)
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
add_library(${PROJECT_NAME}::DENSITY ALIAS density)
|
21
|
+
|
22
|
+
if (BUILD_TESTS)
|
23
|
+
add_subdirectory(test)
|
24
|
+
endif()
|
25
|
+
|
26
|
+
target_include_directories(density
|
27
|
+
INTERFACE
|
28
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
29
|
+
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
|
30
|
+
)
|
31
|
+
|
32
|
+
target_link_libraries(density INTERFACE common)
|
33
|
+
target_compile_features(density INTERFACE cxx_std_11)
|
34
|
+
|
35
|
+
install(TARGETS density
|
36
|
+
EXPORT ${PROJECT_NAME}
|
37
|
+
)
|
38
|
+
|
39
|
+
install(FILES
|
40
|
+
include/density_sketch.hpp
|
41
|
+
include/density_sketch_impl.hpp
|
42
|
+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")
|
@@ -0,0 +1,256 @@
|
|
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
|
+
#ifndef DENSITY_SKETCH_HPP_
|
21
|
+
#define DENSITY_SKETCH_HPP_
|
22
|
+
|
23
|
+
#include <type_traits>
|
24
|
+
#include <vector>
|
25
|
+
#include <functional>
|
26
|
+
#include <numeric>
|
27
|
+
#include <cmath>
|
28
|
+
|
29
|
+
#include "common_defs.hpp"
|
30
|
+
|
31
|
+
namespace datasketches {
|
32
|
+
|
33
|
+
template<typename T>
|
34
|
+
struct gaussian_kernel {
|
35
|
+
T operator()(const std::vector<T>& v1, const std::vector<T>& v2) const {
|
36
|
+
return exp(-std::inner_product(v1.begin(), v1.end(), v2.begin(), 0.0, std::plus<T>(), [](T a, T b){return (a-b)*(a-b);}));
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Density sketch.
|
42
|
+
*
|
43
|
+
* Builds a coreset from the given set of input points. Provides density estimate at a given point.
|
44
|
+
*
|
45
|
+
* Based on the following paper:
|
46
|
+
* Zohar Karnin, Edo Liberty "Discrepancy, Coresets, and Sketches in Machine Learning"
|
47
|
+
* https://proceedings.mlr.press/v99/karnin19a/karnin19a.pdf
|
48
|
+
*
|
49
|
+
* Inspired by the following implementation:
|
50
|
+
* https://github.com/edoliberty/streaming-quantiles/blob/f688c8161a25582457b0a09deb4630a81406293b/gde.py
|
51
|
+
*/
|
52
|
+
template<
|
53
|
+
typename T,
|
54
|
+
typename Kernel = gaussian_kernel<T>,
|
55
|
+
typename Allocator = std::allocator<T>
|
56
|
+
>
|
57
|
+
class density_sketch {
|
58
|
+
static_assert(std::is_floating_point<T>::value, "Floating point type expected");
|
59
|
+
|
60
|
+
public:
|
61
|
+
using Vector = std::vector<T, Allocator>;
|
62
|
+
using Level = std::vector<Vector, typename std::allocator_traits<Allocator>::template rebind_alloc<Vector>>;
|
63
|
+
using Levels = std::vector<Level, typename std::allocator_traits<Allocator>::template rebind_alloc<Level>>;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Constructor
|
67
|
+
* @param k controls the size and error of the sketch.
|
68
|
+
* @param dim dimension of the input domain
|
69
|
+
* @param kernel to use by this instance
|
70
|
+
* @param allocator to use by this instance
|
71
|
+
*/
|
72
|
+
density_sketch(uint16_t k, uint32_t dim, const Kernel& kernel = Kernel(), const Allocator& allocator = Allocator());
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Returns configured parameter K
|
76
|
+
* @return parameter K
|
77
|
+
*/
|
78
|
+
uint16_t get_k() const;
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Returns configured dimensions
|
82
|
+
* @return dimensions
|
83
|
+
*/
|
84
|
+
uint32_t get_dim() const;
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Returns true if this sketch is empty.
|
88
|
+
* @return empty flag
|
89
|
+
*/
|
90
|
+
bool is_empty() const;
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Returns the length of the input stream (number of points observed by this sketch).
|
94
|
+
* @return stream length
|
95
|
+
*/
|
96
|
+
uint64_t get_n() const;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Returns the number of retained points in the sketch.
|
100
|
+
* @return number of retained points
|
101
|
+
*/
|
102
|
+
uint32_t get_num_retained() const;
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Returns true if this sketch is in estimation mode.
|
106
|
+
* @return estimation mode flag
|
107
|
+
*/
|
108
|
+
bool is_estimation_mode() const;
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Updates this sketch with a given point.
|
112
|
+
* @param point given point
|
113
|
+
*/
|
114
|
+
template<typename FwdVector>
|
115
|
+
void update(FwdVector&& point);
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Merges another sketch into this one.
|
119
|
+
* @param other sketch to merge into this one
|
120
|
+
*/
|
121
|
+
template<typename FwdSketch>
|
122
|
+
void merge(FwdSketch&& other);
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Density estimate at a given point
|
126
|
+
* @return density estimate at a given point
|
127
|
+
*/
|
128
|
+
T get_estimate(const std::vector<T>& point) const;
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Returns an instance of the allocator for this sketch.
|
132
|
+
* @return allocator
|
133
|
+
*/
|
134
|
+
Allocator get_allocator() const;
|
135
|
+
|
136
|
+
/**
|
137
|
+
* This method serializes the sketch into a given stream in a binary form
|
138
|
+
* @param os output stream
|
139
|
+
*/
|
140
|
+
void serialize(std::ostream& os) const;
|
141
|
+
|
142
|
+
using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<Allocator>::template rebind_alloc<uint8_t>>;
|
143
|
+
|
144
|
+
/**
|
145
|
+
* This method serializes the sketch as a vector of bytes.
|
146
|
+
* An optional header can be reserved in front of the sketch.
|
147
|
+
* It is an uninitialized space of a given size.
|
148
|
+
* This header is used in Datasketches PostgreSQL extension.
|
149
|
+
* @param header_size_bytes space to reserve in front of the sketch
|
150
|
+
*/
|
151
|
+
vector_bytes serialize(unsigned header_size_bytes = 0) const;
|
152
|
+
|
153
|
+
/**
|
154
|
+
* This method deserializes a sketch from a given stream.
|
155
|
+
* @param is input stream
|
156
|
+
* @param kernel the kernel function to use for this sketch
|
157
|
+
* @param allocator the memory allocator to use with this sketch
|
158
|
+
* @return an instance of the sketch
|
159
|
+
*/
|
160
|
+
static density_sketch deserialize(std::istream& is,
|
161
|
+
const Kernel& kernel=Kernel(), const Allocator& allocator = Allocator());
|
162
|
+
|
163
|
+
/**
|
164
|
+
* This method deserializes a sketch from a given array of bytes.
|
165
|
+
* @param bytes pointer to the array of bytes
|
166
|
+
* @param size the size of the array
|
167
|
+
* @param kernel the kernel function to use for this sketch
|
168
|
+
* @param allocator the memory allocator to use with this sketch
|
169
|
+
* @return an instance of the sketch
|
170
|
+
*/
|
171
|
+
static density_sketch deserialize(const void* bytes, size_t size,
|
172
|
+
const Kernel& kernel=Kernel(), const Allocator& allocator = Allocator());
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Prints a summary of the sketch.
|
176
|
+
* @param print_levels if true include information about levels
|
177
|
+
* @param print_items if true include sketch data
|
178
|
+
*/
|
179
|
+
string<Allocator> to_string(bool print_levels = false, bool print_items = false) const;
|
180
|
+
|
181
|
+
class const_iterator;
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Iterator pointing to the first item in the sketch.
|
185
|
+
* If the sketch is empty, the returned iterator must not be dereferenced or incremented.
|
186
|
+
* @return iterator pointing to the first item in the sketch
|
187
|
+
*/
|
188
|
+
const_iterator begin() const;
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Iterator pointing to the past-the-end item in the sketch.
|
192
|
+
* The past-the-end item is the hypothetical item that would follow the last item.
|
193
|
+
* It does not point to any item, and must not be dereferenced or incremented.
|
194
|
+
* @return iterator pointing to the past-the-end item in the sketch
|
195
|
+
*/
|
196
|
+
const_iterator end() const;
|
197
|
+
|
198
|
+
private:
|
199
|
+
enum flags { RESERVED0, RESERVED1, IS_EMPTY };
|
200
|
+
static const uint8_t PREAMBLE_INTS_SHORT = 3;
|
201
|
+
static const uint8_t PREAMBLE_INTS_LONG = 6;
|
202
|
+
static const uint8_t FAMILY_ID = 19;
|
203
|
+
static const uint8_t SERIAL_VERSION = 1;
|
204
|
+
static const size_t LEVELS_ARRAY_START = 5;
|
205
|
+
|
206
|
+
Allocator allocator_;
|
207
|
+
Kernel kernel_;
|
208
|
+
uint16_t k_;
|
209
|
+
uint32_t dim_;
|
210
|
+
uint32_t num_retained_;
|
211
|
+
uint64_t n_;
|
212
|
+
Levels levels_;
|
213
|
+
|
214
|
+
void compact();
|
215
|
+
void compact_level(unsigned height);
|
216
|
+
|
217
|
+
static void check_k(uint16_t k);
|
218
|
+
static void check_serial_version(uint8_t serial_version);
|
219
|
+
static void check_family_id(uint8_t family_id);
|
220
|
+
static void check_header_validity(uint8_t preamble_ints, uint8_t flags_byte, uint8_t serial_version);
|
221
|
+
|
222
|
+
density_sketch(uint16_t k, uint32_t dim, uint32_t num_retained, uint64_t n, Levels&& levels,
|
223
|
+
const Kernel& kernel = Kernel());
|
224
|
+
};
|
225
|
+
|
226
|
+
template<typename T, typename K, typename A>
|
227
|
+
class density_sketch<T, K, A>::const_iterator {
|
228
|
+
public:
|
229
|
+
using Vector = density_sketch<T, K, A>::Vector;
|
230
|
+
using iterator_category = std::input_iterator_tag;
|
231
|
+
using value_type = std::pair<const Vector&, const uint64_t>;
|
232
|
+
using difference_type = void;
|
233
|
+
using pointer = return_value_holder<value_type>;
|
234
|
+
using reference = const value_type;
|
235
|
+
const_iterator& operator++();
|
236
|
+
const_iterator& operator++(int);
|
237
|
+
bool operator==(const const_iterator& other) const;
|
238
|
+
bool operator!=(const const_iterator& other) const;
|
239
|
+
const value_type operator*() const;
|
240
|
+
const return_value_holder<value_type> operator->() const;
|
241
|
+
private:
|
242
|
+
using LevelsIterator = typename density_sketch<T, K, A>::Levels::const_iterator;
|
243
|
+
using LevelIterator = typename density_sketch<T, K, A>::Level::const_iterator;
|
244
|
+
LevelsIterator levels_it_;
|
245
|
+
LevelsIterator levels_end_;
|
246
|
+
LevelIterator level_it_;
|
247
|
+
unsigned height_;
|
248
|
+
friend class density_sketch<T, K, A>;
|
249
|
+
const_iterator(LevelsIterator begin, LevelsIterator end);
|
250
|
+
};
|
251
|
+
|
252
|
+
} /* namespace datasketches */
|
253
|
+
|
254
|
+
#include "density_sketch_impl.hpp"
|
255
|
+
|
256
|
+
#endif
|