From c4ba0560988719b3daa6a120fd93f9f831a65113 Mon Sep 17 00:00:00 2001 From: Suraj Rajan Date: Mon, 31 Aug 2026 06:38:20 +0530 Subject: [PATCH] Fix PMD findings from Commons Parent 102 Signed-off-by: Suraj Rajan --- .../inference/KolmogorovSmirnovDistribution.java | 9 ++++----- .../statistics/inference/SquareMatrixSupport.java | 4 ++-- src/conf/pmd/pmd-ruleset.xml | 8 ++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistribution.java b/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistribution.java index ce7cbbfa6..3390d4d2a 100644 --- a/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistribution.java +++ b/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovDistribution.java @@ -547,11 +547,6 @@ static double pelzGood(double x, int n) { // This is the form for K0. // Compute all together over odd integers and divide factors // of (k + 1/2)^b by 2^b. - double k0 = 0; - double k1 = 0; - double k2 = 0; - double k3 = 0; - final double rootN = Math.sqrt(n); final double z = x * rootN; final double z3 = z * z2; @@ -579,6 +574,10 @@ static double pelzGood(double x, int n) { // 0 = k^2 - k + log(eps) * 2z^2 / pi^2 // Solve using quadratic equation and eps = ulp(1.0): 4a ~ -288 final int max = (int) Math.ceil((1 + Math.sqrt(1 - FOUR_A * z2 / PI2)) / 2); + double k0 = 0; + double k1 = 0; + double k2 = 0; + double k3 = 0; // Sum smallest terms first for (int k = max; k > 0; k--) { final int j = 2 * k - 1; diff --git a/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/SquareMatrixSupport.java b/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/SquareMatrixSupport.java index 3ca5b8204..99332dcf3 100644 --- a/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/SquareMatrixSupport.java +++ b/commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/SquareMatrixSupport.java @@ -153,8 +153,6 @@ public RealSquareMatrix power(int n) { // Working arrays final double[] col = new double[dim]; - double[] b = new double[data.length]; - double[] tmp; // Initialise result as A^1. final double[] a = data; @@ -168,6 +166,8 @@ public RealSquareMatrix power(int n) { int bits = n << shift; // Process remaining bits below highest set bit. + double[] b = new double[data.length]; + double[] tmp; for (int i = 32 - shift; i != 0; i--, bits <<= 1) { // Square the result er = multiply(r, er, r, er, col, b); diff --git a/src/conf/pmd/pmd-ruleset.xml b/src/conf/pmd/pmd-ruleset.xml index 76cea6979..6a6e45222 100644 --- a/src/conf/pmd/pmd-ruleset.xml +++ b/src/conf/pmd/pmd-ruleset.xml @@ -104,6 +104,14 @@ value="./ancestor-or-self::MethodDeclaration[@Name='twoSampleTwoSidedPStabilizedInner']"/> + + + + + +