datasketches 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/LICENSE +4 -6
  4. data/NOTICE +6 -5
  5. data/ext/datasketches/kll_wrapper.cpp +20 -20
  6. data/ext/datasketches/theta_wrapper.cpp +2 -2
  7. data/lib/datasketches/version.rb +1 -1
  8. data/vendor/datasketches-cpp/CMakeLists.txt +9 -1
  9. data/vendor/datasketches-cpp/LICENSE +4 -6
  10. data/vendor/datasketches-cpp/MANIFEST.in +21 -4
  11. data/vendor/datasketches-cpp/common/CMakeLists.txt +5 -2
  12. data/vendor/datasketches-cpp/common/include/common_defs.hpp +10 -0
  13. data/vendor/datasketches-cpp/common/include/kolmogorov_smirnov_impl.hpp +6 -6
  14. data/vendor/datasketches-cpp/common/include/memory_operations.hpp +1 -0
  15. data/vendor/datasketches-cpp/common/include/{quantile_sketch_sorted_view.hpp → quantiles_sorted_view.hpp} +60 -25
  16. data/vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp +125 -0
  17. data/vendor/datasketches-cpp/common/{test/test_runner.cpp → include/version.hpp.in} +15 -8
  18. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +37 -7
  19. data/vendor/datasketches-cpp/common/test/catch_runner.cpp +22 -1
  20. data/vendor/datasketches-cpp/common/test/integration_test.cpp +1 -1
  21. data/vendor/datasketches-cpp/common/test/quantiles_sorted_view_test.cpp +459 -0
  22. data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -1
  23. data/vendor/datasketches-cpp/cpc/test/compression_test.cpp +1 -1
  24. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +1 -1
  25. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +1 -1
  26. data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +1 -1
  27. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +28 -44
  28. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +70 -78
  29. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +11 -4
  30. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +17 -10
  31. data/vendor/datasketches-cpp/fi/test/CMakeLists.txt +1 -1
  32. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +55 -42
  33. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +1 -1
  34. data/vendor/datasketches-cpp/fi/test/reverse_purge_hash_map_test.cpp +4 -4
  35. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +2 -2
  36. data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +1 -1
  37. data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +1 -1
  38. data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +1 -1
  39. data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +1 -1
  40. data/vendor/datasketches-cpp/hll/test/CrossCountingTest.cpp +1 -1
  41. data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +1 -1
  42. data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +1 -1
  43. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +1 -1
  44. data/vendor/datasketches-cpp/hll/test/IsomorphicTest.cpp +1 -1
  45. data/vendor/datasketches-cpp/hll/test/TablesTest.cpp +1 -1
  46. data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +1 -1
  47. data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -32
  48. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +176 -233
  49. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +337 -395
  50. data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +1 -1
  51. data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +27 -27
  52. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +197 -233
  53. data/vendor/datasketches-cpp/kll/test/kll_sketch_validation.cpp +42 -32
  54. data/vendor/datasketches-cpp/kll/test/kolmogorov_smirnov_test.cpp +1 -1
  55. data/vendor/datasketches-cpp/pyproject.toml +17 -13
  56. data/vendor/datasketches-cpp/python/CMakeLists.txt +8 -1
  57. data/vendor/datasketches-cpp/python/README.md +1 -1
  58. data/vendor/datasketches-cpp/python/datasketches/PySerDe.py +104 -0
  59. data/vendor/datasketches-cpp/python/datasketches/__init__.py +22 -0
  60. data/vendor/datasketches-cpp/python/include/py_serde.hpp +113 -0
  61. data/vendor/datasketches-cpp/python/jupyter/ThetaSketchNotebook.ipynb +31 -24
  62. data/vendor/datasketches-cpp/python/pybind11Path.cmd +19 -1
  63. data/vendor/datasketches-cpp/python/src/__init__.py +17 -1
  64. data/vendor/datasketches-cpp/python/src/datasketches.cpp +9 -3
  65. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +18 -54
  66. data/vendor/datasketches-cpp/python/src/py_serde.cpp +111 -0
  67. data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +17 -53
  68. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +17 -55
  69. data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +62 -67
  70. data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +47 -14
  71. data/vendor/datasketches-cpp/python/tests/__init__.py +16 -0
  72. data/vendor/datasketches-cpp/python/tests/req_test.py +1 -1
  73. data/vendor/datasketches-cpp/python/tests/vo_test.py +25 -1
  74. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +135 -180
  75. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +205 -210
  76. data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +1 -1
  77. data/vendor/datasketches-cpp/quantiles/test/kolmogorov_smirnov_test.cpp +1 -1
  78. data/vendor/datasketches-cpp/quantiles/test/quantiles_compatibility_test.cpp +20 -19
  79. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +241 -233
  80. data/vendor/datasketches-cpp/req/include/req_compactor.hpp +15 -9
  81. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +35 -19
  82. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +126 -147
  83. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +265 -245
  84. data/vendor/datasketches-cpp/req/test/CMakeLists.txt +1 -1
  85. data/vendor/datasketches-cpp/req/test/req_sketch_custom_type_test.cpp +27 -27
  86. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +117 -104
  87. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +22 -46
  88. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +180 -207
  89. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +18 -39
  90. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +75 -85
  91. data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +1 -1
  92. data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +7 -7
  93. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +3 -3
  94. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +5 -5
  95. data/vendor/datasketches-cpp/setup.py +14 -3
  96. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +15 -25
  97. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +0 -9
  98. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +5 -5
  99. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -1
  100. data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +1 -1
  101. data/vendor/datasketches-cpp/theta/test/theta_intersection_test.cpp +1 -1
  102. data/vendor/datasketches-cpp/theta/test/theta_jaccard_similarity_test.cpp +1 -1
  103. data/vendor/datasketches-cpp/theta/test/theta_setop_test.cpp +1 -1
  104. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +3 -2
  105. data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +1 -1
  106. data/vendor/datasketches-cpp/tox.ini +26 -0
  107. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +36 -12
  108. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +41 -35
  109. data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +2 -1
  110. data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +1 -1
  111. data/vendor/datasketches-cpp/tuple/test/engagement_test.cpp +299 -0
  112. data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +1 -1
  113. data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +1 -1
  114. data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +1 -1
  115. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +1 -1
  116. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +27 -1
  117. data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +1 -1
  118. data/vendor/datasketches-cpp/version.cfg.in +1 -0
  119. metadata +14 -7
  120. data/vendor/datasketches-cpp/common/include/quantile_sketch_sorted_view_impl.hpp +0 -91
  121. data/vendor/datasketches-cpp/common/test/catch.hpp +0 -17618
@@ -0,0 +1,299 @@
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 <iostream>
21
+ #include <iomanip>
22
+ #include <set>
23
+ #include <catch2/catch.hpp>
24
+ #include <tuple_sketch.hpp>
25
+ #include <tuple_union.hpp>
26
+ #include <stdexcept>
27
+
28
+ template<typename T>
29
+ class max_value_policy {
30
+ public:
31
+ max_value_policy(const T& initial_value): initial_value(initial_value) {}
32
+ T create() const { return initial_value; }
33
+ void update(T& summary, const T& update) const { summary = std::max(summary, update); }
34
+ private:
35
+ T initial_value;
36
+ };
37
+
38
+ using max_float_update_tuple_sketch = datasketches::update_tuple_sketch<float, float, max_value_policy<float>>;
39
+
40
+ template<typename T>
41
+ class always_one_policy {
42
+ public:
43
+ always_one_policy(): initial_value(1) {}
44
+ T create() const { return 1; }
45
+ void update(T&, const T&) const { }
46
+ private:
47
+ T initial_value;
48
+ };
49
+ using always_one_tuple_sketch = datasketches::update_tuple_sketch<int, int, always_one_policy<int>> ;
50
+
51
+ template<typename T>
52
+ class update_sum_value_policy {
53
+ public:
54
+ update_sum_value_policy(): initial_value(0) {}
55
+ T create() const { return initial_value; }
56
+ void update(T& summary, const T& update) const { summary += update; }
57
+ private:
58
+ T initial_value;
59
+ };
60
+ using sum_update_tuple_sketch = datasketches::update_tuple_sketch<int, int, update_sum_value_policy<int>>;
61
+
62
+ template<typename Summary>
63
+ struct union_sum_value_policy {
64
+ void operator()(Summary& summary, const Summary& other) const {
65
+ summary += other;
66
+ }
67
+ };
68
+
69
+ using sum_union_tuple_sketch = datasketches::tuple_union<int, union_sum_value_policy<int>> ;
70
+
71
+
72
+ class EngagementTest{
73
+ public:
74
+ int num_std_dev = 2 ;
75
+ void test_always_one_update(){
76
+ /*
77
+ * Tests that updates into an update_tuple_sketch sketch only keeps a 1 in the column for stored values.
78
+ */
79
+ int lgK = 8 ;
80
+ std::vector<datasketches::update_tuple_sketch<int, int, always_one_policy<int>>> sketch_array ;
81
+
82
+ auto always_one_sketch = always_one_tuple_sketch::builder(always_one_policy<int>()).set_lg_k(lgK).build() ;
83
+
84
+ always_one_sketch.update(1, 1);
85
+ always_one_sketch.update(1, 2);
86
+ always_one_sketch.update(2, 1);
87
+ always_one_sketch.update(3, 3);
88
+ always_one_sketch.update(3, 7);
89
+
90
+ int num_retained = 0;
91
+ int sum = 0;
92
+ for (const auto& entry: always_one_sketch) {
93
+ sum += entry.second;
94
+ ++num_retained;
95
+ }
96
+ REQUIRE(num_retained == 3);
97
+ REQUIRE(sum == 3); // we only keep 1 for every stored key.
98
+ }
99
+
100
+ void test_sum_update_policy(){
101
+ /*
102
+ * Tests that updates into an sum_update_tuple_sketch sum the stored values on updates.
103
+ */
104
+ int lgK = 8 ;
105
+ auto sum_sketch = sum_update_tuple_sketch::builder().set_lg_k(lgK).build() ;
106
+
107
+ sum_sketch.update(1, 1);
108
+ sum_sketch.update(1, 2);
109
+ sum_sketch.update(2, 1);
110
+ sum_sketch.update(3, 3);
111
+ sum_sketch.update(3, 7);
112
+ int num_retained = 0;
113
+ int sum = 0;
114
+ for (const auto& entry: sum_sketch) {
115
+ sum += entry.second;
116
+ ++num_retained;
117
+ }
118
+ REQUIRE(num_retained == 3);
119
+ REQUIRE(sum == 14); // (1+2) + 1 + (3 + 7) = 14
120
+ }
121
+
122
+ void test_sum_union_policy(){
123
+ /*
124
+ * Tests that updates into two sketches of sum_update_tuple_sketch flavour, which have been unioned,
125
+ * cause the stored values of two of the same keys to be summed.
126
+ */
127
+ auto sketch1 = sum_update_tuple_sketch::builder().build() ;
128
+ auto sketch2 = sum_update_tuple_sketch::builder().build() ;
129
+
130
+ sketch1.update(1, 1);
131
+ sketch1.update(2, 1);
132
+ sketch1.update(3, 3);
133
+
134
+ sketch2.update(1, 2);
135
+ sketch2.update(2, 1);
136
+ sketch2.update(3, 7);
137
+
138
+ auto union_sketch = sum_union_tuple_sketch::builder().build() ;
139
+ union_sketch.update(sketch1) ;
140
+ union_sketch.update(sketch2) ;
141
+ auto union_result = union_sketch.get_result() ;
142
+
143
+ int num_retained = 0;
144
+ int sum = 0;
145
+ for (const auto& entry: union_result) {
146
+ sum += entry.second;
147
+ ++num_retained;
148
+ }
149
+ REQUIRE(num_retained == 3);
150
+ REQUIRE(sum == 15); // 1:(1+2) + 2:(1+1) + 3:(3+7) = 15
151
+ }
152
+
153
+ void compute_engagement_histogram(){
154
+ /*
155
+ * Returns the estimated histogram from the synthetic data.
156
+ * On inspection one can verify this agrees with the
157
+ * https://github.com/apache/datasketches-java/blob/master/src/test/java/org/apache/datasketches/tuple/aninteger/EngagementTest.java
158
+ */
159
+ int lgK = 8 ;
160
+ const int days = 30 ;
161
+ int v = 0 ;
162
+ std::set<int> set_array[days];
163
+ std::vector<datasketches::update_tuple_sketch<int, int, always_one_policy<int>>> sketch_array ;
164
+
165
+
166
+ for(int i=0; i<days ; i++){
167
+ auto builder = always_one_tuple_sketch::builder(always_one_policy<int>()) ;
168
+ builder.set_lg_k(lgK) ;
169
+ auto sketch = builder.build() ;
170
+ sketch_array.push_back(sketch);
171
+ }
172
+ REQUIRE(sketch_array.size() == days) ;
173
+
174
+ for(int i=0; i<=days; i++){
175
+ int32_t num_ids = get_num_ids(days, i) ;
176
+ int32_t num_days = get_num_days(days, i) ;
177
+
178
+ int my_v = v++ ;
179
+ for(int d=0 ; d<num_days; d++){
180
+ for(int id = 0; id < num_ids; id++){
181
+ set_array[d].insert(my_v + id) ;
182
+ sketch_array[d].update(my_v + id, 1) ;
183
+ }
184
+ }
185
+ v += num_ids ;
186
+ }
187
+ union_ops(lgK, sketch_array) ;
188
+ }
189
+ private:
190
+ int32_t get_num_ids(int total_days, int index){
191
+ /*
192
+ * Generates power law distributed synthetic data
193
+ */
194
+ double d = total_days ;
195
+ double i = index ;
196
+ return int(round(exp(i * log(d) / d))) ;
197
+ }
198
+
199
+ int32_t get_num_days(int total_days, int index){
200
+ double d = total_days ;
201
+ double i = index ;
202
+ return int(round(exp( (d-i) * log(d) / d ))) ;
203
+ }
204
+
205
+ int32_t round_double_to_int(double x){
206
+ return int(std::round(x)) ;
207
+ }
208
+
209
+ void union_ops(int lgk, std::vector<datasketches::update_tuple_sketch<int, int, always_one_policy<int>>> sketches){
210
+ int num_sketches = sketches.size() ;
211
+ auto u = sum_union_tuple_sketch::builder().set_lg_k(lgk).build() ;
212
+
213
+ for(auto sk:sketches){
214
+ u.update(sk) ;
215
+ }
216
+ auto union_result = u.get_result() ;
217
+ std::vector<uint64_t> num_days_arr(num_sketches+1) ;
218
+
219
+ for (const auto& entry: union_result) {
220
+ int num_days_visited = entry.second ;
221
+ num_days_arr[num_days_visited]++;
222
+ }
223
+
224
+ int sum_visits = 0;
225
+ double theta = union_result.get_theta();
226
+ std::cout <<"\t\tEngagement Histogram.\t\t\t\n" ;
227
+ std::cout << "Number of Unique Visitors by Number of Days Visited" << std::endl ;
228
+ std::cout << "---------------------------------------------------" << std::endl ;
229
+
230
+ std::cout << std::setw(12) << "Days Visited"
231
+ << std::setw(12) << "Estimate"
232
+ << std::setw(12) << "LB"
233
+ << std::setw(12) << "UB"
234
+ << std:: endl ;
235
+
236
+ for (uint64_t i = 0; i < num_days_arr.size(); i++) {
237
+ int visitors_at_days_visited = num_days_arr[i] ;
238
+ if(visitors_at_days_visited == 0){ continue; }
239
+ sum_visits += visitors_at_days_visited * i ;
240
+
241
+ double est_visitors_at_days_visited = visitors_at_days_visited / theta ;
242
+ double lower_bound_at_days_visited = union_result.get_lower_bound(num_std_dev, visitors_at_days_visited);
243
+ double upper_bound_at_days_visited = union_result.get_upper_bound(num_std_dev, visitors_at_days_visited);
244
+
245
+ std::cout << std::setw(12) << i
246
+ << std::setw(12) << est_visitors_at_days_visited
247
+ << std::setw(12) << lower_bound_at_days_visited
248
+ << std::setw(12) << upper_bound_at_days_visited
249
+ << std:: endl ;
250
+
251
+ }
252
+ std::cout << std::endl << std::endl ;
253
+ std::cout << std::setw(12) << "Totals"
254
+ << std::setw(12) << "Estimate"
255
+ << std::setw(12) << "LB"
256
+ << std::setw(12) << "UB"
257
+ << std:: endl ;
258
+ std::cout << "---------------------------------------------------" << std::endl ;
259
+
260
+ const double total_visitors = union_result.get_estimate() ;
261
+ const double lb_visitors = union_result.get_lower_bound(num_std_dev) ;
262
+ const double ub_visitors = union_result.get_upper_bound(num_std_dev) ;
263
+
264
+
265
+ std::cout << std::setw(12) << "Visitors"
266
+ << std::setw(12) << total_visitors
267
+ << std::setw(12) << lb_visitors
268
+ << std::setw(12) << ub_visitors
269
+ << std:: endl ;
270
+
271
+ // The total number of visits, however, is a scaled metric and takes advantage of the fact that
272
+ // the retained entries in the sketch is a uniform random sample of all unique visitors, and
273
+ // the rest of the unique users will likely behave in the same way.
274
+ const double est_visits = sum_visits / theta;
275
+ const double lb_visits = est_visits * lb_visitors / total_visitors;
276
+ const double ub_visits = est_visits * ub_visitors / total_visitors;
277
+
278
+
279
+ std::cout << std::setw(12) << "Visits"
280
+ << std::setw(12) << est_visits
281
+ << std::setw(12) << lb_visits
282
+ << std::setw(12) << ub_visits
283
+ << std:: endl ;
284
+ }
285
+
286
+ };
287
+
288
+ namespace datasketches {
289
+
290
+ TEST_CASE("engagement", "[engagement]") {
291
+ EngagementTest E ;
292
+ E.test_always_one_update() ;
293
+ E.test_sum_update_policy() ;
294
+ E.test_sum_union_policy() ;
295
+ E.compute_engagement_histogram() ;
296
+ }
297
+
298
+
299
+ } /* namespace datasketches */
@@ -19,7 +19,7 @@
19
19
 
20
20
  #include <iostream>
21
21
 
22
- #include <catch.hpp>
22
+ #include <catch2/catch.hpp>
23
23
  #include <tuple_a_not_b.hpp>
24
24
  #include <theta_sketch.hpp>
25
25
  #include <stdexcept>
@@ -19,7 +19,7 @@
19
19
 
20
20
  #include <iostream>
21
21
 
22
- #include <catch.hpp>
22
+ #include <catch2/catch.hpp>
23
23
  #include <tuple_intersection.hpp>
24
24
  #include <theta_sketch.hpp>
25
25
  #include <stdexcept>
@@ -19,7 +19,7 @@
19
19
 
20
20
  #include <iostream>
21
21
 
22
- #include <catch.hpp>
22
+ #include <catch2/catch.hpp>
23
23
 
24
24
  #include "tuple_jaccard_similarity.hpp"
25
25
 
@@ -19,7 +19,7 @@
19
19
 
20
20
  #include <iostream>
21
21
 
22
- #include <catch.hpp>
22
+ #include <catch2/catch.hpp>
23
23
  #include <tuple_sketch.hpp>
24
24
  #include <test_allocator.hpp>
25
25
  #include <test_type.hpp>
@@ -32,7 +32,7 @@ std::ostream& operator<<(std::ostream& os, const three_doubles& tuple) {
32
32
 
33
33
  }
