Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 223
Accept TDigest bytes with buffered values#704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # 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. | ||
| root = true | ||
| [*] | ||
| end_of_line = lf | ||
| indent_style = space | ||
| insert_final_newline = true | ||
| trim_trailing_whitespace = true | ||
| [*.java] | ||
| indent_size = tab | ||
| tab_width = 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,54 +25,68 @@ | ||
| import static org.apache.datasketches.common.TestUtil.javaPath; | ||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertTrue; | ||
| import java.lang.foreign.MemorySegment; | ||
| import java.io.IOException; | ||
| import java.lang.foreign.MemorySegment; | ||
| import java.nio.file.Files; | ||
| import org.testng.annotations.Test; | ||
| public class TDigestCrossLanguageTest { | ||
| @Test(groups = {CHECK_CPP_FILES}) | ||
| public void deserializeFromCppDouble() throws IOException { | ||
| final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000}; | ||
| for (final int n: nArr) { | ||
| final byte[] bytes = Files.readAllBytes(cppPath.resolve("tdigest_double_n" + n + "_cpp.sk")); | ||
| final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes)); | ||
| assertTrue(n == 0 ? td.isEmpty() : !td.isEmpty()); | ||
| assertEquals(td.getTotalWeight(), n); | ||
| if (n > 0) { | ||
| assertEquals(td.getMinValue(), 1); | ||
| assertEquals(td.getMaxValue(), n); | ||
| assertEquals(td.getRank(0), 0); | ||
| assertEquals(td.getRank(n + 1), 1); | ||
| if (n == 1) { | ||
| assertEquals(td.getRank(n), 0.5); | ||
| final boolean[] with_buffer = {false, true}; | ||
| for (final boolean buffered : with_buffer) { | ||
| final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000}; | ||
| for (final int n : nArr) { | ||
| final byte[] bytes; | ||
| if (buffered) { | ||
| bytes = Files.readAllBytes(cppPath.resolve("tdigest_double_buf_n" + n + "_cpp.sk")); | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will fail without this patch. | ||
| } else { | ||
| assertEquals(td.getRank(n / 2), 0.5, 0.05); | ||
| bytes = Files.readAllBytes(cppPath.resolve("tdigest_double_n" + n + "_cpp.sk")); | ||
| } | ||
| final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes)); | ||
| assertTrue(n == 0 ? td.isEmpty() : !td.isEmpty()); | ||
| assertEquals(td.getTotalWeight(), n); | ||
| if (n > 0) { | ||
| assertEquals(td.getMinValue(), 1); | ||
| assertEquals(td.getMaxValue(), n); | ||
| assertEquals(td.getRank(0), 0); | ||
| assertEquals(td.getRank(n + 1), 1); | ||
| if (n == 1) { | ||
| assertEquals(td.getRank(n), 0.5); | ||
| } else { | ||
| assertEquals(td.getRank(n / 2), 0.5, 0.05); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| @Test(groups = {CHECK_CPP_FILES}) | ||
| public void deserializeFromCppFloat() throws IOException { | ||
| final boolean[] with_buffer = {false, true}; | ||
| final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000}; | ||
| for (final int n: nArr) { | ||
| final byte[] bytes = Files.readAllBytes(cppPath.resolve("tdigest_float_n" + n + "_cpp.sk")); | ||
| final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes), true); | ||
| assertTrue(n == 0 ? td.isEmpty() : !td.isEmpty()); | ||
| assertEquals(td.getTotalWeight(), n); | ||
| if (n > 0) { | ||
| assertEquals(td.getMinValue(), 1); | ||
| assertEquals(td.getMaxValue(), n); | ||
| assertEquals(td.getRank(0), 0); | ||
| assertEquals(td.getRank(n + 1), 1); | ||
| if (n == 1) { | ||
| assertEquals(td.getRank(n), 0.5); | ||
| for (final boolean buffered : with_buffer) { | ||
| for (final int n : nArr) { | ||
| final byte[] bytes; | ||
| if (buffered) { | ||
| bytes = Files.readAllBytes(cppPath.resolve("tdigest_float_buf_n" + n + "_cpp.sk")); | ||
| } else { | ||
| assertEquals(td.getRank(n / 2), 0.5, 0.05); | ||
| bytes = Files.readAllBytes(cppPath.resolve("tdigest_float_n" + n + "_cpp.sk")); | ||
| } | ||
| final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes), true); | ||
| assertTrue(n == 0 ? td.isEmpty() : !td.isEmpty()); | ||
| assertEquals(td.getTotalWeight(), n); | ||
| if (n > 0) { | ||
| assertEquals(td.getMinValue(), 1); | ||
| assertEquals(td.getMaxValue(), n); | ||
| assertEquals(td.getRank(0), 0); | ||
| assertEquals(td.getRank(n + 1), 1); | ||
| if (n == 1) { | ||
| assertEquals(td.getRank(n), 0.5); | ||
| } else { | ||
| assertEquals(td.getRank(n / 2), 0.5, 0.05); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| @@ -81,7 +95,7 @@ public void deserializeFromCppFloat() throws IOException { | ||
| @Test(groups = {GENERATE_JAVA_FILES}) | ||
| public void generateForCppDouble() throws IOException { | ||
| final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000}; | ||
| for (final int n: nArr) { | ||
| for (final int n: nArr) { | ||
| final TDigestDouble td = new TDigestDouble((short) 100); | ||
| for (int i = 1; i <= n; i++) { | ||
| td.update(i); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help IDEA to properly format files without large indentation changes. Can be removed if you don't like to check it into the VCS but IMO it does no harm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of the thread: spotless can help in autoformat over checkstyle
See also: