datasketches 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/NOTICE +1 -1
  4. data/README.md +0 -2
  5. data/ext/datasketches/cpc_wrapper.cpp +3 -3
  6. data/ext/datasketches/kll_wrapper.cpp +0 -10
  7. data/lib/datasketches/version.rb +1 -1
  8. data/lib/datasketches.rb +1 -1
  9. data/vendor/datasketches-cpp/CMakeLists.txt +23 -20
  10. data/vendor/datasketches-cpp/CODE_OF_CONDUCT.md +3 -0
  11. data/vendor/datasketches-cpp/CONTRIBUTING.md +50 -0
  12. data/vendor/datasketches-cpp/Doxyfile +2827 -0
  13. data/vendor/datasketches-cpp/LICENSE +0 -76
  14. data/vendor/datasketches-cpp/README.md +1 -3
  15. data/vendor/datasketches-cpp/common/CMakeLists.txt +12 -11
  16. data/vendor/datasketches-cpp/common/include/MurmurHash3.h +25 -27
  17. data/vendor/datasketches-cpp/common/include/common_defs.hpp +15 -10
  18. data/vendor/datasketches-cpp/common/include/count_zeros.hpp +11 -2
  19. data/vendor/datasketches-cpp/common/include/kolmogorov_smirnov.hpp +9 -6
  20. data/vendor/datasketches-cpp/common/include/memory_operations.hpp +5 -4
  21. data/vendor/datasketches-cpp/common/include/optional.hpp +148 -0
  22. data/vendor/datasketches-cpp/common/include/quantiles_sorted_view.hpp +95 -2
  23. data/vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp +1 -1
  24. data/vendor/datasketches-cpp/common/include/serde.hpp +69 -20
  25. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +2 -2
  26. data/vendor/datasketches-cpp/common/test/integration_test.cpp +6 -0
  27. data/vendor/datasketches-cpp/common/test/optional_test.cpp +85 -0
  28. data/vendor/datasketches-cpp/common/test/test_allocator.hpp +14 -14
  29. data/vendor/datasketches-cpp/{python/src/__init__.py → count/CMakeLists.txt} +25 -1
  30. data/vendor/datasketches-cpp/count/include/count_min.hpp +405 -0
  31. data/vendor/datasketches-cpp/count/include/count_min_impl.hpp +497 -0
  32. data/vendor/datasketches-cpp/{MANIFEST.in → count/test/CMakeLists.txt} +23 -20
  33. data/vendor/datasketches-cpp/count/test/count_min_allocation_test.cpp +155 -0
  34. data/vendor/datasketches-cpp/count/test/count_min_test.cpp +303 -0
  35. data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +14 -20
  36. data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +7 -4
  37. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +17 -17
  38. data/vendor/datasketches-cpp/cpc/include/cpc_confidence.hpp +3 -3
  39. data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +40 -40
  40. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +14 -11
  41. data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +35 -11
  42. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +8 -8
  43. data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +16 -8
  44. data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +3 -2
  45. data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +5 -5
  46. data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +20 -7
  47. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_deserialize_from_java_test.cpp +60 -0
  48. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_serialize_for_java.cpp +38 -0
  49. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +4 -29
  50. data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +4 -4
  51. data/vendor/datasketches-cpp/{tox.ini → density/CMakeLists.txt} +24 -8
  52. data/vendor/datasketches-cpp/density/include/density_sketch.hpp +256 -0
  53. data/vendor/datasketches-cpp/density/include/density_sketch_impl.hpp +543 -0
  54. data/vendor/datasketches-cpp/{python/datasketches/__init__.py → density/test/CMakeLists.txt} +15 -3
  55. data/vendor/datasketches-cpp/density/test/density_sketch_test.cpp +244 -0
  56. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +21 -9
  57. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +6 -4
  58. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +9 -3
  59. data/vendor/datasketches-cpp/fi/test/CMakeLists.txt +14 -1
  60. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_deserialize_from_java_test.cpp +95 -0
  61. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_serialize_for_java.cpp +83 -0
  62. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +3 -42
  63. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +2 -2
  64. data/vendor/datasketches-cpp/hll/include/CouponList.hpp +3 -1
  65. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +19 -11
  66. data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +2 -5
  67. data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +19 -7
  68. data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +1 -1
  69. data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +98 -42
  70. data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +2 -0
  71. data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +94 -61
  72. data/vendor/datasketches-cpp/hll/include/HllArray.hpp +20 -8
  73. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +4 -4
  74. data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +3 -1
  75. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +3 -21
  76. data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +8 -0
  77. data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +14 -18
  78. data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +1 -1
  79. data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +8 -2
  80. data/vendor/datasketches-cpp/hll/include/hll.hpp +79 -65
  81. data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +14 -1
  82. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +7 -1
  83. data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +0 -68
  84. data/vendor/datasketches-cpp/hll/test/hll_sketch_deserialize_from_java_test.cpp +69 -0
  85. data/vendor/datasketches-cpp/hll/test/hll_sketch_serialize_for_java.cpp +52 -0
  86. data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -1
  87. data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +2 -2
  88. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +79 -53
  89. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +61 -132
  90. data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +14 -1
  91. data/vendor/datasketches-cpp/kll/test/kll_sketch_deserialize_from_java_test.cpp +103 -0
  92. data/vendor/datasketches-cpp/kll/test/kll_sketch_serialize_for_java.cpp +62 -0
  93. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +5 -40
  94. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +76 -54
  95. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +66 -136
  96. data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +14 -1
  97. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_deserialize_from_java_test.cpp +84 -0
  98. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_serialize_for_java.cpp +52 -0
  99. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +15 -39
  100. data/vendor/datasketches-cpp/req/include/req_common.hpp +7 -3
  101. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +2 -4
  102. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +105 -26
  103. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +50 -111
  104. data/vendor/datasketches-cpp/req/test/CMakeLists.txt +14 -1
  105. data/vendor/datasketches-cpp/req/test/req_sketch_deserialize_from_java_test.cpp +55 -0
  106. data/vendor/datasketches-cpp/{tuple/include/array_of_doubles_intersection_impl.hpp → req/test/req_sketch_serialize_for_java.cpp} +12 -7
  107. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +3 -89
  108. data/vendor/datasketches-cpp/sampling/CMakeLists.txt +4 -0
  109. data/vendor/datasketches-cpp/sampling/include/ebpps_sample.hpp +210 -0
  110. data/vendor/datasketches-cpp/sampling/include/ebpps_sample_impl.hpp +535 -0
  111. data/vendor/datasketches-cpp/sampling/include/ebpps_sketch.hpp +281 -0
  112. data/vendor/datasketches-cpp/sampling/include/ebpps_sketch_impl.hpp +531 -0
  113. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +89 -32
  114. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +33 -19
  115. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +13 -10
  116. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +23 -19
  117. data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +55 -8
  118. data/vendor/datasketches-cpp/sampling/test/ebpps_allocation_test.cpp +96 -0
  119. data/vendor/datasketches-cpp/sampling/test/ebpps_sample_test.cpp +137 -0
  120. data/vendor/datasketches-cpp/sampling/test/ebpps_sketch_test.cpp +266 -0
  121. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_deserialize_from_java_test.cpp +81 -0
  122. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_serialize_for_java.cpp +54 -0
  123. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +33 -51
  124. data/vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp +50 -0
  125. data/vendor/datasketches-cpp/sampling/test/var_opt_union_serialize_for_java.cpp +56 -0
  126. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +0 -20
  127. data/vendor/datasketches-cpp/theta/CMakeLists.txt +1 -0
  128. data/vendor/datasketches-cpp/theta/include/bit_packing.hpp +6279 -0
  129. data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_sampled_sets.hpp +1 -0
  130. data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_theta_sketched_sets.hpp +7 -6
  131. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +14 -8
  132. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +60 -46
  133. data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +20 -5
  134. data/vendor/datasketches-cpp/theta/include/theta_constants.hpp +10 -4
  135. data/vendor/datasketches-cpp/theta/include/theta_helpers.hpp +3 -1
  136. data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +13 -5
  137. data/vendor/datasketches-cpp/theta/include/theta_intersection_base_impl.hpp +5 -5
  138. data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +3 -3
  139. data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity.hpp +2 -1
  140. data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity_base.hpp +1 -0
  141. data/vendor/datasketches-cpp/theta/include/theta_set_difference_base_impl.hpp +1 -1
  142. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +180 -33
  143. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +430 -130
  144. data/vendor/datasketches-cpp/theta/include/theta_union.hpp +17 -10
  145. data/vendor/datasketches-cpp/theta/include/theta_union_base_impl.hpp +10 -10
  146. data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +3 -3
  147. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +21 -6
  148. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +13 -3
  149. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +15 -1
  150. data/vendor/datasketches-cpp/theta/test/bit_packing_test.cpp +80 -0
  151. data/vendor/datasketches-cpp/theta/test/theta_sketch_deserialize_from_java_test.cpp +57 -0
  152. data/vendor/datasketches-cpp/theta/test/theta_sketch_serialize_for_java.cpp +61 -0
  153. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +39 -188
  154. data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +25 -0
  155. data/vendor/datasketches-cpp/tuple/CMakeLists.txt +8 -7
  156. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch.hpp +19 -144
  157. data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b.hpp → array_tuple_a_not_b.hpp} +24 -16
  158. data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b_impl.hpp → array_tuple_a_not_b_impl.hpp} +4 -4
  159. data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection.hpp +65 -0
  160. data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection_impl.hpp +31 -0
  161. data/vendor/datasketches-cpp/tuple/include/array_tuple_sketch.hpp +237 -0
  162. data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_sketch_impl.hpp → array_tuple_sketch_impl.hpp} +40 -41
  163. data/vendor/datasketches-cpp/tuple/include/array_tuple_union.hpp +81 -0
  164. data/vendor/datasketches-cpp/tuple/include/array_tuple_union_impl.hpp +43 -0
  165. data/vendor/datasketches-cpp/tuple/include/tuple_a_not_b.hpp +11 -2
  166. data/vendor/datasketches-cpp/tuple/include/tuple_intersection.hpp +17 -10
  167. data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +2 -1
  168. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +95 -32
  169. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +2 -1
  170. data/vendor/datasketches-cpp/tuple/include/tuple_union.hpp +19 -11
  171. data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +16 -1
  172. data/vendor/datasketches-cpp/tuple/test/aod_sketch_deserialize_from_java_test.cpp +76 -0
  173. data/vendor/datasketches-cpp/tuple/test/aod_sketch_serialize_for_java.cpp +62 -0
  174. data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +5 -129
  175. data/vendor/datasketches-cpp/tuple/test/engagement_test.cpp +85 -89
  176. data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +3 -1
  177. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_deserialize_from_java_test.cpp +47 -0
  178. data/vendor/datasketches-cpp/{python/src/datasketches.cpp → tuple/test/tuple_sketch_serialize_for_java.cpp} +16 -30
  179. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +1 -1
  180. data/vendor/datasketches-cpp/version.cfg.in +1 -1
  181. metadata +61 -79
  182. data/vendor/datasketches-cpp/fi/test/items_sketch_string_from_java.sk +0 -0
  183. data/vendor/datasketches-cpp/fi/test/items_sketch_string_utf8_from_java.sk +0 -0
  184. data/vendor/datasketches-cpp/fi/test/longs_sketch_from_java.sk +0 -0
  185. data/vendor/datasketches-cpp/hll/test/array6_from_java.sk +0 -0
  186. data/vendor/datasketches-cpp/hll/test/compact_array4_from_java.sk +0 -0
  187. data/vendor/datasketches-cpp/hll/test/compact_set_from_java.sk +0 -0
  188. data/vendor/datasketches-cpp/hll/test/list_from_java.sk +0 -0
  189. data/vendor/datasketches-cpp/hll/test/updatable_array4_from_java.sk +0 -0
  190. data/vendor/datasketches-cpp/hll/test/updatable_set_from_java.sk +0 -0
  191. data/vendor/datasketches-cpp/kll/test/kll_sketch_from_java.sk +0 -0
  192. data/vendor/datasketches-cpp/pyproject.toml +0 -23
  193. data/vendor/datasketches-cpp/python/CMakeLists.txt +0 -81
  194. data/vendor/datasketches-cpp/python/README.md +0 -85
  195. data/vendor/datasketches-cpp/python/datasketches/PySerDe.py +0 -104
  196. data/vendor/datasketches-cpp/python/include/py_serde.hpp +0 -113
  197. data/vendor/datasketches-cpp/python/jupyter/CPCSketch.ipynb +0 -345
  198. data/vendor/datasketches-cpp/python/jupyter/FrequentItemsSketch.ipynb +0 -354
  199. data/vendor/datasketches-cpp/python/jupyter/HLLSketch.ipynb +0 -346
  200. data/vendor/datasketches-cpp/python/jupyter/KLLSketch.ipynb +0 -463
  201. data/vendor/datasketches-cpp/python/jupyter/ThetaSketchNotebook.ipynb +0 -403
  202. data/vendor/datasketches-cpp/python/pybind11Path.cmd +0 -21
  203. data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +0 -90
  204. data/vendor/datasketches-cpp/python/src/fi_wrapper.cpp +0 -128
  205. data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +0 -134
  206. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +0 -210
  207. data/vendor/datasketches-cpp/python/src/ks_wrapper.cpp +0 -68
  208. data/vendor/datasketches-cpp/python/src/py_serde.cpp +0 -111
  209. data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +0 -204
  210. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +0 -215
  211. data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +0 -172
  212. data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +0 -490
  213. data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +0 -173
  214. data/vendor/datasketches-cpp/python/tests/__init__.py +0 -16
  215. data/vendor/datasketches-cpp/python/tests/cpc_test.py +0 -64
  216. data/vendor/datasketches-cpp/python/tests/fi_test.py +0 -110
  217. data/vendor/datasketches-cpp/python/tests/hll_test.py +0 -130
  218. data/vendor/datasketches-cpp/python/tests/kll_test.py +0 -125
  219. data/vendor/datasketches-cpp/python/tests/quantiles_test.py +0 -126
  220. data/vendor/datasketches-cpp/python/tests/req_test.py +0 -126
  221. data/vendor/datasketches-cpp/python/tests/theta_test.py +0 -146
  222. data/vendor/datasketches-cpp/python/tests/vector_of_kll_test.py +0 -148
  223. data/vendor/datasketches-cpp/python/tests/vo_test.py +0 -125
  224. data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
  225. data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
  226. data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
  227. data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
  228. data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
  229. data/vendor/datasketches-cpp/sampling/test/binaries_from_java.txt +0 -67
  230. data/vendor/datasketches-cpp/sampling/test/varopt_sketch_long_sampling.sk +0 -0
  231. data/vendor/datasketches-cpp/sampling/test/varopt_sketch_string_exact.sk +0 -0
  232. data/vendor/datasketches-cpp/sampling/test/varopt_union_double_sampling.sk +0 -0
  233. data/vendor/datasketches-cpp/setup.py +0 -110
  234. data/vendor/datasketches-cpp/theta/test/theta_compact_empty_from_java.sk +0 -0
  235. data/vendor/datasketches-cpp/theta/test/theta_compact_estimation_from_java.sk +0 -0
  236. data/vendor/datasketches-cpp/theta/test/theta_compact_exact_from_java.sk +0 -0
  237. data/vendor/datasketches-cpp/theta/test/theta_compact_single_item_from_java.sk +0 -0
  238. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_intersection.hpp +0 -52
  239. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union.hpp +0 -81
  240. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union_impl.hpp +0 -43
  241. data/vendor/datasketches-cpp/tuple/test/aod_1_compact_empty_from_java.sk +0 -1
  242. data/vendor/datasketches-cpp/tuple/test/aod_1_compact_estimation_from_java.sk +0 -0
  243. data/vendor/datasketches-cpp/tuple/test/aod_1_compact_non_empty_no_entries_from_java.sk +0 -0
  244. data/vendor/datasketches-cpp/tuple/test/aod_2_compact_exact_from_java.sk +0 -0
  245. data/vendor/datasketches-cpp/tuple/test/aod_3_compact_empty_from_java.sk +0 -1
@@ -15,30 +15,77 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- add_executable(sampling_test)
18
+ # separate executables for var_opt and ebpps sampling
19
19
 
20
- target_link_libraries(sampling_test sampling common_test_lib)
20
+ # VAR OPT SAMPLING
21
+ add_executable(var_opt_sampling_test)
21
22
 
22
- set_target_properties(sampling_test PROPERTIES
23
- CXX_STANDARD 11
23
+ target_link_libraries(var_opt_sampling_test sampling common_test_lib)
24
+
25
+ set_target_properties(var_opt_sampling_test PROPERTIES
24
26
  CXX_STANDARD_REQUIRED YES
25
27
  )
26
28
 
27
29
  file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" SAMPLING_TEST_BINARY_PATH)
28
30
  string(APPEND SAMPLING_TEST_BINARY_PATH "/")
29
- target_compile_definitions(sampling_test
31
+ target_compile_definitions(var_opt_sampling_test
30
32
  PRIVATE
31
33
  TEST_BINARY_INPUT_PATH="${SAMPLING_TEST_BINARY_PATH}"
32
34
  )
33
35
 
34
36
  add_test(
35
- NAME sampling_test
36
- COMMAND sampling_test
37
+ NAME var_opt_sampling_test
38
+ COMMAND var_opt_sampling_test
37
39
  )
38
40
 
39
- target_sources(sampling_test
41
+ target_sources(var_opt_sampling_test
40
42
  PRIVATE
41
43
  var_opt_sketch_test.cpp
42
44
  var_opt_union_test.cpp
43
45
  var_opt_allocation_test.cpp
44
46
  )
47
+
48
+
49
+ # EBPPS SAMPLING
50
+ add_executable(ebpps_sampling_test)
51
+
52
+ target_link_libraries(ebpps_sampling_test sampling common_test_lib)
53
+
54
+ set_target_properties(ebpps_sampling_test PROPERTIES
55
+ CXX_STANDARD_REQUIRED YES
56
+ )
57
+
58
+ target_compile_definitions(ebpps_sampling_test
59
+ PRIVATE
60
+ TEST_BINARY_INPUT_PATH="${SAMPLING_TEST_BINARY_PATH}"
61
+ )
62
+
63
+ add_test(
64
+ NAME ebpps_sampling_test
65
+ COMMAND ebpps_sampling_test
66
+ )
67
+
68
+ target_sources(ebpps_sampling_test
69
+ PRIVATE
70
+ ebpps_sample_test.cpp
71
+ ebpps_sketch_test.cpp
72
+ ebpps_allocation_test.cpp
73
+ )
74
+
75
+
76
+ # Compatibility
77
+ if (SERDE_COMPAT)
78
+ target_sources(var_opt_sampling_test
79
+ PRIVATE
80
+ var_opt_sketch_deserialize_from_java_test.cpp
81
+ var_opt_union_deserialize_from_java_test.cpp
82
+ )
83
+ endif()
84
+
85
+ if (GENERATE)
86
+ target_sources(var_opt_sampling_test
87
+ PRIVATE
88
+ var_opt_sketch_serialize_for_java.cpp
89
+ var_opt_union_serialize_for_java.cpp
90
+ )
91
+ endif()
@@ -0,0 +1,96 @@
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 <ebpps_sketch.hpp>
21
+ #include <test_type.hpp>
22
+ #include <test_allocator.hpp>
23
+
24
+ #include <catch2/catch.hpp>
25
+
26
+ #include <sstream>
27
+
28
+ namespace datasketches {
29
+
30
+ using ebpps_test_sketch = ebpps_sketch<test_type, test_allocator<test_type>>;
31
+ using alloc = test_allocator<test_type>;
32
+
33
+ TEST_CASE("ebpps allocation test", "[ebpps_sketch][test_type]") {
34
+ test_allocator_total_bytes = 0;
35
+ test_allocator_net_allocations = 0;
36
+ {
37
+ ebpps_test_sketch sk1(10, 0);
38
+ for (int i = 0; i < 100; ++i)
39
+ sk1.update(i);
40
+ auto bytes1 = sk1.serialize(0, test_type_serde());
41
+ auto sk2 = ebpps_test_sketch::deserialize(bytes1.data(), bytes1.size(), test_type_serde(), 0);
42
+
43
+ std::stringstream ss;
44
+ sk1.serialize(ss, test_type_serde());
45
+ auto sk3 = ebpps_test_sketch::deserialize(ss, test_type_serde(), alloc(0));
46
+
47
+ sk1.merge(sk2); // same size into sk1
48
+ sk3.merge(sk1); // larger into sk3
49
+
50
+ auto bytes2 = sk1.serialize(0, test_type_serde());
51
+ auto sk4 = ebpps_test_sketch::deserialize(bytes2.data(), bytes2.size(), test_type_serde(), 0);
52
+ }
53
+ REQUIRE(test_allocator_total_bytes == 0);
54
+ REQUIRE(test_allocator_net_allocations == 0);
55
+ }
56
+
57
+ TEST_CASE( "ebpps merge", "[ebpps_sketch][test_type]") {
58
+ test_allocator_total_bytes = 0;
59
+ test_allocator_net_allocations = 0;
60
+ {
61
+ uint32_t n = 20;
62
+ uint32_t k = 5;
63
+ ebpps_test_sketch sk1(k, 0);
64
+ ebpps_test_sketch sk2(k, 0);
65
+
66
+ // move udpates
67
+ for (int i = 0; i < (int) n; ++i) {
68
+ sk1.update(i);
69
+ sk2.update(-i);
70
+ sk1.update(n + i); // sk1 heavier than sk2
71
+ }
72
+ REQUIRE(sk1.get_n() == 2 * n);
73
+ REQUIRE(sk2.get_n() == n);
74
+
75
+ // move merge -- lighter into heavier
76
+ sk1.merge(std::move(sk2));
77
+ REQUIRE(sk1.get_n() == 3 * n);
78
+
79
+ // move constructor
80
+ ebpps_test_sketch sk3(std::move(sk1));
81
+ REQUIRE(sk3.get_n() == 3 * n);
82
+
83
+ // move assignment
84
+ ebpps_test_sketch sk4(k, 0);
85
+ sk4 = std::move(sk2);
86
+ REQUIRE(sk4.get_n() == n);
87
+
88
+ // move merge -- heavier into lighter
89
+ sk4.merge(sk3);
90
+ REQUIRE(sk4.get_n() == 4 * n);
91
+ }
92
+ REQUIRE(test_allocator_total_bytes == 0);
93
+ REQUIRE(test_allocator_net_allocations == 0);
94
+ }
95
+
96
+ }
@@ -0,0 +1,137 @@
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 <ebpps_sample.hpp>
21
+
22
+ #include <catch2/catch.hpp>
23
+
24
+ #include <vector>
25
+ #include <string>
26
+ #include <sstream>
27
+ #include <fstream>
28
+ #include <cmath>
29
+ #include <random>
30
+ #include <stdexcept>
31
+
32
+ namespace datasketches {
33
+
34
+ static constexpr double EPS = 1e-15;
35
+
36
+ TEST_CASE("ebpps sample: basic initialization", "[ebpps_sketch]") {
37
+ ebpps_sample<int> sample = ebpps_sample<int>(0);
38
+ REQUIRE(sample.get_c() == 0.0);
39
+ REQUIRE(sample.get_num_retained_items() == 0);
40
+ REQUIRE(sample.get_sample().size() == 0);
41
+ }
42
+
43
+ TEST_CASE("ebpps sample: pre-initialized", "[ebpps_sketch]") {
44
+ double theta = 1.0;
45
+ ebpps_sample<int> sample = ebpps_sample<int>(-1, theta);
46
+ REQUIRE(sample.get_c() == theta);
47
+ REQUIRE(sample.get_num_retained_items() == 1);
48
+ REQUIRE(sample.get_sample().size() == 1);
49
+ REQUIRE(sample.has_partial_item() == false);
50
+
51
+ theta = 1e-300;
52
+ sample = ebpps_sample<int>(-1, theta);
53
+ REQUIRE(sample.get_c() == theta);
54
+ REQUIRE(sample.get_num_retained_items() == 1);
55
+ REQUIRE(sample.get_sample().size() == 0); // assuming the random number is > 1e-300
56
+ REQUIRE(sample.has_partial_item());
57
+ }
58
+
59
+ TEST_CASE("ebpps sample: downsampling", "[ebpps_sketch]") {
60
+ ebpps_sample<char> sample = ebpps_sample<char>('a', 1.0);
61
+
62
+ sample.downsample(2.0); // no-op
63
+ REQUIRE(sample.get_c() == 1.0);
64
+ REQUIRE(sample.get_num_retained_items() == 1);
65
+ REQUIRE(sample.has_partial_item() == false);
66
+
67
+ // downsample and result in an empty sample
68
+ random_utils::override_seed(12);
69
+ std::vector<char> items = {'a', 'b'};
70
+ optional<char> opt; // empty
71
+ sample = ebpps_sample<char>(std::move(items), std::move(opt), 1.8);
72
+ sample.downsample(0.5);
73
+ REQUIRE(sample.get_c() == 0.9);
74
+ REQUIRE(sample.get_num_retained_items() == 0);
75
+ REQUIRE(sample.has_partial_item() == false);
76
+
77
+ // downsample and result in a sample with a partial item
78
+ items = {'a', 'b'};
79
+ opt.reset();
80
+ sample = ebpps_sample<char>(std::move(items), std::move(opt), 1.5);
81
+ sample.downsample(0.5);
82
+ REQUIRE(sample.get_c() == 0.75);
83
+ REQUIRE(sample.get_num_retained_items() == 1);
84
+ REQUIRE(sample.has_partial_item() == true);
85
+ for (char c : sample) {
86
+ REQUIRE((c == 'a' || c == 'b'));
87
+ }
88
+
89
+ // downsample to an exact integer c (7.5 * 0.8 = 6.0)
90
+ items = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
91
+ opt.emplace('h');
92
+ auto ref_items = items; // copy to check contents
93
+ ref_items.emplace_back('h'); // include partial item
94
+ sample = ebpps_sample<char>(std::move(items), std::move(opt), 7.5);
95
+ sample.downsample(0.8);
96
+ REQUIRE(sample.get_c() == 6.0);
97
+ REQUIRE(sample.get_num_retained_items() == 6);
98
+ REQUIRE(sample.has_partial_item() == false);
99
+ for (char c : sample) {
100
+ REQUIRE(std::find(ref_items.begin(), ref_items.end(), c) != ref_items.end());
101
+ }
102
+
103
+ // downsample to c > 1 with partial item
104
+ items = ref_items; // includes previous optional item
105
+ opt.emplace('i');
106
+ sample = ebpps_sample<char>(std::move(items), std::move(opt), 8.5);
107
+ REQUIRE(sample.get_partial_item() == 'i');
108
+ sample.downsample(0.8);
109
+ REQUIRE(sample.get_c() == Approx(6.8).margin(EPS));
110
+ REQUIRE(sample.get_num_retained_items() == 7);
111
+ REQUIRE(sample.has_partial_item() == true);
112
+ ref_items.emplace_back('i');
113
+ for (char c : sample) {
114
+ REQUIRE(std::find(ref_items.begin(), ref_items.end(), c) != ref_items.end());
115
+ }
116
+
117
+ random_utils::override_seed(random_utils::rd());
118
+ }
119
+
120
+ TEST_CASE("ebpps sample: merge unit samples", "[ebpps_sketch]") {
121
+ uint32_t k = 8;
122
+ ebpps_sample<int> sample = ebpps_sample<int>(k);
123
+
124
+ for (uint32_t i = 1; i <= k; ++i) {
125
+ ebpps_sample<int> s = ebpps_sample<int>(i, 1.0);
126
+ sample.merge(s);
127
+ REQUIRE(sample.get_c() == static_cast<double>(i));
128
+ REQUIRE(sample.get_num_retained_items() == i);
129
+ }
130
+
131
+ sample.reset();
132
+ REQUIRE(sample.get_c() == 0);
133
+ REQUIRE(sample.get_num_retained_items() == 0);
134
+ REQUIRE(sample.has_partial_item() == false);
135
+ }
136
+
137
+ } // namespace datasketches
@@ -0,0 +1,266 @@
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 <ebpps_sketch.hpp>
21
+
22
+ #include <catch2/catch.hpp>
23
+
24
+ #include <vector>
25
+ #include <string>
26
+ #include <sstream>
27
+ #include <fstream>
28
+ #include <cmath>
29
+ #include <random>
30
+ #include <stdexcept>
31
+
32
+ #ifdef TEST_BINARY_INPUT_PATH
33
+ static std::string testBinaryInputPath = TEST_BINARY_INPUT_PATH;
34
+ #else
35
+ static std::string testBinaryInputPath = "test/";
36
+ #endif
37
+
38
+ namespace datasketches {
39
+
40
+ static constexpr double EPS = 1e-13;
41
+
42
+ static ebpps_sketch<int> create_unweighted_sketch(uint32_t k, uint64_t n) {
43
+ ebpps_sketch<int> sk(k);
44
+ for (uint64_t i = 0; i < n; ++i) {
45
+ sk.update(static_cast<int>(i), 1.0);
46
+ }
47
+ return sk;
48
+ }
49
+
50
+ template<typename T, typename A>
51
+ static void check_if_equal(ebpps_sketch<T, A>& sk1, ebpps_sketch<T, A>& sk2) {
52
+ REQUIRE(sk1.get_k() == sk2.get_k());
53
+ REQUIRE(sk1.get_n() == sk2.get_n());
54
+ REQUIRE(sk1.get_c() == sk2.get_c());
55
+ REQUIRE(sk1.get_cumulative_weight() == sk2.get_cumulative_weight());
56
+
57
+ auto it1 = sk1.begin();
58
+ auto it2 = sk2.begin();
59
+ size_t count = 0;
60
+
61
+ while ((it1 != sk1.end()) && (it2 != sk2.end())) {
62
+ REQUIRE(*it1 == *it2);
63
+ ++it1;
64
+ ++it2;
65
+ ++count;
66
+ }
67
+
68
+ REQUIRE(((count == std::floor(sk1.get_c())) || (count == std::ceil(sk1.get_c()))));
69
+
70
+ // if c != floor(c) one sketch may not have reached the end,
71
+ // but that's not testable from the external API
72
+ }
73
+
74
+ TEST_CASE("ebpps sketch: invalid k", "[ebpps_sketch]") {
75
+ REQUIRE_THROWS_AS(ebpps_sketch<int>(0), std::invalid_argument);
76
+ REQUIRE_THROWS_AS(ebpps_sketch<int>(ebpps_constants::MAX_K + 1), std::invalid_argument);
77
+ }
78
+
79
+ TEST_CASE("ebpps sketch: invalid weights", "[ebpps_sketch]") {
80
+ uint32_t k = 100;
81
+ ebpps_sketch<int> sk = create_unweighted_sketch(k, 3);
82
+ REQUIRE(sk.get_n() == 3);
83
+ REQUIRE(sk.get_cumulative_weight() == 3.0);
84
+ sk.update(-1, 0.0); // no-op
85
+ REQUIRE(sk.get_n() == 3);
86
+ REQUIRE(sk.get_cumulative_weight() == 3.0);
87
+
88
+ REQUIRE_THROWS_AS(sk.update(-2, -1.0), std::invalid_argument);
89
+
90
+ ebpps_sketch<float> sk2(k);
91
+ REQUIRE_THROWS_AS(sk2.update(-2, std::numeric_limits<float>::infinity()), std::invalid_argument);
92
+ REQUIRE_THROWS_AS(sk2.update(-2, nanf("")), std::invalid_argument);
93
+ }
94
+
95
+ TEST_CASE("ebpps sketch: insert items", "[ebpps_sketch]") {
96
+ size_t n = 0;
97
+ uint32_t k = 5;
98
+ ebpps_sketch<int> sk = create_unweighted_sketch(k, n);
99
+ REQUIRE(sk.get_allocator() == std::allocator<int>());
100
+ REQUIRE(sk.get_k() == k);
101
+ REQUIRE(sk.get_n() == 0);
102
+ REQUIRE(sk.get_c() == 0.0);
103
+ REQUIRE(sk.get_cumulative_weight() == 0.0);
104
+ REQUIRE(sk.is_empty());
105
+
106
+ n = k;
107
+ sk = create_unweighted_sketch(k, n);
108
+ REQUIRE_FALSE(sk.is_empty());
109
+ REQUIRE(sk.get_n() == n);
110
+ REQUIRE(sk.get_cumulative_weight() == static_cast<double>(n));
111
+ for (int val : sk.get_result())
112
+ REQUIRE(val < static_cast<int>(n));
113
+
114
+ n = k * 10;
115
+ sk = create_unweighted_sketch(k, n);
116
+ REQUIRE_FALSE(sk.is_empty());
117
+ REQUIRE(sk.get_n() == n);
118
+ REQUIRE(sk.get_cumulative_weight() == static_cast<double>(n));
119
+
120
+ auto result = sk.get_result();
121
+ REQUIRE(result.size() == sk.get_k()); // uniform weights so should be exactly k
122
+ for (int val : sk.get_result())
123
+ REQUIRE(val < static_cast<int>(n));
124
+ }
125
+
126
+ TEST_CASE("ebpps sketch: serialize/deserialize string", "[ebpps_sketch]") {
127
+ // since C <= k we don't have the usual sketch notion of exact vs estimation
128
+ // mode at any time. The only real serializaiton cases are empty and non-empty
129
+ // with and without a partial item
130
+ uint32_t k = 10;
131
+ ebpps_sketch<std::string> sk(k);
132
+
133
+ // empty
134
+ auto bytes = sk.serialize();
135
+ REQUIRE(bytes.size() == sk.get_serialized_size_bytes());
136
+ REQUIRE_THROWS_AS(ebpps_sketch<std::string>::deserialize(bytes.data(), bytes.size()-1), std::out_of_range);
137
+ auto sk_bytes = ebpps_sketch<std::string>::deserialize(bytes.data(), bytes.size());
138
+ check_if_equal(sk, sk_bytes);
139
+
140
+ std::stringstream ss(std::ios::in | std::ios::out | std::ios::binary);
141
+ sk.serialize(ss);
142
+ auto sk_stream = ebpps_sketch<std::string>::deserialize(ss);
143
+ check_if_equal(sk, sk_stream);
144
+ check_if_equal(sk_bytes, sk_stream); // should be redundant
145
+
146
+ for (uint32_t i = 0; i < k; ++i)
147
+ sk.update(std::to_string(i));
148
+
149
+ // non-empty, no partial item
150
+ bytes = sk.serialize();
151
+ REQUIRE(bytes.size() == sk.get_serialized_size_bytes());
152
+ REQUIRE_THROWS_AS(ebpps_sketch<std::string>::deserialize(bytes.data(), bytes.size()-1), std::out_of_range);
153
+ sk_bytes = ebpps_sketch<std::string>::deserialize(bytes.data(), bytes.size());
154
+ check_if_equal(sk, sk_bytes);
155
+
156
+ ss.str("");
157
+ sk.serialize(ss);
158
+ sk_stream = ebpps_sketch<std::string>::deserialize(ss);
159
+ check_if_equal(sk, sk_stream);
160
+ check_if_equal(sk_bytes, sk_stream); // should be redundant
161
+
162
+ // non-empty with partial item
163
+ sk.update(std::to_string(2 * k), 2.5);
164
+ REQUIRE(sk.get_cumulative_weight() == Approx(k + 2.5).margin(EPS));
165
+ bytes = sk.serialize();
166
+ REQUIRE(bytes.size() == sk.get_serialized_size_bytes());
167
+ REQUIRE_THROWS_AS(ebpps_sketch<std::string>::deserialize(bytes.data(), bytes.size()-1), std::out_of_range);
168
+ sk_bytes = ebpps_sketch<std::string>::deserialize(bytes.data(), bytes.size());
169
+ check_if_equal(sk, sk_bytes);
170
+
171
+ ss.str("");
172
+ sk.serialize(ss);
173
+ sk_stream = ebpps_sketch<std::string>::deserialize(ss);
174
+ check_if_equal(sk, sk_stream);
175
+ check_if_equal(sk_bytes, sk_stream); // should be redundant
176
+ }
177
+
178
+ TEST_CASE("ebpps sketch: serialize/deserialize ints", "[ebpps_sketch]") {
179
+ uint32_t k = 10;
180
+ ebpps_sketch<uint32_t> sk(k);
181
+
182
+ for (uint32_t i = 0; i < k; ++i)
183
+ sk.update(i);
184
+ sk.update(2 * k, 3.5);
185
+ REQUIRE(sk.get_cumulative_weight() == Approx(k + 3.5).margin(EPS));
186
+
187
+ auto bytes = sk.serialize();
188
+ REQUIRE(bytes.size() == sk.get_serialized_size_bytes());
189
+ REQUIRE_THROWS_AS(ebpps_sketch<uint32_t>::deserialize(bytes.data(), bytes.size()-1), std::out_of_range);
190
+ auto sk_bytes = ebpps_sketch<uint32_t>::deserialize(bytes.data(), bytes.size());
191
+ check_if_equal(sk, sk_bytes);
192
+
193
+ std::stringstream ss(std::ios::in | std::ios::out | std::ios::binary);
194
+ sk.serialize(ss);
195
+ auto sk_stream = ebpps_sketch<uint32_t>::deserialize(ss);
196
+ check_if_equal(sk, sk_stream);
197
+ check_if_equal(sk_bytes, sk_stream); // should be redundant
198
+
199
+ sk.reset();
200
+ REQUIRE(sk.get_k() == k);
201
+ REQUIRE(sk.get_n() == 0);
202
+ REQUIRE(sk.get_c() == 0.0);
203
+ REQUIRE(sk.get_cumulative_weight() == 0.0);
204
+ REQUIRE(sk.is_empty());
205
+ }
206
+
207
+ TEST_CASE("ebpps sketch: merge large into small", "[ebpps_sketch]") {
208
+ uint32_t k = 100;
209
+
210
+ // lvalue merge
211
+ ebpps_sketch<int> sk1(k / 2);
212
+ sk1.update(-1, k / 10.0); // one heavy item, but less than sk2 weight
213
+ ebpps_sketch<int> sk2 = create_unweighted_sketch(k, k);
214
+
215
+ sk1.merge(sk2);
216
+ REQUIRE(sk1.get_k() == k / 2);
217
+ REQUIRE(sk1.get_n() == k + 1);
218
+ REQUIRE(sk1.get_c() < k);
219
+ REQUIRE(sk1.get_cumulative_weight() == Approx(1.1 * k).margin(EPS));
220
+
221
+ // rvalue merge
222
+ sk1 = create_unweighted_sketch(k / 2, 0);
223
+ sk1.update(-1, k / 4.0);
224
+ sk1.update(-2, k / 8.0);
225
+ // sk2 should have been unchaged
226
+ REQUIRE(sk2.get_n() == k);
227
+ REQUIRE(sk2.get_c() == Approx(k).margin(EPS));
228
+
229
+ sk1.merge(std::move(sk2));
230
+ REQUIRE(sk1.get_k() == k / 2);
231
+ REQUIRE(sk1.get_n() == k + 2);
232
+ REQUIRE(sk1.get_c() < k);
233
+ // cumulative weight is now (1.5 + 0.2) k
234
+ REQUIRE(sk1.get_cumulative_weight() == Approx(1.375 * k).margin(EPS));
235
+ }
236
+
237
+ TEST_CASE("ebpps sketch: merge small into large", "[ebpps_sketch]") {
238
+ uint32_t k = 100;
239
+
240
+ // lvalue merge
241
+ ebpps_sketch<int> sk1 = create_unweighted_sketch(k, k);
242
+ ebpps_sketch<int> sk2(k / 2);
243
+ sk2.update(-1, k / 10.0); // one heavy item, but less than sk1 weight
244
+
245
+ sk1.merge(sk2);
246
+ REQUIRE(sk1.get_k() == k / 2);
247
+ REQUIRE(sk1.get_n() == k + 1);
248
+ REQUIRE(sk1.get_c() < k);
249
+ REQUIRE(sk1.get_cumulative_weight() == Approx(1.1 * k).margin(EPS));
250
+
251
+ // rvalue merge
252
+ sk1 = create_unweighted_sketch(k, 3 * k / 2);
253
+ // sk2 should have been unchaged
254
+ REQUIRE(sk2.get_n() == 1);
255
+ REQUIRE(sk2.get_c() == 1.0);
256
+ sk2.update(-2, k / 10.0);
257
+
258
+ sk1.merge(std::move(sk2));
259
+ REQUIRE(sk1.get_k() == k / 2);
260
+ REQUIRE(sk1.get_n() == (3 * k / 2) + 2);
261
+ REQUIRE(sk1.get_c() < k);
262
+ // cumulative weight is now (1.5 + 0.2) k
263
+ REQUIRE(sk1.get_cumulative_weight() == Approx(1.7 * k).margin(EPS));
264
+ }
265
+
266
+ }
@@ -0,0 +1,81 @@
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 <catch2/catch.hpp>
21
+ #include <fstream>
22
+ #include <var_opt_sketch.hpp>
23
+
24
+ namespace datasketches {
25
+
26
+ // assume the binary sketches for this test have been generated by datasketches-java code
27
+ // in the subdirectory called "java" in the root directory of this project
28
+ static std::string testBinaryInputPath = std::string(TEST_BINARY_INPUT_PATH) + "../../java/";
29
+
30
+ TEST_CASE("var opt sketch long", "[serde_compat]") {
31
+ const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
32
+ for (const unsigned n: n_arr) {
33
+ std::ifstream is;
34
+ is.exceptions(std::ios::failbit | std::ios::badbit);
35
+ is.open(testBinaryInputPath + "varopt_sketch_long_n" + std::to_string(n) + "_java.sk", std::ios::binary);
36
+ const auto sketch = var_opt_sketch<long>::deserialize(is);
37
+ REQUIRE(sketch.is_empty() == (n == 0));
38
+ REQUIRE(sketch.get_num_samples() == (n > 10 ? 32 : n));
39
+ }
40
+ }
41
+
42
+ TEST_CASE("var opt sketch: deserialize exact from java", "[serde_compat]") {
43
+ const double EPS = 1e-13;
44
+ std::ifstream is;
45
+ is.exceptions(std::ios::failbit | std::ios::badbit);
46
+ is.open(testBinaryInputPath + "varopt_sketch_string_exact_java.sk", std::ios::binary);
47
+ const auto sketch = var_opt_sketch<std::string>::deserialize(is);
48
+ REQUIRE_FALSE(sketch.is_empty());
49
+ REQUIRE(sketch.get_k() == 1024);
50
+ REQUIRE(sketch.get_n() == 200);
51
+ REQUIRE(sketch.get_num_samples() == 200);
52
+ const subset_summary ss = sketch.estimate_subset_sum([](std::string){ return true; });
53
+
54
+ double tgt_wt = 0.0;
55
+ for (int i = 1; i <= 200; ++i) { tgt_wt += 1000.0 / i; }
56
+ REQUIRE(ss.total_sketch_weight == Approx(tgt_wt).margin(EPS));
57
+ }
58
+
59
+
60
+ TEST_CASE("var opt sketch: deserialize sampling from java", "[serde_compat]") {
61
+ const double EPS = 1e-13;
62
+ std::ifstream is;
63
+ is.exceptions(std::ios::failbit | std::ios::badbit);
64
+ is.open(testBinaryInputPath + "varopt_sketch_long_sampling_java.sk", std::ios::binary);
65
+ const auto sketch = var_opt_sketch<int64_t>::deserialize(is);
66
+ REQUIRE_FALSE(sketch.is_empty());
67
+ REQUIRE(sketch.get_k() == 1024);
68
+ REQUIRE(sketch.get_n() == 2003);
69
+ REQUIRE(sketch.get_num_samples() == sketch.get_k());
70
+ subset_summary ss = sketch.estimate_subset_sum([](int64_t){ return true; });
71
+ REQUIRE(ss.estimate == Approx(332000.0).margin(EPS));
72
+ REQUIRE(ss.total_sketch_weight == Approx(332000.0).margin(EPS));
73
+
74
+ ss = sketch.estimate_subset_sum([](int64_t x){ return x < 0; });
75
+ REQUIRE(ss.estimate == 330000.0); // heavy item, weight is exact
76
+
77
+ ss = sketch.estimate_subset_sum([](int64_t x){ return x >= 0; });
78
+ REQUIRE(ss.estimate == Approx(2000.0).margin(EPS));
79
+ }
80
+
81
+ } /* namespace datasketches */