This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch generate_sketches_for_java
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git


The following commit(s) were added to refs/heads/generate_sketches_for_java by 
this push:
     new c3f96ef  generate sketches for testing in Java
c3f96ef is described below

commit c3f96efe4e39ba48167325cb2c0364258362745f
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Fri Aug 25 17:14:09 2023 -0700

    generate sketches for testing in Java
---
 req/test/CMakeLists.txt                            |  7 +++
 req/test/req_sketch_serialize_for_java.cpp         | 36 +++++++++++++
 sampling/test/CMakeLists.txt                       |  8 +++
 .../test/var_opt_sketch_serialize_for_java.cpp     | 54 ++++++++++++++++++++
 sampling/test/var_opt_union_serialize_for_java.cpp | 56 ++++++++++++++++++++
 theta/test/CMakeLists.txt                          |  7 +++
 theta/test/theta_sketch_serialize_for_java.cpp     | 47 +++++++++++++++++
 tuple/test/CMakeLists.txt                          |  7 +++
 tuple/test/aod_sketch_serialize_for_java.cpp       | 59 ++++++++++++++++++++++
 9 files changed, 281 insertions(+)

diff --git a/req/test/CMakeLists.txt b/req/test/CMakeLists.txt
index 72fb39b..8ebaadb 100755
--- a/req/test/CMakeLists.txt
+++ b/req/test/CMakeLists.txt
@@ -47,3 +47,10 @@ target_sources(req_test
     req_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(req_test
+  PRIVATE
+    req_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/req/test/req_sketch_serialize_for_java.cpp 
b/req/test/req_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..d244cb7
--- /dev/null
+++ b/req/test/req_sketch_serialize_for_java.cpp
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <catch2/catch.hpp>
+#include <fstream>
+#include <req_sketch.hpp>
+
+namespace datasketches {
+
+TEST_CASE("req sketch float generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    req_sketch<float> sketch(12);
+    for (unsigned i = 1; i <= n; ++i) sketch.update(i);
+    std::ofstream os("req_float_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+} /* namespace datasketches */
diff --git a/sampling/test/CMakeLists.txt b/sampling/test/CMakeLists.txt
index f62a144..8264f9c 100644
--- a/sampling/test/CMakeLists.txt
+++ b/sampling/test/CMakeLists.txt
@@ -49,3 +49,11 @@ target_sources(sampling_test
    var_opt_union_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(sampling_test
+  PRIVATE
+   var_opt_sketch_serialize_for_java.cpp
+   var_opt_union_serialize_for_java.cpp
+)
+endif()
diff --git a/sampling/test/var_opt_sketch_serialize_for_java.cpp 
b/sampling/test/var_opt_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..dd3f065
--- /dev/null
+++ b/sampling/test/var_opt_sketch_serialize_for_java.cpp
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <catch2/catch.hpp>
+#include <fstream>
+#include <var_opt_sketch.hpp>
+
+namespace datasketches {
+
+TEST_CASE("varopt sketch long generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    var_opt_sketch<long> sketch(32);
+    for (unsigned i = 1; i <= n; ++i) sketch.update(i);
+    std::ofstream os("varopt_sketch_long_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+TEST_CASE("varopt sketch string exact", "[serialize_for_java]") {
+  var_opt_sketch<std::string> sketch(1024);
+  for (unsigned i = 1; i <= 200; ++i) sketch.update(std::to_string(i), 1000.0 
/ i);
+  std::ofstream os("varopt_sketch_string_exact_cpp.sk", std::ios::binary);
+  sketch.serialize(os);
+}
+
+TEST_CASE("varopt sketch long sampling", "[serialize_for_java]") {
+  var_opt_sketch<long> sketch(1024);
+  for (unsigned i = 0; i < 2000; ++i) sketch.update(i);
+  // heavy items have negative weights to allow a simple predicate to filter
+  sketch.update(-1L, 100000.0);
+  sketch.update(-2L, 110000.0);
+  sketch.update(-3L, 120000.0);
+  std::ofstream os("varopt_sketch_long_sampling_cpp.sk", std::ios::binary);
+  sketch.serialize(os);
+}
+
+} /* namespace datasketches */
diff --git a/sampling/test/var_opt_union_serialize_for_java.cpp 
b/sampling/test/var_opt_union_serialize_for_java.cpp
new file mode 100644
index 0000000..b35d78b
--- /dev/null
+++ b/sampling/test/var_opt_union_serialize_for_java.cpp
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <catch2/catch.hpp>
+#include <fstream>
+#include <var_opt_union.hpp>
+
+namespace datasketches {
+
+TEST_CASE("var opt union doulbe sampling", "[serialize_for_java]") {
+  const unsigned k_small = 16;
+  const unsigned k_max = 128;
+  const unsigned n1 = 32;
+  const unsigned n2 = 64;
+
+  // small k sketch, but sampling
+  var_opt_sketch<double> sketch1(k_small);
+  for (unsigned i = 0; i < n1; ++i) sketch1.update(i);
+  // heavy items have negative weights to allow a simple predicate to filter
+  sketch1.update(-1, n1 * n1);
+
+  // another one, but different n to get a different per-item weight
+  var_opt_sketch<double> sketch2(k_small);
+  for (unsigned i = 0; i < n2; ++i) sketch2.update(i);
+
+  var_opt_union<double> u(k_max);
+  u.update(sketch1);
+  u.update(sketch2);
+
+  // must reduce k in the process
+  auto result = u.get_result();
+  REQUIRE(result.get_k() < k_max);
+  REQUIRE(result.get_k() >= k_small);
+  REQUIRE(result.get_n() == 97);
+
+  std::ofstream os("varopt_union_double_sampling_cpp.sk", std::ios::binary);
+  u.serialize(os);
+}
+
+} /* namespace datasketches */
diff --git a/theta/test/CMakeLists.txt b/theta/test/CMakeLists.txt
index 4899831..24b22fe 100644
--- a/theta/test/CMakeLists.txt
+++ b/theta/test/CMakeLists.txt
@@ -52,3 +52,10 @@ target_sources(theta_test
     theta_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(theta_test
+  PRIVATE
+    theta_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/theta/test/theta_sketch_serialize_for_java.cpp 
b/theta/test/theta_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..dbcbaec
--- /dev/null
+++ b/theta/test/theta_sketch_serialize_for_java.cpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <catch2/catch.hpp>
+#include <fstream>
+#include <theta_sketch.hpp>
+
+namespace datasketches {
+
+TEST_CASE("theta sketch generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    auto sketch = update_theta_sketch::builder().build();
+    for (unsigned i = 0; i < n; ++i) sketch.update(i);
+    REQUIRE(sketch.is_empty() == (n == 0));
+    REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
+    std::ofstream os("theta_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.compact().serialize(os);
+  }
+}
+
+TEST_CASE("theta sketch generate non-empty no entries", 
"[serialize_for_java]") {
+  auto sketch = update_theta_sketch::builder().set_p(0.01).build();
+  sketch.update(1);
+  REQUIRE_FALSE(sketch.is_empty());
+  REQUIRE(sketch.get_num_retained() == 0);
+  std::ofstream os("theta_non_empty_no_entries_cpp.sk", std::ios::binary);
+  sketch.compact().serialize(os);
+}
+
+} /* namespace datasketches */
diff --git a/tuple/test/CMakeLists.txt b/tuple/test/CMakeLists.txt
index 003c02c..3b8f30e 100644
--- a/tuple/test/CMakeLists.txt
+++ b/tuple/test/CMakeLists.txt
@@ -53,3 +53,10 @@ target_sources(tuple_test
     aod_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(tuple_test
+  PRIVATE
+    aod_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/tuple/test/aod_sketch_serialize_for_java.cpp 
b/tuple/test/aod_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..59a1d90
--- /dev/null
+++ b/tuple/test/aod_sketch_serialize_for_java.cpp
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <catch2/catch.hpp>
+#include <fstream>
+#include <array_of_doubles_sketch.hpp>
+
+namespace datasketches {
+
+TEST_CASE("aod sketch generate one value", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    auto sketch = update_array_of_doubles_sketch::builder().build();
+    for (unsigned i = 0; i < n; ++i) sketch.update(i, std::vector<double>(1, 
i));
+    REQUIRE(sketch.is_empty() == (n == 0));
+    REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
+    std::ofstream os("aod_1_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.compact().serialize(os);
+  }
+}
+
+TEST_CASE("aod sketch generate three values", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    auto sketch = update_array_of_doubles_sketch::builder(3).build();
+    for (unsigned i = 0; i < n; ++i) sketch.update(i, std::vector<double>(3, 
i));
+    REQUIRE(sketch.is_empty() == (n == 0));
+    REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
+    std::ofstream os("aod_3_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.compact().serialize(os);
+  }
+}
+
+TEST_CASE("aod sketch generate non-empty no entries", "[serialize_for_java]") {
+  auto sketch = update_array_of_doubles_sketch::builder().set_p(0.01).build();
+  sketch.update(1, std::vector<double>({1}));
+  REQUIRE_FALSE(sketch.is_empty());
+  REQUIRE(sketch.get_num_retained() == 0);
+  std::ofstream os("aod_1_non_empty_no_entries_cpp.sk", std::ios::binary);
+  sketch.compact().serialize(os);
+}
+
+} /* namespace datasketches */


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to