[commons-imaging] branch master updated: IMAGING-325: Throw error if the color palette length is negative
This is an automated email from the ASF dual-hosted git repository. kinow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git The following commit(s) were added to refs/heads/master by this push: new 9b1c46e IMAGING-325: Throw error if the color palette length is negative 9b1c46e is described below commit 9b1c46ea51e70d4d30040014d930cf19200f6660 Author: Bruno P. Kinoshita AuthorDate: Sat Jan 22 23:34:30 2022 +1300 IMAGING-325: Throw error if the color palette length is negative --- src/changes/changes.xml| 4 .../apache/commons/imaging/formats/bmp/BmpImageParser.java | 4 .../apache/commons/imaging/formats/bmp/BmpReadTest.java| 9 + .../crash-3afb569de74522535ef65922233e1920455cdc14.bmp | Bin 0 -> 74 bytes 4 files changed, 17 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 95a90b0..313921a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -45,6 +45,10 @@ The type attribute can be add,update,fix,remove. + +Prevent OutOfMemoryError in BmpImageParser. This can happen when the color palette length is +a large negative number. + Read TIFFs with 32-bit samples. diff --git a/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java b/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java index 003dd97..ea956e5 100644 --- a/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java @@ -385,6 +385,10 @@ public class BmpImageParser extends ImageParser { + bhi.compression); } +if (paletteLength < 0) { +throw new ImageReadException("BMP: Invalid negative palette length: " + paletteLength); +} + byte[] colorTable = null; if (paletteLength > 0) { colorTable = readBytes("ColorTable", is, paletteLength, diff --git a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java index 7e31907..6b30bd8 100644 --- a/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/bmp/BmpReadTest.java @@ -17,6 +17,7 @@ package org.apache.commons.imaging.formats.bmp; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.awt.image.BufferedImage; import java.io.File; @@ -76,4 +77,12 @@ public class BmpReadTest extends BmpBaseTest { "/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f"); new BmpImageParser().dumpImageFile(new ByteSourceFile(inputFile)); } + +@Test +public void testNegativePaletteLength() throws ImageReadException, IOException { +final String input = "/images/bmp/IMAGING-325/crash-3afb569de74522535ef65922233e1920455cdc14.bmp"; +final String location = BmpReadTest.class.getResource(input).getFile(); +final File inputFile = new File(location); +assertThrows(ImageReadException.class, () -> new BmpImageParser().dumpImageFile(new ByteSourceFile(inputFile))); +} } diff --git a/src/test/resources/images/bmp/IMAGING-325/crash-3afb569de74522535ef65922233e1920455cdc14.bmp b/src/test/resources/images/bmp/IMAGING-325/crash-3afb569de74522535ef65922233e1920455cdc14.bmp new file mode 100644 index 000..479105a Binary files /dev/null and b/src/test/resources/images/bmp/IMAGING-325/crash-3afb569de74522535ef65922233e1920455cdc14.bmp differ
[commons-codec] 02/02: Add user guide entry for Blake3
This is an automated email from the ASF dual-hosted git repository. mattsicker pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git commit 5024e646b87f2efd0cabbeeea4defae720204fec Author: Matt Sicker AuthorDate: Sat Jan 22 16:31:16 2022 -0600 Add user guide entry for Blake3 --- src/site/xdoc/userguide.xml | 22 +- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/site/xdoc/userguide.xml b/src/site/xdoc/userguide.xml index 36155b5..ef70a9e 100644 --- a/src/site/xdoc/userguide.xml +++ b/src/site/xdoc/userguide.xml @@ -100,6 +100,26 @@ tasks and provides GNU libc crypt(3) compatible password hashing functions. + + + Blake3 + + + Provides a pure Java implementation of the + https://github.com/BLAKE3-team/BLAKE3";>Blake3 hash function which can be used for computing + https://en.wikipedia.org/wiki/Cryptographic_hash_function";>cryptographic hashes + (message digests) which are extensible to arbitrary output lengths (known as an extensible-output + function or XOF), computing + https://en.wikipedia.org/wiki/Message_authentication_code";>message authentication codes + using a 32 byte (256-bit) secret key, computing subkeys from a primary key using a + https://en.wikipedia.org/wiki/Key_derivation_function";>key derivation function, and can be + used as the basis for a + https://en.wikipedia.org/wiki/Cryptographically-secure_pseudorandom_number_generator";> + cryptographically-secure pseudorandom number generator. WARNING: Blake3 is + not a password hashing algorithm! An algorithm such as + https://github.com/P-H-C/phc-winner-argon2";>Argon2 is more appropriate for password hashing. + + @@ -224,4 +244,4 @@ - \ No newline at end of file +
[commons-codec] branch master updated (afa3687 -> 5024e64)
This is an automated email from the ASF dual-hosted git repository. mattsicker pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git. from afa3687 [maven-release-plugin] prepare for next development iteration new de35b0b Add links to 1.16 docs and downloads new 5024e64 Add user guide entry for Blake3 The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: src/site/site.xml | 1 + src/site/xdoc/index.xml | 4 +++- src/site/xdoc/userguide.xml | 22 +- 3 files changed, 25 insertions(+), 2 deletions(-)
[commons-codec] 01/02: Add links to 1.16 docs and downloads
This is an automated email from the ASF dual-hosted git repository. mattsicker pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git commit de35b0bc88545fd6a571c75482969262d81de203 Author: Matt Sicker AuthorDate: Sat Jan 22 16:31:04 2022 -0600 Add links to 1.16 docs and downloads --- src/site/site.xml | 1 + src/site/xdoc/index.xml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/site/site.xml b/src/site/site.xml index 24f3513..b0378aa 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -28,6 +28,7 @@ https://commons.apache.org/codec/download_codec.cgi"/> + diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 4e83389..342ecfe 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -72,6 +72,7 @@ The Javadoc API documents are available online: Javadoc current (git master) + Javadoc 1.16 Javadoc 1.15 Javadoc 1.14 Javadoc 1.13 @@ -90,7 +91,8 @@ The subversion repository can be - https://commons.apache.org/codec/download_codec.cgi";>Codec 1.15 (mirrors) requires Java 7 + https://commons.apache.org/codec/download_codec.cgi";>Codec 1.16 (mirrors) requires Java 8 + https://archive.apache.org/dist/commons/codec/";>Codec 1.15 (archives) requires Java 7 https://archive.apache.org/dist/commons/codec/";>Codec 1.14 (archives) requires Java 7 https://archive.apache.org/dist/commons/codec/";>Codec 1.13 (archives) requires Java 7 https://archive.apache.org/dist/commons/codec/";>Codec 1.12 (archives) requires Java 7
[commons-statistics] branch master updated: STATISTICS-25: T-dist to use the complement of the regularized beta
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-statistics.git The following commit(s) were added to refs/heads/master by this push: new 876b5ec STATISTICS-25: T-dist to use the complement of the regularized beta 876b5ec is described below commit 876b5ec9782a36887f08612bee5b0ee8917df6f2 Author: Alex Herbert AuthorDate: Sat Jan 22 14:32:20 2022 + STATISTICS-25: T-dist to use the complement of the regularized beta NUMBERS-181 improved the regularized beta function. This allows increasing the threshold for switching to the normal approximation. --- .../statistics/distribution/TDistribution.java | 56 +++--- .../statistics/distribution/TDistributionTest.java | 48 +++ 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java index 7c93318..50fc554 100644 --- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java +++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java @@ -108,8 +108,9 @@ public abstract class TDistribution extends AbstractContinuousDistribution { /** 2. */ private static final double TWO = 2; /** Number of degrees of freedom above which to use the normal distribution. - * This is used to check the CDF when the degrees of freedom is large. */ -private static final double DOF_THRESHOLD_NORMAL = 2.99e6; + * This is used to check the CDF when the degrees of freedom is large. + * Set to 1 / machine epsilon, 2^52, or 4.50e15. */ +private static final double DOF_THRESHOLD_NORMAL = 0x1.0p52; /** degreesOfFreedom / 2. */ private final double dofOver2; @@ -167,36 +168,33 @@ public abstract class TDistribution extends AbstractContinuousDistribution { if (x == 0) { return 0.5; } -final double df = getDegreesOfFreedom(); -if (df > DOF_THRESHOLD_NORMAL) { +final double v = getDegreesOfFreedom(); + +// This threshold may no longer be required. +// See STATISTICS-25. +if (v > DOF_THRESHOLD_NORMAL) { return STANDARD_NORMAL.cumulativeProbability(x); } -final double x2 = x * x; -// z = 1 / (1 + x^2/df) -// Simplify by multiplication by df -final double z = df / (df + x2); - -// The RegularizedBeta has the complement: -// I(z, a, b) = 1 - I(1 - z, a, b) -// This is used when z > (a + 1) / (2 + b + a). -// Detect this condition and directly use the complement. -if (z > (dofOver2 + 1) / (2.5 + dofOver2)) { -// zc = 1 - z; pc = 1 - p -final double zc = x2 / (df + x2); -final double pc = RegularizedBeta.value(zc, 0.5, dofOver2); - -return x < 0 ? -// 0.5 * p == 0.5 * (1 - pc) = 0.5 - 0.5 * pc -0.5 - 0.5 * pc : -// 1 - 0.5 * p == 1 - 0.5 * (1 - pc) = 0.5 + 0.5 * pc -0.5 + 0.5 * pc; -} - -final double p = RegularizedBeta.value(z, dofOver2, 0.5); -return x < 0 ? -0.5 * p : -1 - 0.5 * p; +// cdf(t) = 1 - 0.5 * I_x(t)(v/2, 1/2) +// where x(t) = v / (v + t^2) +// +// When t^2 << v using the regularized beta results +// in loss of precision. Use the complement instead: +// I[x](a,b) = 1 - I[1-x](b,a) +// x = v / (v + t^2) +// 1-x = t^2 / (v + t^2) +// Use the threshold documented in the Boost t-distribution: +// https://www.boost.org/doc/libs/1_78_0/libs/math/doc/html/math_toolkit/dist_ref/dists/students_t_dist.html + +final double t2 = x * x; +double z; +if (v < 2 * t2) { +z = RegularizedBeta.value(v / (v + t2), dofOver2, 0.5) / 2; +} else { +z = RegularizedBeta.complement(t2 / (v + t2), 0.5, dofOver2) / 2; +} +return x > 0 ? 1 - z : z; } @Override diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TDistributionTest.java index ab27303..106a1f3 100644 --- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribut
[commons-numbers] 05/05: NUMBERS-181: Track changes
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git commit c32f544c28a64dc569392ecc567c79d9d7ee85eb Author: Alex Herbert AuthorDate: Sat Jan 22 13:12:50 2022 + NUMBERS-181: Track changes --- src/changes/changes.xml | 6 ++ 1 file changed, 6 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1e210b4..3a684d7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -72,6 +72,12 @@ N.B. the Performance testing module requires Java 9+. (The unit tests require Java 8+) "> + +Updated support for the beta functions. "RegularizedBeta": Added the +complement and derivative of the regularized beta function. +Added "IncompleteBeta" and "Beta" classes. +Functionality is ported from the Boost C++ library. + Improve the binomial coefficient classes. Avoid recursive method calls. Avoid overflow for BinomialCoefficientDouble for large results close to infinity.
[commons-numbers] branch master updated (f83679e -> c32f544)
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git. from f83679e NUMBERS-183: Track changes new d64d4ba Move BoostGamma.Policy to package level class new 5a9f808 Move DataReader to package level class new ad04a07 NUMBERS-181: Port the Boost beta functions new e7b1d6c NUMBERS-181: New public API for beta functions new c32f544 NUMBERS-181: Track changes The 5 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../org/apache/commons/numbers/gamma/Beta.java | 58 + .../apache/commons/numbers/gamma/BoostBeta.java| 1356 ++ .../apache/commons/numbers/gamma/BoostGamma.java | 76 +- .../commons/numbers/gamma/IncompleteBeta.java | 127 ++ .../commons/numbers/gamma/IncompleteGamma.java |2 - .../org/apache/commons/numbers/gamma/Policy.java | 79 + .../commons/numbers/gamma/RegularizedBeta.java | 176 +- .../commons/numbers/gamma/RegularizedGamma.java|2 - .../org/apache/commons/numbers/gamma/BetaTest.java | 20 +- .../commons/numbers/gamma/BoostBetaTest.java | 1236 + .../commons/numbers/gamma/BoostGammaTest.java | 97 +- .../apache/commons/numbers/gamma/DataReader.java | 113 ++ .../commons/numbers/gamma/IncompleteBetaTest.java | 112 ++ .../commons/numbers/gamma/RegularizedBetaTest.java | 175 +- .../apache/commons/numbers/gamma/beta_exp_data.csv | 373 .../apache/commons/numbers/gamma/beta_med_data.csv | 1852 .../commons/numbers/gamma/beta_small_data.csv | 45 + .../numbers/gamma/binomial_extra_large_data.csv| 531 ++ .../commons/numbers/gamma/binomial_huge_data.csv | 530 ++ .../commons/numbers/gamma/binomial_large_data.csv | 252 +++ .../commons/numbers/gamma/binomial_small_data.csv | 181 ++ .../numbers/gamma/ibeta_derivative_large_data.csv | 1233 + .../numbers/gamma/ibeta_derivative_med_data.csv| 523 ++ .../numbers/gamma/ibeta_derivative_small_data.csv | 523 ++ .../gamma/ibeta_derivative_small_int_data.csv | 1023 +++ .../commons/numbers/gamma/ibeta_large_data.csv | 1233 + .../commons/numbers/gamma/ibeta_med_data.csv | 523 ++ .../commons/numbers/gamma/ibeta_small_data.csv | 523 ++ .../commons/numbers/gamma/ibeta_small_int_data.csv | 1023 +++ src/changes/changes.xml|6 + .../checkstyle/checkstyle-suppressions.xml |3 + src/main/resources/pmd/pmd-ruleset.xml | 20 +- 32 files changed, 13749 insertions(+), 277 deletions(-) create mode 100644 commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Beta.java create mode 100644 commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostBeta.java create mode 100644 commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteBeta.java create mode 100644 commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java copy commons-numbers-rootfinder/src/test/java/org/apache/commons/numbers/rootfinder/Sin.java => commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BetaTest.java (58%) create mode 100644 commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostBetaTest.java create mode 100644 commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DataReader.java create mode 100644 commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/IncompleteBetaTest.java create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/beta_exp_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/beta_med_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/beta_small_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/binomial_extra_large_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/binomial_huge_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/binomial_large_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/binomial_small_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/ibeta_derivative_large_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/commons/numbers/gamma/ibeta_derivative_med_data.csv create mode 100644 commons-numbers-gamma/src/test/resources/org/apache/
[commons-numbers] 04/05: NUMBERS-181: New public API for beta functions
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git commit e7b1d6c7a9a5d654189650a1dd30180ae27552f7 Author: Alex Herbert AuthorDate: Thu Jan 20 23:17:31 2022 + NUMBERS-181: New public API for beta functions --- .../org/apache/commons/numbers/gamma/Beta.java | 58 +++ .../commons/numbers/gamma/IncompleteBeta.java | 127 +++ .../commons/numbers/gamma/RegularizedBeta.java | 176 +++-- .../org/apache/commons/numbers/gamma/BetaTest.java | 35 .../commons/numbers/gamma/IncompleteBetaTest.java | 112 + .../commons/numbers/gamma/RegularizedBetaTest.java | 175 +--- 6 files changed, 580 insertions(+), 103 deletions(-) diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Beta.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Beta.java new file mode 100644 index 000..7f5a9d9 --- /dev/null +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Beta.java @@ -0,0 +1,58 @@ +/* + * 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. + */ +package org.apache.commons.numbers.gamma; + +/** + * https://mathworld.wolfram.com/BetaFunction.html";>Beta function. + * + * \[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} = \frac{(a-1)!\ (b-1)!}{(a+b-1)!} \] + * + * where \( \Gamma(z) \) is the gamma function. + * + * This code has been adapted from the https://www.boost.org/";>Boost + * {@code c++} implementation {@code }. + * + * @see + * https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html";> + * Boost C++ Beta function + * @since 1.1 + */ +public final class Beta { + +/** Private constructor. */ +private Beta() { +// intentionally empty. +} + +/** + * Computes the value of the + * https://mathworld.wolfram.com/BetaFunction.html";> + * beta function B(a, b). + * + * \[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} \] + * + * where \( \Gamma(z) \) is the gamma function. + * + * @param a Parameter {@code a}. + * @param b Parameter {@code b}. + * @return the beta function \( B(a, b) \). + */ +public static double value(double a, + double b) { +return BoostBeta.beta(a, b); +} +} diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteBeta.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteBeta.java new file mode 100644 index 000..dc4911f --- /dev/null +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteBeta.java @@ -0,0 +1,127 @@ +/* + * 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. + */ +package org.apache.commons.numbers.gamma; + +/** + * https://mathworld.wolfram.com/IncompleteBetaFunction.html";> + * Incomplete Beta function. + * + * \[ B_x(a,b) = \int_0^x t^{a-1}\,(1-t)^{b-1}\,dt \] + * + * This code has been adapted from the https://www.boost.org/";>Boost + * {@code c++} implementation {@code }. + * + * @see + * https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html";> + * Boost C++ Incomplete Beta functions + * @since 1.1 + */ +public final class IncompleteBeta { + +/** Private constructor. */ +private IncompleteB
[commons-numbers] 02/05: Move DataReader to package level class
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git commit 5a9f808ec97470a044212b445e62b6cb9fd1c02e Author: Alex Herbert AuthorDate: Tue Jan 4 23:06:33 2022 + Move DataReader to package level class --- .../commons/numbers/gamma/BoostGammaTest.java | 92 - .../apache/commons/numbers/gamma/DataReader.java | 113 + 2 files changed, 113 insertions(+), 92 deletions(-) diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java index fd94d8a..8cea38e 100644 --- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java +++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java @@ -16,15 +16,11 @@ */ package org.apache.commons.numbers.gamma; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.math.BigDecimal; import java.util.Arrays; import java.util.function.DoubleBinaryOperator; import java.util.function.DoubleUnaryOperator; -import java.util.regex.Pattern; import org.apache.commons.numbers.gamma.BoostGamma.Lanczos; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer; @@ -1989,94 +1985,6 @@ class BoostGammaTest { } /** - * Class to read data fields from a test resource file. - */ -private static class DataReader implements AutoCloseable { -/** Comment character. */ -private static final char COMMENT = '#'; -/** Pattern to split data fields. */ -private static final Pattern FIELD_PATTERN = Pattern.compile("[, ]+"); - -/** Input to read. */ -private final BufferedReader in; - -/** The current set of fields. */ -private String[] tokens; - -/** - * @param filename Resource filename to read - */ -DataReader(String filename) { -final InputStream resourceAsStream = this.getClass().getResourceAsStream(filename); -Assertions.assertNotNull(resourceAsStream, () -> "Could not find resource " + filename); -in = new BufferedReader(new InputStreamReader(resourceAsStream)); -} - -/** - * Read the next line of data fields. - * - * @return true if data is available - * @throws IOException Signals that an I/O exception has occurred. - */ -boolean next() throws IOException { -tokens = null; -for (String line = in.readLine(); line != null; line = in.readLine()) { -if (line.isEmpty() || line.charAt(0) == COMMENT || line.trim().isEmpty()) { -continue; -} -tokens = FIELD_PATTERN.split(line); -return true; -} -return false; -} - -/** - * Gets the double from the field. - * - * @param i Field index - * @return the number - * @see #next() - * @throws NumberFormatException if the field cannot be parsed as a double - * @throws NullPointerException if no field data is available - * @throws IndexOutOfBoundsException if the field index is invalid - */ -double getDouble(int i) { -return Double.parseDouble(tokens[i]); -} - -/** - * Gets the BigDecimal from the field. - * - * @param i Field index - * @return the number - * @see #next() - * @throws NumberFormatException if the field cannot be parsed as a BigDecimal - * @throws NullPointerException if no field data is available - * @throws IndexOutOfBoundsException if the field index is invalid - */ -BigDecimal getBigDecimal(int i) { -return new BigDecimal(tokens[i]); -} - -/** - * Gets the current fields. This is returned as a reference. - * - * This is null if no fields are available for reading. - * - * @return the fields - * @see #next() - */ -String[] getFields() { -return tokens; -} - -@Override -public void close() throws IOException { -in.close(); -} -} - -/** * Assert the Root Mean Square (RMS) error of the function is below the allowed * maximum for the specified TestError. * diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DataReader.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DataReader.java new file mode 100644 index 000..024d5c2 --- /dev/null +++ b/commons-numbers-gamma/src/test
[commons-numbers] 01/05: Move BoostGamma.Policy to package level class
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git commit d64d4ba5a344ef92fc89ab9547f7fd146a77fd27 Author: Alex Herbert AuthorDate: Tue Jan 4 21:17:50 2022 + Move BoostGamma.Policy to package level class --- .../apache/commons/numbers/gamma/BoostGamma.java | 61 - .../commons/numbers/gamma/IncompleteGamma.java | 2 - .../org/apache/commons/numbers/gamma/Policy.java | 79 ++ .../commons/numbers/gamma/RegularizedGamma.java| 2 - .../commons/numbers/gamma/BoostGammaTest.java | 5 +- 5 files changed, 81 insertions(+), 68 deletions(-) diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java index 976458b..ea79786 100644 --- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java @@ -294,67 +294,6 @@ final class BoostGamma { }; /** - * Encapsulate the policy for function evaluation. - * This is a reduced implementation of the Boost {@code boost::math::policies} - * functionality. No settings are preserved for the error handling policy or - * promotion of data types for computations. - * This controls the convergence criteria and maximum iterations for series evaluations. - * - * @see https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/policy.html";> - * Policies: Controlling Precision, Error Handling etc - */ -static final class Policy { -/** Default policy. The Boost default uses 2^-52 for the epsilon. This uses - * 2^-53 to use an extra guard digit in the Kahan series summations. - * The minimum value for the Commons continued fraction epsilon is also 2^-53. */ -private static final Policy DEFAULT = new Policy(0x1.0p-53, 100); - -/** Epsilon value for relative error. */ -private final double eps; -/** The maximum number of iterations permitted in a series evaluation. */ -private final int maxIterations; - -/** - * Instantiates a new policy. - * - * @param eps the eps - * @param maxIterations the maximum number of iterations permitted in a series - * evaluation - */ -Policy(double eps, int maxIterations) { -this.eps = eps; -this.maxIterations = maxIterations; -} - -/** - * Gets the default. - * - * @return the default policy - */ -static Policy getDefault() { -return DEFAULT; -} - -/** - * Gets the epsilon value for relative error. - * - * @return the epsilon - */ -double getEps() { -return eps; -} - -/** - * Gets the maximum number of iterations permitted in a series evaluation. - * - * @return max iterations - */ -int getMaxIterations() { -return maxIterations; -} -} - -/** * 53-bit precision implementation of the Lanczos approximation. * * This implementation is in partial fraction form with the leading constant diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java index cac2a25..210e8ff 100644 --- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java @@ -16,8 +16,6 @@ */ package org.apache.commons.numbers.gamma; -import org.apache.commons.numbers.gamma.BoostGamma.Policy; - /** * https://mathworld.wolfram.com/IncompleteGammaFunction.html";> * Incomplete Gamma functions. diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java new file mode 100644 index 000..bf0d7bf --- /dev/null +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java @@ -0,0 +1,79 @@ +/* + * 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 ag
[commons-statistics] branch master updated: Drop redundant test.
This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-statistics.git The following commit(s) were added to refs/heads/master by this push: new c7d6e9d Drop redundant test. c7d6e9d is described below commit c7d6e9d6dd8e8f7e29822fa06e9b1ca2ab3bb116 Author: Alex Herbert AuthorDate: Sat Jan 22 09:37:10 2022 + Drop redundant test. --- .../AbstractDiscreteDistributionTest.java | 33 -- 1 file changed, 33 deletions(-) diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java index 916f17e..390ae37 100644 --- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java +++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistributionTest.java @@ -192,39 +192,6 @@ class AbstractDiscreteDistributionTest { Assertions.assertEquals(dist.getSupportUpperBound(), dist.inverseSurvivalProbability(0.0)); } -@Test -void testInverseProbabilityWithNaN() { -final DiscreteDistribution dist = new AbstractDiscreteDistribution() { -@Override -public double probability(int x) { -return 0; -} -@Override -public double cumulativeProbability(int x) { -// NaN is not allowed -return Double.NaN; -} -@Override -public double getMean() { -return 0; -} -@Override -public double getVariance() { -return 0; -} -@Override -public int getSupportLowerBound() { -return Integer.MIN_VALUE; -} -@Override -public int getSupportUpperBound() { -return Integer.MAX_VALUE; -} -}; -Assertions.assertThrows(IllegalStateException.class, () -> dist.inverseCumulativeProbability(0.5)); -Assertions.assertThrows(IllegalStateException.class, () -> dist.inverseSurvivalProbability(0.5)); -} - /** * Simple distribution modeling a 6-sided die */