-
Notifications
You must be signed in to change notification settings - Fork 216
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")); | ||
|
Member
Author
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); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: