datasketches 0.2.6 → 0.3.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 +9 -0
- data/LICENSE +4 -6
- data/NOTICE +6 -5
- data/ext/datasketches/kll_wrapper.cpp +20 -20
- data/ext/datasketches/theta_wrapper.cpp +2 -2
- data/lib/datasketches/version.rb +1 -1
- data/vendor/datasketches-cpp/CMakeLists.txt +9 -1
- data/vendor/datasketches-cpp/LICENSE +4 -6
- data/vendor/datasketches-cpp/MANIFEST.in +21 -4
- data/vendor/datasketches-cpp/common/CMakeLists.txt +5 -2
- data/vendor/datasketches-cpp/common/include/common_defs.hpp +10 -0
- data/vendor/datasketches-cpp/common/include/kolmogorov_smirnov_impl.hpp +6 -6
- data/vendor/datasketches-cpp/common/include/memory_operations.hpp +1 -0
- data/vendor/datasketches-cpp/common/include/{quantile_sketch_sorted_view.hpp → quantiles_sorted_view.hpp} +60 -25
- data/vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp +125 -0
- data/vendor/datasketches-cpp/common/{test/test_runner.cpp → include/version.hpp.in} +15 -8
- data/vendor/datasketches-cpp/common/test/CMakeLists.txt +37 -7
- data/vendor/datasketches-cpp/common/test/catch_runner.cpp +22 -1
- data/vendor/datasketches-cpp/common/test/integration_test.cpp +1 -1
- data/vendor/datasketches-cpp/common/test/quantiles_sorted_view_test.cpp +459 -0
- data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/cpc/test/compression_test.cpp +1 -1
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +1 -1
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +1 -1
- data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +1 -1
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +28 -44
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +70 -78
- data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +11 -4
- data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +17 -10
- data/vendor/datasketches-cpp/fi/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +55 -42
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +1 -1
- data/vendor/datasketches-cpp/fi/test/reverse_purge_hash_map_test.cpp +4 -4
- data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +2 -2
- data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/CrossCountingTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/IsomorphicTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/TablesTest.cpp +1 -1
- data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +1 -1
- data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -32
- data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +176 -233
- data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +337 -395
- data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +27 -27
- data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +197 -233
- data/vendor/datasketches-cpp/kll/test/kll_sketch_validation.cpp +42 -32
- data/vendor/datasketches-cpp/kll/test/kolmogorov_smirnov_test.cpp +1 -1
- data/vendor/datasketches-cpp/pyproject.toml +17 -13
- data/vendor/datasketches-cpp/python/CMakeLists.txt +8 -1
- data/vendor/datasketches-cpp/python/README.md +1 -1
- data/vendor/datasketches-cpp/python/datasketches/PySerDe.py +104 -0
- data/vendor/datasketches-cpp/python/datasketches/__init__.py +22 -0
- data/vendor/datasketches-cpp/python/include/py_serde.hpp +113 -0
- data/vendor/datasketches-cpp/python/jupyter/ThetaSketchNotebook.ipynb +31 -24
- data/vendor/datasketches-cpp/python/pybind11Path.cmd +19 -1
- data/vendor/datasketches-cpp/python/src/__init__.py +17 -1
- data/vendor/datasketches-cpp/python/src/datasketches.cpp +9 -3
- data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +18 -54
- data/vendor/datasketches-cpp/python/src/py_serde.cpp +111 -0
- data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +17 -53
- data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +17 -55
- data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +62 -67
- data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +47 -14
- data/vendor/datasketches-cpp/python/tests/__init__.py +16 -0
- data/vendor/datasketches-cpp/python/tests/req_test.py +1 -1
- data/vendor/datasketches-cpp/python/tests/vo_test.py +25 -1
- data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +135 -180
- data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +205 -210
- data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/quantiles/test/kolmogorov_smirnov_test.cpp +1 -1
- data/vendor/datasketches-cpp/quantiles/test/quantiles_compatibility_test.cpp +20 -19
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +241 -233
- data/vendor/datasketches-cpp/req/include/req_compactor.hpp +15 -9
- data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +35 -19
- data/vendor/datasketches-cpp/req/include/req_sketch.hpp +126 -147
- data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +265 -245
- data/vendor/datasketches-cpp/req/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/req/test/req_sketch_custom_type_test.cpp +27 -27
- data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +117 -104
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +22 -46
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +180 -207
- data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +18 -39
- data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +75 -85
- data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +7 -7
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +3 -3
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +5 -5
- data/vendor/datasketches-cpp/setup.py +14 -3
- data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +15 -25
- data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +0 -9
- data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +5 -5
- data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -1
- data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +1 -1
- data/vendor/datasketches-cpp/theta/test/theta_intersection_test.cpp +1 -1
- data/vendor/datasketches-cpp/theta/test/theta_jaccard_similarity_test.cpp +1 -1
- data/vendor/datasketches-cpp/theta/test/theta_setop_test.cpp +1 -1
- data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +3 -2
- data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +1 -1
- data/vendor/datasketches-cpp/tox.ini +26 -0
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +36 -12
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +41 -35
- data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +2 -1
- data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +1 -1
- data/vendor/datasketches-cpp/tuple/test/engagement_test.cpp +299 -0
- data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +1 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +1 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +1 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +1 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +27 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +1 -1
- data/vendor/datasketches-cpp/version.cfg.in +1 -0
- metadata +14 -7
- data/vendor/datasketches-cpp/common/include/quantile_sketch_sorted_view_impl.hpp +0 -91
- data/vendor/datasketches-cpp/common/test/catch.hpp +0 -17618
@@ -17,7 +17,7 @@
|
|
17
17
|
* under the License.
|
18
18
|
*/
|
19
19
|
|
20
|
-
#include <catch.hpp>
|
20
|
+
#include <catch2/catch.hpp>
|
21
21
|
#include <sstream>
|
22
22
|
#include <stdexcept>
|
23
23
|
|
@@ -27,62 +27,75 @@
|
|
27
27
|
|
28
28
|
namespace datasketches {
|
29
29
|
|
30
|
-
using frequent_test_type_sketch = frequent_items_sketch<test_type, float, test_type_hash, test_type_equal,
|
30
|
+
using frequent_test_type_sketch = frequent_items_sketch<test_type, float, test_type_hash, test_type_equal, test_allocator<test_type>>;
|
31
31
|
using alloc = test_allocator<test_type>;
|
32
32
|
|
33
33
|
TEST_CASE("frequent items: custom type", "[frequent_items_sketch]") {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
test_allocator_total_bytes = 0;
|
35
|
+
{
|
36
|
+
frequent_test_type_sketch sketch(3, frequent_test_type_sketch::LG_MIN_MAP_SIZE, test_type_equal(), 0);
|
37
|
+
sketch.update(1, 10); // should survive the purge
|
38
|
+
sketch.update(2);
|
39
|
+
sketch.update(3);
|
40
|
+
sketch.update(4);
|
41
|
+
sketch.update(5);
|
42
|
+
sketch.update(6);
|
43
|
+
sketch.update(7);
|
44
|
+
test_type a8(8);
|
45
|
+
sketch.update(a8);
|
46
|
+
REQUIRE_FALSE(sketch.is_empty());
|
47
|
+
REQUIRE(sketch.get_total_weight() == 17);
|
48
|
+
REQUIRE(sketch.get_estimate(1) == 10);
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
auto items = sketch.get_frequent_items(frequent_items_error_type::NO_FALSE_POSITIVES);
|
51
|
+
REQUIRE(items.size() == 1); // only 1 item should be above threshold
|
52
|
+
REQUIRE(items[0].get_item().get_value() == 1);
|
53
|
+
REQUIRE(items[0].get_estimate() == 10);
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
|
56
|
+
sketch.serialize(s, test_type_serde());
|
57
|
+
auto sketch2 = frequent_test_type_sketch::deserialize(s, test_type_serde(), test_type_equal(), 0);
|
58
|
+
REQUIRE_FALSE(sketch2.is_empty());
|
59
|
+
REQUIRE(sketch2.get_total_weight() == 17);
|
60
|
+
REQUIRE(sketch2.get_estimate(1) == 10);
|
61
|
+
REQUIRE(sketch.get_num_active_items() == sketch2.get_num_active_items());
|
62
|
+
REQUIRE(sketch.get_maximum_error() == sketch2.get_maximum_error());
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
auto bytes = sketch.serialize(0, test_type_serde());
|
65
|
+
auto sketch3 = frequent_test_type_sketch::deserialize(bytes.data(), bytes.size(), test_type_serde(),
|
66
|
+
test_type_equal(), 0);
|
67
|
+
REQUIRE_FALSE(sketch3.is_empty());
|
68
|
+
REQUIRE(sketch3.get_total_weight() == 17);
|
69
|
+
REQUIRE(sketch3.get_estimate(1) == 10);
|
70
|
+
REQUIRE(sketch.get_num_active_items() == sketch3.get_num_active_items());
|
71
|
+
REQUIRE(sketch.get_maximum_error() == sketch3.get_maximum_error());
|
72
|
+
}
|
73
|
+
REQUIRE(test_allocator_total_bytes == 0);
|
69
74
|
}
|
70
75
|
|
71
76
|
// this is to see the debug print from test_type if enabled there to make sure items are moved
|
72
77
|
TEST_CASE("frequent items: moving merge", "[frequent_items_sketch]") {
|
73
|
-
|
74
|
-
|
78
|
+
test_allocator_total_bytes = 0;
|
79
|
+
{
|
80
|
+
frequent_test_type_sketch sketch1(3, frequent_test_type_sketch::LG_MIN_MAP_SIZE, test_type_equal(), 0);
|
81
|
+
sketch1.update(1);
|
75
82
|
|
76
|
-
|
77
|
-
|
83
|
+
frequent_test_type_sketch sketch2(3, frequent_test_type_sketch::LG_MIN_MAP_SIZE, test_type_equal(), 0);
|
84
|
+
sketch2.update(2);
|
78
85
|
|
79
|
-
|
80
|
-
|
86
|
+
sketch2.merge(std::move(sketch1));
|
87
|
+
REQUIRE(sketch2.get_total_weight() == 2);
|
88
|
+
}
|
89
|
+
REQUIRE(test_allocator_total_bytes == 0);
|
81
90
|
}
|
82
91
|
|
83
92
|
TEST_CASE("frequent items: negative weight", "[frequent_items_sketch]") {
|
84
|
-
|
85
|
-
|
93
|
+
test_allocator_total_bytes = 0;
|
94
|
+
{
|
95
|
+
frequent_test_type_sketch sketch(3, frequent_test_type_sketch::LG_MIN_MAP_SIZE, test_type_equal(), 0);
|
96
|
+
REQUIRE_THROWS_AS(sketch.update(1, -1), std::invalid_argument);
|
97
|
+
}
|
98
|
+
REQUIRE(test_allocator_total_bytes == 0);
|
86
99
|
}
|
87
100
|
|
88
101
|
} /* namespace datasketches */
|
@@ -17,27 +17,27 @@
|
|
17
17
|
* under the License.
|
18
18
|
*/
|
19
19
|
|
20
|
-
#include <catch.hpp>
|
20
|
+
#include <catch2/catch.hpp>
|
21
21
|
|
22
22
|
#include <reverse_purge_hash_map.hpp>
|
23
23
|
|
24
24
|
namespace datasketches {
|
25
25
|
|
26
26
|
TEST_CASE("reverse purge hash map: empty", "[frequent_items_sketch]") {
|
27
|
-
reverse_purge_hash_map<int> map(3, 3, std::allocator<int>());
|
27
|
+
reverse_purge_hash_map<int> map(3, 3, std::equal_to<int>(), std::allocator<int>());
|
28
28
|
REQUIRE(map.get_num_active() == 0);
|
29
29
|
REQUIRE(map.get_lg_cur_size() == 3); // static_cast<uint8_t>(3)
|
30
30
|
}
|
31
31
|
|
32
32
|
TEST_CASE("reverse purge hash map: one item", "[frequent_items_sketch]") {
|
33
|
-
reverse_purge_hash_map<int> map(3, 3, std::allocator<int>());
|
33
|
+
reverse_purge_hash_map<int> map(3, 3, std::equal_to<int>(), std::allocator<int>());
|
34
34
|
map.adjust_or_insert(1, 1);
|
35
35
|
REQUIRE(map.get_num_active() == 1);
|
36
36
|
REQUIRE(map.get(1) == 1);
|
37
37
|
}
|
38
38
|
|
39
39
|
TEST_CASE("reverse purge hash map: iterator", "[frequent_items_sketch]") {
|
40
|
-
reverse_purge_hash_map<int> map(3, 4, std::allocator<int>());
|
40
|
+
reverse_purge_hash_map<int> map(3, 4, std::equal_to<int>(), std::allocator<int>());
|
41
41
|
for (int i = 0; i < 11; i++) map.adjust_or_insert(i, 1); // this should fit with no purge
|
42
42
|
uint64_t sum = 0;
|
43
43
|
for (auto it: map) sum += it.second;
|
@@ -267,10 +267,10 @@ void Hll4Array<A>::shiftToBiggerCurMin() {
|
|
267
267
|
for (const auto coupon: *auxHashMap_) {
|
268
268
|
slotNum = HllUtil<A>::getLow26(coupon) & configKmask;
|
269
269
|
oldActualVal = HllUtil<A>::getValue(coupon);
|
270
|
-
|
271
|
-
if (newShiftedVal < 0) {
|
270
|
+
if (oldActualVal < newCurMin) {
|
272
271
|
throw std::logic_error("oldActualVal < newCurMin when incrementing curMin");
|
273
272
|
}
|
273
|
+
newShiftedVal = oldActualVal - newCurMin;
|
274
274
|
|
275
275
|
if (getSlot(slotNum) != hll_constants::AUX_TOKEN) {
|
276
276
|
throw std::logic_error("getSlot(slotNum) != AUX_TOKEN for item in auxiliary hash map");
|
@@ -48,38 +48,6 @@ class kll_helper {
|
|
48
48
|
static inline uint16_t int_cap_aux_aux(uint16_t k, uint8_t depth);
|
49
49
|
static inline uint64_t sum_the_sample_weights(uint8_t num_levels, const uint32_t* levels);
|
50
50
|
|
51
|
-
/*
|
52
|
-
* This version is for floating point types
|
53
|
-
* Checks the sequential validity of the given array of values.
|
54
|
-
* They must be unique, monotonically increasing and not NaN.
|
55
|
-
*/
|
56
|
-
template <typename T, typename C>
|
57
|
-
static typename std::enable_if<std::is_floating_point<T>::value, void>::type
|
58
|
-
validate_values(const T* values, uint32_t size) {
|
59
|
-
for (uint32_t i = 0; i < size ; i++) {
|
60
|
-
if (std::isnan(values[i])) {
|
61
|
-
throw std::invalid_argument("Values must not be NaN");
|
62
|
-
}
|
63
|
-
if ((i < (size - 1)) && !(C()(values[i], values[i + 1]))) {
|
64
|
-
throw std::invalid_argument("Values must be unique and monotonically increasing");
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
/*
|
69
|
-
* This version is for non-floating point types
|
70
|
-
* Checks the sequential validity of the given array of values.
|
71
|
-
* They must be unique and monotonically increasing.
|
72
|
-
*/
|
73
|
-
template <typename T, typename C>
|
74
|
-
static typename std::enable_if<!std::is_floating_point<T>::value, void>::type
|
75
|
-
validate_values(const T* values, uint32_t size) {
|
76
|
-
for (uint32_t i = 0; i < size ; i++) {
|
77
|
-
if ((i < (size - 1)) && !(C()(values[i], values[i + 1]))) {
|
78
|
-
throw std::invalid_argument("Values must be unique and monotonically increasing");
|
79
|
-
}
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
51
|
template <typename T>
|
84
52
|
static void randomly_halve_down(T* buf, uint32_t start, uint32_t length);
|
85
53
|
|