34
34
 
35
- #include <catch.hpp>
35
+ #include <catch2/catch.hpp>
36
36
  #include <tuple_sketch.hpp>
37
37
 
38
38
  namespace datasketches {
@@ -56,7 +56,13 @@ TEST_CASE("tuple sketch float: empty", "[tuple_sketch]") {
56
56
  REQUIRE(!update_sketch.is_estimation_mode());
57
57
  REQUIRE(update_sketch.get_estimate() == 0);
58
58
  REQUIRE(update_sketch.get_lower_bound(1) == 0);
59
+ REQUIRE(update_sketch.get_lower_bound(1, 1) == 0);
60
+ REQUIRE(update_sketch.get_lower_bound(1, update_sketch.get_num_retained()) == 0);
61
+ REQUIRE(update_sketch.get_lower_bound(1, update_sketch.get_num_retained()+1) == 0);
59
62
  REQUIRE(update_sketch.get_upper_bound(1) == 0);
63
+ REQUIRE(update_sketch.get_upper_bound(1, 1) == 0);
64
+ REQUIRE(update_sketch.get_upper_bound(1, update_sketch.get_num_retained()) == 0);
65
+ REQUIRE(update_sketch.get_upper_bound(1, update_sketch.get_num_retained()+1) == 0);
60
66
  REQUIRE(update_sketch.get_theta() == 1);
61
67
  REQUIRE(update_sketch.get_num_retained() == 0);
62
68
  REQUIRE(update_sketch.is_ordered());
@@ -67,7 +73,11 @@ TEST_CASE("tuple sketch float: empty", "[tuple_sketch]") {
67
73
  REQUIRE(!compact_sketch.is_estimation_mode());
68
74
  REQUIRE(compact_sketch.get_estimate() == 0);
69
75
  REQUIRE(compact_sketch.get_lower_bound(1) == 0);
76
+ REQUIRE(compact_sketch.get_lower_bound(1, 1) == 0);
77
+ REQUIRE(compact_sketch.get_lower_bound(1, update_sketch.get_num_retained()) == 0);
70
78
  REQUIRE(compact_sketch.get_upper_bound(1) == 0);
79
+ REQUIRE(compact_sketch.get_upper_bound(1, 1) == 0);
80
+ REQUIRE(compact_sketch.get_upper_bound(1, update_sketch.get_num_retained()) == 0);
71
81
  REQUIRE(compact_sketch.get_theta() == 1);
72
82
  REQUIRE(compact_sketch.get_num_retained() == 0);
73
83
  REQUIRE(compact_sketch.is_ordered());
@@ -110,7 +120,11 @@ TEST_CASE("tuple sketch float: exact mode", "[tuple_sketch]") {
110
120
  REQUIRE_FALSE(update_sketch.is_estimation_mode());
111
121
  REQUIRE(update_sketch.get_estimate() == 2);
112
122
  REQUIRE(update_sketch.get_lower_bound(1) == 2);
123
+ REQUIRE(update_sketch.get_lower_bound(1, 1) == 1);
124
+ REQUIRE(update_sketch.get_lower_bound(1, update_sketch.get_num_retained()) == 2);
113
125
  REQUIRE(update_sketch.get_upper_bound(1) == 2);
126
+ REQUIRE(update_sketch.get_upper_bound(1, 1) == 1);
127
+ REQUIRE(update_sketch.get_upper_bound(1, update_sketch.get_num_retained()) == 2);
114
128
  REQUIRE(update_sketch.get_theta() == 1);
115
129
  REQUIRE(update_sketch.get_num_retained() == 2);
116
130
  REQUIRE_FALSE(update_sketch.is_ordered());
@@ -127,7 +141,11 @@ TEST_CASE("tuple sketch float: exact mode", "[tuple_sketch]") {
127
141
  REQUIRE_FALSE(compact_sketch.is_estimation_mode());
128
142
  REQUIRE(compact_sketch.get_estimate() == 2);
129
143
  REQUIRE(compact_sketch.get_lower_bound(1) == 2);
144
+ REQUIRE(compact_sketch.get_lower_bound(1, 1) == 1);
145
+ REQUIRE(compact_sketch.get_lower_bound(1, compact_sketch.get_num_retained()) == 2);
130
146
  REQUIRE(compact_sketch.get_upper_bound(1) == 2);
147
+ REQUIRE(compact_sketch.get_upper_bound(1, 1) == 1);
148
+ REQUIRE(compact_sketch.get_upper_bound(1, compact_sketch.get_num_retained()) == 2);
131
149
  REQUIRE(compact_sketch.get_theta() == 1);
132
150
  REQUIRE(compact_sketch.get_num_retained() == 2);
133
151
  REQUIRE(compact_sketch.is_ordered());
@@ -146,7 +164,11 @@ TEST_CASE("tuple sketch float: exact mode", "[tuple_sketch]") {
146
164
  REQUIRE(!deserialized_sketch.is_estimation_mode());
147
165
  REQUIRE(deserialized_sketch.get_estimate() == 2);
148
166
  REQUIRE(deserialized_sketch.get_lower_bound(1) == 2);
167
+ REQUIRE(deserialized_sketch.get_lower_bound(1, 1) == 1);
168
+ REQUIRE(deserialized_sketch.get_lower_bound(1, deserialized_sketch.get_num_retained()) == 2);
149
169
  REQUIRE(deserialized_sketch.get_upper_bound(1) == 2);
170
+ REQUIRE(deserialized_sketch.get_upper_bound(1, 1) == 1);
171
+ REQUIRE(deserialized_sketch.get_upper_bound(1, deserialized_sketch.get_num_retained()) == 2);
150
172
  REQUIRE(deserialized_sketch.get_theta() == 1);
151
173
  REQUIRE(deserialized_sketch.get_num_retained() == 2);
152
174
  REQUIRE(deserialized_sketch.is_ordered());
@@ -160,7 +182,11 @@ TEST_CASE("tuple sketch float: exact mode", "[tuple_sketch]") {
160
182
  REQUIRE(!deserialized_sketch.is_estimation_mode());
161
183
  REQUIRE(deserialized_sketch.get_estimate() == 2);
162
184
  REQUIRE(deserialized_sketch.get_lower_bound(1) == 2);
185
+ REQUIRE(deserialized_sketch.get_lower_bound(1, 1) == 1);
186
+ REQUIRE(deserialized_sketch.get_lower_bound(1, deserialized_sketch.get_num_retained()) == 2);
163
187
  REQUIRE(deserialized_sketch.get_upper_bound(1) == 2);
188
+ REQUIRE(deserialized_sketch.get_upper_bound(1, 1) == 1);
189
+ REQUIRE(deserialized_sketch.get_upper_bound(1, deserialized_sketch.get_num_retained()) == 2);
164
190
  REQUIRE(deserialized_sketch.get_theta() == 1);
165
191
  REQUIRE(deserialized_sketch.get_num_retained() == 2);
166
192
  REQUIRE(deserialized_sketch.is_ordered());
@@ -20,7 +20,7 @@
20
20
  #include <iostream>
21
21
  #include <stdexcept>
22
22
 
23
- #include <catch.hpp>
23
+ #include <catch2/catch.hpp>
24
24
  #include <tuple_union.hpp>
25
25
  #include <theta_sketch.hpp>
26
26
 
@@ -0,0 +1 @@
1
+ 4.0.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datasketches
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2022-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -65,16 +65,16 @@ files:
65
65
  - vendor/datasketches-cpp/common/include/kolmogorov_smirnov.hpp
66
66
  - vendor/datasketches-cpp/common/include/kolmogorov_smirnov_impl.hpp
67
67
  - vendor/datasketches-cpp/common/include/memory_operations.hpp
68
- - vendor/datasketches-cpp/common/include/quantile_sketch_sorted_view.hpp
69
- - vendor/datasketches-cpp/common/include/quantile_sketch_sorted_view_impl.hpp
68
+ - vendor/datasketches-cpp/common/include/quantiles_sorted_view.hpp
69
+ - vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp
70
70
  - vendor/datasketches-cpp/common/include/serde.hpp
71
+ - vendor/datasketches-cpp/common/include/version.hpp.in
71
72
  - vendor/datasketches-cpp/common/test/CMakeLists.txt
72
- - vendor/datasketches-cpp/common/test/catch.hpp
73
73
  - vendor/datasketches-cpp/common/test/catch_runner.cpp
74
74
  - vendor/datasketches-cpp/common/test/integration_test.cpp
75
+ - vendor/datasketches-cpp/common/test/quantiles_sorted_view_test.cpp
75
76
  - vendor/datasketches-cpp/common/test/test_allocator.cpp
76
77
  - vendor/datasketches-cpp/common/test/test_allocator.hpp
77
- - vendor/datasketches-cpp/common/test/test_runner.cpp
78
78
  - vendor/datasketches-cpp/common/test/test_type.hpp
79
79
  - vendor/datasketches-cpp/cpc/CMakeLists.txt
80
80
  - vendor/datasketches-cpp/cpc/include/compression_data.hpp
@@ -173,6 +173,9 @@ files:
173
173
  - vendor/datasketches-cpp/pyproject.toml
174
174
  - vendor/datasketches-cpp/python/CMakeLists.txt
175
175
  - vendor/datasketches-cpp/python/README.md
176
+ - vendor/datasketches-cpp/python/datasketches/PySerDe.py
177
+ - vendor/datasketches-cpp/python/datasketches/__init__.py
178
+ - vendor/datasketches-cpp/python/include/py_serde.hpp
176
179
  - vendor/datasketches-cpp/python/jupyter/CPCSketch.ipynb
177
180
  - vendor/datasketches-cpp/python/jupyter/FrequentItemsSketch.ipynb
178
181
  - vendor/datasketches-cpp/python/jupyter/HLLSketch.ipynb
@@ -186,6 +189,7 @@ files:
186
189
  - vendor/datasketches-cpp/python/src/hll_wrapper.cpp
187
190
  - vendor/datasketches-cpp/python/src/kll_wrapper.cpp
188
191
  - vendor/datasketches-cpp/python/src/ks_wrapper.cpp
192
+ - vendor/datasketches-cpp/python/src/py_serde.cpp
189
193
  - vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp
190
194
  - vendor/datasketches-cpp/python/src/req_wrapper.cpp
191
195
  - vendor/datasketches-cpp/python/src/theta_wrapper.cpp
@@ -285,6 +289,7 @@ files:
285
289
  - vendor/datasketches-cpp/theta/test/theta_setop_test.cpp
286
290
  - vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp
287
291
  - vendor/datasketches-cpp/theta/test/theta_union_test.cpp
292
+ - vendor/datasketches-cpp/tox.ini
288
293
  - vendor/datasketches-cpp/tuple/CMakeLists.txt
289
294
  - vendor/datasketches-cpp/tuple/include/array_of_doubles_a_not_b.hpp
290
295
  - vendor/datasketches-cpp/tuple/include/array_of_doubles_a_not_b_impl.hpp
@@ -310,12 +315,14 @@ files:
310
315
  - vendor/datasketches-cpp/tuple/test/aod_2_compact_exact_from_java.sk
311
316
  - vendor/datasketches-cpp/tuple/test/aod_3_compact_empty_from_java.sk
312
317
  - vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp
318
+ - vendor/datasketches-cpp/tuple/test/engagement_test.cpp
313
319
  - vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp
314
320
  - vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp
315
321
  - vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp
316
322
  - vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp
317
323
  - vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp
318
324
  - vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp
325
+ - vendor/datasketches-cpp/version.cfg.in
319
326
  homepage: https://github.com/ankane/datasketches-ruby
320
327
  licenses:
321
328
  - Apache-2.0
@@ -328,7 +335,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
328
335
  requirements:
329
336
  - - ">="
330
337
  - !ruby/object:Gem::Version
331
- version: '2.6'
338
+ version: '2.7'
332
339
  required_rubygems_version: !ruby/object:Gem::Requirement
333
340
  requirements:
334
341
  - - ">="
@@ -1,91 +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
- #ifndef QUANTILE_SKETCH_SORTED_VIEW_IMPL_HPP_
21
- #define QUANTILE_SKETCH_SORTED_VIEW_IMPL_HPP_
22
-
23
- #include <algorithm>
24
- #include <stdexcept>
25
-
26
- namespace datasketches {
27
-
28
- template<typename T, typename C, typename A>
29
- quantile_sketch_sorted_view<T, C, A>::quantile_sketch_sorted_view(uint32_t num, const A& allocator):
30
- total_weight_(0),
31
- entries_(allocator)
32
- {
33
- entries_.reserve(num);
34
- }
35
-
36
- template<typename T, typename C, typename A>
37
- template<typename Iterator>
38
- void quantile_sketch_sorted_view<T, C, A>::add(Iterator first, Iterator last, uint64_t weight) {
39
- const size_t size_before = entries_.size();
40
- for (auto it = first; it != last; ++it) entries_.push_back(Entry(ref_helper(*it), weight));
41
- if (size_before > 0) {
42
- Container tmp(entries_.get_allocator());
43
- tmp.reserve(entries_.capacity());
44
- std::merge(
45
- entries_.begin(), entries_.begin() + size_before,
46
- entries_.begin() + size_before, entries_.end(),
47
- std::back_inserter(tmp), compare_pairs_by_first()
48
- );
49
- std::swap(tmp, entries_);
50
- }
51
- }
52
-
53
- template<typename T, typename C, typename A>
54
- template<bool inclusive>
55
- void quantile_sketch_sorted_view<T, C, A>::convert_to_cummulative() {
56
- uint64_t subtotal = 0;
57
- for (auto& entry: entries_) {
58
- const uint64_t new_subtotal = subtotal + entry.second;
59
- entry.second = inclusive ? new_subtotal : subtotal;
60
- subtotal = new_subtotal;
61
- }
62
- total_weight_ = subtotal;
63
- }
64
-
65
- template<typename T, typename C, typename A>
66
- auto quantile_sketch_sorted_view<T, C, A>::get_quantile(double rank) const -> quantile_return_type {
67
- if (total_weight_ == 0) throw std::invalid_argument("supported for cumulative weight only");
68
- uint64_t weight = static_cast<uint64_t>(rank * total_weight_);
69
- auto it = std::lower_bound(entries_.begin(), entries_.end(), make_dummy_entry<T>(weight), compare_pairs_by_second());
70
- if (it == entries_.end()) return deref_helper(entries_[entries_.size() - 1].first);
71
- return deref_helper(it->first);
72
- }
73
-
74
- template<typename T, typename C, typename A>
75
- auto quantile_sketch_sorted_view<T, C, A>::begin() const -> const_iterator {
76
- return entries_.begin();
77
- }
78
-
79
- template<typename T, typename C, typename A>
80
- auto quantile_sketch_sorted_view<T, C, A>::end() const -> const_iterator {
81
- return entries_.end();
82
- }
83
-
84
- template<typename T, typename C, typename A>
85
- size_t quantile_sketch_sorted_view<T, C, A>::size() const {
86
- return entries_.size();
87
- }
88
-
89
- } /* namespace datasketches */
90
-
91
- #endif