From 21e230ae83f57f8823f1ce4d1a2155a515ad107f Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Thu, 14 Oct 2021 10:56:56 +0200 Subject: [PATCH] MATH-1630: Runtime switch between JDK and CM implementations of the methods defined in "java.lang.Math". Default is to use the CM implementations in order to retain previous behaviour. When using the JDK implementations, some unit tests fail (on Java 8). Class "AccurateMath" was moved to "o.a.c.math4.core" package. [Unit tests for that class were not moved because they depend on "legacy" classes.] --- .../math4}/core/jdkmath/AccurateMath.java | 2 +- .../math4}/core/jdkmath/AccurateMathCalc.java | 10 +- .../jdkmath/AccurateMathLiteralArrays.java | 2 +- .../commons/math4/core/jdkmath/JdkMath.java | 1108 +++++++++++++++++ commons-math-legacy-core/pom.xml | 5 + .../commons/math4/legacy/core/MathArrays.java | 16 +- .../ExtendedFieldElementAbstractTest.java | 78 +- .../math4/legacy/core/MathArraysTest.java | 10 +- .../math4/legacy/core/dfp/DfpTest.java | 6 +- .../AccurateMathStrictComparisonTest.java | 4 + .../legacy/core/jdkmath/AccurateMathTest.java | 6 +- .../analysis/differentiation/DSCompiler.java | 94 +- .../differentiation/DerivativeStructure.java | 22 +- .../FiniteDifferencesDifferentiator.java | 10 +- .../differentiation/SparseGradient.java | 84 +- .../math4/legacy/analysis/function/Abs.java | 4 +- .../math4/legacy/analysis/function/Acos.java | 4 +- .../math4/legacy/analysis/function/Acosh.java | 4 +- .../math4/legacy/analysis/function/Asin.java | 4 +- .../math4/legacy/analysis/function/Asinh.java | 4 +- .../math4/legacy/analysis/function/Atan.java | 4 +- .../math4/legacy/analysis/function/Atan2.java | 4 +- .../math4/legacy/analysis/function/Atanh.java | 4 +- .../math4/legacy/analysis/function/Cbrt.java | 4 +- .../math4/legacy/analysis/function/Ceil.java | 4 +- .../math4/legacy/analysis/function/Cos.java | 4 +- .../math4/legacy/analysis/function/Cosh.java | 4 +- .../math4/legacy/analysis/function/Exp.java | 4 +- .../math4/legacy/analysis/function/Expm1.java | 4 +- .../math4/legacy/analysis/function/Floor.java | 4 +- .../legacy/analysis/function/Gaussian.java | 8 +- .../analysis/function/HarmonicOscillator.java | 10 +- .../math4/legacy/analysis/function/Log.java | 4 +- .../math4/legacy/analysis/function/Log10.java | 4 +- .../math4/legacy/analysis/function/Log1p.java | 4 +- .../legacy/analysis/function/Logistic.java | 10 +- .../math4/legacy/analysis/function/Logit.java | 6 +- .../math4/legacy/analysis/function/Max.java | 4 +- .../math4/legacy/analysis/function/Min.java | 4 +- .../math4/legacy/analysis/function/Pow.java | 4 +- .../math4/legacy/analysis/function/Power.java | 4 +- .../math4/legacy/analysis/function/Rint.java | 4 +- .../legacy/analysis/function/Sigmoid.java | 8 +- .../legacy/analysis/function/Signum.java | 4 +- .../math4/legacy/analysis/function/Sin.java | 4 +- .../math4/legacy/analysis/function/Sinc.java | 20 +- .../math4/legacy/analysis/function/Sinh.java | 4 +- .../math4/legacy/analysis/function/Sqrt.java | 4 +- .../math4/legacy/analysis/function/Tan.java | 4 +- .../math4/legacy/analysis/function/Tanh.java | 4 +- .../math4/legacy/analysis/function/Ulp.java | 4 +- .../IterativeLegendreGaussIntegrator.java | 12 +- .../integration/MidPointIntegrator.java | 8 +- .../integration/RombergIntegrator.java | 6 +- .../integration/SimpsonIntegrator.java | 6 +- .../integration/TrapezoidIntegrator.java | 6 +- .../integration/gauss/HermiteRuleFactory.java | 16 +- .../AkimaSplineInterpolator.java | 6 +- .../InterpolatingMicrosphere.java | 6 +- .../InterpolatingMicrosphere2D.java | 6 +- .../interpolation/LoessInterpolator.java | 12 +- .../polynomials/PolynomialFunction.java | 16 +- .../PolynomialFunctionLagrangeForm.java | 4 +- .../polynomials/PolynomialsUtils.java | 8 +- .../analysis/solvers/BaseSecantSolver.java | 6 +- .../analysis/solvers/BisectionSolver.java | 4 +- .../BracketingNthOrderBrentSolver.java | 14 +- .../analysis/solvers/LaguerreSolver.java | 14 +- .../legacy/analysis/solvers/MullerSolver.java | 20 +- .../analysis/solvers/MullerSolver2.java | 24 +- .../analysis/solvers/NewtonRaphsonSolver.java | 4 +- .../analysis/solvers/RiddersSolver.java | 18 +- .../legacy/analysis/solvers/SecantSolver.java | 6 +- .../solvers/UnivariateSolverUtils.java | 18 +- .../AbstractIntegerDistribution.java | 12 +- .../AbstractRealDistribution.java | 10 +- .../distribution/EmpiricalDistribution.java | 4 +- .../MultivariateNormalDistribution.java | 12 +- ...eNormalMixtureExpectationMaximization.java | 8 +- .../legacy/fitting/GaussianCurveFitter.java | 4 +- .../legacy/fitting/HarmonicCurveFitter.java | 12 +- .../leastsquares/AbstractEvaluation.java | 8 +- .../leastsquares/LeastSquaresFactory.java | 4 +- .../LevenbergMarquardtOptimizer.java | 54 +- .../genetics/ElitisticListPopulation.java | 4 +- .../legacy/genetics/OrderedCrossover.java | 6 +- .../legacy/linear/AbstractRealMatrix.java | 8 +- .../math4/legacy/linear/ArrayRealVector.java | 20 +- .../legacy/linear/BiDiagonalTransformer.java | 12 +- .../math4/legacy/linear/BlockFieldMatrix.java | 94 +- .../math4/legacy/linear/BlockRealMatrix.java | 100 +- .../legacy/linear/CholeskyDecomposition.java | 8 +- .../math4/legacy/linear/DiagonalMatrix.java | 4 +- .../legacy/linear/EigenDecomposition.java | 64 +- .../legacy/linear/HessenbergTransformer.java | 6 +- .../math4/legacy/linear/LUDecomposition.java | 8 +- .../math4/legacy/linear/MatrixUtils.java | 10 +- .../legacy/linear/OpenIntToDoubleHashMap.java | 4 +- .../legacy/linear/OpenIntToFieldHashMap.java | 4 +- .../legacy/linear/OpenMapRealVector.java | 14 +- .../math4/legacy/linear/QRDecomposition.java | 24 +- .../legacy/linear/RRQRDecomposition.java | 4 +- .../math4/legacy/linear/RealVector.java | 14 +- .../RectangularCholeskyDecomposition.java | 4 +- .../math4/legacy/linear/SchurTransformer.java | 34 +- .../linear/SingularValueDecomposition.java | 52 +- .../commons/math4/legacy/linear/SymmLQ.java | 38 +- .../legacy/linear/TriDiagonalTransformer.java | 4 +- .../ml/clustering/FuzzyKMeansClusterer.java | 16 +- .../legacy/ml/distance/CanberraDistance.java | 6 +- .../ml/distance/EarthMoversDistance.java | 4 +- .../legacy/ode/AbstractFieldIntegrator.java | 8 +- .../math4/legacy/ode/AbstractIntegrator.java | 8 +- .../ode/ContinuousOutputFieldModel.java | 8 +- .../legacy/ode/ContinuousOutputModel.java | 14 +- .../math4/legacy/ode/JacobianMatrices.java | 2 +- .../legacy/ode/MultistepFieldIntegrator.java | 6 +- .../math4/legacy/ode/MultistepIntegrator.java | 8 +- .../math4/legacy/ode/events/EventState.java | 22 +- .../legacy/ode/events/FieldEventState.java | 8 +- .../math4/legacy/ode/events/Transformer.java | 6 +- .../nonstiff/AdamsBashforthIntegrator.java | 6 +- .../ode/nonstiff/AdamsMoultonIntegrator.java | 6 +- .../AdaptiveStepsizeFieldIntegrator.java | 10 +- .../nonstiff/AdaptiveStepsizeIntegrator.java | 30 +- .../nonstiff/DormandPrince54Integrator.java | 6 +- .../nonstiff/DormandPrince853Integrator.java | 46 +- .../EmbeddedRungeKuttaIntegrator.java | 12 +- .../legacy/ode/nonstiff/GillIntegrator.java | 8 +- .../ode/nonstiff/GillStepInterpolator.java | 6 +- .../GraggBulirschStoerIntegrator.java | 50 +- .../GraggBulirschStoerStepInterpolator.java | 6 +- .../ode/nonstiff/HighamHall54Integrator.java | 6 +- .../legacy/ode/nonstiff/LutherIntegrator.java | 4 +- .../ode/nonstiff/LutherStepInterpolator.java | 4 +- .../ode/nonstiff/RungeKuttaIntegrator.java | 4 +- .../ode/sampling/FieldStepNormalizer.java | 6 +- .../sampling/NordsieckStepInterpolator.java | 4 +- .../legacy/ode/sampling/StepNormalizer.java | 6 +- .../legacy/optim/SimplePointChecker.java | 6 +- .../legacy/optim/SimpleValueChecker.java | 6 +- .../optim/SimpleVectorValueChecker.java | 6 +- .../legacy/optim/linear/SimplexSolver.java | 4 +- .../MultivariateFunctionMappingAdapter.java | 10 +- .../MultivariateFunctionPenaltyAdapter.java | 4 +- .../scalar/noderiv/BOBYQAOptimizer.java | 140 +-- .../scalar/noderiv/CMAESOptimizer.java | 46 +- .../scalar/noderiv/PowellOptimizer.java | 8 +- .../optim/univariate/BracketFinder.java | 4 +- .../optim/univariate/BrentOptimizer.java | 16 +- .../SimpleUnivariateValueChecker.java | 6 +- .../random/CorrelatedVectorFactory.java | 4 +- .../legacy/random/SobolSequenceGenerator.java | 4 +- .../commons/math4/legacy/special/BesselJ.java | 26 +- .../stat/correlation/KendallsCorrelation.java | 8 +- .../stat/correlation/PearsonsCorrelation.java | 10 +- .../descriptive/DescriptiveStatistics.java | 6 +- .../MultivariateSummaryStatistics.java | 4 +- .../descriptive/ResizableDoubleArray.java | 8 +- .../descriptive/StatisticalSummaryValues.java | 4 +- .../stat/descriptive/SummaryStatistics.java | 6 +- .../descriptive/moment/GeometricMean.java | 6 +- .../stat/descriptive/moment/Kurtosis.java | 10 +- .../stat/descriptive/moment/Skewness.java | 6 +- .../descriptive/moment/StandardDeviation.java | 12 +- .../stat/descriptive/rank/KthSelector.java | 6 +- .../stat/descriptive/rank/Percentile.java | 12 +- .../stat/descriptive/summary/Product.java | 4 +- .../stat/descriptive/summary/SumOfLogs.java | 8 +- .../legacy/stat/inference/ChiSquareTest.java | 6 +- .../math4/legacy/stat/inference/GTest.java | 14 +- .../stat/inference/KolmogorovSmirnovTest.java | 52 +- .../stat/inference/MannWhitneyUTest.java | 6 +- .../math4/legacy/stat/inference/TTest.java | 14 +- .../inference/WilcoxonSignedRankTest.java | 8 +- .../stat/interval/AgrestiCoullInterval.java | 6 +- .../interval/NormalApproximationInterval.java | 4 +- .../stat/interval/WilsonScoreInterval.java | 4 +- .../legacy/stat/ranking/NaturalRanking.java | 6 +- .../AbstractMultipleLinearRegression.java | 6 +- .../regression/MillerUpdatingRegression.java | 30 +- .../stat/regression/RegressionResults.java | 6 +- .../stat/regression/SimpleRegression.java | 18 +- .../commons/math4/legacy/TestUtils.java | 4 +- .../legacy/analysis/FunctionUtilsTest.java | 26 +- .../DerivativeStructureTest.java | 182 +-- .../FiniteDifferencesDifferentiatorTest.java | 44 +- .../differentiation/GradientFunctionTest.java | 4 +- .../differentiation/JacobianFunctionTest.java | 18 +- .../differentiation/SparseGradientTest.java | 126 +- .../function/BivariateFunctionTest.java | 4 +- .../analysis/function/GaussianTest.java | 6 +- .../function/HarmonicOscillatorTest.java | 20 +- .../analysis/function/LogisticTest.java | 12 +- .../legacy/analysis/function/LogitTest.java | 4 +- .../legacy/analysis/function/SincTest.java | 4 +- .../legacy/analysis/function/SqrtTest.java | 8 +- .../UnivariateDifferentiableFunctionTest.java | 76 +- .../function/UnivariateFunctionTest.java | 4 +- .../IterativeLegendreGaussIntegratorTest.java | 18 +- .../integration/MidPointIntegratorTest.java | 20 +- .../integration/RombergIntegratorTest.java | 16 +- .../integration/SimpsonIntegratorTest.java | 36 +- .../integration/TrapezoidIntegratorTest.java | 16 +- .../gauss/GaussianQuadratureAbstractTest.java | 4 +- .../gauss/HermiteParametricTest.java | 4 +- .../integration/gauss/HermiteTest.java | 10 +- .../integration/gauss/LaguerreTest.java | 4 +- .../AkimaSplineInterpolatorTest.java | 4 +- .../BicubicInterpolatingFunctionTest.java | 4 +- .../DividedDifferenceInterpolatorTest.java | 20 +- .../FieldHermiteInterpolatorTest.java | 14 +- .../HermiteInterpolatorTest.java | 30 +- .../interpolation/LoessInterpolatorTest.java | 18 +- ...MicrosphereProjectionInterpolatorTest.java | 6 +- .../NevilleInterpolatorTest.java | 20 +- ...icubicSplineInterpolatingFunctionTest.java | 4 +- .../interpolation/SplineInterpolatorTest.java | 22 +- .../TricubicInterpolatingFunctionTest.java | 20 +- .../TricubicInterpolatorTest.java | 4 +- .../UnivariatePeriodicInterpolatorTest.java | 8 +- .../polynomials/PolynomialFunctionTest.java | 10 +- .../polynomials/PolynomialsUtilsTest.java | 18 +- .../solvers/BaseSecantSolverAbstractTest.java | 6 +- .../analysis/solvers/BisectionSolverTest.java | 8 +- .../analysis/solvers/BrentSolverTest.java | 22 +- .../analysis/solvers/LaguerreSolverTest.java | 34 +- .../analysis/solvers/MullerSolver2Test.java | 36 +- .../analysis/solvers/MullerSolverTest.java | 36 +- .../solvers/NewtonRaphsonSolverTest.java | 6 +- .../solvers/RegulaFalsiSolverTest.java | 4 +- .../analysis/solvers/RiddersSolverTest.java | 36 +- .../solvers/UnivariateSolverUtilsTest.java | 6 +- .../EmpiricalDistributionTest.java | 8 +- .../EnumeratedIntegerDistributionTest.java | 4 +- .../EnumeratedRealDistributionTest.java | 4 +- .../IntegerDistributionAbstractTest.java | 4 +- .../RealDistributionAbstractTest.java | 8 +- .../ExtendedFieldElementAbstractTest.java | 78 +- .../math4/legacy/filter/KalmanFilterTest.java | 26 +- .../fitting/HarmonicCurveFitterTest.java | 4 +- .../fitting/PolynomialCurveFitterTest.java | 22 +- ...ractLeastSquaresOptimizerAbstractTest.java | 14 +- .../leastsquares/BevingtonProblem.java | 14 +- .../fitting/leastsquares/CircleProblem.java | 6 +- ...ectorMultivariateJacobianFunctionTest.java | 6 +- .../fitting/leastsquares/EvaluationTest.java | 10 +- .../EvaluationTestValidation.java | 4 +- .../GaussNewtonOptimizerWithSVDTest.java | 4 +- .../LevenbergMarquardtOptimizerTest.java | 8 +- .../fitting/leastsquares/MinpackTest.java | 80 +- .../RandomCirclePointGenerator.java | 6 +- .../StatisticalReferenceDatasetFactory.java | 22 +- .../legacy/genetics/FixedElapsedTimeTest.java | 4 +- .../GeneticAlgorithmTestPermutations.java | 4 +- .../linear/Array2DRowRealMatrixTest.java | 6 +- .../linear/BiDiagonalTransformerTest.java | 10 +- .../math4/legacy/linear/BigRealTest.java | 10 +- .../legacy/linear/BlockRealMatrixTest.java | 6 +- .../legacy/linear/ConjugateGradientTest.java | 20 +- .../legacy/linear/EigenDecompositionTest.java | 20 +- .../legacy/linear/RealVectorAbstractTest.java | 28 +- .../math4/legacy/linear/SymmLQTest.java | 20 +- .../linear/TriDiagonalTransformerTest.java | 4 +- .../UnmodifiableRealVectorAbstractTest.java | 12 +- .../ml/distance/EuclideanDistanceTest.java | 4 +- .../ode/ContinuousOutputFieldModelTest.java | 18 +- .../legacy/ode/ContinuousOutputModelTest.java | 22 +- .../legacy/ode/FirstOrderConverterTest.java | 20 +- .../legacy/ode/JacobianMatricesTest.java | 46 +- .../math4/legacy/ode/TestFieldProblem4.java | 10 +- .../math4/legacy/ode/TestProblem1.java | 4 +- .../math4/legacy/ode/TestProblem2.java | 4 +- .../math4/legacy/ode/TestProblem3.java | 20 +- .../math4/legacy/ode/TestProblem4.java | 18 +- .../math4/legacy/ode/TestProblemHandler.java | 18 +- .../legacy/ode/events/EventFilterTest.java | 52 +- ...EmbeddedRungeKuttaFieldIntegratorTest.java | 12 +- ...AbstractRungeKuttaFieldIntegratorTest.java | 16 +- .../AdamsBashforthIntegratorTest.java | 8 +- .../AdamsFieldIntegratorAbstractTest.java | 4 +- .../nonstiff/AdamsMoultonIntegratorTest.java | 8 +- .../ClassicalRungeKuttaIntegratorTest.java | 18 +- .../math4/legacy/ode/nonstiff/Decimal64.java | 76 +- .../DormandPrince54IntegratorTest.java | 12 +- .../DormandPrince54StepInterpolatorTest.java | 6 +- .../DormandPrince853IntegratorTest.java | 18 +- .../DormandPrince853StepInterpolatorTest.java | 6 +- ...RungeKuttaFieldIntegratorAbstractTest.java | 12 +- .../ode/nonstiff/EulerIntegratorTest.java | 10 +- .../nonstiff/EulerStepInterpolatorTest.java | 20 +- .../ode/nonstiff/GillIntegratorTest.java | 10 +- .../GraggBulirschStoerIntegratorTest.java | 16 +- ...raggBulirschStoerStepInterpolatorTest.java | 6 +- .../nonstiff/HighamHall54IntegratorTest.java | 4 +- .../HighamHall54StepInterpolatorTest.java | 6 +- .../ode/nonstiff/LutherIntegratorTest.java | 14 +- .../ode/nonstiff/MidpointIntegratorTest.java | 10 +- ...RungeKuttaFieldIntegratorAbstractTest.java | 16 +- ...uttaFieldStepInterpolatorAbstractTest.java | 14 +- .../nonstiff/ThreeEighthesIntegratorTest.java | 10 +- .../sampling/DummyStepInterpolatorTest.java | 10 +- .../sampling/StepInterpolatorTestUtils.java | 6 +- .../ode/sampling/StepNormalizerTest.java | 4 +- .../scalar/noderiv/CMAESOptimizerTest.java | 8 +- .../scalar/noderiv/OptimTestUtils.java | 8 +- .../scalar/noderiv/PowellOptimizerTest.java | 4 +- .../SimplexOptimizerMultiDirectionalTest.java | 4 +- .../optim/univariate/BrentOptimizerTest.java | 4 +- .../MultiStartUnivariateOptimizerTest.java | 6 +- .../random/CorrelatedVectorFactoryTest.java | 8 +- .../math4/legacy/stat/StatUtilsTest.java | 18 +- .../correlation/PearsonsCorrelationTest.java | 4 +- .../MultivariateSummaryStatisticsTest.java | 6 +- ...relessUnivariateStatisticAbstractTest.java | 4 +- .../descriptive/SummaryStatisticsTest.java | 6 +- .../UnivariateStatisticAbstractTest.java | 6 +- .../moment/StandardDeviationTest.java | 4 +- .../rank/PSquarePercentileTest.java | 10 +- .../legacy/stat/inference/GTestTest.java | 20 +- .../inference/InferenceTestUtilsTest.java | 20 +- .../inference/KolmogorovSmirnovTestTest.java | 4 +- .../MillerUpdatingRegressionTest.java | 124 +- .../stat/regression/SimpleRegressionTest.java | 30 +- .../util/ComplexFormatAbstractTest.java | 4 +- .../RealFunctionValidation.java | 8 +- pom.xml | 7 + .../checkstyle/checkstyle-suppressions.xml | 2 +- 328 files changed, 3519 insertions(+), 2393 deletions(-) rename {commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy => commons-math-core/src/main/java/org/apache/commons/math4}/core/jdkmath/AccurateMath.java (99%) rename {commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy => commons-math-core/src/main/java/org/apache/commons/math4}/core/jdkmath/AccurateMathCalc.java (98%) rename {commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy => commons-math-core/src/main/java/org/apache/commons/math4}/core/jdkmath/AccurateMathLiteralArrays.java (99%) create mode 100644 commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/JdkMath.java diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMath.java similarity index 99% rename from commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java rename to commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMath.java index 88cd91a63..86870308d 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java +++ b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMath.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.legacy.core.jdkmath; +package org.apache.commons.math4.core.jdkmath; import java.io.PrintStream; diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMathCalc.java similarity index 98% rename from commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java rename to commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMathCalc.java index e9ec154ff..b4b57aa84 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java +++ b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMathCalc.java @@ -14,11 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.legacy.core.jdkmath; +package org.apache.commons.math4.core.jdkmath; import java.io.PrintStream; -import org.apache.commons.math4.legacy.exception.DimensionMismatchException; /** Class used to compute the classical functions tables. * @since 3.0 @@ -647,12 +646,11 @@ final class AccurateMathCalc { * Check two lengths are equal. * @param expectedLen expected length * @param actual actual length - * @exception DimensionMismatchException if the two lengths are not equal + * @throws IllegalStateException if the two lengths are not equal */ - private static void checkLen(int expectedLen, int actual) - throws DimensionMismatchException { + private static void checkLen(int expectedLen, int actual) { if (expectedLen != actual) { - throw new DimensionMismatchException(actual, expectedLen); + throw new IllegalStateException(actual + " != " + expectedLen); } } } diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMathLiteralArrays.java similarity index 99% rename from commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java rename to commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMathLiteralArrays.java index 7d7c1baaa..c53a4bc47 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java +++ b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMathLiteralArrays.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.core.jdkmath; +package org.apache.commons.math4.core.jdkmath; /** * Utility class for loading tabulated data used by {@link AccurateMath}. diff --git a/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/JdkMath.java b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/JdkMath.java new file mode 100644 index 000000000..37295c817 --- /dev/null +++ b/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/JdkMath.java @@ -0,0 +1,1108 @@ +/* + * 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.math4.core.jdkmath; + +import java.util.function.IntUnaryOperator; +import java.util.function.IntBinaryOperator; +import java.util.function.LongUnaryOperator; +import java.util.function.LongBinaryOperator; +import java.util.function.DoubleUnaryOperator; +import java.util.function.DoubleBinaryOperator; +import java.util.function.DoubleToLongFunction; +import java.util.function.DoubleToIntFunction; +import java.util.function.LongToIntFunction; +import java.util.function.DoubleSupplier; + +/** + * Wrapper for alternative implementations of {@link Math} functions. + * + * Based on the value, at class initialization, of the system property + * {@code org.apache.commons.math.jdkmath}, this class redirects to a + * specific implementation: + * + * When the property is undefined, {@code CM} is the default value. + */ +public final class JdkMath { + /** Constant. */ + public static final double PI; + /** Constant. */ + public static final double E; + /** Property identifier.. */ + private static final String PROPERTY_KEY = "org.apache.commons.math.jdkmath"; + /** abs(x). */ + private static final IntUnaryOperator ABS_INT; + /** abs(x). */ + private static final LongUnaryOperator ABS_LONG; + /** abs(x). */ + private static final FloatUnaryOperator ABS_FLOAT; + /** abs(x). */ + private static final DoubleUnaryOperator ABS_DOUBLE; + /** acos(x). */ + private static final DoubleUnaryOperator ACOS; + /** acosh(x). */ + private static final DoubleUnaryOperator ACOSH; + /** addExact(x, y). */ + private static final IntBinaryOperator ADDEXACT_INT; + /** addExact(x, y). */ + private static final LongBinaryOperator ADDEXACT_LONG; + /** asin(x). */ + private static final DoubleUnaryOperator ASIN; + /** asinh(x). */ + private static final DoubleUnaryOperator ASINH; + /** atan(x). */ + private static final DoubleUnaryOperator ATAN; + /** atan2(x, y). */ + private static final DoubleBinaryOperator ATAN2; + /** atanh(x). */ + private static final DoubleUnaryOperator ATANH; + /** cbrt(x). */ + private static final DoubleUnaryOperator CBRT; + /** ceil(x). */ + private static final DoubleUnaryOperator CEIL; + /** copySign(x, y). */ + private static final FloatBinaryOperator COPYSIGN_FLOAT; + /** copySign(x, y). */ + private static final DoubleBinaryOperator COPYSIGN_DOUBLE; + /** cos(x). */ + private static final DoubleUnaryOperator COS; + /** cosh(x). */ + private static final DoubleUnaryOperator COSH; + /** decrementExact(x). */ + private static final IntUnaryOperator DECREMENTEXACT_INT; + /** decrementExact(x). */ + private static final LongUnaryOperator DECREMENTEXACT_LONG; + /** exp(x). */ + private static final DoubleUnaryOperator EXP; + /** expm1(x). */ + private static final DoubleUnaryOperator EXPM1; + /** floor(x). */ + private static final DoubleUnaryOperator FLOOR; + /** floorDiv(x, y). */ + private static final IntBinaryOperator FLOORDIV_INT; + /** floorDiv(x, y). */ + private static final LongBinaryOperator FLOORDIV_LONG; + /** floorMod(x, y). */ + private static final IntBinaryOperator FLOORMOD_INT; + /** floorMod(x, y). */ + private static final LongBinaryOperator FLOORMOD_LONG; + /** getExponent(x). */ + private static final FloatToIntFunction GETEXPONENT_FLOAT; + /** getExponent(x). */ + private static final DoubleToIntFunction GETEXPONENT_DOUBLE; + /** hypot(x, y). */ + private static final DoubleBinaryOperator HYPOT; + /** IEEEremainder(x, y). */ + private static final DoubleBinaryOperator IEEEREMAINDER; + /** incrementExact(x). */ + private static final IntUnaryOperator INCREMENTEXACT_INT; + /** incrementExact(x). */ + private static final LongUnaryOperator INCREMENTEXACT_LONG; + /** log(x). */ + private static final DoubleUnaryOperator LOG; + /** log10(x). */ + private static final DoubleUnaryOperator LOG10; + /** log1p(x). */ + private static final DoubleUnaryOperator LOG1P; + /** max(x, y). */ + private static final IntBinaryOperator MAX_INT; + /** max(x, y). */ + private static final LongBinaryOperator MAX_LONG; + /** max(x, y). */ + private static final FloatBinaryOperator MAX_FLOAT; + /** max(x, y). */ + private static final DoubleBinaryOperator MAX_DOUBLE; + /** min(x, y). */ + private static final IntBinaryOperator MIN_INT; + /** min(x, y). */ + private static final LongBinaryOperator MIN_LONG; + /** min(x, y). */ + private static final FloatBinaryOperator MIN_FLOAT; + /** min(x, y). */ + private static final DoubleBinaryOperator MIN_DOUBLE; + /** multiplyExact(x, y). */ + private static final IntBinaryOperator MULTIPLYEXACT_INT; + /** multiplyExact(x, y). */ + private static final LongBinaryOperator MULTIPLYEXACT_LONG; + /** negateExact(x). */ + private static final IntUnaryOperator NEGATEEXACT_INT; + /** negateExact(x). */ + private static final LongUnaryOperator NEGATEEXACT_LONG; + /** nextAfter(x, y). */ + private static final FloatDouble2FloatOperator NEXTAFTER_FLOAT; + /** nextAfter(x, y). */ + private static final DoubleBinaryOperator NEXTAFTER_DOUBLE; + /** nextDown(x). */ + private static final FloatUnaryOperator NEXTDOWN_FLOAT; + /** nextDown(x). */ + private static final DoubleUnaryOperator NEXTDOWN_DOUBLE; + /** nextUp(x). */ + private static final FloatUnaryOperator NEXTUP_FLOAT; + /** nextUp(x). */ + private static final DoubleUnaryOperator NEXTUP_DOUBLE; + /** pow(x, y). */ + private static final DoubleBinaryOperator POW; + /** random(). */ + private static final DoubleSupplier RANDOM; + /** rint(x). */ + private static final DoubleUnaryOperator RINT; + /** round(x). */ + private static final DoubleToLongFunction ROUND_DOUBLE; + /** round(x). */ + private static final FloatToIntFunction ROUND_FLOAT; + /** scalb(x, y). */ + private static final DoubleInt2DoubleOperator SCALB_DOUBLE; + /** scalb(x, y). */ + private static final FloatInt2FloatOperator SCALB_FLOAT; + /** signum(x). */ + private static final FloatUnaryOperator SIGNUM_FLOAT; + /** signum(x). */ + private static final DoubleUnaryOperator SIGNUM_DOUBLE; + /** sin(x). */ + private static final DoubleUnaryOperator SIN; + /** sinh(x). */ + private static final DoubleUnaryOperator SINH; + /** sqrt(x). */ + private static final DoubleUnaryOperator SQRT; + /** subtractExact(x, y). */ + private static final IntBinaryOperator SUBTRACTEXACT_INT; + /** subtractExact(x, y). */ + private static final LongBinaryOperator SUBTRACTEXACT_LONG; + /** tan(x). */ + private static final DoubleUnaryOperator TAN; + /** tanh(x). */ + private static final DoubleUnaryOperator TANH; + /** toDegrees(x). */ + private static final DoubleUnaryOperator TODEGREES; + /** toIntExact(x). */ + private static final LongToIntFunction TOINTEXACT; + /** toRadians(x). */ + private static final DoubleUnaryOperator TORADIANS; + /** ulp(x). */ + private static final DoubleUnaryOperator ULP_DOUBLE; + /** ulp(x). */ + private static final FloatUnaryOperator ULP_FLOAT; + + /** Available implementations of {@link Math} functions. */ + public enum Impl { + /** {@link AccurateMath Commons Math}. */ + CM, + /** {@link Math JDK}. */ + JDK + } + + static { + final String prop = System.getProperty(PROPERTY_KEY); + final Impl impl = prop != null ? + Impl.valueOf(prop) : + Impl.CM; + + + switch (impl) { + case CM: + PI = AccurateMath.PI; + E = AccurateMath.E; + ABS_INT = AccurateMath::abs; + ABS_LONG = AccurateMath::abs; + ABS_FLOAT = AccurateMath::abs; + ABS_DOUBLE = AccurateMath::abs; + ACOS = AccurateMath::acos; + ACOSH = AccurateMath::acosh; + ADDEXACT_INT = AccurateMath::addExact; + ADDEXACT_LONG = AccurateMath::addExact; + ASIN = AccurateMath::asin; + ASINH = AccurateMath::asinh; + ATAN = AccurateMath::atan; + ATAN2 = AccurateMath::atan2; + ATANH = AccurateMath::atanh; + CBRT = AccurateMath::cbrt; + CEIL = AccurateMath::ceil; + COPYSIGN_FLOAT = AccurateMath::copySign; + COPYSIGN_DOUBLE = AccurateMath::copySign; + COS = AccurateMath::cos; + COSH = AccurateMath::cosh; + DECREMENTEXACT_INT = AccurateMath::decrementExact; + DECREMENTEXACT_LONG = AccurateMath::decrementExact; + EXP = AccurateMath::exp; + EXPM1 = AccurateMath::expm1; + FLOOR = AccurateMath::floor; + FLOORDIV_INT = AccurateMath::floorDiv; + FLOORDIV_LONG = AccurateMath::floorDiv; + FLOORMOD_INT = AccurateMath::floorMod; + FLOORMOD_LONG = AccurateMath::floorMod; + GETEXPONENT_FLOAT = AccurateMath::getExponent; + GETEXPONENT_DOUBLE = AccurateMath::getExponent; + HYPOT = AccurateMath::hypot; + IEEEREMAINDER = AccurateMath::IEEEremainder; + INCREMENTEXACT_INT = AccurateMath::incrementExact; + INCREMENTEXACT_LONG = AccurateMath::incrementExact; + LOG = AccurateMath::log; + LOG10 = AccurateMath::log10; + LOG1P = AccurateMath::log1p; + MAX_INT = AccurateMath::max; + MAX_LONG = AccurateMath::max; + MAX_FLOAT = AccurateMath::max; + MAX_DOUBLE = AccurateMath::max; + MIN_INT = AccurateMath::min; + MIN_LONG = AccurateMath::min; + MIN_FLOAT = AccurateMath::min; + MIN_DOUBLE = AccurateMath::min; + MULTIPLYEXACT_INT = AccurateMath::multiplyExact; + MULTIPLYEXACT_LONG = AccurateMath::multiplyExact; + NEGATEEXACT_INT = Math::negateExact; // Not implemented. + NEGATEEXACT_LONG = Math::negateExact; // Not implemented. + NEXTAFTER_FLOAT = AccurateMath::nextAfter; + NEXTAFTER_DOUBLE = AccurateMath::nextAfter; + NEXTDOWN_FLOAT = AccurateMath::nextDown; + NEXTDOWN_DOUBLE = AccurateMath::nextDown; + NEXTUP_FLOAT = AccurateMath::nextUp; + NEXTUP_DOUBLE = AccurateMath::nextUp; + POW = AccurateMath::pow; + RANDOM = AccurateMath::random; + RINT = AccurateMath::rint; + ROUND_DOUBLE = AccurateMath::round; + ROUND_FLOAT = AccurateMath::round; + SCALB_DOUBLE = AccurateMath::scalb; + SCALB_FLOAT = AccurateMath::scalb; + SIGNUM_DOUBLE = AccurateMath::signum; + SIGNUM_FLOAT = AccurateMath::signum; + SQRT = AccurateMath::sqrt; + SIN = AccurateMath::sin; + SINH = AccurateMath::sinh; + SUBTRACTEXACT_INT = AccurateMath::subtractExact; + SUBTRACTEXACT_LONG = AccurateMath::subtractExact; + TAN = AccurateMath::tan; + TANH = AccurateMath::tanh; + TODEGREES = AccurateMath::toDegrees; + TOINTEXACT = AccurateMath::toIntExact; + TORADIANS = AccurateMath::toRadians; + ULP_DOUBLE = AccurateMath::ulp; + ULP_FLOAT = AccurateMath::ulp; + break; + + case JDK: + PI = Math.PI; + E = Math.E; + ABS_INT = Math::abs; + ABS_LONG = Math::abs; + ABS_FLOAT = Math::abs; + ABS_DOUBLE = Math::abs; + ACOS = Math::acos; + ACOSH = AccurateMath::acosh; // Not implemented. + ADDEXACT_INT = Math::addExact; + ADDEXACT_LONG = Math::addExact; + ASIN = Math::asin; + ASINH = AccurateMath::asinh; // Not implemented. + ATAN = Math::atan; + ATAN2 = Math::atan2; + ATANH = AccurateMath::atanh; // Not implemented. + CBRT = Math::cbrt; + CEIL = Math::ceil; + COPYSIGN_FLOAT = Math::copySign; + COPYSIGN_DOUBLE = Math::copySign; + COS = Math::cos; + COSH = Math::cosh; + DECREMENTEXACT_INT = Math::decrementExact; + DECREMENTEXACT_LONG = Math::decrementExact; + EXP = Math::exp; + EXPM1 = Math::expm1; + FLOOR = Math::floor; + FLOORDIV_INT = Math::floorDiv; + FLOORDIV_LONG = Math::floorDiv; + FLOORMOD_INT = Math::floorMod; + FLOORMOD_LONG = Math::floorMod; + GETEXPONENT_FLOAT = Math::getExponent; + GETEXPONENT_DOUBLE = Math::getExponent; + HYPOT = Math::hypot; + IEEEREMAINDER = Math::IEEEremainder; + INCREMENTEXACT_INT = Math::incrementExact; + INCREMENTEXACT_LONG = Math::incrementExact; + LOG = Math::log; + LOG10 = Math::log10; + LOG1P = Math::log1p; + MAX_INT = Math::max; + MAX_LONG = Math::max; + MAX_FLOAT = Math::max; + MAX_DOUBLE = Math::max; + MIN_INT = Math::min; + MIN_LONG = Math::min; + MIN_FLOAT = Math::min; + MIN_DOUBLE = Math::min; + MULTIPLYEXACT_INT = Math::multiplyExact; + MULTIPLYEXACT_LONG = Math::multiplyExact; + NEGATEEXACT_INT = Math::negateExact; + NEGATEEXACT_LONG = Math::negateExact; + NEXTAFTER_FLOAT = Math::nextAfter; + NEXTAFTER_DOUBLE = Math::nextAfter; + NEXTDOWN_FLOAT = Math::nextDown; + NEXTDOWN_DOUBLE = Math::nextDown; + NEXTUP_FLOAT = Math::nextUp; + NEXTUP_DOUBLE = Math::nextUp; + POW = Math::pow; + RANDOM = Math::random; + RINT = Math::rint; + ROUND_DOUBLE = Math::round; + ROUND_FLOAT = Math::round; + SCALB_DOUBLE = Math::scalb; + SCALB_FLOAT = Math::scalb; + SIGNUM_DOUBLE = Math::signum; + SIGNUM_FLOAT = Math::signum; + SIN = Math::sin; + SINH = Math::sinh; + SQRT = Math::sqrt; + SUBTRACTEXACT_INT = Math::subtractExact; + SUBTRACTEXACT_LONG = Math::subtractExact; + TAN = Math::tan; + TANH = Math::tanh; + TODEGREES = Math::toDegrees; + TOINTEXACT = Math::toIntExact; + TORADIANS = Math::toRadians; + ULP_DOUBLE = Math::ulp; + ULP_FLOAT = Math::ulp; + break; + + default: + throw new IllegalStateException("Internal error"); // Should never happen. + } + } + + /** Utility class. */ + private JdkMath() {} + + /** + * @param x Number. + * @return abs(x). + */ + public static int abs(int x) { + return ABS_INT.applyAsInt(x); + } + + /** + * @param x Number. + * @return abs(x). + */ + public static long abs(long x) { + return ABS_LONG.applyAsLong(x); + } + + /** + * @param x Number. + * @return abs(x). + */ + public static float abs(float x) { + return ABS_FLOAT.applyAsFloat(x); + } + + /** + * @param x Number. + * @return abs(x). + */ + public static double abs(double x) { + return ABS_DOUBLE.applyAsDouble(x); + } + + /** + * @param x Number. + * @return acos(x). + */ + public static double acos(double x) { + return ACOS.applyAsDouble(x); + } + + /** + * @param x Number. + * @return acosh(x). + */ + public static double acosh(double x) { + return ACOSH.applyAsDouble(x); + } + + /** + * @param x Number. + * @param y Number. + * @return addExact(x, y). + */ + public static int addExact(int x, + int y) { + return ADDEXACT_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return addExact(x, y). + */ + public static long addExact(long x, + long y) { + return ADDEXACT_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @return asin(x). + */ + public static double asin(double x) { + return ASIN.applyAsDouble(x); + } + + /** + * @param x Number. + * @return asinh(x). + */ + public static double asinh(double x) { + return ASINH.applyAsDouble(x); + } + + /** + * @param x Number. + * @return asin(x). + */ + public static double atan(double x) { + return ATAN.applyAsDouble(x); + } + + /** + * @param y Number. + * @param x Number. + * @return atan2(y, x). + */ + public static double atan2(double y, + double x) { + return ATAN2.applyAsDouble(y, x); + } + + /** + * @param x Number. + * @return atanh(x). + */ + public static double atanh(double x) { + return ATANH.applyAsDouble(x); + } + + /** + * @param x Number. + * @return cbrt(x). + */ + public static double cbrt(double x) { + return CBRT.applyAsDouble(x); + } + + /** + * @param x Number. + * @return ceil(x). + */ + public static double ceil(double x) { + return CEIL.applyAsDouble(x); + } + + /** + * @param x Number. + * @param y Number. + * @return copySign(x, y). + */ + public static float copySign(float x, + float y) { + return COPYSIGN_FLOAT.applyAsFloat(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return copySign(x, y). + */ + public static double copySign(double x, + double y) { + return COPYSIGN_DOUBLE.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @return cos(x). + */ + public static double cos(double x) { + return COS.applyAsDouble(x); + } + + /** + * @param x Number. + * @return cosh(x). + */ + public static double cosh(double x) { + return COSH.applyAsDouble(x); + } + + /** + * @param x Number. + * @return decrementExact(x). + */ + public static int decrementExact(int x) { + return DECREMENTEXACT_INT.applyAsInt(x); + } + + /** + * @param x Number. + * @return decrementExact(x). + */ + public static long decrementExact(long x) { + return DECREMENTEXACT_LONG.applyAsLong(x); + } + + /** + * @param x Number. + * @return exp(x). + */ + public static double exp(double x) { + return EXP.applyAsDouble(x); + } + + /** + * @param x Number. + * @return expm1(x). + */ + public static double expm1(double x) { + return EXPM1.applyAsDouble(x); + } + + /** + * @param x Number. + * @return floor(x). + */ + public static double floor(double x) { + return FLOOR.applyAsDouble(x); + } + + /** + * @param x Number. + * @param y Number. + * @return floorDiv(x, y). + */ + public static int floorDiv(int x, + int y) { + return FLOORDIV_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return floorDiv(x, y). + */ + public static long floorDiv(long x, + long y) { + return FLOORDIV_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return floorMod(x, y). + */ + public static int floorMod(int x, + int y) { + return FLOORMOD_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return floorMod(x, y). + */ + public static long floorMod(long x, + long y) { + return FLOORMOD_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @return getExponent(x). + */ + public static int getExponent(float x) { + return GETEXPONENT_FLOAT.applyAsInt(x); + } + + /** + * @param x Number. + * @return getExponent(x). + */ + public static int getExponent(double x) { + return GETEXPONENT_DOUBLE.applyAsInt(x); + } + + /** + * @param x Number. + * @param y Number. + * @return hypot(x, y). + */ + public static double hypot(double x, + double y) { + return HYPOT.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return IEEEremainder(x, y). + */ + public static double IEEEremainder(double x, + double y) { + return IEEEREMAINDER.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @return incrementExact(x). + */ + public static int incrementExact(int x) { + return INCREMENTEXACT_INT.applyAsInt(x); + } + + /** + * @param x Number. + * @return incrementExact(x). + */ + public static long incrementExact(long x) { + return INCREMENTEXACT_LONG.applyAsLong(x); + } + + /** + * @param x Number. + * @return log(x). + */ + public static double log(double x) { + return LOG.applyAsDouble(x); + } + + /** + * @param x Number. + * @return log10(x). + */ + public static double log10(double x) { + return LOG10.applyAsDouble(x); + } + + /** + * @param x Number. + * @return log1p(x). + */ + public static double log1p(double x) { + return LOG1P.applyAsDouble(x); + } + + /** + * @param x Number. + * @param y Number. + * @return max(x, y). + */ + public static int max(int x, + int y) { + return MAX_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return max(x, y). + */ + public static long max(long x, + long y) { + return MAX_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return max(x, y). + */ + public static float max(float x, + float y) { + return MAX_FLOAT.applyAsFloat(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return max(x, y). + */ + public static double max(double x, + double y) { + return MAX_DOUBLE.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return min(x, y). + */ + public static int min(int x, + int y) { + return MIN_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return min(x, y). + */ + public static long min(long x, + long y) { + return MIN_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return min(x, y). + */ + public static float min(float x, + float y) { + return MIN_FLOAT.applyAsFloat(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return min(x, y). + */ + public static double min(double x, + double y) { + return MIN_DOUBLE.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return multiplyExact(x, y). + */ + public static int multiplyExact(int x, + int y) { + return MULTIPLYEXACT_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return multiplyExact(x, y). + */ + public static long multiplyExact(long x, + long y) { + return MULTIPLYEXACT_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @return negateExact(x). + */ + public static int negateExact(int x) { + return NEGATEEXACT_INT.applyAsInt(x); + } + + /** + * @param x Number. + * @return negateExact(x). + */ + public static long negateExact(long x) { + return NEGATEEXACT_LONG.applyAsLong(x); + } + + /** + * @param x Number. + * @param y Number. + * @return nextAfter(x, y). + */ + public static double nextAfter(double x, + double y) { + return NEXTAFTER_DOUBLE.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return nextAfter(x, y). + */ + public static float nextAfter(float x, + double y) { + return NEXTAFTER_FLOAT.applyAsFloat(x, y); + } + + /** + * @param x Number. + * @return nextDown(x). + */ + public static double nextDown(double x) { + return NEXTDOWN_DOUBLE.applyAsDouble(x); + } + + /** + * @param x Number. + * @return nextDown(x). + */ + public static float nextDown(float x) { + return NEXTDOWN_FLOAT.applyAsFloat(x); + } + + /** + * @param x Number. + * @return nextUp(x). + */ + public static double nextUp(double x) { + return NEXTUP_DOUBLE.applyAsDouble(x); + } + + /** + * @param x Number. + * @return nextUp(x). + */ + public static float nextUp(float x) { + return NEXTUP_FLOAT.applyAsFloat(x); + } + + /** + * @param x Number. + * @param y Number. + * @return pow(x, y). + */ + public static double pow(double x, + double y) { + return POW.applyAsDouble(x, y); + } + + /** + * @return a random number between 0 and 1. + */ + public static double random() { + return RANDOM.getAsDouble(); + } + + /** + * @param x Number. + * @return rint(x). + */ + public static double rint(double x) { + return RINT.applyAsDouble(x); + } + + /** + * @param x Number. + * @return round(x). + */ + public static int round(float x) { + return ROUND_FLOAT.applyAsInt(x); + } + + /** + * @param x Number. + * @return round(x). + */ + public static long round(double x) { + return ROUND_DOUBLE.applyAsLong(x); + } + + /** + * @param x Number. + * @param y Number. + * @return scalb(x, y). + */ + public static double scalb(double x, + int y) { + return SCALB_DOUBLE.applyAsDouble(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return scalb(x, y). + */ + public static float scalb(float x, + int y) { + return SCALB_FLOAT.applyAsFloat(x, y); + } + + /** + * @param x Number. + * @return signum(x). + */ + public static double signum(double x) { + return SIGNUM_DOUBLE.applyAsDouble(x); + } + + /** + * @param x Number. + * @return signum(x). + */ + public static float signum(float x) { + return SIGNUM_FLOAT.applyAsFloat(x); + } + + /** + * @param x Number. + * @return sin(x). + */ + public static double sin(double x) { + return SIN.applyAsDouble(x); + } + + /** + * @param x Number. + * @return sinh(x). + */ + public static double sinh(double x) { + return SINH.applyAsDouble(x); + } + + /** + * @param x Number. + * @return sqrt(x). + */ + public static double sqrt(double x) { + return SQRT.applyAsDouble(x); + } + + /** + * @param x Number. + * @param y Number. + * @return subtractExact(x, y). + */ + public static int subtractExact(int x, + int y) { + return SUBTRACTEXACT_INT.applyAsInt(x, y); + } + + /** + * @param x Number. + * @param y Number. + * @return subtractExact(x, y). + */ + public static long subtractExact(long x, + long y) { + return SUBTRACTEXACT_LONG.applyAsLong(x, y); + } + + /** + * @param x Number. + * @return tan(x). + */ + public static double tan(double x) { + return TAN.applyAsDouble(x); + } + + /** + * @param x Number. + * @return tanh(x). + */ + public static double tanh(double x) { + return TANH.applyAsDouble(x); + } + + /** + * @param x Number. + * @return toDegrees(x). + */ + public static double toDegrees(double x) { + return TODEGREES.applyAsDouble(x); + } + + /** + * @param x Number. + * @return toIntExact(x). + */ + public static int toIntExact(long x) { + return TOINTEXACT.applyAsInt(x); + } + + /** + * @param x Number. + * @return toRadians(x). + */ + public static double toRadians(double x) { + return TORADIANS.applyAsDouble(x); + } + + /** + * @param x Number. + * @return ulp(x). + */ + public static double ulp(double x) { + return ULP_DOUBLE.applyAsDouble(x); + } + + /** + * @param x Number. + * @return ulp(x). + */ + public static float ulp(float x) { + return ULP_FLOAT.applyAsFloat(x); + } + + /** Interface missing from "java.util.function" package. */ + private interface FloatUnaryOperator { + /** + * @param x Operand. + * @return the result of applying this operator. + */ + float applyAsFloat(float x); + } + + /** Interface missing from "java.util.function" package. */ + private interface FloatBinaryOperator { + /** + * @param x Operand. + * @param y Operand. + * @return the result of applying this operator. + */ + float applyAsFloat(float x, float y); + } + + /** Interface missing from "java.util.function" package. */ + private interface FloatDouble2FloatOperator { + /** + * @param x Operand. + * @param y Operand. + * @return the result of applying this operator. + */ + float applyAsFloat(float x, double y); + } + + /** Interface missing from "java.util.function" package. */ + private interface FloatToIntFunction { + /** + * @param x Operand. + * @return the result of applying this operator. + */ + int applyAsInt(float x); + } + + /** Interface missing from "java.util.function" package. */ + private interface FloatInt2FloatOperator { + /** + * @param x Operand. + * @param y Operand. + * @return the result of applying this operator. + */ + float applyAsFloat(float x, int y); + } + + /** Interface missing from "java.util.function" package. */ + private interface DoubleInt2DoubleOperator { + /** + * @param x Operand. + * @param y Operand. + * @return the result of applying this operator. + */ + double applyAsDouble(double x, int y); + } +} diff --git a/commons-math-legacy-core/pom.xml b/commons-math-legacy-core/pom.xml index 01110e64a..759734d64 100644 --- a/commons-math-legacy-core/pom.xml +++ b/commons-math-legacy-core/pom.xml @@ -44,6 +44,11 @@ + + org.apache.commons + commons-math4-core + + org.apache.commons commons-math4-legacy-exception diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java index d92362b55..7b4284b8f 100644 --- a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java @@ -35,7 +35,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Arrays utilities. @@ -192,7 +192,7 @@ public final class MathArrays { checkEqualLength(p1, p2); double sum = 0; for (int i = 0; i < p1.length; i++) { - sum += AccurateMath.abs(p1[i] - p2[i]); + sum += JdkMath.abs(p1[i] - p2[i]); } return sum; } @@ -209,7 +209,7 @@ public final class MathArrays { checkEqualLength(p1, p2); int sum = 0; for (int i = 0; i < p1.length; i++) { - sum += AccurateMath.abs(p1[i] - p2[i]); + sum += JdkMath.abs(p1[i] - p2[i]); } return sum; } @@ -229,7 +229,7 @@ public final class MathArrays { final double dp = p1[i] - p2[i]; sum += dp * dp; } - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } /** @@ -247,7 +247,7 @@ public final class MathArrays { final double dp = (double) p1[i] - p2[i]; sum += dp * dp; } - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } /** @@ -262,7 +262,7 @@ public final class MathArrays { checkEqualLength(p1, p2); double max = 0; for (int i = 0; i < p1.length; i++) { - max = AccurateMath.max(max, AccurateMath.abs(p1[i] - p2[i])); + max = JdkMath.max(max, JdkMath.abs(p1[i] - p2[i])); } return max; } @@ -279,7 +279,7 @@ public final class MathArrays { checkEqualLength(p1, p2); int max = 0; for (int i = 0; i < p1.length; i++) { - max = AccurateMath.max(max, AccurateMath.abs(p1[i] - p2[i])); + max = JdkMath.max(max, JdkMath.abs(p1[i] - p2[i])); } return max; } @@ -845,7 +845,7 @@ public final class MathArrays { // straightforward implementation of the convolution sum for (int n = 0; n < totalLength; n++) { double yn = 0; - int k = AccurateMath.max(0, n + 1 - xLen); + int k = JdkMath.max(0, n + 1 - xLen); int j = n - k; while (k < hLen && j >= 0) { yn += x[j--] * h[k++]; diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java index c2bb57ee2..4f1f358ac 100644 --- a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.apache.commons.numbers.core.Sum; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; public abstract class ExtendedFieldElementAbstractTest> { @@ -113,7 +113,7 @@ public abstract class ExtendedFieldElementAbstractTest { DfpField localField = new DfpField(100); Assert.assertEquals(0.0, localField.getZero().toDouble(), Precision.SAFE_MIN); Assert.assertEquals(0.0, localField.newDfp(0.0).toDouble(), Precision.SAFE_MIN); - Assert.assertEquals(-1, AccurateMath.copySign(1, localField.newDfp(-0.0).toDouble()), Precision.EPSILON); - Assert.assertEquals(+1, AccurateMath.copySign(1, localField.newDfp(+0.0).toDouble()), Precision.EPSILON); + Assert.assertEquals(-1, JdkMath.copySign(1, localField.newDfp(-0.0).toDouble()), Precision.EPSILON); + Assert.assertEquals(+1, JdkMath.copySign(1, localField.newDfp(+0.0).toDouble()), Precision.EPSILON); } @Test diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java index baf2b3a43..7714e234f 100644 --- a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java @@ -31,6 +31,10 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +// Unit test should be moved to module "commons-math-core". +// [Currently, it can't be because it depends on "legacy" classes.] +import org.apache.commons.math4.core.jdkmath.AccurateMath; + /** * Test to compare AccurateMath results against StrictMath results for boundary values. *

diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java index 27752114f..fbfe40c92 100644 --- a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java @@ -40,9 +40,13 @@ import org.apache.commons.math4.legacy.core.dfp.DfpMath; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; +// Unit test should be moved to module "commons-math-core". +// [Currently, it can't be because it depends on "legacy" classes.] +import org.apache.commons.math4.core.jdkmath.AccurateMath; + public class AccurateMathTest { // CHECKSTYLE: stop Regexp - // The above comment allowa System.out.print + // The above comment allows System.out.print private static final double MAX_ERROR_ULP = 0.51; private static final int NUMBER_OF_TRIALS = 1000; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java index dc1931902..6d85b986d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.MathInternalError; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.numbers.combinatorics.FactorialDouble; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** Class holding "compiled" computation rules for derivative structures. *

This class implements the computation rules described in Dan Kalman's paper 0; --i) { function[i] = xk; xk *= operand[operandOffset]; @@ -947,8 +947,8 @@ public final class DSCompiler { if (n > 0) { // strictly positive power - final int maxOrder = AccurateMath.min(order, n); - double xk = AccurateMath.pow(operand[operandOffset], n - maxOrder); + final int maxOrder = JdkMath.min(order, n); + double xk = JdkMath.pow(operand[operandOffset], n - maxOrder); for (int i = maxOrder; i > 0; --i) { function[i] = xk; xk *= operand[operandOffset]; @@ -957,7 +957,7 @@ public final class DSCompiler { } else { // strictly negative power final double inv = 1.0 / operand[operandOffset]; - double xk = AccurateMath.pow(inv, -n); + double xk = JdkMath.pow(inv, -n); for (int i = 0; i <= order; ++i) { function[i] = xk; xk *= inv; @@ -1012,14 +1012,14 @@ public final class DSCompiler { double[] function = new double[1 + order]; double xk; if (n == 2) { - function[0] = AccurateMath.sqrt(operand[operandOffset]); + function[0] = JdkMath.sqrt(operand[operandOffset]); xk = 0.5 / function[0]; } else if (n == 3) { - function[0] = AccurateMath.cbrt(operand[operandOffset]); + function[0] = JdkMath.cbrt(operand[operandOffset]); xk = 1.0 / (3.0 * function[0] * function[0]); } else { - function[0] = AccurateMath.pow(operand[operandOffset], 1.0 / n); - xk = 1.0 / (n * AccurateMath.pow(function[0], n - 1)); + function[0] = JdkMath.pow(operand[operandOffset], 1.0 / n); + xk = 1.0 / (n * JdkMath.pow(function[0], n - 1)); } final double nReciprocal = 1.0 / n; final double xReciprocal = 1.0 / operand[operandOffset]; @@ -1046,7 +1046,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - Arrays.fill(function, AccurateMath.exp(operand[operandOffset])); + Arrays.fill(function, JdkMath.exp(operand[operandOffset])); // apply function composition compose(operand, operandOffset, function, result, resultOffset); @@ -1066,8 +1066,8 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.expm1(operand[operandOffset]); - Arrays.fill(function, 1, 1 + order, AccurateMath.exp(operand[operandOffset])); + function[0] = JdkMath.expm1(operand[operandOffset]); + Arrays.fill(function, 1, 1 + order, JdkMath.exp(operand[operandOffset])); // apply function composition compose(operand, operandOffset, function, result, resultOffset); @@ -1087,7 +1087,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.log(operand[operandOffset]); + function[0] = JdkMath.log(operand[operandOffset]); if (order > 0) { double inv = 1.0 / operand[operandOffset]; double xk = inv; @@ -1114,7 +1114,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.log1p(operand[operandOffset]); + function[0] = JdkMath.log1p(operand[operandOffset]); if (order > 0) { double inv = 1.0 / (1.0 + operand[operandOffset]); double xk = inv; @@ -1141,10 +1141,10 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.log10(operand[operandOffset]); + function[0] = JdkMath.log10(operand[operandOffset]); if (order > 0) { double inv = 1.0 / operand[operandOffset]; - double xk = inv / AccurateMath.log(10.0); + double xk = inv / JdkMath.log(10.0); for (int i = 1; i <= order; ++i) { function[i] = xk; xk *= -i * inv; @@ -1169,9 +1169,9 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.cos(operand[operandOffset]); + function[0] = JdkMath.cos(operand[operandOffset]); if (order > 0) { - function[1] = -AccurateMath.sin(operand[operandOffset]); + function[1] = -JdkMath.sin(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } @@ -1195,9 +1195,9 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.sin(operand[operandOffset]); + function[0] = JdkMath.sin(operand[operandOffset]); if (order > 0) { - function[1] = AccurateMath.cos(operand[operandOffset]); + function[1] = JdkMath.cos(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } @@ -1221,7 +1221,7 @@ public final class DSCompiler { // create the function value and derivatives final double[] function = new double[1 + order]; - final double t = AccurateMath.tan(operand[operandOffset]); + final double t = JdkMath.tan(operand[operandOffset]); function[0] = t; if (order > 0) { @@ -1277,7 +1277,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = AccurateMath.acos(x); + function[0] = JdkMath.acos(x); if (order > 0) { // the nth order derivative of acos has the form: // dn(acos(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2) @@ -1290,7 +1290,7 @@ public final class DSCompiler { p[0] = -1; final double x2 = x * x; final double f = 1.0 / (1 - x2); - double coeff = AccurateMath.sqrt(f); + double coeff = JdkMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1334,7 +1334,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = AccurateMath.asin(x); + function[0] = JdkMath.asin(x); if (order > 0) { // the nth order derivative of asin has the form: // dn(asin(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2) @@ -1347,7 +1347,7 @@ public final class DSCompiler { p[0] = 1; final double x2 = x * x; final double f = 1.0 / (1 - x2); - double coeff = AccurateMath.sqrt(f); + double coeff = JdkMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1391,7 +1391,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = AccurateMath.atan(x); + function[0] = JdkMath.atan(x); if (order > 0) { // the nth order derivative of atan has the form: // dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n @@ -1473,7 +1473,7 @@ public final class DSCompiler { divide(y, yOffset, tmp2, 0, tmp1, 0); // y /(r - x) atan(tmp1, 0, tmp2, 0); // atan(y / (r - x)) result[resultOffset] = - ((tmp2[0] <= 0) ? -AccurateMath.PI : AccurateMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x)) + ((tmp2[0] <= 0) ? -JdkMath.PI : JdkMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x)) for (int i = 1; i < tmp2.length; ++i) { result[resultOffset + i] = -2 * tmp2[i]; // +/-pi - 2 * atan(y / (r - x)) } @@ -1481,7 +1481,7 @@ public final class DSCompiler { } // fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly - result[resultOffset] = AccurateMath.atan2(y[yOffset], x[xOffset]); + result[resultOffset] = JdkMath.atan2(y[yOffset], x[xOffset]); } @@ -1498,9 +1498,9 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.cosh(operand[operandOffset]); + function[0] = JdkMath.cosh(operand[operandOffset]); if (order > 0) { - function[1] = AccurateMath.sinh(operand[operandOffset]); + function[1] = JdkMath.sinh(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = function[i - 2]; } @@ -1524,9 +1524,9 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = AccurateMath.sinh(operand[operandOffset]); + function[0] = JdkMath.sinh(operand[operandOffset]); if (order > 0) { - function[1] = AccurateMath.cosh(operand[operandOffset]); + function[1] = JdkMath.cosh(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = function[i - 2]; } @@ -1550,7 +1550,7 @@ public final class DSCompiler { // create the function value and derivatives final double[] function = new double[1 + order]; - final double t = AccurateMath.tanh(operand[operandOffset]); + final double t = JdkMath.tanh(operand[operandOffset]); function[0] = t; if (order > 0) { @@ -1606,7 +1606,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = AccurateMath.acosh(x); + function[0] = JdkMath.acosh(x); if (order > 0) { // the nth order derivative of acosh has the form: // dn(acosh(x)/dxn = P_n(x) / [x^2 - 1]^((2n-1)/2) @@ -1619,7 +1619,7 @@ public final class DSCompiler { p[0] = 1; final double x2 = x * x; final double f = 1.0 / (x2 - 1); - double coeff = AccurateMath.sqrt(f); + double coeff = JdkMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1663,7 +1663,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = AccurateMath.asinh(x); + function[0] = JdkMath.asinh(x); if (order > 0) { // the nth order derivative of asinh has the form: // dn(asinh(x)/dxn = P_n(x) / [x^2 + 1]^((2n-1)/2) @@ -1676,7 +1676,7 @@ public final class DSCompiler { p[0] = 1; final double x2 = x * x; final double f = 1.0 / (1 + x2); - double coeff = AccurateMath.sqrt(f); + double coeff = JdkMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1720,7 +1720,7 @@ public final class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = AccurateMath.atanh(x); + function[0] = JdkMath.atanh(x); if (order > 0) { // the nth order derivative of atanh has the form: // dn(atanh(x)/dxn = Q_n(x) / (1 - x^2)^n @@ -1806,7 +1806,7 @@ public final class DSCompiler { for (int k = 0; k < orders.length; ++k) { if (orders[k] > 0) { try { - term *= AccurateMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]); + term *= JdkMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]); } catch (NotPositiveException e) { // this cannot happen throw new MathInternalError(e); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java index 11fc04d65..66c52b797 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** Class representing both the value and the differentials of a function. @@ -389,7 +389,7 @@ public class DerivativeStructure implements RealFieldElement @@ -156,7 +156,7 @@ public class FiniteDifferencesDifferentiator if (2 * halfSampleSpan >= tUpper - tLower) { throw new NumberIsTooLargeException(2 * halfSampleSpan, tUpper - tLower, false); } - final double safety = AccurateMath.ulp(halfSampleSpan); + final double safety = JdkMath.ulp(halfSampleSpan); this.tMin = tLower + halfSampleSpan + safety; this.tMax = tUpper - halfSampleSpan - safety; @@ -262,7 +262,7 @@ public class FiniteDifferencesDifferentiator } // compute sample position, trying to be centered if possible - final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; + final double t0 = JdkMath.max(JdkMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points final double[] y = new double[nbPoints]; @@ -305,7 +305,7 @@ public class FiniteDifferencesDifferentiator } // compute sample position, trying to be centered if possible - final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; + final double t0 = JdkMath.max(JdkMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points double[][] y = null; @@ -359,7 +359,7 @@ public class FiniteDifferencesDifferentiator } // compute sample position, trying to be centered if possible - final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; + final double t0 = JdkMath.max(JdkMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points double[][][] y = null; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java index 7e71c6dcb..7f7714a2e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java @@ -26,7 +26,7 @@ import org.apache.commons.numbers.core.Precision; import org.apache.commons.math4.legacy.core.Field; import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.core.RealFieldElement; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * First derivative computation with large number of variables. @@ -328,7 +328,7 @@ public final class SparseGradient implements RealFieldElement, S /** {@inheritDoc} */ @Override public SparseGradient remainder(final double a) { - return new SparseGradient(AccurateMath.IEEEremainder(value, a), derivatives); + return new SparseGradient(JdkMath.IEEEremainder(value, a), derivatives); } /** {@inheritDoc} */ @@ -336,8 +336,8 @@ public final class SparseGradient implements RealFieldElement, S public SparseGradient remainder(final SparseGradient a) { // compute k such that lhs % rhs = lhs - k rhs - final double rem = AccurateMath.IEEEremainder(value, a.value); - final double k = AccurateMath.rint((value - rem) / a.value); + final double rem = JdkMath.IEEEremainder(value, a.value); + final double k = JdkMath.rint((value - rem) / a.value); return subtract(a.multiply(k)); @@ -357,31 +357,31 @@ public final class SparseGradient implements RealFieldElement, S /** {@inheritDoc} */ @Override public SparseGradient ceil() { - return createConstant(AccurateMath.ceil(value)); + return createConstant(JdkMath.ceil(value)); } /** {@inheritDoc} */ @Override public SparseGradient floor() { - return createConstant(AccurateMath.floor(value)); + return createConstant(JdkMath.floor(value)); } /** {@inheritDoc} */ @Override public SparseGradient rint() { - return createConstant(AccurateMath.rint(value)); + return createConstant(JdkMath.rint(value)); } /** {@inheritDoc} */ @Override public long round() { - return AccurateMath.round(value); + return JdkMath.round(value); } /** {@inheritDoc} */ @Override public SparseGradient signum() { - return createConstant(AccurateMath.signum(value)); + return createConstant(JdkMath.signum(value)); } /** {@inheritDoc} */ @@ -409,9 +409,9 @@ public final class SparseGradient implements RealFieldElement, S /** {@inheritDoc} */ @Override public SparseGradient scalb(final int n) { - final SparseGradient out = new SparseGradient(AccurateMath.scalb(value, n), Collections.emptyMap()); + final SparseGradient out = new SparseGradient(JdkMath.scalb(value, n), Collections.emptyMap()); for (Map.Entry entry : derivatives.entrySet()) { - out.derivatives.put(entry.getKey(), AccurateMath.scalb(entry.getValue(), n)); + out.derivatives.put(entry.getKey(), JdkMath.scalb(entry.getValue(), n)); } return out; } @@ -425,8 +425,8 @@ public final class SparseGradient implements RealFieldElement, S return createConstant(Double.NaN); } else { - final int expX = AccurateMath.getExponent(value); - final int expY = AccurateMath.getExponent(y.value); + final int expX = JdkMath.getExponent(value); + final int expY = JdkMath.getExponent(y.value); if (expX > expY + 27) { // y is negligible with respect to x return abs(); @@ -481,14 +481,14 @@ public final class SparseGradient implements RealFieldElement, S /** {@inheritDoc} */ @Override public SparseGradient sqrt() { - final double sqrt = AccurateMath.sqrt(value); + final double sqrt = JdkMath.sqrt(value); return new SparseGradient(sqrt, 0.5 / sqrt, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient cbrt() { - final double cbrt = AccurateMath.cbrt(value); + final double cbrt = JdkMath.cbrt(value); return new SparseGradient(cbrt, 1.0 / (3 * cbrt * cbrt), derivatives); } @@ -500,15 +500,15 @@ public final class SparseGradient implements RealFieldElement, S } else if (n == 3) { return cbrt(); } else { - final double root = AccurateMath.pow(value, 1.0 / n); - return new SparseGradient(root, 1.0 / (n * AccurateMath.pow(root, n - 1)), derivatives); + final double root = JdkMath.pow(value, 1.0 / n); + return new SparseGradient(root, 1.0 / (n * JdkMath.pow(root, n - 1)), derivatives); } } /** {@inheritDoc} */ @Override public SparseGradient pow(final double p) { - return new SparseGradient(AccurateMath.pow(value, p), p * AccurateMath.pow(value, p - 1), derivatives); + return new SparseGradient(JdkMath.pow(value, p), p * JdkMath.pow(value, p - 1), derivatives); } /** {@inheritDoc} */ @@ -517,7 +517,7 @@ public final class SparseGradient implements RealFieldElement, S if (n == 0) { return getField().getOne(); } else { - final double valueNm1 = AccurateMath.pow(value, n - 1); + final double valueNm1 = JdkMath.pow(value, n - 1); return new SparseGradient(value * valueNm1, n * valueNm1, derivatives); } } @@ -543,28 +543,28 @@ public final class SparseGradient implements RealFieldElement, S return x.getField().getZero(); } } else { - final double ax = AccurateMath.pow(a, x.value); - return new SparseGradient(ax, ax * AccurateMath.log(a), x.derivatives); + final double ax = JdkMath.pow(a, x.value); + return new SparseGradient(ax, ax * JdkMath.log(a), x.derivatives); } } /** {@inheritDoc} */ @Override public SparseGradient exp() { - final double e = AccurateMath.exp(value); + final double e = JdkMath.exp(value); return new SparseGradient(e, e, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient expm1() { - return new SparseGradient(AccurateMath.expm1(value), AccurateMath.exp(value), derivatives); + return new SparseGradient(JdkMath.expm1(value), JdkMath.exp(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient log() { - return new SparseGradient(AccurateMath.log(value), 1.0 / value, derivatives); + return new SparseGradient(JdkMath.log(value), 1.0 / value, derivatives); } /** Base 10 logarithm. @@ -572,50 +572,50 @@ public final class SparseGradient implements RealFieldElement, S */ @Override public SparseGradient log10() { - return new SparseGradient(AccurateMath.log10(value), 1.0 / (AccurateMath.log(10.0) * value), derivatives); + return new SparseGradient(JdkMath.log10(value), 1.0 / (JdkMath.log(10.0) * value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient log1p() { - return new SparseGradient(AccurateMath.log1p(value), 1.0 / (1.0 + value), derivatives); + return new SparseGradient(JdkMath.log1p(value), 1.0 / (1.0 + value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient cos() { - return new SparseGradient(AccurateMath.cos(value), -AccurateMath.sin(value), derivatives); + return new SparseGradient(JdkMath.cos(value), -JdkMath.sin(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient sin() { - return new SparseGradient(AccurateMath.sin(value), AccurateMath.cos(value), derivatives); + return new SparseGradient(JdkMath.sin(value), JdkMath.cos(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient tan() { - final double t = AccurateMath.tan(value); + final double t = JdkMath.tan(value); return new SparseGradient(t, 1 + t * t, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient acos() { - return new SparseGradient(AccurateMath.acos(value), -1.0 / AccurateMath.sqrt(1 - value * value), derivatives); + return new SparseGradient(JdkMath.acos(value), -1.0 / JdkMath.sqrt(1 - value * value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient asin() { - return new SparseGradient(AccurateMath.asin(value), 1.0 / AccurateMath.sqrt(1 - value * value), derivatives); + return new SparseGradient(JdkMath.asin(value), 1.0 / JdkMath.sqrt(1 - value * value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient atan() { - return new SparseGradient(AccurateMath.atan(value), 1.0 / (1 + value * value), derivatives); + return new SparseGradient(JdkMath.atan(value), 1.0 / (1 + value * value), derivatives); } /** {@inheritDoc} */ @@ -635,12 +635,12 @@ public final class SparseGradient implements RealFieldElement, S // compute atan2(y, x) = +/- pi - 2 atan(y / (r - x)) final SparseGradient tmp = divide(r.subtract(x)).atan().multiply(-2); - a = tmp.add(tmp.value <= 0 ? -AccurateMath.PI : AccurateMath.PI); + a = tmp.add(tmp.value <= 0 ? -JdkMath.PI : JdkMath.PI); } // fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly - a.value = AccurateMath.atan2(value, x.value); + a.value = JdkMath.atan2(value, x.value); return a; @@ -658,52 +658,52 @@ public final class SparseGradient implements RealFieldElement, S /** {@inheritDoc} */ @Override public SparseGradient cosh() { - return new SparseGradient(AccurateMath.cosh(value), AccurateMath.sinh(value), derivatives); + return new SparseGradient(JdkMath.cosh(value), JdkMath.sinh(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient sinh() { - return new SparseGradient(AccurateMath.sinh(value), AccurateMath.cosh(value), derivatives); + return new SparseGradient(JdkMath.sinh(value), JdkMath.cosh(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient tanh() { - final double t = AccurateMath.tanh(value); + final double t = JdkMath.tanh(value); return new SparseGradient(t, 1 - t * t, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient acosh() { - return new SparseGradient(AccurateMath.acosh(value), 1.0 / AccurateMath.sqrt(value * value - 1.0), derivatives); + return new SparseGradient(JdkMath.acosh(value), 1.0 / JdkMath.sqrt(value * value - 1.0), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient asinh() { - return new SparseGradient(AccurateMath.asinh(value), 1.0 / AccurateMath.sqrt(value * value + 1.0), derivatives); + return new SparseGradient(JdkMath.asinh(value), 1.0 / JdkMath.sqrt(value * value + 1.0), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient atanh() { - return new SparseGradient(AccurateMath.atanh(value), 1.0 / (1.0 - value * value), derivatives); + return new SparseGradient(JdkMath.atanh(value), 1.0 / (1.0 - value * value), derivatives); } /** Convert radians to degrees, with error of less than 0.5 ULP. * @return instance converted into degrees */ public SparseGradient toDegrees() { - return new SparseGradient(AccurateMath.toDegrees(value), AccurateMath.toDegrees(1.0), derivatives); + return new SparseGradient(JdkMath.toDegrees(value), JdkMath.toDegrees(1.0), derivatives); } /** Convert degrees to radians, with error of less than 0.5 ULP. * @return instance converted into radians */ public SparseGradient toRadians() { - return new SparseGradient(AccurateMath.toRadians(value), AccurateMath.toRadians(1.0), derivatives); + return new SparseGradient(JdkMath.toRadians(value), JdkMath.toRadians(1.0), derivatives); } /** Evaluate Taylor expansion of a sparse gradient. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java index 668a8869d..e9595910e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Absolute value function. @@ -29,6 +29,6 @@ public class Abs implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.abs(x); + return JdkMath.abs(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java index fcfde56b0..b6309387a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Arc-cosine function. @@ -30,7 +30,7 @@ public class Acos implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.acos(x); + return JdkMath.acos(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java index 3f8569619..8ace23c20 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Hyperbolic arc-cosine function. @@ -30,7 +30,7 @@ public class Acosh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.acosh(x); + return JdkMath.acosh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java index fc9459101..8a8a56590 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Arc-sine function. @@ -30,7 +30,7 @@ public class Asin implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.asin(x); + return JdkMath.asin(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java index 98e38ce0d..0da7c05a1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Hyperbolic arc-sine function. @@ -30,7 +30,7 @@ public class Asinh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.asinh(x); + return JdkMath.asinh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java index c52d68605..99d508564 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Arc-tangent function. @@ -30,7 +30,7 @@ public class Atan implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.atan(x); + return JdkMath.atan(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java index 927787bdd..e7ae65f62 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Arc-tangent function. @@ -29,6 +29,6 @@ public class Atan2 implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double y, double x) { - return AccurateMath.atan2(y, x); + return JdkMath.atan2(y, x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java index 6061dd1a8..588599fc4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Hyperbolic arc-tangent function. @@ -30,7 +30,7 @@ public class Atanh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.atanh(x); + return JdkMath.atanh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java index ed9784471..26f7225bf 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Cube root function. @@ -30,7 +30,7 @@ public class Cbrt implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.cbrt(x); + return JdkMath.cbrt(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java index 5ec6b3686..7cbec78b6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * {@code ceil} function. @@ -29,6 +29,6 @@ public class Ceil implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.ceil(x); + return JdkMath.ceil(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java index c82e2375b..7751f5cd3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Cosine function. @@ -30,7 +30,7 @@ public class Cos implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.cos(x); + return JdkMath.cos(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java index 32aa17e8d..f172f3750 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Hyperbolic cosine function. @@ -30,7 +30,7 @@ public class Cosh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.cosh(x); + return JdkMath.cosh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java index bc8530e8a..49192a8b6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Exponential function. @@ -30,7 +30,7 @@ public class Exp implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.exp(x); + return JdkMath.exp(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java index 1d683e249..767e4b233 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * ex-1 function. @@ -30,7 +30,7 @@ public class Expm1 implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.expm1(x); + return JdkMath.expm1(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java index 26267cead..8ceccf357 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * {@code floor} function. @@ -29,6 +29,6 @@ public class Floor implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.floor(x); + return JdkMath.floor(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java index 92f3fbcfc..0ac316afa 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -76,7 +76,7 @@ public class Gaussian implements UnivariateDifferentiableFunction { public Gaussian(double mean, double sigma) throws NotStrictlyPositiveException { - this(1 / (sigma * AccurateMath.sqrt(2 * Math.PI)), mean, sigma); + this(1 / (sigma * JdkMath.sqrt(2 * Math.PI)), mean, sigma); } /** @@ -194,7 +194,7 @@ public class Gaussian implements UnivariateDifferentiableFunction { private static double value(double xMinusMean, double norm, double i2s2) { - return norm * AccurateMath.exp(-xMinusMean * xMinusMean * i2s2); + return norm * JdkMath.exp(-xMinusMean * xMinusMean * i2s2); } /** {@inheritDoc} @@ -217,7 +217,7 @@ public class Gaussian implements UnivariateDifferentiableFunction { final double[] p = new double[f.length]; p[0] = 1; final double u2 = u * u; - double coeff = norm * AccurateMath.exp(-0.5 * u2); + double coeff = norm * JdkMath.exp(-0.5 * u2); if (coeff <= Precision.SAFE_MIN) { Arrays.fill(f, 0.0); } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java index b0c03e371..e3df48d57 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * @@ -112,7 +112,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction { final double xTimesOmegaPlusPhase = omega * x + phase; final double a = HarmonicOscillator.value(xTimesOmegaPlusPhase, 1); - final double p = -amplitude * AccurateMath.sin(xTimesOmegaPlusPhase); + final double p = -amplitude * JdkMath.sin(xTimesOmegaPlusPhase); final double w = p * x; return new double[] { a, w, p }; @@ -147,7 +147,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction { */ private static double value(double xTimesOmegaPlusPhase, double amplitude) { - return amplitude * AccurateMath.cos(xTimesOmegaPlusPhase); + return amplitude * JdkMath.cos(xTimesOmegaPlusPhase); } /** {@inheritDoc} @@ -160,9 +160,9 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction { double[] f = new double[t.getOrder() + 1]; final double alpha = omega * x + phase; - f[0] = amplitude * AccurateMath.cos(alpha); + f[0] = amplitude * JdkMath.cos(alpha); if (f.length > 1) { - f[1] = -amplitude * omega * AccurateMath.sin(alpha); + f[1] = -amplitude * omega * JdkMath.sin(alpha); final double mo2 = - omega * omega; for (int i = 2; i < f.length; ++i) { f[i] = mo2 * f[i - 2]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java index 6dfdb21f1..99bf7eded 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Natural logarithm function. @@ -30,7 +30,7 @@ public class Log implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.log(x); + return JdkMath.log(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java index e7228a365..57ba7882a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Base 10 logarithm function. @@ -31,7 +31,7 @@ public class Log10 implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.log10(x); + return JdkMath.log10(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java index 1f244046e..474a4c7c4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * log(1 + p) function. @@ -30,7 +30,7 @@ public class Log1p implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.log1p(x); + return JdkMath.log1p(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java index 9dc43c9a3..3c38b71e2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * @@ -147,10 +147,10 @@ public class Logistic implements UnivariateDifferentiableFunction { final double mMinusX = param[1] - x; final double oneOverN = 1 / param[5]; - final double exp = AccurateMath.exp(b * mMinusX); + final double exp = JdkMath.exp(b * mMinusX); final double qExp = q * exp; final double qExp1 = qExp + 1; - final double factor1 = (param[0] - param[4]) * oneOverN / AccurateMath.pow(qExp1, oneOverN); + final double factor1 = (param[0] - param[4]) * oneOverN / JdkMath.pow(qExp1, oneOverN); final double factor2 = -factor1 / qExp1; // Components of the gradient. @@ -159,7 +159,7 @@ public class Logistic implements UnivariateDifferentiableFunction { final double gb = factor2 * mMinusX * qExp; final double gq = factor2 * exp; final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN); - final double gn = factor1 * AccurateMath.log(qExp1) * oneOverN; + final double gn = factor1 * JdkMath.log(qExp1) * oneOverN; return new double[] { gk, gm, gb, gq, ga, gn }; } @@ -207,7 +207,7 @@ public class Logistic implements UnivariateDifferentiableFunction { double q, double a, double oneOverN) { - return a + (k - a) / AccurateMath.pow(1 + q * AccurateMath.exp(b * mMinusX), oneOverN); + return a + (k - a) / JdkMath.pow(1 + q * JdkMath.exp(b * mMinusX), oneOverN); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java index 0da8537ae..9b9ce73a9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * @@ -153,7 +153,7 @@ public class Logit implements UnivariateDifferentiableFunction { if (x < lo || x > hi) { throw new OutOfRangeException(x, lo, hi); } - return AccurateMath.log((x - lo) / (hi - x)); + return JdkMath.log((x - lo) / (hi - x)); } /** {@inheritDoc} @@ -170,7 +170,7 @@ public class Logit implements UnivariateDifferentiableFunction { double[] f = new double[t.getOrder() + 1]; // function value - f[0] = AccurateMath.log((x - lo) / (hi - x)); + f[0] = JdkMath.log((x - lo) / (hi - x)); if (Double.isInfinite(f[0])) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java index f338b8138..b672e1a81 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Maximum function. @@ -29,6 +29,6 @@ public class Max implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double x, double y) { - return AccurateMath.max(x, y); + return JdkMath.max(x, y); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java index 90eba84a6..f5399f117 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Minimum function. @@ -29,6 +29,6 @@ public class Min implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double x, double y) { - return AccurateMath.min(x, y); + return JdkMath.min(x, y); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java index 70b691544..c008095af 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Power function. @@ -29,6 +29,6 @@ public class Pow implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double x, double y) { - return AccurateMath.pow(x, y); + return JdkMath.pow(x, y); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java index 91cfc58ad..2342d15d2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Power function. @@ -40,7 +40,7 @@ public class Power implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.pow(x, p); + return JdkMath.pow(x, p); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java index 7b81161a9..686078a07 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * {@code rint} function. @@ -29,6 +29,6 @@ public class Rint implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.rint(x); + return JdkMath.rint(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java index 2f1dfe5e2..46eb5858e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * @@ -114,7 +114,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction { DimensionMismatchException { validateParameters(param); - final double invExp1 = 1 / (1 + AccurateMath.exp(-x)); + final double invExp1 = 1 / (1 + JdkMath.exp(-x)); return new double[] { 1 - invExp1, invExp1 }; } @@ -150,7 +150,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction { private static double value(double x, double lo, double hi) { - return lo + (hi - lo) / (1 + AccurateMath.exp(-x)); + return lo + (hi - lo) / (1 + JdkMath.exp(-x)); } /** {@inheritDoc} @@ -161,7 +161,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction { throws DimensionMismatchException { double[] f = new double[t.getOrder() + 1]; - final double exp = AccurateMath.exp(-t.getValue()); + final double exp = JdkMath.exp(-t.getValue()); if (Double.isInfinite(exp)) { // special handling near lower boundary, to avoid NaN diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java index 067eac336..ddc1322d1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * {@code signum} function. @@ -29,6 +29,6 @@ public class Signum implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.signum(x); + return JdkMath.signum(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java index 81aaedde4..c5b82c981 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Sine function. @@ -30,7 +30,7 @@ public class Sin implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.sin(x); + return JdkMath.sin(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java index a33e0da5d..1de98df2a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Sinc function, @@ -81,14 +81,14 @@ public class Sinc implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(final double x) { - final double scaledX = normalized ? AccurateMath.PI * x : x; - if (AccurateMath.abs(scaledX) <= SHORTCUT) { + final double scaledX = normalized ? JdkMath.PI * x : x; + if (JdkMath.abs(scaledX) <= SHORTCUT) { // use Taylor series final double scaledX2 = scaledX * scaledX; return ((scaledX2 - 20) * scaledX2 + 120) / 120; } else { // use definition expression - return AccurateMath.sin(scaledX) / scaledX; + return JdkMath.sin(scaledX) / scaledX; } } @@ -99,12 +99,12 @@ public class Sinc implements UnivariateDifferentiableFunction { public DerivativeStructure value(final DerivativeStructure t) throws DimensionMismatchException { - final double scaledX = (normalized ? AccurateMath.PI : 1) * t.getValue(); + final double scaledX = (normalized ? JdkMath.PI : 1) * t.getValue(); final double scaledX2 = scaledX * scaledX; double[] f = new double[t.getOrder() + 1]; - if (AccurateMath.abs(scaledX) <= SHORTCUT) { + if (JdkMath.abs(scaledX) <= SHORTCUT) { for (int i = 0; i < f.length; ++i) { final int k = i / 2; @@ -122,8 +122,8 @@ public class Sinc implements UnivariateDifferentiableFunction { } else { final double inv = 1 / scaledX; - final double cos = AccurateMath.cos(scaledX); - final double sin = AccurateMath.sin(scaledX); + final double cos = JdkMath.cos(scaledX); + final double sin = JdkMath.sin(scaledX); f[0] = inv * sin; @@ -182,10 +182,10 @@ public class Sinc implements UnivariateDifferentiableFunction { } if (normalized) { - double scale = AccurateMath.PI; + double scale = JdkMath.PI; for (int i = 1; i < f.length; ++i) { f[i] *= scale; - scale *= AccurateMath.PI; + scale *= JdkMath.PI; } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java index 4a9a51580..3c6f85147 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Hyperbolic sine function. @@ -30,7 +30,7 @@ public class Sinh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.sinh(x); + return JdkMath.sinh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java index f8146aa4f..35ec90ed2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Square-root function. @@ -30,7 +30,7 @@ public class Sqrt implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.sqrt(x); + return JdkMath.sqrt(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java index 5fa6f4f45..626bd142a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Tangent function. @@ -30,7 +30,7 @@ public class Tan implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.tan(x); + return JdkMath.tan(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java index 26f801607..d539d4450 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Hyperbolic tangent function. @@ -30,7 +30,7 @@ public class Tanh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.tanh(x); + return JdkMath.tanh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java index 840024049..9ff52ade4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * {@code ulp} function. @@ -29,6 +29,6 @@ public class Ulp implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return AccurateMath.ulp(x); + return JdkMath.ulp(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java index e9011bc66..51ee8acd9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.integration.gauss.GaussIntegrato import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This algorithm divides the integration interval into equally-sized @@ -122,10 +122,10 @@ public class IterativeLegendreGaussIntegrator final double t = stage(n); // Estimate the error. - final double delta = AccurateMath.abs(t - oldt); + final double delta = JdkMath.abs(t - oldt); final double limit = - AccurateMath.max(getAbsoluteAccuracy(), - getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5); + JdkMath.max(getAbsoluteAccuracy(), + getRelativeAccuracy() * (JdkMath.abs(oldt) + JdkMath.abs(t)) * 0.5); // check convergence if (iterations.getCount() + 1 >= getMinimalIterationCount() && @@ -134,8 +134,8 @@ public class IterativeLegendreGaussIntegrator } // Prepare next iteration. - final double ratio = AccurateMath.min(4, AccurateMath.pow(delta / limit, 0.5 / numberOfPoints)); - n = AccurateMath.max((int) (ratio * n), n + 1); + final double ratio = JdkMath.min(4, JdkMath.pow(delta / limit, 0.5 / numberOfPoints)); + n = JdkMath.max((int) (ratio * n), n + 1); oldt = t; iterations.increment(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java index 30668512c..00f255b74 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the @@ -113,7 +113,7 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator { double diffMaxMin) { // number of points in the previous stage. This stage will contribute // 2*3^{n-1} more points. - final long np = (long) AccurateMath.pow(3, n - 1); + final long np = (long) JdkMath.pow(3, n - 1); double sum = 0; // spacing between adjacent new points @@ -151,9 +151,9 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator { final int i = iterations.getCount(); final double t = stage(i, oldt, min, diff); if (i >= getMinimalIterationCount()) { - final double delta = AccurateMath.abs(t - oldt); + final double delta = JdkMath.abs(t - oldt); final double rLimit = - getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5; + getRelativeAccuracy() * (JdkMath.abs(oldt) + JdkMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java index 8ce1d908d..4ee7c1854 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the @@ -120,8 +120,8 @@ public class RombergIntegrator extends BaseAbstractUnivariateIntegrator { } final double s = currentRow[i]; if (i >= getMinimalIterationCount()) { - final double delta = AccurateMath.abs(s - olds); - final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5; + final double delta = JdkMath.abs(s - olds); + final double rLimit = getRelativeAccuracy() * (JdkMath.abs(olds) + JdkMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java index 2ce475bd5..df1fe7273 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements @@ -113,8 +113,8 @@ public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator { final double t = qtrap.stage(this, i + 1); // 1-stage ahead of the iteration final double s = (4 * t - oldt) / 3.0; if (i >= getMinimalIterationCount()) { - final double delta = AccurateMath.abs(s - olds); - final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5; + final double delta = JdkMath.abs(s - olds); + final double rLimit = getRelativeAccuracy() * (JdkMath.abs(olds) + JdkMath.abs(s)) * 0.5; if (delta <= rLimit || delta <= getAbsoluteAccuracy()) { return s; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java index f009df0bb..1fea13a00 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the @@ -146,9 +146,9 @@ public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator { final int i = iterations.getCount(); final double t = stage(this, i); if (i >= getMinimalIterationCount()) { - final double delta = AccurateMath.abs(t - oldt); + final double delta = JdkMath.abs(t - oldt); final double rLimit = - getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5; + getRelativeAccuracy() * (JdkMath.abs(oldt) + JdkMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java index 30cb26ab5..4cdbc0f68 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.analysis.integration.gauss; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.Pair; /** @@ -74,8 +74,8 @@ public class HermiteRuleFactory extends BaseRuleFactory { final Double[] points = new Double[numberOfPoints]; final Double[] weights = new Double[numberOfPoints]; - final double sqrtTwoTimesLastNumPoints = AccurateMath.sqrt(2.0 * lastNumPoints); - final double sqrtTwoTimesNumPoints = AccurateMath.sqrt(2.0 * numberOfPoints); + final double sqrtTwoTimesLastNumPoints = JdkMath.sqrt(2.0 * lastNumPoints); + final double sqrtTwoTimesNumPoints = JdkMath.sqrt(2.0 * numberOfPoints); // Find i-th root of H[n+1] by bracketing. final int iMax = numberOfPoints / 2; @@ -96,8 +96,8 @@ public class HermiteRuleFactory extends BaseRuleFactory { for (int j = 1; j < numberOfPoints; j++) { // Compute H[j+1](a) and H[j+1](b) final double jp1 = j + 1.0; - final double s = AccurateMath.sqrt(2 / jp1); - final double sm = AccurateMath.sqrt(j / jp1); + final double s = JdkMath.sqrt(2 / jp1); + final double sm = JdkMath.sqrt(j / jp1); final double hpa = s * a * ha - sm * hma; final double hpb = s * b * hb - sm * hmb; hma = ha; @@ -121,8 +121,8 @@ public class HermiteRuleFactory extends BaseRuleFactory { for (int j = 1; j < numberOfPoints; j++) { // Compute H[j+1](c) final double jp1 = j + 1.0; - final double s = AccurateMath.sqrt(2 / jp1); - final double sm = AccurateMath.sqrt(j / jp1); + final double s = JdkMath.sqrt(2 / jp1); + final double sm = JdkMath.sqrt(j / jp1); final double hpc = s * c * hc - sm * hmc; hmc = hc; hc = hpc; @@ -160,7 +160,7 @@ public class HermiteRuleFactory extends BaseRuleFactory { double hm = H0; for (int j = 1; j < numberOfPoints; j += 2) { final double jp1 = j + 1.0; - hm = -AccurateMath.sqrt(j / jp1) * hm; + hm = -JdkMath.sqrt(j / jp1) * hm; } final double d = sqrtTwoTimesNumPoints * hm; final double w = 2 / (d * d); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java index 2d1520d29..740b5a01a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; @@ -123,11 +123,11 @@ public class AkimaSplineInterpolator for (int i = 1; i < weights.length; i++) { final double a = differences[i]; final double b = differences[i - 1]; - weights[i] = AccurateMath.abs(a - b) + 0.5 * AccurateMath.abs(a + b); + weights[i] = JdkMath.abs(a - b) + 0.5 * JdkMath.abs(a + b); } } else { for (int i = 1; i < weights.length; i++) { - weights[i] = AccurateMath.abs(differences[i] - differences[i - 1]); + weights[i] = JdkMath.abs(differences[i] - differences[i - 1]); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java index 88f5c021a..d4d4cd466 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -224,13 +224,13 @@ public class InterpolatingMicrosphere { final double[] diff = MathArrays.ebeSubtract(samplePoints[i], point); final double diffNorm = Norm.L2.of(diff); - if (AccurateMath.abs(diffNorm) < noInterpolationTolerance) { + if (JdkMath.abs(diffNorm) < noInterpolationTolerance) { // No need to interpolate, as the interpolation point is // actually (very close to) one of the sampled points. return sampleValues[i]; } - final double weight = AccurateMath.pow(diffNorm, -exponent); + final double weight = JdkMath.pow(diffNorm, -exponent); illuminate(diff, sampleValues[i], weight); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java index eaca3ca7a..b92e7b2fd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.analysis.interpolation; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm. @@ -60,8 +60,8 @@ public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere { for (int i = 0; i < size; i++) { final double angle = i * twopi / size; - add(new double[] { AccurateMath.cos(angle), - AccurateMath.sin(angle) }, + add(new double[] { JdkMath.cos(angle), + JdkMath.sin(angle) }, false); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java index 63a94f77b..933f5b223 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -296,7 +296,7 @@ public class LoessInterpolator double sumXSquared = 0; double sumY = 0; double sumXY = 0; - double denom = AccurateMath.abs(1.0 / (xval[edge] - x)); + double denom = JdkMath.abs(1.0 / (xval[edge] - x)); for (int k = ileft; k <= iright; ++k) { final double xk = xval[k]; final double yk = yval[k]; @@ -316,7 +316,7 @@ public class LoessInterpolator final double meanXSquared = sumXSquared / sumWeights; final double beta; - if (AccurateMath.sqrt(AccurateMath.abs(meanXSquared - meanX * meanX)) < accuracy) { + if (JdkMath.sqrt(JdkMath.abs(meanXSquared - meanX * meanX)) < accuracy) { beta = 0; } else { beta = (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX); @@ -325,7 +325,7 @@ public class LoessInterpolator final double alpha = meanY - beta * meanX; res[i] = beta * x + alpha; - residuals[i] = AccurateMath.abs(yval[i] - res[i]); + residuals[i] = JdkMath.abs(yval[i] - res[i]); } // No need to recompute the robustness weights at the last @@ -343,7 +343,7 @@ public class LoessInterpolator Arrays.sort(sortedResiduals); final double medianResidual = sortedResiduals[n / 2]; - if (AccurateMath.abs(medianResidual) < accuracy) { + if (JdkMath.abs(medianResidual) < accuracy) { break; } @@ -454,7 +454,7 @@ public class LoessInterpolator * @return (1 - |x|3)3 for |x| < 1, 0 otherwise. */ private static double tricube(final double x) { - final double absX = AccurateMath.abs(x); + final double absX = JdkMath.abs(x); if (absX >= 1.0) { return 0.0; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java index d9884c8a3..b85cffc82 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Immutable representation of a real polynomial function with real coefficients. @@ -167,8 +167,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser */ public PolynomialFunction add(final PolynomialFunction p) { // identify the lowest degree polynomial - final int lowLength = AccurateMath.min(coefficients.length, p.coefficients.length); - final int highLength = AccurateMath.max(coefficients.length, p.coefficients.length); + final int lowLength = JdkMath.min(coefficients.length, p.coefficients.length); + final int highLength = JdkMath.max(coefficients.length, p.coefficients.length); // build the coefficients array double[] newCoefficients = new double[highLength]; @@ -192,8 +192,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser */ public PolynomialFunction subtract(final PolynomialFunction p) { // identify the lowest degree polynomial - int lowLength = AccurateMath.min(coefficients.length, p.coefficients.length); - int highLength = AccurateMath.max(coefficients.length, p.coefficients.length); + int lowLength = JdkMath.min(coefficients.length, p.coefficients.length); + int highLength = JdkMath.max(coefficients.length, p.coefficients.length); // build the coefficients array double[] newCoefficients = new double[highLength]; @@ -236,8 +236,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser for (int i = 0; i < newCoefficients.length; ++i) { newCoefficients[i] = 0.0; - for (int j = AccurateMath.max(0, i + 1 - p.coefficients.length); - j < AccurateMath.min(coefficients.length, i + 1); + for (int j = JdkMath.max(0, i + 1 - p.coefficients.length); + j < JdkMath.min(coefficients.length, i + 1); ++j) { newCoefficients[i] += coefficients[j] * p.coefficients[i-j]; } @@ -320,7 +320,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser } } - double absAi = AccurateMath.abs(coefficients[i]); + double absAi = JdkMath.abs(coefficients[i]); if ((absAi - 1) != 0) { s.append(toString(absAi)); s.append(' '); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java index 14f94b7c6..689743adc 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -216,7 +216,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction { c[i] = y[i]; d[i] = y[i]; // find out the abscissa closest to z - final double dist = AccurateMath.abs(z - x[i]); + final double dist = JdkMath.abs(z - x[i]); if (dist < minDist) { nearest = i; minDist = dist; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java index 9842a05b9..08ce03e9d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.commons.numbers.fraction.BigFraction; import org.apache.commons.numbers.combinatorics.BinomialCoefficient; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * A collection of static methods that operate on or return polynomials. @@ -341,7 +341,7 @@ public final class PolynomialsUtils { // First polynomial coefficient. for (int i = 0; i < dp1; i++){ - newCoefficients[0] += coefficients[i] * AccurateMath.pow(shift, i); + newCoefficients[0] += coefficients[i] * JdkMath.pow(shift, i); } // Superior order. @@ -349,7 +349,7 @@ public final class PolynomialsUtils { for (int i = 0; i < d; i++) { for (int j = i; j < d; j++){ newCoefficients[i + 1] += coeff[j + 1][j - i] * - coefficients[j + 1] * AccurateMath.pow(shift, j - i); + coefficients[j + 1] * JdkMath.pow(shift, j - i); } } @@ -370,7 +370,7 @@ public final class PolynomialsUtils { // case, the lock object is an immutable field that belongs to this // class. synchronized (coefficients) { - final int maxDegree = (int) AccurateMath.floor(AccurateMath.sqrt(2.0 * coefficients.size())) - 1; + final int maxDegree = (int) JdkMath.floor(JdkMath.sqrt(2.0 * coefficients.size())) - 1; if (degree > maxDegree) { computeUpToDegree(degree, maxDegree, generator, coefficients); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java index 8f952e144..ff1f7533c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.exception.ConvergenceException; import org.apache.commons.math4.legacy.exception.MathInternalError; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Base class for all bracketing Secant-based methods for root-finding @@ -210,7 +210,7 @@ public abstract class BaseSecantSolver // If the function value of the last approximation is too small, // given the function value accuracy, then we can't get closer to // the root than we already are. - if (AccurateMath.abs(f1) <= ftol) { + if (JdkMath.abs(f1) <= ftol) { switch (allowed) { case ANY_SIDE: return x1; @@ -241,7 +241,7 @@ public abstract class BaseSecantSolver // If the current interval is within the given accuracies, we // are satisfied with the current approximation. - if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1), + if (JdkMath.abs(x1 - x0) < JdkMath.max(rtol * JdkMath.abs(x1), atol)) { switch (allowed) { case ANY_SIDE: diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java index ff0290c71..b833b28c9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the @@ -82,7 +82,7 @@ public class BisectionSolver extends AbstractUnivariateSolver { max = m; } - if (AccurateMath.abs(max - min) <= absoluteAccuracy) { + if (JdkMath.abs(max - min) <= absoluteAccuracy) { m = UnivariateSolverUtils.midpoint(min, max); return m; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java index 4a41726dc..f314a6df2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -199,11 +199,11 @@ public class BracketingNthOrderBrentSolver // current tightest bracketing of the root double xA = x[signChangeIndex - 1]; double yA = y[signChangeIndex - 1]; - double absYA = AccurateMath.abs(yA); + double absYA = JdkMath.abs(yA); int agingA = 0; double xB = x[signChangeIndex]; double yB = y[signChangeIndex]; - double absYB = AccurateMath.abs(yB); + double absYB = JdkMath.abs(yB); int agingB = 0; // search loop @@ -211,8 +211,8 @@ public class BracketingNthOrderBrentSolver // check convergence of bracketing interval final double xTol = getAbsoluteAccuracy() + - getRelativeAccuracy() * AccurateMath.max(AccurateMath.abs(xA), AccurateMath.abs(xB)); - if (((xB - xA) <= xTol) || (AccurateMath.max(absYA, absYB) < getFunctionValueAccuracy())) { + getRelativeAccuracy() * JdkMath.max(JdkMath.abs(xA), JdkMath.abs(xB)); + if (((xB - xA) <= xTol) || (JdkMath.max(absYA, absYB) < getFunctionValueAccuracy())) { switch (allowed) { case ANY_SIDE : return absYA < absYB ? xA : xB; @@ -332,14 +332,14 @@ public class BracketingNthOrderBrentSolver // the sign change occurs before the inserted point xB = nextX; yB = nextY; - absYB = AccurateMath.abs(yB); + absYB = JdkMath.abs(yB); ++agingA; agingB = 0; } else { // the sign change occurs after the inserted point xA = nextX; yA = nextY; - absYA = AccurateMath.abs(yA); + absYA = JdkMath.abs(yA); agingA = 0; ++agingB; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java index cd20e75eb..902c83b01 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the @@ -100,13 +100,13 @@ public class LaguerreSolver extends AbstractPolynomialSolver { // Return the initial guess if it is good enough. final double yInitial = computeObjectiveValue(initial); - if (AccurateMath.abs(yInitial) <= functionValueAccuracy) { + if (JdkMath.abs(yInitial) <= functionValueAccuracy) { return initial; } // Return the first endpoint if it is good enough. final double yMin = computeObjectiveValue(min); - if (AccurateMath.abs(yMin) <= functionValueAccuracy) { + if (JdkMath.abs(yMin) <= functionValueAccuracy) { return min; } @@ -117,7 +117,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver { // Return the second endpoint if it is good enough. final double yMax = computeObjectiveValue(max); - if (AccurateMath.abs(yMax) <= functionValueAccuracy) { + if (JdkMath.abs(yMax) <= functionValueAccuracy) { return max; } @@ -241,8 +241,8 @@ public class LaguerreSolver extends AbstractPolynomialSolver { */ public boolean isRoot(double min, double max, Complex z) { if (isSequence(min, z.getReal(), max)) { - double tolerance = AccurateMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); - return (AccurateMath.abs(z.getImaginary()) <= tolerance) || + double tolerance = JdkMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); + return (JdkMath.abs(z.getImaginary()) <= tolerance) || (z.abs() <= getFunctionValueAccuracy()); } return false; @@ -347,7 +347,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver { d2v = d2v.multiply(Complex.ofCartesian(2.0, 0.0)); // Check for convergence. - final double tolerance = AccurateMath.max(relativeAccuracy * z.abs(), + final double tolerance = JdkMath.max(relativeAccuracy * z.abs(), absoluteAccuracy); if ((z.subtract(oldz)).abs() <= tolerance) { return z; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java index ac262cca5..f71cdc6bf 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements the @@ -94,15 +94,15 @@ public class MullerSolver extends AbstractUnivariateSolver { // check for zeros before verifying bracketing final double fMin = computeObjectiveValue(min); - if (AccurateMath.abs(fMin) < functionValueAccuracy) { + if (JdkMath.abs(fMin) < functionValueAccuracy) { return min; } final double fMax = computeObjectiveValue(max); - if (AccurateMath.abs(fMax) < functionValueAccuracy) { + if (JdkMath.abs(fMax) < functionValueAccuracy) { return max; } final double fInitial = computeObjectiveValue(initial); - if (AccurateMath.abs(fInitial) < functionValueAccuracy) { + if (JdkMath.abs(fInitial) < functionValueAccuracy) { return initial; } @@ -156,17 +156,17 @@ public class MullerSolver extends AbstractUnivariateSolver { final double d012 = (d12 - d01) / (x2 - x0); final double c1 = d01 + (x1 - x0) * d012; final double delta = c1 * c1 - 4 * y1 * d012; - final double xplus = x1 + (-2.0 * y1) / (c1 + AccurateMath.sqrt(delta)); - final double xminus = x1 + (-2.0 * y1) / (c1 - AccurateMath.sqrt(delta)); + final double xplus = x1 + (-2.0 * y1) / (c1 + JdkMath.sqrt(delta)); + final double xminus = x1 + (-2.0 * y1) / (c1 - JdkMath.sqrt(delta)); // xplus and xminus are two roots of parabola and at least // one of them should lie in (x0, x2) final double x = isSequence(x0, xplus, x2) ? xplus : xminus; final double y = computeObjectiveValue(x); // check for convergence - final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy); - if (AccurateMath.abs(x - oldx) <= tolerance || - AccurateMath.abs(y) <= functionValueAccuracy) { + final double tolerance = JdkMath.max(relativeAccuracy * JdkMath.abs(x), absoluteAccuracy); + if (JdkMath.abs(x - oldx) <= tolerance || + JdkMath.abs(y) <= functionValueAccuracy) { return x; } @@ -188,7 +188,7 @@ public class MullerSolver extends AbstractUnivariateSolver { } else { double xm = 0.5 * (x0 + x2); double ym = computeObjectiveValue(xm); - if (AccurateMath.signum(y0) + AccurateMath.signum(ym) == 0.0) { + if (JdkMath.signum(y0) + JdkMath.signum(ym) == 0.0) { x2 = xm; y2 = ym; } else { x0 = xm; y0 = ym; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java index e137ef822..fd8d3e558 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements the @@ -99,12 +99,12 @@ public class MullerSolver2 extends AbstractUnivariateSolver { double x0 = min; double y0 = computeObjectiveValue(x0); - if (AccurateMath.abs(y0) < functionValueAccuracy) { + if (JdkMath.abs(y0) < functionValueAccuracy) { return x0; } double x1 = max; double y1 = computeObjectiveValue(x1); - if (AccurateMath.abs(y1) < functionValueAccuracy) { + if (JdkMath.abs(y1) < functionValueAccuracy) { return x1; } @@ -127,12 +127,12 @@ public class MullerSolver2 extends AbstractUnivariateSolver { final double denominator; if (delta >= 0.0) { // choose a denominator larger in magnitude - double dplus = b + AccurateMath.sqrt(delta); - double dminus = b - AccurateMath.sqrt(delta); - denominator = AccurateMath.abs(dplus) > AccurateMath.abs(dminus) ? dplus : dminus; + double dplus = b + JdkMath.sqrt(delta); + double dminus = b - JdkMath.sqrt(delta); + denominator = JdkMath.abs(dplus) > JdkMath.abs(dminus) ? dplus : dminus; } else { - // take the modulus of (B +/- AccurateMath.sqrt(delta)) - denominator = AccurateMath.sqrt(b * b - delta); + // take the modulus of (B +/- JdkMath.sqrt(delta)) + denominator = JdkMath.sqrt(b * b - delta); } if (denominator != 0) { x = x2 - 2.0 * c * (x2 - x1) / denominator; @@ -143,15 +143,15 @@ public class MullerSolver2 extends AbstractUnivariateSolver { } } else { // extremely rare case, get a random number to skip it - x = min + AccurateMath.random() * (max - min); + x = min + JdkMath.random() * (max - min); oldx = Double.POSITIVE_INFINITY; } final double y = computeObjectiveValue(x); // check for convergence - final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy); - if (AccurateMath.abs(x - oldx) <= tolerance || - AccurateMath.abs(y) <= functionValueAccuracy) { + final double tolerance = JdkMath.max(relativeAccuracy * JdkMath.abs(x), absoluteAccuracy); + if (JdkMath.abs(x - oldx) <= tolerance || + JdkMath.abs(y) <= functionValueAccuracy) { return x; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java index 4b2982635..4b5c5480e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements @@ -82,7 +82,7 @@ public class NewtonRaphsonSolver extends AbstractUnivariateDifferentiableSolver while (true) { final DerivativeStructure y0 = computeObjectiveValueAndDerivative(x0); x1 = x0 - (y0.getValue() / y0.getPartialDerivative(1)); - if (AccurateMath.abs(x1 - x0) <= absoluteAccuracy) { + if (JdkMath.abs(x1 - x0) <= absoluteAccuracy) { return x1; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java index 8b059750f..4a73eb1dc 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the @@ -95,28 +95,28 @@ public class RiddersSolver extends AbstractUnivariateSolver { // calculate the new root approximation final double x3 = 0.5 * (x1 + x2); final double y3 = computeObjectiveValue(x3); - if (AccurateMath.abs(y3) <= functionValueAccuracy) { + if (JdkMath.abs(y3) <= functionValueAccuracy) { return x3; } final double delta = 1 - (y1 * y2) / (y3 * y3); // delta > 1 due to bracketing - final double correction = (AccurateMath.signum(y2) * AccurateMath.signum(y3)) * - (x3 - x1) / AccurateMath.sqrt(delta); + final double correction = (JdkMath.signum(y2) * JdkMath.signum(y3)) * + (x3 - x1) / JdkMath.sqrt(delta); final double x = x3 - correction; // correction != 0 final double y = computeObjectiveValue(x); // check for convergence - final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy); - if (AccurateMath.abs(x - oldx) <= tolerance) { + final double tolerance = JdkMath.max(relativeAccuracy * JdkMath.abs(x), absoluteAccuracy); + if (JdkMath.abs(x - oldx) <= tolerance) { return x; } - if (AccurateMath.abs(y) <= functionValueAccuracy) { + if (JdkMath.abs(y) <= functionValueAccuracy) { return x; } // prepare the new interval for next iteration // Ridders' method guarantees x1 < x < x2 if (correction > 0.0) { // x1 < x < x3 - if (AccurateMath.signum(y1) + AccurateMath.signum(y) == 0.0) { + if (JdkMath.signum(y1) + JdkMath.signum(y) == 0.0) { x2 = x; y2 = y; } else { @@ -126,7 +126,7 @@ public class RiddersSolver extends AbstractUnivariateSolver { y2 = y3; } } else { // x3 < x < x2 - if (AccurateMath.signum(y2) + AccurateMath.signum(y) == 0.0) { + if (JdkMath.signum(y2) + JdkMath.signum(y) == 0.0) { x1 = x; y1 = y; } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java index 5c1e24143..14d9cb2d5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implements the Secant method for root-finding (approximating a @@ -120,13 +120,13 @@ public class SecantSolver extends AbstractUnivariateSolver { // If the function value of the last approximation is too small, // given the function value accuracy, then we can't get closer to // the root than we already are. - if (AccurateMath.abs(f1) <= ftol) { + if (JdkMath.abs(f1) <= ftol) { return x1; } // If the current interval is within the given accuracies, we // are satisfied with the current approximation. - if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1), atol)) { + if (JdkMath.abs(x1 - x0) < JdkMath.max(rtol * JdkMath.abs(x1), atol)) { return x1; } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java index daace2d08..d8cfdb91e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Utility routines for {@link UnivariateSolver} objects. @@ -111,11 +111,11 @@ public final class UnivariateSolverUtils { } // find a very small interval bracketing the root - final double step = AccurateMath.max(bracketing.getAbsoluteAccuracy(), - AccurateMath.abs(baseRoot * bracketing.getRelativeAccuracy())); - double xLo = AccurateMath.max(min, baseRoot - step); + final double step = JdkMath.max(bracketing.getAbsoluteAccuracy(), + JdkMath.abs(baseRoot * bracketing.getRelativeAccuracy())); + double xLo = JdkMath.max(min, baseRoot - step); double fLo = f.value(xLo); - double xHi = AccurateMath.min(max, baseRoot + step); + double xHi = JdkMath.min(max, baseRoot + step); double fHi = f.value(xHi); int remainingEval = maxEval - 2; while (remainingEval > 0) { @@ -150,14 +150,14 @@ public final class UnivariateSolverUtils { // update the lower bound if (changeLo) { - xLo = AccurateMath.max(min, xLo - step); + xLo = JdkMath.max(min, xLo - step); fLo = f.value(xLo); remainingEval--; } // update the higher bound if (changeHi) { - xHi = AccurateMath.min(max, xHi + step); + xHi = JdkMath.min(max, xHi + step); fHi = f.value(xHi); remainingEval--; } @@ -325,8 +325,8 @@ public final class UnivariateSolverUtils { final double previousFb = fb; delta = r * delta + q; - a = AccurateMath.max(initial - delta, lowerBound); - b = AccurateMath.min(initial + delta, upperBound); + a = JdkMath.max(initial - delta, lowerBound); + b = JdkMath.min(initial + delta, upperBound); fa = function.value(a); fb = function.value(b); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java index f4a0402b5..15a7c5340 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java @@ -25,7 +25,7 @@ import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler; import org.apache.commons.rng.sampling.distribution.DiscreteInverseCumulativeProbabilityFunction; import org.apache.commons.rng.sampling.distribution.DiscreteSampler; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Base class for integer-valued discrete distributions. Default @@ -90,19 +90,19 @@ public abstract class AbstractIntegerDistribution // use the one-sided Chebyshev inequality to narrow the bracket // cf. AbstractRealDistribution.inverseCumulativeProbability(double) final double mu = getMean(); - final double sigma = AccurateMath.sqrt(getVariance()); + final double sigma = JdkMath.sqrt(getVariance()); final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0); if (chebyshevApplies) { - double k = AccurateMath.sqrt((1.0 - p) / p); + double k = JdkMath.sqrt((1.0 - p) / p); double tmp = mu - k * sigma; if (tmp > lower) { - lower = ((int) AccurateMath.ceil(tmp)) - 1; + lower = ((int) JdkMath.ceil(tmp)) - 1; } k = 1.0 / k; tmp = mu + k * sigma; if (tmp < upper) { - upper = ((int) AccurateMath.ceil(tmp)) - 1; + upper = ((int) JdkMath.ceil(tmp)) - 1; } } @@ -171,7 +171,7 @@ public abstract class AbstractIntegerDistribution */ @Override public double logProbability(int x) { - return AccurateMath.log(probability(x)); + return JdkMath.log(probability(x)); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java index e422e17c3..3d79914bc 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java @@ -26,7 +26,7 @@ import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.sampling.distribution.InverseTransformContinuousSampler; import org.apache.commons.rng.sampling.distribution.ContinuousInverseCumulativeProbabilityFunction; import org.apache.commons.rng.sampling.distribution.ContinuousSampler; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Base class for probability distributions on the reals. @@ -129,14 +129,14 @@ public abstract class AbstractRealDistribution } final double mu = getMean(); - final double sig = AccurateMath.sqrt(getVariance()); + final double sig = JdkMath.sqrt(getVariance()); final boolean chebyshevApplies; chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || Double.isInfinite(sig) || Double.isNaN(sig)); if (lowerBound == Double.NEGATIVE_INFINITY) { if (chebyshevApplies) { - lowerBound = mu - sig * AccurateMath.sqrt((1. - p) / p); + lowerBound = mu - sig * JdkMath.sqrt((1. - p) / p); } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { @@ -147,7 +147,7 @@ public abstract class AbstractRealDistribution if (upperBound == Double.POSITIVE_INFINITY) { if (chebyshevApplies) { - upperBound = mu + sig * AccurateMath.sqrt(p / (1. - p)); + upperBound = mu + sig * JdkMath.sqrt(p / (1. - p)); } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { @@ -209,7 +209,7 @@ public abstract class AbstractRealDistribution */ @Override public double logDensity(double x) { - return AccurateMath.log(density(x)); + return JdkMath.log(density(x)); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java index 8058ea50a..f3bf604c4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java @@ -29,7 +29,7 @@ import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary; import org.apache.commons.math4.legacy.stat.descriptive.SummaryStatistics; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** *

Represents an @@ -207,7 +207,7 @@ public final class EmpiricalDistribution extends AbstractRealDistribution * @return the index of the bin containing the value. */ private int findBin(double value) { - return Math.min(Math.max((int) AccurateMath.ceil((value - min) / delta) - 1, + return Math.min(Math.max((int) JdkMath.ceil((value - min) / delta) - 1, 0), binCount - 1); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java index b216816e5..8470f9541 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.linear.NonPositiveDefiniteMatrixException import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.SingularMatrixException; import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implementation of the multivariate normal (Gaussian) distribution. @@ -120,7 +120,7 @@ public class MultivariateNormalDistribution // Scale each eigenvector by the square root of its eigenvalue. for (int row = 0; row < dim; row++) { - final double factor = AccurateMath.sqrt(covMatEigenvalues[row]); + final double factor = JdkMath.sqrt(covMatEigenvalues[row]); for (int col = 0; col < dim; col++) { tmpMatrix.multiplyEntry(row, col, factor); } @@ -155,8 +155,8 @@ public class MultivariateNormalDistribution throw new DimensionMismatchException(vals.length, dim); } - return AccurateMath.pow(2 * AccurateMath.PI, -0.5 * dim) * - AccurateMath.pow(covarianceMatrixDeterminant, -0.5) * + return JdkMath.pow(2 * JdkMath.PI, -0.5 * dim) * + JdkMath.pow(covarianceMatrixDeterminant, -0.5) * getExponentTerm(vals); } @@ -171,7 +171,7 @@ public class MultivariateNormalDistribution final double[] std = new double[dim]; final double[][] s = covarianceMatrix.getData(); for (int i = 0; i < dim; i++) { - std[i] = AccurateMath.sqrt(s[i][i]); + std[i] = JdkMath.sqrt(s[i][i]); } return std; } @@ -220,6 +220,6 @@ public class MultivariateNormalDistribution for (int i = 0; i < preMultiplied.length; i++) { sum += preMultiplied[i] * centered[i]; } - return AccurateMath.exp(-0.5 * sum); + return JdkMath.exp(-0.5 * sum); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java index 450a1ba3b..afca6ea7d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java @@ -32,7 +32,7 @@ import org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.SingularMatrixException; import org.apache.commons.math4.legacy.stat.correlation.Covariance; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.math4.legacy.core.Pair; @@ -166,7 +166,7 @@ public class MultivariateNormalMixtureExpectationMaximization { fittedModel = new MixtureMultivariateNormalDistribution(initialMixture.getComponents()); while (numIterations++ <= maxIterations && - AccurateMath.abs(previousLogLikelihood - logLikelihood) > threshold) { + JdkMath.abs(previousLogLikelihood - logLikelihood) > threshold) { previousLogLikelihood = logLikelihood; double sumLogLikelihood = 0d; @@ -198,7 +198,7 @@ public class MultivariateNormalMixtureExpectationMaximization { for (int i = 0; i < n; i++) { final double rowDensity = fittedModel.density(data[i]); - sumLogLikelihood += AccurateMath.log(rowDensity); + sumLogLikelihood += JdkMath.log(rowDensity); for (int j = 0; j < k; j++) { gamma[i][j] = weights[j] * mvns[j].density(data[i]) / rowDensity; @@ -252,7 +252,7 @@ public class MultivariateNormalMixtureExpectationMaximization { newCovMatArrays); } - if (AccurateMath.abs(previousLogLikelihood - logLikelihood) > threshold) { + if (JdkMath.abs(previousLogLikelihood - logLikelihood) > threshold) { // Did not converge before the maximum number of iterations throw new ConvergenceException(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java index 28e31704c..b35cf6273 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Fits points to a {@link @@ -173,7 +173,7 @@ public final class GaussianCurveFitter extends SimpleCurveFitter { // TODO: Exceptions should not be used for flow control. fwhmApprox = points[points.length - 1].getX() - points[0].getX(); } - final double s = fwhmApprox / (2 * AccurateMath.sqrt(2 * AccurateMath.log(2))); + final double s = fwhmApprox / (2 * JdkMath.sqrt(2 * JdkMath.log(2))); return new double[] { n, points[maxYIdx].getX(), s }; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java index c29a14ce2..f186d98cf 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.MathIllegalStateException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.ZeroException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Fits points to a {@link @@ -288,8 +288,8 @@ public final class HarmonicCurveFitter extends SimpleCurveFitter { throw new MathIllegalStateException(LocalizedFormats.ZERO_DENOMINATOR); } - aOmega[0] = AccurateMath.sqrt(c1 / c2); - aOmega[1] = AccurateMath.sqrt(c2 / c3); + aOmega[0] = JdkMath.sqrt(c1 / c2); + aOmega[1] = JdkMath.sqrt(c2 / c3); } return aOmega; @@ -319,13 +319,13 @@ public final class HarmonicCurveFitter extends SimpleCurveFitter { final double currentYPrime = (currentY - previousY) / (currentX - previousX); double omegaX = omega * currentX; - double cosine = AccurateMath.cos(omegaX); - double sine = AccurateMath.sin(omegaX); + double cosine = JdkMath.cos(omegaX); + double sine = JdkMath.sin(omegaX); fcMean += omega * currentY * cosine - currentYPrime * sine; fsMean += omega * currentY * sine + currentYPrime * cosine; } - return AccurateMath.atan2(-fsMean, fcMean); + return JdkMath.atan2(-fsMean, fcMean); } } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java index bb881e073..9509ab7ff 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.linear.DecompositionSolver; import org.apache.commons.math4.legacy.linear.QRDecomposition; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.RealVector; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * An implementation of {@link Evaluation} that is designed for extension. All of the @@ -69,7 +69,7 @@ public abstract class AbstractEvaluation implements Evaluation { final int nC = cov.getColumnDimension(); final RealVector sig = new ArrayRealVector(nC); for (int i = 0; i < nC; ++i) { - sig.setEntry(i, AccurateMath.sqrt(cov.getEntry(i,i))); + sig.setEntry(i, JdkMath.sqrt(cov.getEntry(i,i))); } return sig; } @@ -77,13 +77,13 @@ public abstract class AbstractEvaluation implements Evaluation { /** {@inheritDoc} */ @Override public double getRMS() { - return AccurateMath.sqrt(getReducedChiSquare(1)); + return JdkMath.sqrt(getReducedChiSquare(1)); } /** {@inheritDoc} */ @Override public double getCost() { - return AccurateMath.sqrt(getChiSquare()); + return JdkMath.sqrt(getChiSquare()); } /** {@inheritDoc} */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java index c923c099b..415a7536e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.linear.RealVector; import org.apache.commons.math4.legacy.optim.AbstractOptimizationProblem; import org.apache.commons.math4.legacy.optim.ConvergenceChecker; import org.apache.commons.math4.legacy.optim.PointVectorValuePair; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.IntegerSequence; import org.apache.commons.math4.legacy.core.Pair; @@ -278,7 +278,7 @@ public final class LeastSquaresFactory { final int dim = m.getRowDimension(); final RealMatrix sqrtM = new DiagonalMatrix(dim); for (int i = 0; i < dim; i++) { - sqrtM.setEntry(i, i, AccurateMath.sqrt(m.getEntry(i, i))); + sqrtM.setEntry(i, i, JdkMath.sqrt(m.getEntry(i, i))); } return sqrtM; } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java index 2ca7e2ce1..14518e696 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresProblem. import org.apache.commons.math4.legacy.linear.ArrayRealVector; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.optim.ConvergenceChecker; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.IntegerSequence; import org.apache.commons.numbers.core.Precision; @@ -305,7 +305,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { final ConvergenceChecker checker = problem.getConvergenceChecker(); // arrays shared with the other private methods - final int solvedCols = AccurateMath.min(nR, nC); + final int solvedCols = JdkMath.min(nR, nC); /* Parameters evolution direction associated with lmPar. */ double[] lmDir = new double[nC]; /* Levenberg-Marquardt parameter. */ @@ -375,7 +375,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { xNorm += xk * xk; diag[k] = dk; } - xNorm = AccurateMath.sqrt(xNorm); + xNorm = JdkMath.sqrt(xNorm); // initialize the step bound delta delta = (xNorm == 0) ? initialStepBoundFactor : (initialStepBoundFactor * xNorm); @@ -392,7 +392,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { for (int i = 0; i <= j; ++i) { sum += weightedJacobian[i][pj] * qtf[i]; } - maxCosine = AccurateMath.max(maxCosine, AccurateMath.abs(sum) / (s * currentCost)); + maxCosine = JdkMath.max(maxCosine, JdkMath.abs(sum) / (s * currentCost)); } } } @@ -406,7 +406,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // rescale if necessary for (int j = 0; j < nC; ++j) { - diag[j] = AccurateMath.max(diag[j], jacNorm[j]); + diag[j] = JdkMath.max(diag[j], jacNorm[j]); } // Inner loop. @@ -436,10 +436,10 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { double s = diag[pj] * lmDir[pj]; lmNorm += s * s; } - lmNorm = AccurateMath.sqrt(lmNorm); + lmNorm = JdkMath.sqrt(lmNorm); // on the first iteration, adjust the initial step bound. if (firstIteration) { - delta = AccurateMath.min(delta, lmNorm); + delta = JdkMath.min(delta, lmNorm); } // Evaluate the function at x + p and calculate its norm. @@ -486,7 +486,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { if ((0.1 * currentCost >= previousCost) || (tmp < 0.1)) { tmp = 0.1; } - delta = tmp * AccurateMath.min(delta, 10.0 * lmNorm); + delta = tmp * JdkMath.min(delta, 10.0 * lmNorm); lmPar /= tmp; } else if ((lmPar == 0) || (ratio >= 0.75)) { delta = 2 * lmNorm; @@ -502,7 +502,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { double xK = diag[k] * currentPoint[k]; xNorm += xK * xK; } - xNorm = AccurateMath.sqrt(xNorm); + xNorm = JdkMath.sqrt(xNorm); // tests for convergence. if (checker != null && checker.converged(iterationCounter.getCount(), previous, current)) { @@ -523,7 +523,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { } // Default convergence criteria. - if ((AccurateMath.abs(actRed) <= costRelativeTolerance && + if ((JdkMath.abs(actRed) <= costRelativeTolerance && preRed <= costRelativeTolerance && ratio <= 2.0) || delta <= parRelativeTolerance * xNorm) { @@ -531,7 +531,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { } // tests for termination and stringent tolerances - if (AccurateMath.abs(actRed) <= TWO_EPS && + if (JdkMath.abs(actRed) <= TWO_EPS && preRed <= TWO_EPS && ratio <= 2.0) { throw new ConvergenceException(LocalizedFormats.TOO_SMALL_COST_RELATIVE_TOLERANCE, @@ -655,7 +655,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { work1[pj] = s; dxNorm += s * s; } - dxNorm = AccurateMath.sqrt(dxNorm); + dxNorm = JdkMath.sqrt(dxNorm); double fp = dxNorm - delta; if (fp <= 0.1 * delta) { lmPar = 0; @@ -697,15 +697,15 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { sum /= diag[pj]; sum2 += sum * sum; } - double gNorm = AccurateMath.sqrt(sum2); + double gNorm = JdkMath.sqrt(sum2); double paru = gNorm / delta; if (paru == 0) { - paru = Precision.SAFE_MIN / AccurateMath.min(delta, 0.1); + paru = Precision.SAFE_MIN / JdkMath.min(delta, 0.1); } // if the input par lies outside of the interval (parl,paru), // set par to the closer endpoint - lmPar = AccurateMath.min(paru, AccurateMath.max(lmPar, parl)); + lmPar = JdkMath.min(paru, JdkMath.max(lmPar, parl)); if (lmPar == 0) { lmPar = gNorm / dxNorm; } @@ -714,9 +714,9 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // evaluate the function at the current value of lmPar if (lmPar == 0) { - lmPar = AccurateMath.max(Precision.SAFE_MIN, 0.001 * paru); + lmPar = JdkMath.max(Precision.SAFE_MIN, 0.001 * paru); } - double sPar = AccurateMath.sqrt(lmPar); + double sPar = JdkMath.sqrt(lmPar); for (int j = 0; j < solvedCols; ++j) { int pj = permutation[j]; work1[pj] = sPar * diag[pj]; @@ -730,13 +730,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { work3[pj] = s; dxNorm += s * s; } - dxNorm = AccurateMath.sqrt(dxNorm); + dxNorm = JdkMath.sqrt(dxNorm); double previousFP = fp; fp = dxNorm - delta; // if the function is small enough, accept the current value // of lmPar, also test for the exceptional cases where parl is zero - if (AccurateMath.abs(fp) <= 0.1 * delta || + if (JdkMath.abs(fp) <= 0.1 * delta || (parl == 0 && fp <= previousFP && previousFP < 0)) { @@ -765,13 +765,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // depending on the sign of the function, update parl or paru. if (fp > 0) { - parl = AccurateMath.max(parl, lmPar); + parl = JdkMath.max(parl, lmPar); } else if (fp < 0) { - paru = AccurateMath.min(paru, lmPar); + paru = JdkMath.min(paru, lmPar); } // compute an improved estimate for lmPar - lmPar = AccurateMath.max(parl, lmPar + correction); + lmPar = JdkMath.max(parl, lmPar + correction); } return lmPar; @@ -847,13 +847,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { final double sin; final double cos; double rkk = weightedJacobian[k][pk]; - if (AccurateMath.abs(rkk) < AccurateMath.abs(lmDiag[k])) { + if (JdkMath.abs(rkk) < JdkMath.abs(lmDiag[k])) { final double cotan = rkk / lmDiag[k]; - sin = 1.0 / AccurateMath.sqrt(1.0 + cotan * cotan); + sin = 1.0 / JdkMath.sqrt(1.0 + cotan * cotan); cos = sin * cotan; } else { final double tan = lmDiag[k] / rkk; - cos = 1.0 / AccurateMath.sqrt(1.0 + tan * tan); + cos = 1.0 / JdkMath.sqrt(1.0 + tan * tan); sin = cos * tan; } @@ -956,7 +956,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { double akk = weightedJacobian[i][k]; norm2 += akk * akk; } - jacNorm[k] = AccurateMath.sqrt(norm2); + jacNorm[k] = JdkMath.sqrt(norm2); } // transform the matrix column after column @@ -989,7 +989,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // choose alpha such that Hk.u = alpha ek double akk = weightedJacobian[k][pk]; - double alpha = (akk > 0) ? -AccurateMath.sqrt(ak2) : AccurateMath.sqrt(ak2); + double alpha = (akk > 0) ? -JdkMath.sqrt(ak2) : JdkMath.sqrt(ak2); double betak = 1.0 / (ak2 - akk * alpha); beta[pk] = betak; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java index 59f5288be..836160783 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Population of chromosomes which uses elitism (certain percentage of the best @@ -87,7 +87,7 @@ public class ElitisticListPopulation extends ListPopulation { Collections.sort(oldChromosomes); // index of the last "not good enough" chromosome - int boundIndex = (int) AccurateMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size()); + int boundIndex = (int) JdkMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size()); for (int i = boundIndex; i < oldChromosomes.size(); i++) { nextGeneration.addChromosome(oldChromosomes.get(i)); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java index c28c253f0..7669b55ba 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Order 1 Crossover [OX1] builds offspring from ordered chromosomes by copying a @@ -111,8 +111,8 @@ public class OrderedCrossover implements CrossoverPolicy { b = random.nextInt(length); } while (a == b); // determine the lower and upper bounds - final int lb = AccurateMath.min(a, b); - final int ub = AccurateMath.max(a, b); + final int lb = JdkMath.min(a, b); + final int ub = JdkMath.max(a, b); // add the subLists that are between lb and ub child1.addAll(parent1Rep.subList(lb, ub + 1)); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java index 23bacf250..6373041e0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Basic implementation of RealMatrix methods regardless of the underlying storage. @@ -270,9 +270,9 @@ public abstract class AbstractRealMatrix /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final double value) { - columnSum += AccurateMath.abs(value); + columnSum += JdkMath.abs(value); if (row == endRow) { - maxColSum = AccurateMath.max(maxColSum, columnSum); + maxColSum = JdkMath.max(maxColSum, columnSum); columnSum = 0; } } @@ -310,7 +310,7 @@ public abstract class AbstractRealMatrix /** {@inheritDoc} */ @Override public double end() { - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } }); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java index 0858c86eb..13a49ddf0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements the {@link RealVector} interface with a double array. @@ -470,7 +470,7 @@ public class ArrayRealVector extends RealVector implements Serializable { for (double a : data) { sum += a * a; } - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } /** {@inheritDoc} */ @@ -478,7 +478,7 @@ public class ArrayRealVector extends RealVector implements Serializable { public double getL1Norm() { double sum = 0; for (double a : data) { - sum += AccurateMath.abs(a); + sum += JdkMath.abs(a); } return sum; } @@ -488,7 +488,7 @@ public class ArrayRealVector extends RealVector implements Serializable { public double getLInfNorm() { double max = 0; for (double a : data) { - max = AccurateMath.max(max, AccurateMath.abs(a)); + max = JdkMath.max(max, JdkMath.abs(a)); } return max; } @@ -504,7 +504,7 @@ public class ArrayRealVector extends RealVector implements Serializable { final double delta = data[i] - vData[i]; sum += delta * delta; } - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } else { checkVectorDimensions(v); double sum = 0; @@ -512,7 +512,7 @@ public class ArrayRealVector extends RealVector implements Serializable { final double delta = data[i] - v.getEntry(i); sum += delta * delta; } - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } } @@ -526,7 +526,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double sum = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - vData[i]; - sum += AccurateMath.abs(delta); + sum += JdkMath.abs(delta); } return sum; } else { @@ -534,7 +534,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double sum = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - v.getEntry(i); - sum += AccurateMath.abs(delta); + sum += JdkMath.abs(delta); } return sum; } @@ -550,7 +550,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double max = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - vData[i]; - max = AccurateMath.max(max, AccurateMath.abs(delta)); + max = JdkMath.max(max, JdkMath.abs(delta)); } return max; } else { @@ -558,7 +558,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double max = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - v.getEntry(i); - max = AccurateMath.max(max, AccurateMath.abs(delta)); + max = JdkMath.max(max, JdkMath.abs(delta)); } return max; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java index e0630a031..2eee0c0a2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -62,7 +62,7 @@ class BiDiagonalTransformer { final int m = matrix.getRowDimension(); final int n = matrix.getColumnDimension(); - final int p = AccurateMath.min(m, n); + final int p = JdkMath.min(m, n); householderVectors = matrix.getData(); main = new double[p]; secondary = new double[p - 1]; @@ -266,7 +266,7 @@ class BiDiagonalTransformer { xNormSqr += c * c; } final double[] hK = householderVectors[k]; - final double a = (hK[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); + final double a = (hK[k] > 0) ? -JdkMath.sqrt(xNormSqr) : JdkMath.sqrt(xNormSqr); main[k] = a; if (a != 0.0) { hK[k] -= a; @@ -291,7 +291,7 @@ class BiDiagonalTransformer { final double c = hK[j]; xNormSqr += c * c; } - final double b = (hK[k + 1] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); + final double b = (hK[k + 1] > 0) ? -JdkMath.sqrt(xNormSqr) : JdkMath.sqrt(xNormSqr); secondary[k] = b; if (b != 0.0) { hK[k + 1] -= b; @@ -330,7 +330,7 @@ class BiDiagonalTransformer { final double c = hK[j]; xNormSqr += c * c; } - final double a = (hK[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); + final double a = (hK[k] > 0) ? -JdkMath.sqrt(xNormSqr) : JdkMath.sqrt(xNormSqr); main[k] = a; if (a != 0.0) { hK[k] -= a; @@ -355,7 +355,7 @@ class BiDiagonalTransformer { final double c = householderVectors[i][k]; xNormSqr += c * c; } - final double b = (hKp1[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); + final double b = (hKp1[k] > 0) ? -JdkMath.sqrt(xNormSqr) : JdkMath.sqrt(xNormSqr); secondary[k] = b; if (b != 0.0) { hKp1[k] -= b; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java index 3caf51ea5..7c8380219 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -224,11 +224,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; // allocate new block @@ -273,11 +273,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = MathArrays.buildArray(field, iHeight * jWidth); ++blockIndex; @@ -333,9 +333,9 @@ public class BlockFieldMatrix> extends AbstractFieldMa final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -404,9 +404,9 @@ public class BlockFieldMatrix> extends AbstractFieldMa final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -505,12 +505,12 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); // select current block final T[] outBlock = out.blocks[blockIndex]; @@ -567,7 +567,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); @@ -627,7 +627,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); int regularPos = 0; int lastPos = 0; for (int p = pStart; p < pEnd; ++p) { @@ -804,14 +804,14 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) { final int iHeight = blockHeight(iBlock); final int firstRow = iBlock * BLOCK_SIZE; - final int iStart = AccurateMath.max(row, firstRow); - final int iEnd = AccurateMath.min(endRow + 1, firstRow + iHeight); + final int iStart = JdkMath.max(row, firstRow); + final int iEnd = JdkMath.min(endRow + 1, firstRow + iHeight); for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) { final int jWidth = blockWidth(jBlock); final int firstColumn = jBlock * BLOCK_SIZE; - final int jStart = AccurateMath.max(column, firstColumn); - final int jEnd = AccurateMath.min(endColumn + 1, firstColumn + jWidth); + final int jStart = JdkMath.max(column, firstColumn); + final int jEnd = JdkMath.min(endColumn + 1, firstColumn + jWidth); final int jLength = jEnd - jStart; // handle one block, row by row @@ -1226,9 +1226,9 @@ public class BlockFieldMatrix> extends AbstractFieldMa final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[jBlock * blockColumns + iBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, columns); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, columns); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, rows); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, rows); int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lInc = pEnd - pStart; @@ -1273,11 +1273,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa // perform multiplication block-wise, to ensure good cache behavior for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final T[] block = blocks[iBlock * blockColumns + jBlock]; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { T sum = zero; @@ -1319,11 +1319,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final T[] block = blocks[iBlock * blockColumns + jBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int q = qStart; q < qEnd; ++q) { int k = q - qStart; T sum = zero; @@ -1355,12 +1355,12 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1379,12 +1379,12 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1407,14 +1407,14 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1437,14 +1437,14 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1464,10 +1464,10 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1489,10 +1489,10 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1517,13 +1517,13 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; @@ -1547,13 +1547,13 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java index 7c63518b2..a9c50d1f7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Cache-friendly implementation of RealMatrix using a flat arrays to store @@ -215,11 +215,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; // allocate new block @@ -259,11 +259,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = new double[iHeight * jWidth]; ++blockIndex; @@ -317,9 +317,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -385,9 +385,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -483,11 +483,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); // select current block final double[] outBlock = out.blocks[blockIndex]; @@ -540,7 +540,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); @@ -597,7 +597,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); int regularPos = 0; int lastPos = 0; for (int p = pStart; p < pEnd; ++p) { @@ -631,13 +631,13 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int j = 0; j < jWidth; ++j) { double sum = 0; for (int i = 0; i < iHeight; ++i) { - sum += AccurateMath.abs(block[i * jWidth + j]); + sum += JdkMath.abs(block[i * jWidth + j]); } colSums[j] += sum; } } for (int j = 0; j < jWidth; ++j) { - maxColSum = AccurateMath.max(maxColSum, colSums[j]); + maxColSum = JdkMath.max(maxColSum, colSums[j]); } } return maxColSum; @@ -652,7 +652,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable sum2 += entry * entry; } } - return AccurateMath.sqrt(sum2); + return JdkMath.sqrt(sum2); } /** {@inheritDoc} */ @@ -812,14 +812,14 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) { final int iHeight = blockHeight(iBlock); final int firstRow = iBlock * BLOCK_SIZE; - final int iStart = AccurateMath.max(row, firstRow); - final int iEnd = AccurateMath.min(endRow + 1, firstRow + iHeight); + final int iStart = JdkMath.max(row, firstRow); + final int iEnd = JdkMath.min(endRow + 1, firstRow + iHeight); for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) { final int jWidth = blockWidth(jBlock); final int firstColumn = jBlock * BLOCK_SIZE; - final int jStart = AccurateMath.max(column, firstColumn); - final int jEnd = AccurateMath.min(endColumn + 1, firstColumn + jWidth); + final int jStart = JdkMath.max(column, firstColumn); + final int jEnd = JdkMath.min(endColumn + 1, firstColumn + jWidth); final int jLength = jEnd - jStart; // handle one block, row by row @@ -1221,9 +1221,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[jBlock * blockColumns + iBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, columns); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, columns); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, rows); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, rows); int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lInc = pEnd - pStart; @@ -1266,11 +1266,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable // perform multiplication block-wise, to ensure good cache behavior for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final double[] block = blocks[iBlock * blockColumns + jBlock]; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { double sum = 0; @@ -1310,11 +1310,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final double[] block = blocks[iBlock * blockColumns + jBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int q = qStart; q < qEnd; ++q) { int k = q - qStart; double sum = 0; @@ -1345,12 +1345,12 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1369,12 +1369,12 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1397,14 +1397,14 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1427,14 +1427,14 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1454,10 +1454,10 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1479,10 +1479,10 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = JdkMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = JdkMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1508,13 +1508,13 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; @@ -1539,13 +1539,13 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = AccurateMath.max(startRow, p0); - final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = JdkMath.max(startRow, p0); + final int pEnd = JdkMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = AccurateMath.max(startColumn, q0); - final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = JdkMath.max(startColumn, q0); + final int qEnd = JdkMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java index 1ad63228a..ef54331bf 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -123,8 +123,8 @@ public class CholeskyDecomposition { final double lIJ = lI[j]; final double lJI = lJ[i]; final double maxDelta = - relativeSymmetryThreshold * AccurateMath.max(AccurateMath.abs(lIJ), AccurateMath.abs(lJI)); - if (AccurateMath.abs(lIJ - lJI) > maxDelta) { + relativeSymmetryThreshold * JdkMath.max(JdkMath.abs(lIJ), JdkMath.abs(lJI)); + if (JdkMath.abs(lIJ - lJI) > maxDelta) { throw new NonSymmetricMatrixException(i, j, relativeSymmetryThreshold); } lJ[i] = 0; @@ -141,7 +141,7 @@ public class CholeskyDecomposition { throw new NonPositiveDefiniteMatrixException(ltI[i], i, absolutePositivityThreshold); } - ltI[i] = AccurateMath.sqrt(ltI[i]); + ltI[i] = JdkMath.sqrt(ltI[i]); final double inverse = 1.0 / ltI[i]; for (int q = order - 1; q > i; --q) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java index 49306911b..ee705c825 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -313,7 +313,7 @@ public class DiagonalMatrix extends AbstractRealMatrix */ private void ensureZero(final double value) throws NumberIsTooLargeException { if (!Precision.equals(0.0, value, 1)) { - throw new NumberIsTooLargeException(AccurateMath.abs(value), 0, true); + throw new NumberIsTooLargeException(JdkMath.abs(value), 0, true); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java index 1a079417e..5e8b08699 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.MathUnsupportedOperationException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Calculates the eigen decomposition of a real matrix. @@ -349,7 +349,7 @@ public class EigenDecomposition { if (eigen <= 0) { throw new MathUnsupportedOperationException(); } - sqrtEigenValues[i] = AccurateMath.sqrt(eigen); + sqrtEigenValues[i] = JdkMath.sqrt(eigen); } final RealMatrix sqrtEigen = MatrixUtils.createRealDiagonalMatrix(sqrtEigenValues); final RealMatrix v = getV(); @@ -487,7 +487,7 @@ public class EigenDecomposition { // Looping over all values (in case they are not sorted in decreasing // order of their norm). for (int i = 0; i < realEigenvalues.length; ++i) { - largestEigenvalueNorm = AccurateMath.max(largestEigenvalueNorm, eigenvalueNorm(i)); + largestEigenvalueNorm = JdkMath.max(largestEigenvalueNorm, eigenvalueNorm(i)); } // Corner case: zero matrix, all exactly 0 eigenvalues if (largestEigenvalueNorm == 0.0) { @@ -510,7 +510,7 @@ public class EigenDecomposition { private double eigenvalueNorm(int i) { final double re = realEigenvalues[i]; final double im = imagEigenvalues[i]; - return AccurateMath.sqrt(re * re + im * im); + return JdkMath.sqrt(re * re + im * im); } /** @@ -577,20 +577,20 @@ public class EigenDecomposition { // Determine the largest main and secondary value in absolute term. double maxAbsoluteValue = 0; for (int i = 0; i < n; i++) { - if (AccurateMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { - maxAbsoluteValue = AccurateMath.abs(realEigenvalues[i]); + if (JdkMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { + maxAbsoluteValue = JdkMath.abs(realEigenvalues[i]); } - if (AccurateMath.abs(e[i]) > maxAbsoluteValue) { - maxAbsoluteValue = AccurateMath.abs(e[i]); + if (JdkMath.abs(e[i]) > maxAbsoluteValue) { + maxAbsoluteValue = JdkMath.abs(e[i]); } } // Make null any main and secondary value too small to be significant if (maxAbsoluteValue != 0) { for (int i=0; i < n; i++) { - if (AccurateMath.abs(realEigenvalues[i]) <= Precision.EPSILON * maxAbsoluteValue) { + if (JdkMath.abs(realEigenvalues[i]) <= Precision.EPSILON * maxAbsoluteValue) { realEigenvalues[i] = 0; } - if (AccurateMath.abs(e[i]) <= Precision.EPSILON * maxAbsoluteValue) { + if (JdkMath.abs(e[i]) <= Precision.EPSILON * maxAbsoluteValue) { e[i]=0; } } @@ -601,9 +601,9 @@ public class EigenDecomposition { int m; do { for (m = j; m < n - 1; m++) { - double delta = AccurateMath.abs(realEigenvalues[m]) + - AccurateMath.abs(realEigenvalues[m + 1]); - if (AccurateMath.abs(e[m]) + delta == delta) { + double delta = JdkMath.abs(realEigenvalues[m]) + + JdkMath.abs(realEigenvalues[m + 1]); + if (JdkMath.abs(e[m]) + delta == delta) { break; } } @@ -614,7 +614,7 @@ public class EigenDecomposition { } its++; double q = (realEigenvalues[j + 1] - realEigenvalues[j]) / (2 * e[j]); - double t = AccurateMath.sqrt(1 + q * q); + double t = JdkMath.sqrt(1 + q * q); if (q < 0.0) { q = realEigenvalues[m] - realEigenvalues[j] + e[j] / (q - t); } else { @@ -627,15 +627,15 @@ public class EigenDecomposition { for (i = m - 1; i >= j; i--) { double p = s * e[i]; double h = c * e[i]; - if (AccurateMath.abs(p) >= AccurateMath.abs(q)) { + if (JdkMath.abs(p) >= JdkMath.abs(q)) { c = q / p; - t = AccurateMath.sqrt(c * c + 1.0); + t = JdkMath.sqrt(c * c + 1.0); e[i + 1] = p * t; s = 1.0 / t; c *= s; } else { s = p / q; - t = AccurateMath.sqrt(s * s + 1.0); + t = JdkMath.sqrt(s * s + 1.0); e[i + 1] = q * t; c = 1.0 / t; s *= c; @@ -690,14 +690,14 @@ public class EigenDecomposition { // Determine the largest eigen value in absolute term. maxAbsoluteValue = 0; for (int i = 0; i < n; i++) { - if (AccurateMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { - maxAbsoluteValue=AccurateMath.abs(realEigenvalues[i]); + if (JdkMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { + maxAbsoluteValue=JdkMath.abs(realEigenvalues[i]); } } // Make null any eigen value too small to be significant if (maxAbsoluteValue != 0.0) { for (int i=0; i < n; i++) { - if (AccurateMath.abs(realEigenvalues[i]) < Precision.EPSILON * maxAbsoluteValue) { + if (JdkMath.abs(realEigenvalues[i]) < Precision.EPSILON * maxAbsoluteValue) { realEigenvalues[i] = 0; } } @@ -732,7 +732,7 @@ public class EigenDecomposition { } else { final double x = matT[i + 1][i + 1]; final double p = 0.5 * (matT[i][i] - x); - final double z = AccurateMath.sqrt(AccurateMath.abs(p * p + matT[i + 1][i] * matT[i][i + 1])); + final double z = JdkMath.sqrt(JdkMath.abs(p * p + matT[i + 1][i] * matT[i][i + 1])); realEigenvalues[i] = x + p; imagEigenvalues[i] = z; realEigenvalues[i + 1] = x + p; @@ -773,8 +773,8 @@ public class EigenDecomposition { // compute matrix norm double norm = 0.0; for (int i = 0; i < n; i++) { - for (int j = AccurateMath.max(i - 1, 0); j < n; j++) { - norm += AccurateMath.abs(matrixT[i][j]); + for (int j = JdkMath.max(i - 1, 0); j < n; j++) { + norm += JdkMath.abs(matrixT[i][j]); } } @@ -822,7 +822,7 @@ public class EigenDecomposition { imagEigenvalues[i] * imagEigenvalues[i]; double t = (x * s - z * r) / q; matrixT[i][idx] = t; - if (AccurateMath.abs(x) > AccurateMath.abs(z)) { + if (JdkMath.abs(x) > JdkMath.abs(z)) { matrixT[i + 1][idx] = (-r - w * t) / x; } else { matrixT[i + 1][idx] = (-s - y * t) / z; @@ -830,7 +830,7 @@ public class EigenDecomposition { } // Overflow control - double t = AccurateMath.abs(matrixT[i][idx]); + double t = JdkMath.abs(matrixT[i][idx]); if ((Precision.EPSILON * t) * t > 1) { for (int j = i; j <= idx; j++) { matrixT[j][idx] /= t; @@ -843,7 +843,7 @@ public class EigenDecomposition { int l = idx - 1; // Last vector component imaginary so matrix is triangular - if (AccurateMath.abs(matrixT[idx][idx - 1]) > AccurateMath.abs(matrixT[idx - 1][idx])) { + if (JdkMath.abs(matrixT[idx][idx - 1]) > JdkMath.abs(matrixT[idx - 1][idx])) { matrixT[idx - 1][idx - 1] = q / matrixT[idx][idx - 1]; matrixT[idx - 1][idx] = -(matrixT[idx][idx] - p) / matrixT[idx][idx - 1]; } else { @@ -884,15 +884,15 @@ public class EigenDecomposition { final double vi = (realEigenvalues[i] - p) * 2.0 * q; if (Precision.equals(vr, 0.0) && Precision.equals(vi, 0.0)) { vr = Precision.EPSILON * norm * - (AccurateMath.abs(w) + AccurateMath.abs(q) + AccurateMath.abs(x) + - AccurateMath.abs(y) + AccurateMath.abs(z)); + (JdkMath.abs(w) + JdkMath.abs(q) + JdkMath.abs(x) + + JdkMath.abs(y) + JdkMath.abs(z)); } final Complex c = cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi); matrixT[i][idx - 1] = c.getReal(); matrixT[i][idx] = c.getImaginary(); - if (AccurateMath.abs(x) > (AccurateMath.abs(z) + AccurateMath.abs(q))) { + if (JdkMath.abs(x) > (JdkMath.abs(z) + JdkMath.abs(q))) { matrixT[i + 1][idx - 1] = (-ra - w * matrixT[i][idx - 1] + q * matrixT[i][idx]) / x; matrixT[i + 1][idx] = (-sa - w * matrixT[i][idx] - @@ -906,8 +906,8 @@ public class EigenDecomposition { } // Overflow control - double t = AccurateMath.max(AccurateMath.abs(matrixT[i][idx - 1]), - AccurateMath.abs(matrixT[i][idx])); + double t = JdkMath.max(JdkMath.abs(matrixT[i][idx - 1]), + JdkMath.abs(matrixT[i][idx])); if ((Precision.EPSILON * t) * t > 1) { for (int j = i; j <= idx; j++) { matrixT[j][idx - 1] /= t; @@ -923,7 +923,7 @@ public class EigenDecomposition { for (int j = n - 1; j >= 0; j--) { for (int i = 0; i <= n - 1; i++) { z = 0.0; - for (int k = 0; k <= AccurateMath.min(j, n - 1); k++) { + for (int k = 0; k <= JdkMath.min(j, n - 1); k++) { z += matrixP[i][k] * matrixT[k][j]; } matrixP[i][j] = z; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java index 240d73194..3b7d9df1b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -184,7 +184,7 @@ class HessenbergTransformer { // Scale column. double scale = 0; for (int i = m; i <= high; i++) { - scale += AccurateMath.abs(householderVectors[i][m - 1]); + scale += JdkMath.abs(householderVectors[i][m - 1]); } if (!Precision.equals(scale, 0)) { @@ -194,7 +194,7 @@ class HessenbergTransformer { ort[i] = householderVectors[i][m - 1] / scale; h += ort[i] * ort[i]; } - final double g = (ort[m] > 0) ? -AccurateMath.sqrt(h) : AccurateMath.sqrt(h); + final double g = (ort[m] > 0) ? -JdkMath.sqrt(h) : JdkMath.sqrt(h); h -= ort[m] * g; ort[m] -= g; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java index 6cfa36f2b..f2e170a23 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Calculates the LUP-decomposition of a square matrix. @@ -127,14 +127,14 @@ public class LUDecomposition { luRow[col] = sum; // maintain best permutation choice - if (AccurateMath.abs(sum) > largest) { - largest = AccurateMath.abs(sum); + if (JdkMath.abs(sum) > largest) { + largest = JdkMath.abs(sum); max = row; } } // Singularity check - if (AccurateMath.abs(lu[max][col]) < singularityThreshold) { + if (JdkMath.abs(lu[max][col]) < singularityThreshold) { singular = true; return; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java index 7504cac5f..2c7dca5bd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java @@ -32,7 +32,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.ZeroException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; @@ -412,8 +412,8 @@ public final class MatrixUtils { for (int j = i + 1; j < rows; j++) { final double mij = matrix.getEntry(i, j); final double mji = matrix.getEntry(j, i); - if (AccurateMath.abs(mij - mji) > - AccurateMath.max(AccurateMath.abs(mij), AccurateMath.abs(mji)) * relativeTolerance) { + if (JdkMath.abs(mij - mji) > + JdkMath.max(JdkMath.abs(mij), JdkMath.abs(mji)) * relativeTolerance) { if (raiseException) { throw new NonSymmetricMatrixException(i, j, relativeTolerance); } else { @@ -845,7 +845,7 @@ public final class MatrixUtils { int rows = rm.getRowDimension(); for( int i = 0 ; i < rows ; i++ ){ double diag = rm.getEntry(i, i); - if( AccurateMath.abs(diag) < Precision.SAFE_MIN ){ + if( JdkMath.abs(diag) < Precision.SAFE_MIN ){ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } double bi = b.getEntry(i)/diag; @@ -890,7 +890,7 @@ public final class MatrixUtils { int rows = rm.getRowDimension(); for( int i = rows-1 ; i >-1 ; i-- ){ double diag = rm.getEntry(i, i); - if( AccurateMath.abs(diag) < Precision.SAFE_MIN ){ + if( JdkMath.abs(diag) < Precision.SAFE_MIN ){ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } double bi = b.getEntry(i)/diag; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java index f17886cd3..ea98eeba5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import java.io.IOException; import java.io.ObjectInputStream; @@ -151,7 +151,7 @@ class OpenIntToDoubleHashMap implements Serializable { // Not in public API. if (expectedSize == 0) { return 1; } - final int capacity = (int) AccurateMath.ceil(expectedSize / LOAD_FACTOR); + final int capacity = (int) JdkMath.ceil(expectedSize / LOAD_FACTOR); final int powerOfTwo = Integer.highestOneBit(capacity); if (powerOfTwo == capacity) { return capacity; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java index 27903706f..2dc00ddca 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java @@ -25,7 +25,7 @@ import java.util.NoSuchElementException; import org.apache.commons.math4.legacy.core.Field; import org.apache.commons.math4.legacy.core.FieldElement; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Open addressed map from int to FieldElement. @@ -163,7 +163,7 @@ class OpenIntToFieldHashMap> implements Serializable { if (expectedSize == 0) { return 1; } - final int capacity = (int) AccurateMath.ceil(expectedSize / LOAD_FACTOR); + final int capacity = (int) JdkMath.ceil(expectedSize / LOAD_FACTOR); final int powerOfTwo = Integer.highestOneBit(capacity); if (powerOfTwo == capacity) { return capacity; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java index 4d4a55c66..17da319d5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.linear.OpenIntToDoubleHashMap.Iterator; /** @@ -225,7 +225,7 @@ public class OpenMapRealVector extends SparseRealVector * @since 2.1 */ protected boolean isDefaultValue(double value) { - return AccurateMath.abs(value) < epsilon; + return JdkMath.abs(value) < epsilon; } /** {@inheritDoc} */ @@ -401,7 +401,7 @@ public class OpenMapRealVector extends SparseRealVector res += value * value; } } - return AccurateMath.sqrt(res); + return JdkMath.sqrt(res); } /** {@inheritDoc} */ @@ -439,7 +439,7 @@ public class OpenMapRealVector extends SparseRealVector Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); - double delta = AccurateMath.abs(iter.value() - v.getEntry(iter.key())); + double delta = JdkMath.abs(iter.value() - v.getEntry(iter.key())); max += delta; } iter = v.getEntries().iterator(); @@ -447,8 +447,8 @@ public class OpenMapRealVector extends SparseRealVector iter.advance(); int key = iter.key(); if (!entries.containsKey(key)) { - double delta = AccurateMath.abs(iter.value()); - max += AccurateMath.abs(delta); + double delta = JdkMath.abs(iter.value()); + max += JdkMath.abs(delta); } } return max; @@ -480,7 +480,7 @@ public class OpenMapRealVector extends SparseRealVector Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); - double delta = AccurateMath.abs(iter.value() - v.getEntry(iter.key())); + double delta = JdkMath.abs(iter.value() - v.getEntry(iter.key())); if (delta > max) { max = delta; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java index f7a493b69..20975023f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.linear; import java.util.Arrays; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; @@ -97,7 +97,7 @@ public class QRDecomposition { final int m = matrix.getRowDimension(); final int n = matrix.getColumnDimension(); qrt = matrix.transpose().getData(); - rDiag = new double[AccurateMath.min(m, n)]; + rDiag = new double[JdkMath.min(m, n)]; cachedQ = null; cachedQT = null; cachedR = null; @@ -112,7 +112,7 @@ public class QRDecomposition { * @since 3.2 */ protected void decompose(double[][] matrix) { - for (int minor = 0; minor < AccurateMath.min(matrix.length, matrix[0].length); minor++) { + for (int minor = 0; minor < JdkMath.min(matrix.length, matrix[0].length); minor++) { performHouseholderReflection(minor, matrix); } } @@ -138,7 +138,7 @@ public class QRDecomposition { final double c = qrtMinor[row]; xNormSqr += c * c; } - final double a = (qrtMinor[minor] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); + final double a = (qrtMinor[minor] > 0) ? -JdkMath.sqrt(xNormSqr) : JdkMath.sqrt(xNormSqr); rDiag[minor] = a; if (a != 0.0) { @@ -196,7 +196,7 @@ public class QRDecomposition { final int m = qrt[0].length; double[][] ra = new double[m][n]; // copy the diagonal from rDiag and the upper triangle of qr - for (int row = AccurateMath.min(m, n) - 1; row >= 0; row--) { + for (int row = JdkMath.min(m, n) - 1; row >= 0; row--) { ra[row][row] = rDiag[row]; for (int col = row + 1; col < n; col++) { ra[row][col] = qrt[col][row]; @@ -239,11 +239,11 @@ public class QRDecomposition { * applying the Householder transformations Q_(m-1),Q_(m-2),...,Q1 in * succession to the result */ - for (int minor = m - 1; minor >= AccurateMath.min(m, n); minor--) { + for (int minor = m - 1; minor >= JdkMath.min(m, n); minor--) { qta[minor][minor] = 1.0d; } - for (int minor = AccurateMath.min(m, n)-1; minor >= 0; minor--){ + for (int minor = JdkMath.min(m, n)-1; minor >= 0; minor--){ final double[] qrtMinor = qrt[minor]; qta[minor][minor] = 1.0d; if (qrtMinor[minor] != 0.0) { @@ -281,7 +281,7 @@ public class QRDecomposition { final int m = qrt[0].length; double[][] ha = new double[m][n]; for (int i = 0; i < m; ++i) { - for (int j = 0; j < AccurateMath.min(i + 1, n); ++j) { + for (int j = 0; j < JdkMath.min(i + 1, n); ++j) { ha[i][j] = qrt[j][i] / -rDiag[j]; } } @@ -357,7 +357,7 @@ public class QRDecomposition { final double[] y = b.toArray(); // apply Householder transforms to solve Q.y = b - for (int minor = 0; minor < AccurateMath.min(m, n); minor++) { + for (int minor = 0; minor < JdkMath.min(m, n); minor++) { final double[] qrtMinor = qrt[minor]; double dotProduct = 0; @@ -404,14 +404,14 @@ public class QRDecomposition { for (int kBlock = 0; kBlock < cBlocks; ++kBlock) { final int kStart = kBlock * blockSize; - final int kEnd = AccurateMath.min(kStart + blockSize, columns); + final int kEnd = JdkMath.min(kStart + blockSize, columns); final int kWidth = kEnd - kStart; // get the right hand side vector b.copySubMatrix(0, m - 1, kStart, kEnd - 1, y); // apply Householder transforms to solve Q.y = b - for (int minor = 0; minor < AccurateMath.min(m, n); minor++) { + for (int minor = 0; minor < JdkMath.min(m, n); minor++) { final double[] qrtMinor = qrt[minor]; final double factor = 1.0 / (rDiag[minor] * qrtMinor[minor]); @@ -490,7 +490,7 @@ public class QRDecomposition { final int len = diag.length; for (int i = 0; i < len; i++) { final double d = diag[i]; - if (AccurateMath.abs(d) <= min) { + if (JdkMath.abs(d) <= min) { if (raise) { final SingularMatrixException e = new SingularMatrixException(); e.getContext().addMessage(LocalizedFormats.NUMBER_TOO_SMALL, d, min); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java index 40df29c27..9988f8ffe 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -169,7 +169,7 @@ public class RRQRDecomposition extends QRDecomposition { int rank = 1; double lastNorm = r.getFrobeniusNorm(); double rNorm = lastNorm; - while (rank < AccurateMath.min(rows, columns)) { + while (rank < JdkMath.min(rows, columns)) { double thisNorm = r.getSubMatrix(rank, rows - 1, rank, columns - 1).getFrobeniusNorm(); if (thisNorm == 0 || (thisNorm / lastNorm) * rNorm < dropThreshold) { break; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java index fbeea9b88..e581b2ae5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java @@ -32,7 +32,7 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Class defining a real-valued vector with basic algebraic operations. @@ -380,7 +380,7 @@ public abstract class RealVector { final double diff = e.getValue() - v.getEntry(e.getIndex()); d += diff * diff; } - return AccurateMath.sqrt(d); + return JdkMath.sqrt(d); } /** @@ -401,7 +401,7 @@ public abstract class RealVector { final double value = e.getValue(); sum += value * value; } - return AccurateMath.sqrt(sum); + return JdkMath.sqrt(sum); } /** @@ -419,7 +419,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - norm += AccurateMath.abs(e.getValue()); + norm += JdkMath.abs(e.getValue()); } return norm; } @@ -439,7 +439,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - norm = AccurateMath.max(norm, AccurateMath.abs(e.getValue())); + norm = JdkMath.max(norm, JdkMath.abs(e.getValue())); } return norm; } @@ -462,7 +462,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - d += AccurateMath.abs(e.getValue() - v.getEntry(e.getIndex())); + d += JdkMath.abs(e.getValue() - v.getEntry(e.getIndex())); } return d; } @@ -488,7 +488,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - d = AccurateMath.max(AccurateMath.abs(e.getValue() - v.getEntry(e.getIndex())), d); + d = JdkMath.max(JdkMath.abs(e.getValue() - v.getEntry(e.getIndex())), d); } return d; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java index 68882a51b..9e57cd63b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Calculates the rectangular Cholesky decomposition of a matrix. @@ -138,7 +138,7 @@ public class RectangularCholeskyDecomposition { } else { // transform the matrix - final double sqrt = AccurateMath.sqrt(c[ir][ir]); + final double sqrt = JdkMath.sqrt(c[ir][ir]); b[r][r] = sqrt; final double inverse = 1 / sqrt; final double inverse2 = 1 / c[ir][ir]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java index 2aa8273c6..f5182ad6b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -159,17 +159,17 @@ class SchurTransformer { matrixT[iu - 1][iu - 1] += shift.exShift; if (q >= 0) { - double z = AccurateMath.sqrt(AccurateMath.abs(q)); + double z = JdkMath.sqrt(JdkMath.abs(q)); if (p >= 0) { z = p + z; } else { z = p - z; } final double x = matrixT[iu][iu - 1]; - final double s = AccurateMath.abs(x) + AccurateMath.abs(z); + final double s = JdkMath.abs(x) + JdkMath.abs(z); p = x / s; q = z / s; - final double r = AccurateMath.sqrt(p * p + q * q); + final double r = JdkMath.sqrt(p * p + q * q); p /= r; q /= r; @@ -224,8 +224,8 @@ class SchurTransformer { double norm = 0.0; for (int i = 0; i < matrixT.length; i++) { // as matrix T is (quasi-)triangular, also take the sub-diagonal element into account - for (int j = AccurateMath.max(i - 1, 0); j < matrixT.length; j++) { - norm += AccurateMath.abs(matrixT[i][j]); + for (int j = JdkMath.max(i - 1, 0); j < matrixT.length; j++) { + norm += JdkMath.abs(matrixT[i][j]); } } return norm; @@ -241,11 +241,11 @@ class SchurTransformer { private int findSmallSubDiagonalElement(final int startIdx, final double norm) { int l = startIdx; while (l > 0) { - double s = AccurateMath.abs(matrixT[l - 1][l - 1]) + AccurateMath.abs(matrixT[l][l]); + double s = JdkMath.abs(matrixT[l - 1][l - 1]) + JdkMath.abs(matrixT[l][l]); if (s == 0.0) { s = norm; } - if (AccurateMath.abs(matrixT[l][l - 1]) < epsilon * s) { + if (JdkMath.abs(matrixT[l][l - 1]) < epsilon * s) { break; } l--; @@ -276,7 +276,7 @@ class SchurTransformer { for (int i = 0; i <= idx; i++) { matrixT[i][i] -= shift.x; } - final double s = AccurateMath.abs(matrixT[idx][idx - 1]) + AccurateMath.abs(matrixT[idx - 1][idx - 2]); + final double s = JdkMath.abs(matrixT[idx][idx - 1]) + JdkMath.abs(matrixT[idx - 1][idx - 2]); shift.x = 0.75 * s; shift.y = 0.75 * s; shift.w = -0.4375 * s * s; @@ -287,7 +287,7 @@ class SchurTransformer { double s = (shift.y - shift.x) / 2.0; s = s * s + shift.w; if (s > 0.0) { - s = AccurateMath.sqrt(s); + s = JdkMath.sqrt(s); if (shift.y < shift.x) { s = -s; } @@ -325,10 +325,10 @@ class SchurTransformer { break; } - final double lhs = AccurateMath.abs(matrixT[im][im - 1]) * (AccurateMath.abs(hVec[1]) + AccurateMath.abs(hVec[2])); - final double rhs = AccurateMath.abs(hVec[0]) * (AccurateMath.abs(matrixT[im - 1][im - 1]) + - AccurateMath.abs(z) + - AccurateMath.abs(matrixT[im + 1][im + 1])); + final double lhs = JdkMath.abs(matrixT[im][im - 1]) * (JdkMath.abs(hVec[1]) + JdkMath.abs(hVec[2])); + final double rhs = JdkMath.abs(hVec[0]) * (JdkMath.abs(matrixT[im - 1][im - 1]) + + JdkMath.abs(z) + + JdkMath.abs(matrixT[im + 1][im + 1])); if (lhs < epsilon * rhs) { break; @@ -362,7 +362,7 @@ class SchurTransformer { p = matrixT[k][k - 1]; q = matrixT[k + 1][k - 1]; r = notlast ? matrixT[k + 2][k - 1] : 0.0; - shift.x = AccurateMath.abs(p) + AccurateMath.abs(q) + AccurateMath.abs(r); + shift.x = JdkMath.abs(p) + JdkMath.abs(q) + JdkMath.abs(r); if (Precision.equals(shift.x, 0.0, epsilon)) { continue; } @@ -370,7 +370,7 @@ class SchurTransformer { q /= shift.x; r /= shift.x; } - double s = AccurateMath.sqrt(p * p + q * q + r * r); + double s = JdkMath.sqrt(p * p + q * q + r * r); if (p < 0.0) { s = -s; } @@ -399,7 +399,7 @@ class SchurTransformer { } // Column modification - for (int i = 0; i <= AccurateMath.min(iu, k + 3); i++) { + for (int i = 0; i <= JdkMath.min(iu, k + 3); i++) { p = shift.x * matrixT[i][k] + shift.y * matrixT[i][k + 1]; if (notlast) { p += z * matrixT[i][k + 2]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java index fe8ea6440..610ce8364 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -107,16 +107,16 @@ public class SingularValueDecomposition { final double[] work = new double[m]; // Reduce A to bidiagonal form, storing the diagonal elements // in s and the super-diagonal elements in e. - final int nct = AccurateMath.min(m - 1, n); - final int nrt = AccurateMath.max(0, n - 2); - for (int k = 0; k < AccurateMath.max(nct, nrt); k++) { + final int nct = JdkMath.min(m - 1, n); + final int nrt = JdkMath.max(0, n - 2); + for (int k = 0; k < JdkMath.max(nct, nrt); k++) { if (k < nct) { // Compute the transformation for the k-th column and // place the k-th diagonal in s[k]. // Compute 2-norm of k-th column without under/overflow. singularValues[k] = 0; for (int i = k; i < m; i++) { - singularValues[k] = AccurateMath.hypot(singularValues[k], A[i][k]); + singularValues[k] = JdkMath.hypot(singularValues[k], A[i][k]); } if (singularValues[k] != 0) { if (A[k][k] < 0) { @@ -159,7 +159,7 @@ public class SingularValueDecomposition { // Compute 2-norm without under/overflow. e[k] = 0; for (int i = k + 1; i < n; i++) { - e[k] = AccurateMath.hypot(e[k], e[i]); + e[k] = JdkMath.hypot(e[k], e[i]); } if (e[k] != 0) { if (e[k + 1] < 0) { @@ -281,16 +281,16 @@ public class SingularValueDecomposition { // kase = 4 if e(p-1) is negligible (convergence). for (k = p - 2; k >= 0; k--) { final double threshold - = TINY + EPS * (AccurateMath.abs(singularValues[k]) + - AccurateMath.abs(singularValues[k + 1])); + = TINY + EPS * (JdkMath.abs(singularValues[k]) + + JdkMath.abs(singularValues[k + 1])); // the following condition is written this way in order // to break out of the loop when NaN occurs, writing it - // as "if (AccurateMath.abs(e[k]) <= threshold)" would loop + // as "if (JdkMath.abs(e[k]) <= threshold)" would loop // indefinitely in case of NaNs because comparison on NaNs // always return false, regardless of what is checked // see issue MATH-947 - if (!(AccurateMath.abs(e[k]) > threshold)) { + if (!(JdkMath.abs(e[k]) > threshold)) { e[k] = 0; break; } @@ -305,9 +305,9 @@ public class SingularValueDecomposition { if (ks == k) { break; } - final double t = (ks != p ? AccurateMath.abs(e[ks]) : 0) + - (ks != k + 1 ? AccurateMath.abs(e[ks - 1]) : 0); - if (AccurateMath.abs(singularValues[ks]) <= TINY + EPS * t) { + final double t = (ks != p ? JdkMath.abs(e[ks]) : 0) + + (ks != k + 1 ? JdkMath.abs(e[ks - 1]) : 0); + if (JdkMath.abs(singularValues[ks]) <= TINY + EPS * t) { singularValues[ks] = 0; break; } @@ -330,7 +330,7 @@ public class SingularValueDecomposition { f = e[p - 2]; e[p - 2] = 0; for (int j = p - 2; j >= k; j--) { - double t = AccurateMath.hypot(singularValues[j], f); + double t = JdkMath.hypot(singularValues[j], f); final double cs = singularValues[j] / t; final double sn = f / t; singularValues[j] = t; @@ -351,7 +351,7 @@ public class SingularValueDecomposition { f = e[k - 1]; e[k - 1] = 0; for (int j = k; j < p; j++) { - double t = AccurateMath.hypot(singularValues[j], f); + double t = JdkMath.hypot(singularValues[j], f); final double cs = singularValues[j] / t; final double sn = f / t; singularValues[j] = t; @@ -368,12 +368,12 @@ public class SingularValueDecomposition { // Perform one qr step. case 3: // Calculate the shift. - final double maxPm1Pm2 = AccurateMath.max(AccurateMath.abs(singularValues[p - 1]), - AccurateMath.abs(singularValues[p - 2])); - final double scale = AccurateMath.max(AccurateMath.max(AccurateMath.max(maxPm1Pm2, - AccurateMath.abs(e[p - 2])), - AccurateMath.abs(singularValues[k])), - AccurateMath.abs(e[k])); + final double maxPm1Pm2 = JdkMath.max(JdkMath.abs(singularValues[p - 1]), + JdkMath.abs(singularValues[p - 2])); + final double scale = JdkMath.max(JdkMath.max(JdkMath.max(maxPm1Pm2, + JdkMath.abs(e[p - 2])), + JdkMath.abs(singularValues[k])), + JdkMath.abs(e[k])); final double sp = singularValues[p - 1] / scale; final double spm1 = singularValues[p - 2] / scale; final double epm1 = e[p - 2] / scale; @@ -384,7 +384,7 @@ public class SingularValueDecomposition { double shift = 0; if (b != 0 || c != 0) { - shift = AccurateMath.sqrt(b * b + c); + shift = JdkMath.sqrt(b * b + c); if (b < 0) { shift = -shift; } @@ -394,7 +394,7 @@ public class SingularValueDecomposition { double g = sk * ek; // Chase zeros. for (int j = k; j < p - 1; j++) { - double t = AccurateMath.hypot(f, g); + double t = JdkMath.hypot(f, g); double cs = f / t; double sn = g / t; if (j != k) { @@ -410,7 +410,7 @@ public class SingularValueDecomposition { V[i][j + 1] = -sn * V[i][j] + cs * V[i][j + 1]; V[i][j] = t; } - t = AccurateMath.hypot(f, g); + t = JdkMath.hypot(f, g); cs = f / t; sn = g / t; singularValues[j] = t; @@ -468,8 +468,8 @@ public class SingularValueDecomposition { } // Set the small value tolerance used to calculate rank and pseudo-inverse - tol = AccurateMath.max(m * singularValues[0] * EPS, - AccurateMath.sqrt(Precision.SAFE_MIN)); + tol = JdkMath.max(m * singularValues[0] * EPS, + JdkMath.sqrt(Precision.SAFE_MIN)); if (!transposed) { cachedU = MatrixUtils.createRealMatrix(U); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java index 77880c136..33925213b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.ExceptionContext; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** *

@@ -360,8 +360,8 @@ public class SymmLQ private boolean bIsNull; static { - MACH_PREC = AccurateMath.ulp(1.); - CBRT_MACH_PREC = AccurateMath.cbrt(MACH_PREC); + MACH_PREC = JdkMath.ulp(1.); + CBRT_MACH_PREC = JdkMath.cbrt(MACH_PREC); } /** @@ -416,7 +416,7 @@ public class SymmLQ final double s = y.dotProduct(y); final double t = x.dotProduct(z); final double epsa = (s + MACH_PREC) * CBRT_MACH_PREC; - if (AccurateMath.abs(s - t) > epsa) { + if (JdkMath.abs(s - t) > epsa) { final NonSelfAdjointOperatorException e; e = new NonSelfAdjointOperatorException(); final ExceptionContext context = e.getContext(); @@ -511,11 +511,11 @@ public class SymmLQ } } } else { - final double anorm = AccurateMath.sqrt(tnorm); + final double anorm = JdkMath.sqrt(tnorm); final double diag = gbar == 0. ? anorm * MACH_PREC : gbar; final double zbar = gammaZeta / diag; final double step = (bstep + snprod * zbar) / beta1; - // ynorm = AccurateMath.sqrt(ynorm2 + zbar * zbar); + // ynorm = JdkMath.sqrt(ynorm2 + zbar * zbar); if (!goodb) { for (int i = 0; i < n; i++) { final double xi = this.xL.getEntry(i); @@ -560,7 +560,7 @@ public class SymmLQ return; } this.bIsNull = false; - this.beta1 = AccurateMath.sqrt(this.beta1); + this.beta1 = JdkMath.sqrt(this.beta1); /* At this point * r1 = b, * y = M * b, @@ -596,7 +596,7 @@ public class SymmLQ if (this.beta < 0.) { throwNPDLOException(this.m, this.y); } - this.beta = AccurateMath.sqrt(this.beta); + this.beta = JdkMath.sqrt(this.beta); /* * At this point * oldb = beta[1] @@ -613,7 +613,7 @@ public class SymmLQ this.snprod = 1.; this.tnorm = alpha * alpha + this.beta * this.beta; this.ynorm2 = 0.; - this.gmax = AccurateMath.abs(alpha) + MACH_PREC; + this.gmax = JdkMath.abs(alpha) + MACH_PREC; this.gmin = this.gmax; if (this.goodb) { @@ -670,7 +670,7 @@ public class SymmLQ if (beta < 0.) { throwNPDLOException(m, y); } - beta = AccurateMath.sqrt(beta); + beta = JdkMath.sqrt(beta); /* * At this point * r1 = beta[k] * M^(-1) * P' * v[k], @@ -687,7 +687,7 @@ public class SymmLQ * c = c[k-1], * s = s[k-1]. */ - final double gamma = AccurateMath.sqrt(gbar * gbar + oldb * oldb); + final double gamma = JdkMath.sqrt(gbar * gbar + oldb * oldb); final double c = gbar / gamma; final double s = oldb / gamma; /* @@ -730,8 +730,8 @@ public class SymmLQ */ bstep += snprod * c * zeta; snprod *= s; - gmax = AccurateMath.max(gmax, gamma); - gmin = AccurateMath.min(gmin, gamma); + gmax = JdkMath.max(gmax, gamma); + gmin = JdkMath.min(gmin, gamma); ynorm2 += zeta * zeta; gammaZeta = minusEpsZeta - deltak * zeta; minusEpsZeta = -eps * zeta; @@ -755,16 +755,16 @@ public class SymmLQ * Updates {@link #lqnorm} and {@link #cgnorm}. */ private void updateNorms() { - final double anorm = AccurateMath.sqrt(tnorm); - final double ynorm = AccurateMath.sqrt(ynorm2); + final double anorm = JdkMath.sqrt(tnorm); + final double ynorm = JdkMath.sqrt(ynorm2); final double epsa = anorm * MACH_PREC; final double epsx = anorm * ynorm * MACH_PREC; final double epsr = anorm * ynorm * delta; final double diag = gbar == 0. ? epsa : gbar; - lqnorm = AccurateMath.sqrt(gammaZeta * gammaZeta + + lqnorm = JdkMath.sqrt(gammaZeta * gammaZeta + minusEpsZeta * minusEpsZeta); final double qrnorm = snprod * beta1; - cgnorm = qrnorm * beta / AccurateMath.abs(diag); + cgnorm = qrnorm * beta / JdkMath.abs(diag); /* * Estimate cond(A). In this version we look at the diagonals of L @@ -776,7 +776,7 @@ public class SymmLQ if (lqnorm <= cgnorm) { acond = gmax / gmin; } else { - acond = gmax / AccurateMath.min(gmin, AccurateMath.abs(diag)); + acond = gmax / JdkMath.min(gmin, JdkMath.abs(diag)); } if (acond * MACH_PREC >= 0.1) { throw new IllConditionedOperatorException(acond); @@ -788,7 +788,7 @@ public class SymmLQ */ throw new SingularOperatorException(); } - rnorm = AccurateMath.min(cgnorm, lqnorm); + rnorm = JdkMath.min(cgnorm, lqnorm); hasConverged = (cgnorm <= epsx) || (cgnorm <= epsr); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java index f57ba2ba3..1320eb6b0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.linear; import java.util.Arrays; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -201,7 +201,7 @@ class TriDiagonalTransformer { final double c = hK[j]; xNormSqr += c * c; } - final double a = (hK[k + 1] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); + final double a = (hK[k + 1] > 0) ? -JdkMath.sqrt(xNormSqr) : JdkMath.sqrt(xNormSqr); secondary[k] = a; if (a != 0.0) { // apply Householder transform from left and right simultaneously diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java index 69c97123f..c5dcba5fd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; import org.apache.commons.math4.legacy.ml.distance.EuclideanDistance; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -244,7 +244,7 @@ public class FuzzyKMeansClusterer extends Clusterer { int j = 0; for (final CentroidCluster cluster : clusters) { final double dist = distance(point, cluster.getCenter()); - objFunction += (dist * dist) * AccurateMath.pow(membershipMatrix[i][j], fuzziness); + objFunction += (dist * dist) * JdkMath.pow(membershipMatrix[i][j], fuzziness); j++; } i++; @@ -318,7 +318,7 @@ public class FuzzyKMeansClusterer extends Clusterer { double[] arr = new double[center.getPoint().length]; double sum = 0.0; for (final T point : points) { - final double u = AccurateMath.pow(membershipMatrix[i][j], fuzziness); + final double u = JdkMath.pow(membershipMatrix[i][j], fuzziness); final double[] pointArr = point.getPoint(); for (int idx = 0; idx < arr.length; idx++) { arr[idx] += u * pointArr[idx]; @@ -345,16 +345,16 @@ public class FuzzyKMeansClusterer extends Clusterer { int newCluster = -1; for (int j = 0; j < clusters.size(); j++) { double sum = 0.0; - final double distA = AccurateMath.abs(distance(point, clusters.get(j).getCenter())); + final double distA = JdkMath.abs(distance(point, clusters.get(j).getCenter())); if (distA != 0.0) { for (final CentroidCluster c : clusters) { - final double distB = AccurateMath.abs(distance(point, c.getCenter())); + final double distB = JdkMath.abs(distance(point, c.getCenter())); if (distB == 0.0) { sum = Double.POSITIVE_INFINITY; break; } - sum += AccurateMath.pow(distA / distB, 2.0 / (fuzziness - 1.0)); + sum += JdkMath.pow(distA / distB, 2.0 / (fuzziness - 1.0)); } } @@ -400,8 +400,8 @@ public class FuzzyKMeansClusterer extends Clusterer { double maxMembership = 0.0; for (int i = 0; i < points.size(); i++) { for (int j = 0; j < clusters.size(); j++) { - double v = AccurateMath.abs(membershipMatrix[i][j] - matrix[i][j]); - maxMembership = AccurateMath.max(v, maxMembership); + double v = JdkMath.abs(membershipMatrix[i][j] - matrix[i][j]); + maxMembership = JdkMath.max(v, maxMembership); } } return maxMembership; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java index 628ee6d0a..8da439028 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -37,8 +37,8 @@ public class CanberraDistance implements DistanceMeasure { MathArrays.checkEqualLength(a, b); double sum = 0; for (int i = 0; i < a.length; i++) { - final double num = AccurateMath.abs(a[i] - b[i]); - final double denom = AccurateMath.abs(a[i]) + AccurateMath.abs(b[i]); + final double num = JdkMath.abs(a[i] - b[i]); + final double denom = JdkMath.abs(a[i]) + JdkMath.abs(b[i]); sum += num == 0.0 && denom == 0.0 ? 0.0 : num / denom; } return sum; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java index fd72d469c..c62b57074 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -41,7 +41,7 @@ public class EarthMoversDistance implements DistanceMeasure { double totalDistance = 0; for (int i = 0; i < a.length; i++) { final double currentDistance = (a[i] + lastDistance) - b[i]; - totalDistance += AccurateMath.abs(currentDistance); + totalDistance += JdkMath.abs(currentDistance); lastDistance = currentDistance; } return totalDistance; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java index 8b7ba2933..5658f6ffd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java @@ -39,7 +39,7 @@ import org.apache.commons.math4.legacy.ode.events.FieldEventHandler; import org.apache.commons.math4.legacy.ode.events.FieldEventState; import org.apache.commons.math4.legacy.ode.sampling.AbstractFieldStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.FieldStepHandler; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.IntegerSequence; /** @@ -385,7 +385,7 @@ public abstract class AbstractFieldIntegrator> imp state.stepAccepted(currentState); isLastStep = isLastStep || state.stop(); } - isLastStep = isLastStep || currentState.getTime().subtract(tEnd).abs().getReal() <= AccurateMath.ulp(tEnd.getReal()); + isLastStep = isLastStep || currentState.getTime().subtract(tEnd).abs().getReal() <= JdkMath.ulp(tEnd.getReal()); // handle the remaining part of the step, after all events if any for (FieldStepHandler handler : stepHandlers) { @@ -406,8 +406,8 @@ public abstract class AbstractFieldIntegrator> imp protected void sanityChecks(final FieldODEState eqn, final T t) throws NumberIsTooSmallException, DimensionMismatchException { - final double threshold = 1000 * AccurateMath.ulp(AccurateMath.max(AccurateMath.abs(eqn.getTime().getReal()), - AccurateMath.abs(t.getReal()))); + final double threshold = 1000 * JdkMath.ulp(JdkMath.max(JdkMath.abs(eqn.getTime().getReal()), + JdkMath.abs(t.getReal()))); final double dt = eqn.getTime().subtract(t).abs().getReal(); if (dt <= threshold) { throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java index 25f1c1615..9a3945eec 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java @@ -37,7 +37,7 @@ import org.apache.commons.math4.legacy.ode.events.EventHandler; import org.apache.commons.math4.legacy.ode.events.EventState; import org.apache.commons.math4.legacy.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.IntegerSequence; import org.apache.commons.numbers.core.Precision; @@ -458,9 +458,9 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { protected void sanityChecks(final ExpandableStatefulODE equations, final double t) throws NumberIsTooSmallException, DimensionMismatchException { - final double threshold = 1000 * AccurateMath.ulp(AccurateMath.max(AccurateMath.abs(equations.getTime()), - AccurateMath.abs(t))); - final double dt = AccurateMath.abs(equations.getTime() - t); + final double threshold = 1000 * JdkMath.ulp(JdkMath.max(JdkMath.abs(equations.getTime()), + JdkMath.abs(t))); + final double dt = JdkMath.abs(equations.getTime() - t); if (dt <= threshold) { throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, dt, threshold, false); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java index b2656a1b7..85e8ff647 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.ode.sampling.FieldStepHandler; import org.apache.commons.math4.legacy.ode.sampling.FieldStepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class stores all information provided by an ODE integrator @@ -292,12 +292,12 @@ public class ContinuousOutputFieldModel> subtract(dt1.multiply(dt3).multiply(d13).multiply(iMed)). add( dt1.multiply(dt2).multiply(d12).multiply(iMin)). divide(d12.multiply(d23).multiply(d13)); - index = (int) AccurateMath.rint(iLagrange.getReal()); + index = (int) JdkMath.rint(iLagrange.getReal()); } // force the next size reduction to be at least one tenth - final int low = AccurateMath.max(iMin + 1, (9 * iMin + iMax) / 10); - final int high = AccurateMath.min(iMax - 1, (iMin + 9 * iMax) / 10); + final int low = JdkMath.max(iMin + 1, (9 * iMin + iMax) / 10); + final int high = JdkMath.min(iMax - 1, (iMin + 9 * iMax) / 10); if (index < low) { index = low; } else if (index > high) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java index 4e29d2200..c062e3f4e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class stores all information provided by an ODE integrator @@ -152,9 +152,9 @@ public class ContinuousOutputModel final double previous = lastInterpolator.getPreviousTime(); final double step = current - previous; final double gap = model.getInitialTime() - current; - if (AccurateMath.abs(gap) > 1.0e-3 * AccurateMath.abs(step)) { + if (JdkMath.abs(gap) > 1.0e-3 * JdkMath.abs(step)) { throw new MathIllegalArgumentException(LocalizedFormats.HOLE_BETWEEN_MODELS_TIME_RANGES, - AccurateMath.abs(gap)); + JdkMath.abs(gap)); } } @@ -296,7 +296,7 @@ public void handleStep(final StepInterpolator interpolator, final boolean isLast final StepInterpolator sMed = steps.get(iMed); final double tMed = 0.5 * (sMed.getPreviousTime() + sMed.getCurrentTime()); - if ((AccurateMath.abs(tMed - tMin) < 1e-6) || (AccurateMath.abs(tMax - tMed) < 1e-6)) { + if ((JdkMath.abs(tMed - tMin) < 1e-6) || (JdkMath.abs(tMax - tMed) < 1e-6)) { // too close to the bounds, we estimate using a simple dichotomy index = iMed; } else { @@ -313,12 +313,12 @@ public void handleStep(final StepInterpolator interpolator, final boolean isLast (dt1 * dt3 * d13) * iMed + (dt1 * dt2 * d12) * iMin) / (d12 * d23 * d13); - index = (int) AccurateMath.rint(iLagrange); + index = (int) JdkMath.rint(iLagrange); } // force the next size reduction to be at least one tenth - final int low = AccurateMath.max(iMin + 1, (9 * iMin + iMax) / 10); - final int high = AccurateMath.min(iMax - 1, (iMin + 9 * iMax) / 10); + final int low = JdkMath.max(iMin + 1, (9 * iMin + iMax) / 10); + final int high = JdkMath.min(iMax - 1, (iMin + 9 * iMax) / 10); if (index < low) { index = low; } else if (index > high) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java index e326611e6..481237c57 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java @@ -198,7 +198,7 @@ public class JacobianMatrices { *

*

* Given a non zero parameter value pval for the parameter, a reasonable value - * for such a step is {@code pval * AccurateMath.sqrt(Precision.EPSILON)}. + * for such a step is {@code pval * JdkMath.sqrt(Precision.EPSILON)}. *

*

* A zero value for such a step doesn't enable to compute the parameter Jacobian matrix. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java index a25518d7c..2e6c1146b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.ode.nonstiff.AdaptiveStepsizeFieldIntegra import org.apache.commons.math4.legacy.ode.nonstiff.DormandPrince853FieldIntegrator; import org.apache.commons.math4.legacy.ode.sampling.FieldStepHandler; import org.apache.commons.math4.legacy.ode.sampling.FieldStepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -139,7 +139,7 @@ public abstract class MultistepFieldIntegrator> // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(AccurateMath.pow(2.0, -exp)); + setMaxGrowth(JdkMath.pow(2.0, -exp)); } @@ -179,7 +179,7 @@ public abstract class MultistepFieldIntegrator> // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(AccurateMath.pow(2.0, -exp)); + setMaxGrowth(JdkMath.pow(2.0, -exp)); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java index 222f66343..42cf07ede 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.ode.nonstiff.AdaptiveStepsizeIntegrator; import org.apache.commons.math4.legacy.ode.nonstiff.DormandPrince853Integrator; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class is the base class for multistep integrators for Ordinary @@ -133,7 +133,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(AccurateMath.pow(2.0, -exp)); + setMaxGrowth(JdkMath.pow(2.0, -exp)); } @@ -172,7 +172,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(AccurateMath.pow(2.0, -exp)); + setMaxGrowth(JdkMath.pow(2.0, -exp)); } @@ -331,7 +331,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { * @return grow/shrink factor for next step */ protected double computeStepGrowShrinkFactor(final double error) { - return AccurateMath.min(maxGrowth, AccurateMath.max(minReduction, safety * AccurateMath.pow(error, exp))); + return JdkMath.min(maxGrowth, JdkMath.max(minReduction, safety * JdkMath.pow(error, exp))); } /** Transformer used to convert the first step to Nordsieck representation. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java index eeec951c8..aa4f1a607 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** This class handles the state for one {@link EventHandler * event handler} during integration steps. @@ -106,7 +106,7 @@ public class EventState { final UnivariateSolver solver) { this.handler = handler; this.maxCheckInterval = maxCheckInterval; - this.convergence = AccurateMath.abs(convergence); + this.convergence = JdkMath.abs(convergence); this.maxIterationCount = maxIterationCount; this.solver = solver; @@ -183,8 +183,8 @@ public class EventState { // extremely rare case: there is a zero EXACTLY at interval start // we will use the sign slightly after step beginning to force ignoring this zero - final double epsilon = AccurateMath.max(solver.getAbsoluteAccuracy(), - AccurateMath.abs(solver.getRelativeAccuracy() * t0)); + final double epsilon = JdkMath.max(solver.getAbsoluteAccuracy(), + JdkMath.abs(solver.getRelativeAccuracy() * t0)); final double tStart = t0 + 0.5 * epsilon; interpolator.setInterpolatedTime(tStart); g0 = handler.g(tStart, getCompleteState(interpolator)); @@ -228,11 +228,11 @@ public class EventState { forward = interpolator.isForward(); final double t1 = interpolator.getCurrentTime(); final double dt = t1 - t0; - if (AccurateMath.abs(dt) < convergence) { + if (JdkMath.abs(dt) < convergence) { // we cannot do anything on such a small step, don't trigger any events return false; } - final int n = AccurateMath.max(1, (int) AccurateMath.ceil(AccurateMath.abs(dt) / maxCheckInterval)); + final int n = JdkMath.max(1, (int) JdkMath.ceil(JdkMath.abs(dt) / maxCheckInterval)); final double h = dt / n; final UnivariateFunction f = new UnivariateFunction() { @@ -288,8 +288,8 @@ public class EventState { } if ((!Double.isNaN(previousEventTime)) && - (AccurateMath.abs(root - ta) <= convergence) && - (AccurateMath.abs(root - previousEventTime) <= convergence)) { + (JdkMath.abs(root - ta) <= convergence) && + (JdkMath.abs(root - previousEventTime) <= convergence)) { // we have either found nothing or found (again ?) a past event, // retry the substep excluding this value, and taking care to have the // required sign in case the g function is noisy around its zero and @@ -311,7 +311,7 @@ public class EventState { return true; } } else if (Double.isNaN(previousEventTime) || - (AccurateMath.abs(previousEventTime - root) > convergence)) { + (JdkMath.abs(previousEventTime - root) > convergence)) { pendingEventTime = root; pendingEvent = true; return true; @@ -361,7 +361,7 @@ public class EventState { t0 = t; g0 = handler.g(t, y); - if (pendingEvent && (AccurateMath.abs(pendingEventTime - t) <= convergence)) { + if (pendingEvent && (JdkMath.abs(pendingEventTime - t) <= convergence)) { // force the sign to its value "just after the event" previousEventTime = t; g0Positive = increasing; @@ -389,7 +389,7 @@ public class EventState { */ public boolean reset(final double t, final double[] y) { - if (!(pendingEvent && (AccurateMath.abs(pendingEventTime - t) <= convergence))) { + if (!(pendingEvent && (JdkMath.abs(pendingEventTime - t) <= convergence))) { return false; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java index e91bacc36..d7e523b8d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; import org.apache.commons.math4.legacy.ode.sampling.FieldStepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** This class handles the state for one {@link EventHandler * event handler} during integration steps. @@ -171,8 +171,8 @@ public class FieldEventState> { // extremely rare case: there is a zero EXACTLY at interval start // we will use the sign slightly after step beginning to force ignoring this zero - final double epsilon = AccurateMath.max(solver.getAbsoluteAccuracy().getReal(), - AccurateMath.abs(solver.getRelativeAccuracy().multiply(t0).getReal())); + final double epsilon = JdkMath.max(solver.getAbsoluteAccuracy().getReal(), + JdkMath.abs(solver.getRelativeAccuracy().multiply(t0).getReal())); final T tStart = t0.add(0.5 * epsilon); g0 = handler.g(interpolator.getInterpolatedState(tStart)); } @@ -199,7 +199,7 @@ public class FieldEventState> { // we cannot do anything on such a small step, don't trigger any events return false; } - final int n = AccurateMath.max(1, (int) AccurateMath.ceil(AccurateMath.abs(dt.getReal()) / maxCheckInterval)); + final int n = JdkMath.max(1, (int) JdkMath.ceil(JdkMath.abs(dt.getReal()) / maxCheckInterval)); final T h = dt.divide(n); final RealFieldUnivariateFunction f = new RealFieldUnivariateFunction() { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java index c2e005fa2..b4b2a5125 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.events; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; @@ -80,7 +80,7 @@ enum Transformer { /** {@inheritDoc} */ @Override protected double transformed(final double g) { - return AccurateMath.min(-Precision.SAFE_MIN, AccurateMath.min(-g, +g)); + return JdkMath.min(-Precision.SAFE_MIN, JdkMath.min(-g, +g)); } }, @@ -94,7 +94,7 @@ enum Transformer { /** {@inheritDoc} */ @Override protected double transformed(final double g) { - return AccurateMath.max(+Precision.SAFE_MIN, AccurateMath.max(-g, +g)); + return JdkMath.max(+Precision.SAFE_MIN, JdkMath.max(-g, +g)); } }; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java index 2cd9ea03f..c1ac06c8d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.sampling.NordsieckStepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -207,7 +207,7 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator { double error = 0; for (int i = 0; i < mainSetDimension; ++i) { - final double yScale = AccurateMath.abs(predictedState[i]); + final double yScale = JdkMath.abs(predictedState[i]); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); @@ -227,7 +227,7 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator { } - return AccurateMath.sqrt(error / mainSetDimension); + return JdkMath.sqrt(error / mainSetDimension); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java index ed6be4678..20b05db0e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.linear.RealMatrixPreservingVisitor; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.sampling.NordsieckStepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -406,7 +406,7 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator { for (int i = 0; i < after.length; ++i) { after[i] += previous[i] + scaled[i]; if (i < mainSetDimension) { - final double yScale = AccurateMath.max(AccurateMath.abs(previous[i]), AccurateMath.abs(after[i])); + final double yScale = JdkMath.max(JdkMath.abs(previous[i]), JdkMath.abs(after[i])); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); @@ -415,7 +415,7 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator { } } - return AccurateMath.sqrt(error / mainSetDimension); + return JdkMath.sqrt(error / mainSetDimension); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java index c13624561..0f8dfaeac 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.ode.AbstractFieldIntegrator; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -159,8 +159,8 @@ public abstract class AdaptiveStepsizeFieldIntegrator= 1.0) { // reject the step and attempt to reduce error by stepsize control final double factor = - AccurateMath.min(maxGrowth, - AccurateMath.max(minReduction, safety * AccurateMath.pow(error, exp))); + JdkMath.min(maxGrowth, + JdkMath.max(minReduction, safety * JdkMath.pow(error, exp))); hNew = filterStep(stepSize * factor, forward, false); } @@ -313,7 +313,7 @@ public abstract class EmbeddedRungeKuttaIntegrator // stepsize control for next step final double factor = - AccurateMath.min(maxGrowth, AccurateMath.max(minReduction, safety * AccurateMath.pow(error, exp))); + JdkMath.min(maxGrowth, JdkMath.max(minReduction, safety * JdkMath.pow(error, exp))); final double scaledH = stepSize * factor; final double nextT = stepStart + scaledH; final boolean nextIsLast = forward ? (nextT >= t) : (nextT <= t); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java index 7c584edfb..e5a1832e9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -54,13 +54,13 @@ public class GillIntegrator extends RungeKuttaIntegrator { /** Internal weights Butcher array. */ private static final double[][] STATIC_A = { { 1.0 / 2.0 }, - { (AccurateMath.sqrt(2.0) - 1.0) / 2.0, (2.0 - AccurateMath.sqrt(2.0)) / 2.0 }, - { 0.0, -AccurateMath.sqrt(2.0) / 2.0, (2.0 + AccurateMath.sqrt(2.0)) / 2.0 } + { (JdkMath.sqrt(2.0) - 1.0) / 2.0, (2.0 - JdkMath.sqrt(2.0)) / 2.0 }, + { 0.0, -JdkMath.sqrt(2.0) / 2.0, (2.0 + JdkMath.sqrt(2.0)) / 2.0 } }; /** Propagation weights Butcher array. */ private static final double[] STATIC_B = { - 1.0 / 6.0, (2.0 - AccurateMath.sqrt(2.0)) / 6.0, (2.0 + AccurateMath.sqrt(2.0)) / 6.0, 1.0 / 6.0 + 1.0 / 6.0, (2.0 - JdkMath.sqrt(2.0)) / 6.0, (2.0 + JdkMath.sqrt(2.0)) / 6.0, 1.0 / 6.0 }; /** Simple constructor. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java index 87b82aa67..71b77c2a1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements a step interpolator for the Gill fourth @@ -55,10 +55,10 @@ class GillStepInterpolator extends RungeKuttaStepInterpolator { /** First Gill coefficient. */ - private static final double ONE_MINUS_INV_SQRT_2 = 1 - AccurateMath.sqrt(0.5); + private static final double ONE_MINUS_INV_SQRT_2 = 1 - JdkMath.sqrt(0.5); /** Second Gill coefficient. */ - private static final double ONE_PLUS_INV_SQRT_2 = 1 + AccurateMath.sqrt(0.5); + private static final double ONE_PLUS_INV_SQRT_2 = 1 + JdkMath.sqrt(0.5); /** Serializable version identifier. */ private static final long serialVersionUID = 20111120L; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java index e2b0a61d5..9916e0b6e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.events.EventHandler; import org.apache.commons.math4.legacy.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements a Gragg-Bulirsch-Stoer integrator for @@ -425,12 +425,12 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { private void rescale(final double[] y1, final double[] y2, final double[] scale) { if (vecAbsoluteTolerance == null) { for (int i = 0; i < scale.length; ++i) { - final double yi = AccurateMath.max(AccurateMath.abs(y1[i]), AccurateMath.abs(y2[i])); + final double yi = JdkMath.max(JdkMath.abs(y1[i]), JdkMath.abs(y2[i])); scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * yi; } } else { for (int i = 0; i < scale.length; ++i) { - final double yi = AccurateMath.max(AccurateMath.abs(y1[i]), AccurateMath.abs(y2[i])); + final double yi = JdkMath.max(JdkMath.abs(y1[i]), JdkMath.abs(y2[i])); scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yi; } } @@ -500,7 +500,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { final double ratio = (f[j+1][l] - f[0][l]) / scale[l]; deltaNorm += ratio * ratio; } - if (deltaNorm > 4 * AccurateMath.max(1.0e-15, initialNorm)) { + if (deltaNorm > 4 * JdkMath.max(1.0e-15, initialNorm)) { return false; } } @@ -595,10 +595,10 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { // initial order selection final double tol = (vecRelativeTolerance == null) ? scalRelativeTolerance : vecRelativeTolerance[0]; - final double log10R = AccurateMath.log10(AccurateMath.max(1.0e-10, tol)); - int targetIter = AccurateMath.max(1, - AccurateMath.min(sequence.length - 2, - (int) AccurateMath.floor(0.5 - 0.6 * log10R))); + final double log10R = JdkMath.log10(JdkMath.max(1.0e-10, tol)); + int targetIter = JdkMath.max(1, + JdkMath.min(sequence.length - 2, + (int) JdkMath.floor(0.5 - 0.6 * log10R))); // set up an interpolator sharing the integrator arrays final AbstractStepInterpolator interpolator = @@ -665,7 +665,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { yTmp)) { // the stability check failed, we reduce the global step - hNew = AccurateMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); + hNew = JdkMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); reject = true; loop = false; @@ -682,26 +682,26 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { // estimate the error at the end of the step. error = 0; for (int j = 0; j < mainSetDimension; ++j) { - final double e = AccurateMath.abs(y1[j] - y1Diag[0][j]) / scale[j]; + final double e = JdkMath.abs(y1[j] - y1Diag[0][j]) / scale[j]; error += e * e; } - error = AccurateMath.sqrt(error / mainSetDimension); + error = JdkMath.sqrt(error / mainSetDimension); if ((error > 1.0e15) || ((k > 1) && (error > maxError))) { // error is too big, we reduce the global step - hNew = AccurateMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); + hNew = JdkMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); reject = true; loop = false; } else { - maxError = AccurateMath.max(4 * error, 1.0); + maxError = JdkMath.max(4 * error, 1.0); // compute optimal stepsize for this order final double exp = 1.0 / (2 * k + 1); - double fac = stepControl2 / AccurateMath.pow(error / stepControl1, exp); - final double pow = AccurateMath.pow(stepControl3, exp); - fac = AccurateMath.max(pow / stepControl4, AccurateMath.min(1 / pow, fac)); - optimalStep[k] = AccurateMath.abs(filterStep(stepSize * fac, forward, true)); + double fac = stepControl2 / JdkMath.pow(error / stepControl1, exp); + final double pow = JdkMath.pow(stepControl3, exp); + fac = JdkMath.max(pow / stepControl4, JdkMath.min(1 / pow, fac)); + optimalStep[k] = JdkMath.abs(filterStep(stepSize * fac, forward, true)); costPerTimeUnit[k] = costPerStep[k] / optimalStep[k]; // check convergence @@ -807,13 +807,13 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { // derivative at middle point of the step final int l2 = l / 2; - double factor = AccurateMath.pow(0.5 * sequence[l2], l); + double factor = JdkMath.pow(0.5 * sequence[l2], l); int middleIndex = fk[l2].length / 2; for (int i = 0; i < y0.length; ++i) { yMidDots[l+1][i] = factor * fk[l2][middleIndex + l][i]; } for (int j = 1; j <= k - l2; ++j) { - factor = AccurateMath.pow(0.5 * sequence[j + l2], l); + factor = JdkMath.pow(0.5 * sequence[j + l2], l); middleIndex = fk[l2+j].length / 2; for (int i = 0; i < y0.length; ++i) { diagonal[j-1][i] = factor * fk[l2+j][middleIndex+l][i]; @@ -845,7 +845,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { if (useInterpolationError) { // use the interpolation error to limit stepsize final double interpError = gbsInterpolator.estimateError(scale); - hInt = AccurateMath.abs(stepSize / AccurateMath.max(AccurateMath.pow(interpError, 1.0 / (mu+4)), + hInt = JdkMath.abs(stepSize / JdkMath.max(JdkMath.pow(interpError, 1.0 / (mu+4)), 0.01)); if (interpError > 10.0) { hNew = hInt; @@ -880,7 +880,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { if (costPerTimeUnit[k-1] < orderControl1 * costPerTimeUnit[k]) { optimalIter = k-1; } else if (costPerTimeUnit[k] < orderControl2 * costPerTimeUnit[k-1]) { - optimalIter = AccurateMath.min(k+1, sequence.length - 2); + optimalIter = JdkMath.min(k+1, sequence.length - 2); } } else { optimalIter = k - 1; @@ -889,15 +889,15 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { optimalIter = k - 2; } if (costPerTimeUnit[k] < orderControl2 * costPerTimeUnit[optimalIter]) { - optimalIter = AccurateMath.min(k, sequence.length - 2); + optimalIter = JdkMath.min(k, sequence.length - 2); } } if (previousRejected) { // after a rejected step neither order nor stepsize // should increase - targetIter = AccurateMath.min(optimalIter, k); - hNew = AccurateMath.min(AccurateMath.abs(stepSize), optimalStep[targetIter]); + targetIter = JdkMath.min(optimalIter, k); + hNew = JdkMath.min(JdkMath.abs(stepSize), optimalStep[targetIter]); } else { // stepsize control if (optimalIter <= k) { @@ -921,7 +921,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { } - hNew = AccurateMath.min(hNew, hInt); + hNew = JdkMath.min(hNew, hInt); if (! forward) { hNew = -hNew; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java index 3b0963b37..41f5de47d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java @@ -24,7 +24,7 @@ import java.io.ObjectOutput; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements an interpolator for the Gragg-Bulirsch-Stoer @@ -216,7 +216,7 @@ class GraggBulirschStoerStepInterpolator for (int i = 0; i < errfac.length; ++i) { final int ip5 = i + 5; errfac[i] = 1.0 / (ip5 * ip5); - final double e = 0.5 * AccurateMath.sqrt (((double) (i + 1)) / ip5); + final double e = 0.5 * JdkMath.sqrt (((double) (i + 1)) / ip5); for (int j = 0; j <= i; ++j) { errfac[i] *= e / (j + 1); } @@ -306,7 +306,7 @@ class GraggBulirschStoerStepInterpolator final double e = polynomials[currentDegree][i] / scale[i]; error += e * e; } - error = AccurateMath.sqrt(error / scale.length) * errfac[currentDegree - 5]; + error = JdkMath.sqrt(error / scale.length) * errfac[currentDegree - 5]; } return error; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java index c0a10b95e..eaf6fb864 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -119,7 +119,7 @@ public class HighamHall54Integrator extends EmbeddedRungeKuttaIntegrator { errSum += STATIC_E[l] * yDotK[l][j]; } - final double yScale = AccurateMath.max(AccurateMath.abs(y0[j]), AccurateMath.abs(y1[j])); + final double yScale = JdkMath.max(JdkMath.abs(y0[j]), JdkMath.abs(y1[j])); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[j] + vecRelativeTolerance[j] * yScale); @@ -128,7 +128,7 @@ public class HighamHall54Integrator extends EmbeddedRungeKuttaIntegrator { } - return AccurateMath.sqrt(error / mainSetDimension); + return JdkMath.sqrt(error / mainSetDimension); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java index d5388831b..7fb3cf06d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -56,7 +56,7 @@ import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; public class LutherIntegrator extends RungeKuttaIntegrator { /** Square root. */ - private static final double Q = AccurateMath.sqrt(21); + private static final double Q = JdkMath.sqrt(21); /** Time steps Butcher array. */ private static final double[] STATIC_C = { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java index 46b6ead64..03b9ddbf7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class represents an interpolator over the last step during an @@ -38,7 +38,7 @@ class LutherStepInterpolator extends RungeKuttaStepInterpolator { private static final long serialVersionUID = 20140416L; /** Square root. */ - private static final double Q = AccurateMath.sqrt(21); + private static final double Q = JdkMath.sqrt(21); /** Simple constructor. * This constructor builds an instance that is not usable yet, the diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java index 229ed4d0e..7c3eb2819 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.ode.AbstractIntegrator; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.FirstOrderDifferentialEquations; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements the common part of all fixed step Runge-Kutta @@ -86,7 +86,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { this.a = a; this.b = b; this.prototype = prototype; - this.step = AccurateMath.abs(step); + this.step = JdkMath.abs(step); } /** {@inheritDoc} */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java index d97ee34e5..94cd515d8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.ode.sampling; import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -156,7 +156,7 @@ public class FieldStepNormalizer> implements Field */ public FieldStepNormalizer(final double h, final FieldFixedStepHandler handler, final StepNormalizerMode mode, final StepNormalizerBounds bounds) { - this.h = AccurateMath.abs(h); + this.h = JdkMath.abs(h); this.handler = handler; this.mode = mode; this.bounds = bounds; @@ -210,7 +210,7 @@ public class FieldStepNormalizer> implements Field // Calculate next normalized step time. T nextTime = (mode == StepNormalizerMode.INCREMENT) ? last.getTime().add(h) : - last.getTime().getField().getZero().add((AccurateMath.floor(last.getTime().getReal() / h) + 1) * h); + last.getTime().getField().getZero().add((JdkMath.floor(last.getTime().getReal() / h) + 1) * h); if (mode == StepNormalizerMode.MULTIPLES && Precision.equals(nextTime.getReal(), last.getTime().getReal(), 1)) { nextTime = nextTime.add(h); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java index 1faffa25f..aa1b8ae84 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java @@ -25,7 +25,7 @@ import java.util.Arrays; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix; import org.apache.commons.math4.legacy.ode.EquationsMapper; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class implements an interpolator for integrators using Nordsieck representation. @@ -200,7 +200,7 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator { for (int i = nData.length - 1; i >= 0; --i) { final int order = i + 2; final double[] nDataI = nData[i]; - final double power = AccurateMath.pow(normalizedAbscissa, order); + final double power = JdkMath.pow(normalizedAbscissa, order); for (int j = 0; j < nDataI.length; ++j) { final double d = nDataI[j] * power; stateVariation[j] += d; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java index 6d58d6153..636d9eeee 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.ode.sampling; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -159,7 +159,7 @@ public class StepNormalizer implements StepHandler { public StepNormalizer(final double h, final FixedStepHandler handler, final StepNormalizerMode mode, final StepNormalizerBounds bounds) { - this.h = AccurateMath.abs(h); + this.h = JdkMath.abs(h); this.handler = handler; this.mode = mode; this.bounds = bounds; @@ -219,7 +219,7 @@ public class StepNormalizer implements StepHandler { // Calculate next normalized step time. double nextTime = (mode == StepNormalizerMode.INCREMENT) ? lastTime + h : - (AccurateMath.floor(lastTime / h) + 1) * h; + (JdkMath.floor(lastTime / h) + 1) * h; if (mode == StepNormalizerMode.MULTIPLES && Precision.equals(nextTime, lastTime, 1)) { nextTime += h; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java index 7906dda3f..c35d70b79 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.optim; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.Pair; /** @@ -121,8 +121,8 @@ public class SimplePointChecker> for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; - final double difference = AccurateMath.abs(pi - ci); - final double size = AccurateMath.max(AccurateMath.abs(pi), AccurateMath.abs(ci)); + final double difference = JdkMath.abs(pi - ci); + final double size = JdkMath.max(JdkMath.abs(pi), JdkMath.abs(ci)); if (difference > size * getRelativeThreshold() && difference > getAbsoluteThreshold()) { return false; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java index e621d3625..3e3421ed0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.optim; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Simple implementation of the {@link ConvergenceChecker} interface using @@ -117,8 +117,8 @@ public class SimpleValueChecker final double p = previous.getValue(); final double c = current.getValue(); - final double difference = AccurateMath.abs(p - c); - final double size = AccurateMath.max(AccurateMath.abs(p), AccurateMath.abs(c)); + final double difference = JdkMath.abs(p - c); + final double size = JdkMath.max(JdkMath.abs(p), JdkMath.abs(c)); return difference <= size * getRelativeThreshold() || difference <= getAbsoluteThreshold(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java index 200711c2a..1ce82b0e4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.optim; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Simple implementation of the {@link ConvergenceChecker} interface using @@ -122,8 +122,8 @@ public class SimpleVectorValueChecker for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; - final double difference = AccurateMath.abs(pi - ci); - final double size = AccurateMath.max(AccurateMath.abs(pi), AccurateMath.abs(ci)); + final double difference = JdkMath.abs(pi - ci); + final double size = JdkMath.max(JdkMath.abs(pi), JdkMath.abs(ci)); if (difference > size * getRelativeThreshold() && difference > getAbsoluteThreshold()) { return false; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java index b72971048..91b8d7ec9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.commons.math4.legacy.exception.TooManyIterationsException; import org.apache.commons.math4.legacy.optim.OptimizationData; import org.apache.commons.math4.legacy.optim.PointValuePair; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -256,7 +256,7 @@ public class SimplexSolver extends LinearOptimizer { // only consider pivot elements larger than the cutOff threshold // selecting others may lead to degeneracy or numerical instabilities if (Precision.compareTo(entry, 0d, cutOff) > 0) { - final double ratio = AccurateMath.abs(rhs / entry); + final double ratio = JdkMath.abs(rhs / entry); // check if the entry is strictly equal to the current min ratio // do not use a ulp/epsilon check final int cmp = Double.compare(ratio, minRatio); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java index c1008ab0e..46a96fa8c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.function.Sigmoid; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** *

Adapter for mapping bounded {@link MultivariateFunction} to unbounded ones.

@@ -232,13 +232,13 @@ public class MultivariateFunctionMappingAdapter /** {@inheritDoc} */ @Override public double unboundedToBounded(final double y) { - return lower + AccurateMath.exp(y); + return lower + JdkMath.exp(y); } /** {@inheritDoc} */ @Override public double boundedToUnbounded(final double x) { - return AccurateMath.log(x - lower); + return JdkMath.log(x - lower); } } @@ -259,13 +259,13 @@ public class MultivariateFunctionMappingAdapter /** {@inheritDoc} */ @Override public double unboundedToBounded(final double y) { - return upper - AccurateMath.exp(-y); + return upper - JdkMath.exp(-y); } /** {@inheritDoc} */ @Override public double boundedToUnbounded(final double x) { - return -AccurateMath.log(upper - x); + return -JdkMath.log(upper - x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java index 910c36bcb..bbeea7ea4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.analysis.MultivariateFunction; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** *

Adapter extending bounded {@link MultivariateFunction} to an unbouded @@ -174,7 +174,7 @@ public class MultivariateFunctionPenaltyAdapter } else { overshoot = 0; } - sum += AccurateMath.sqrt(overshoot); + sum += JdkMath.sqrt(overshoot); } return offset + sum; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java index 4b2ad1284..336528265 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.linear.RealVector; import org.apache.commons.math4.legacy.optim.PointValuePair; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimizer; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Powell's BOBYQA algorithm. This implementation is translated and @@ -317,7 +317,7 @@ public class BOBYQAOptimizer lowerDifference.setEntry(j, -initialTrustRegionRadius); // Computing MAX final double deltaOne = upperBound[j] - currentBest.getEntry(j); - upperDifference.setEntry(j, AccurateMath.max(deltaOne, initialTrustRegionRadius)); + upperDifference.setEntry(j, JdkMath.max(deltaOne, initialTrustRegionRadius)); } } else if (upperDifference.getEntry(j) <= initialTrustRegionRadius) { if (upperDifference.getEntry(j) <= ZERO) { @@ -329,7 +329,7 @@ public class BOBYQAOptimizer // Computing MIN final double deltaOne = lowerBound[j] - currentBest.getEntry(j); final double deltaTwo = -initialTrustRegionRadius; - lowerDifference.setEntry(j, AccurateMath.min(deltaOne, deltaTwo)); + lowerDifference.setEntry(j, JdkMath.min(deltaOne, deltaTwo)); upperDifference.setEntry(j, initialTrustRegionRadius); } } @@ -501,8 +501,8 @@ public class BOBYQAOptimizer // Computing MIN double deltaOne = delta; - double deltaTwo = AccurateMath.sqrt(dsq); - dnorm = AccurateMath.min(deltaOne, deltaTwo); + double deltaTwo = JdkMath.sqrt(dsq); + dnorm = JdkMath.min(deltaOne, deltaTwo); if (dnorm < HALF * rho) { ntrits = -1; // Computing 2nd power @@ -519,8 +519,8 @@ public class BOBYQAOptimizer // of likely improvements to the model within distance HALF*RHO of XOPT. // Computing MAX - deltaOne = AccurateMath.max(diffa, diffb); - final double errbig = AccurateMath.max(deltaOne, diffc); + deltaOne = JdkMath.max(diffa, diffb); + final double errbig = JdkMath.max(deltaOne, diffc); final double frhosq = rho * ONE_OVER_EIGHT * rho; if (crvmin > ZERO && errbig > frhosq * crvmin) { @@ -794,7 +794,7 @@ public class BOBYQAOptimizer // Computing MAX // Computing 2nd power final double d4 = distsq / delsq; - final double temp = AccurateMath.max(ONE, d4 * d4); + final double temp = JdkMath.max(ONE, d4 * d4); if (temp * den > scaden) { scaden = temp * den; knew = k; @@ -803,7 +803,7 @@ public class BOBYQAOptimizer // Computing MAX // Computing 2nd power final double d5 = lagrangeValuesAtNewPoint.getEntry(k); - biglsq = AccurateMath.max(biglsq, temp * (d5 * d5)); + biglsq = JdkMath.max(biglsq, temp * (d5 * d5)); } } @@ -821,9 +821,9 @@ public class BOBYQAOptimizer // Computing MAX final double d3 = lowerBound[i]; final double d4 = originShift.getEntry(i) + newPoint.getEntry(i); - final double d1 = AccurateMath.max(d3, d4); + final double d1 = JdkMath.max(d3, d4); final double d2 = upperBound[i]; - currentBest.setEntry(i, AccurateMath.min(d1, d2)); + currentBest.setEntry(i, JdkMath.min(d1, d2)); if (newPoint.getEntry(i) == lowerDifference.getEntry(i)) { currentBest.setEntry(i, lowerBound[i]); } @@ -868,7 +868,7 @@ public class BOBYQAOptimizer final double diff = f - fopt - vquad; diffc = diffb; diffb = diffa; - diffa = AccurateMath.abs(diff); + diffa = JdkMath.abs(diff); if (dnorm > rho) { nfsav = getEvaluations(); } @@ -883,13 +883,13 @@ public class BOBYQAOptimizer final double hDelta = HALF * delta; if (ratio <= ONE_OVER_TEN) { // Computing MIN - delta = AccurateMath.min(hDelta, dnorm); + delta = JdkMath.min(hDelta, dnorm); } else if (ratio <= .7) { // Computing MAX - delta = AccurateMath.max(hDelta, dnorm); + delta = JdkMath.max(hDelta, dnorm); } else { // Computing MAX - delta = AccurateMath.max(hDelta, 2 * dnorm); + delta = JdkMath.max(hDelta, 2 * dnorm); } if (delta <= rho * 1.5) { delta = rho; @@ -923,7 +923,7 @@ public class BOBYQAOptimizer // Computing MAX // Computing 2nd power final double d3 = distsq / delsq; - final double temp = AccurateMath.max(ONE, d3 * d3); + final double temp = JdkMath.max(ONE, d3 * d3); if (temp * den > scaden) { scaden = temp * den; knew = k; @@ -933,7 +933,7 @@ public class BOBYQAOptimizer // Computing 2nd power final double d4 = lagrangeValuesAtNewPoint.getEntry(k); final double d5 = temp * (d4 * d4); - biglsq = AccurateMath.max(biglsq, d5); + biglsq = JdkMath.max(biglsq, d5); } if (scaden <= HALF * biglsq) { knew = ksav; @@ -1058,18 +1058,18 @@ public class BOBYQAOptimizer if (trustRegionCenterOffset.getEntry(i) == lowerDifference.getEntry(i)) { // Computing MIN // Computing 2nd power - final double d1 = AccurateMath.min(ZERO, gradientAtTrustRegionCenter.getEntry(i)); + final double d1 = JdkMath.min(ZERO, gradientAtTrustRegionCenter.getEntry(i)); gqsq += d1 * d1; // Computing 2nd power - final double d2 = AccurateMath.min(ZERO, sum); + final double d2 = JdkMath.min(ZERO, sum); gisq += d2 * d2; } else if (trustRegionCenterOffset.getEntry(i) == upperDifference.getEntry(i)) { // Computing MAX // Computing 2nd power - final double d1 = AccurateMath.max(ZERO, gradientAtTrustRegionCenter.getEntry(i)); + final double d1 = JdkMath.max(ZERO, gradientAtTrustRegionCenter.getEntry(i)); gqsq += d1 * d1; // Computing 2nd power - final double d2 = AccurateMath.max(ZERO, sum); + final double d2 = JdkMath.max(ZERO, sum); gisq += d2 * d2; } else { // Computing 2nd power @@ -1088,7 +1088,7 @@ public class BOBYQAOptimizer itest = 0; } if (itest >= 3) { - for (int i = 0, max = AccurateMath.max(npt, nh); i < max; i++) { + for (int i = 0, max = JdkMath.max(npt, nh); i < max; i++) { if (i < n) { gradientAtTrustRegionCenter.setEntry(i, lagrangeValuesAtNewPoint.getEntry(npt + i)); } @@ -1122,7 +1122,7 @@ public class BOBYQAOptimizer final double d1 = TWO * delta; // Computing 2nd power final double d2 = TEN * rho; - distsq = AccurateMath.max(d1 * d1, d2 * d2); + distsq = JdkMath.max(d1 * d1, d2 * d2); } case 650: { printState(650); // XXX @@ -1147,10 +1147,10 @@ public class BOBYQAOptimizer // current RHO are complete. if (knew >= 0) { - final double dist = AccurateMath.sqrt(distsq); + final double dist = JdkMath.sqrt(distsq); if (ntrits == -1) { // Computing MIN - delta = AccurateMath.min(ONE_OVER_TEN * delta, HALF * dist); + delta = JdkMath.min(ONE_OVER_TEN * delta, HALF * dist); if (delta <= rho * 1.5) { delta = rho; } @@ -1158,8 +1158,8 @@ public class BOBYQAOptimizer ntrits = 0; // Computing MAX // Computing MIN - final double d1 = AccurateMath.min(ONE_OVER_TEN * dist, delta); - adelt = AccurateMath.max(d1, rho); + final double d1 = JdkMath.min(ONE_OVER_TEN * dist, delta); + adelt = JdkMath.max(d1, rho); dsq = adelt * adelt; state = 90; break; } @@ -1169,7 +1169,7 @@ public class BOBYQAOptimizer if (ratio > ZERO) { state = 60; break; } - if (AccurateMath.max(delta, dnorm) > rho) { + if (JdkMath.max(delta, dnorm) > rho) { state = 60; break; } @@ -1184,11 +1184,11 @@ public class BOBYQAOptimizer if (ratio <= SIXTEEN) { rho = stoppingTrustRegionRadius; } else if (ratio <= TWO_HUNDRED_FIFTY) { - rho = AccurateMath.sqrt(ratio) * stoppingTrustRegionRadius; + rho = JdkMath.sqrt(ratio) * stoppingTrustRegionRadius; } else { rho *= ONE_OVER_TEN; } - delta = AccurateMath.max(delta, rho); + delta = JdkMath.max(delta, rho); ntrits = 0; nfsav = getEvaluations(); state = 60; break; @@ -1209,9 +1209,9 @@ public class BOBYQAOptimizer // Computing MAX final double d3 = lowerBound[i]; final double d4 = originShift.getEntry(i) + trustRegionCenterOffset.getEntry(i); - final double d1 = AccurateMath.max(d3, d4); + final double d1 = JdkMath.max(d3, d4); final double d2 = upperBound[i]; - currentBest.setEntry(i, AccurateMath.min(d1, d2)); + currentBest.setEntry(i, JdkMath.min(d1, d2)); if (trustRegionCenterOffset.getEntry(i) == lowerDifference.getEntry(i)) { currentBest.setEntry(i, lowerBound[i]); } @@ -1329,11 +1329,11 @@ public class BOBYQAOptimizer dderiv += glag.getEntry(i) * tmp; distsq += tmp * tmp; } - double subd = adelt / AccurateMath.sqrt(distsq); + double subd = adelt / JdkMath.sqrt(distsq); double slbd = -subd; int ilbd = 0; int iubd = 0; - final double sumin = AccurateMath.min(ONE, subd); + final double sumin = JdkMath.min(ONE, subd); // Revise SLBD and SUBD if necessary because of the bounds in SL and SU. @@ -1346,7 +1346,7 @@ public class BOBYQAOptimizer } if (subd * tmp > upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) { // Computing MAX - subd = AccurateMath.max(sumin, + subd = JdkMath.max(sumin, (upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) / tmp); iubd = i + 1; } @@ -1357,7 +1357,7 @@ public class BOBYQAOptimizer } if (subd * tmp < lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) { // Computing MAX - subd = AccurateMath.max(sumin, + subd = JdkMath.max(sumin, (lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) / tmp); iubd = -i - 1; } @@ -1374,7 +1374,7 @@ public class BOBYQAOptimizer final double diff = dderiv - ONE; vlag = slbd * (dderiv - slbd * diff); final double d1 = subd * (dderiv - subd * diff); - if (AccurateMath.abs(d1) > AccurateMath.abs(vlag)) { + if (JdkMath.abs(d1) > JdkMath.abs(vlag)) { step = subd; vlag = d1; isbd = iubd; @@ -1384,7 +1384,7 @@ public class BOBYQAOptimizer final double d4 = d2 - diff * subd; if (d3 * d4 < ZERO) { final double d5 = d2 * d2 / diff; - if (AccurateMath.abs(d5) > AccurateMath.abs(vlag)) { + if (JdkMath.abs(d5) > JdkMath.abs(vlag)) { step = d2 / diff; vlag = d5; isbd = 0; @@ -1396,12 +1396,12 @@ public class BOBYQAOptimizer } else { vlag = slbd * (ONE - slbd); final double tmp = subd * (ONE - subd); - if (AccurateMath.abs(tmp) > AccurateMath.abs(vlag)) { + if (JdkMath.abs(tmp) > JdkMath.abs(vlag)) { step = subd; vlag = tmp; isbd = iubd; } - if (subd > HALF && AccurateMath.abs(vlag) < ONE_OVER_FOUR) { + if (subd > HALF && JdkMath.abs(vlag) < ONE_OVER_FOUR) { step = HALF; vlag = ONE_OVER_FOUR; isbd = 0; @@ -1425,8 +1425,8 @@ public class BOBYQAOptimizer for (int i = 0; i < n; i++) { final double tmp = trustRegionCenterOffset.getEntry(i) + stpsav * (interpolationPoints.getEntry(ksav, i) - trustRegionCenterOffset.getEntry(i)); - newPoint.setEntry(i, AccurateMath.max(lowerDifference.getEntry(i), - AccurateMath.min(upperDifference.getEntry(i), tmp))); + newPoint.setEntry(i, JdkMath.max(lowerDifference.getEntry(i), + JdkMath.min(upperDifference.getEntry(i), tmp))); } if (ibdsav < 0) { newPoint.setEntry(-ibdsav - 1, lowerDifference.getEntry(-ibdsav - 1)); @@ -1449,8 +1449,8 @@ public class BOBYQAOptimizer for (int i = 0; i < n; i++) { final double glagValue = glag.getEntry(i); work1.setEntry(i, ZERO); - if (AccurateMath.min(trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i), glagValue) > ZERO || - AccurateMath.max(trustRegionCenterOffset.getEntry(i) - upperDifference.getEntry(i), glagValue) < ZERO) { + if (JdkMath.min(trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i), glagValue) > ZERO || + JdkMath.max(trustRegionCenterOffset.getEntry(i) - upperDifference.getEntry(i), glagValue) < ZERO) { work1.setEntry(i, bigstp); // Computing 2nd power ggfree += glagValue * glagValue; @@ -1463,7 +1463,7 @@ public class BOBYQAOptimizer // Investigate whether more components of W can be fixed. final double tmp1 = adelt * adelt - wfixsq; if (tmp1 > ZERO) { - step = AccurateMath.sqrt(tmp1 / ggfree); + step = JdkMath.sqrt(tmp1 / ggfree); ggfree = ZERO; for (int i = 0; i < n; i++) { if (work1.getEntry(i) == bigstp) { @@ -1495,9 +1495,9 @@ public class BOBYQAOptimizer final double glagValue = glag.getEntry(i); if (work1.getEntry(i) == bigstp) { work1.setEntry(i, -step * glagValue); - final double min = AccurateMath.min(upperDifference.getEntry(i), + final double min = JdkMath.min(upperDifference.getEntry(i), trustRegionCenterOffset.getEntry(i) + work1.getEntry(i)); - alternativeNewPoint.setEntry(i, AccurateMath.max(lowerDifference.getEntry(i), min)); + alternativeNewPoint.setEntry(i, JdkMath.max(lowerDifference.getEntry(i), min)); } else if (work1.getEntry(i) == ZERO) { alternativeNewPoint.setEntry(i, trustRegionCenterOffset.getEntry(i)); } else if (glagValue > ZERO) { @@ -1525,12 +1525,12 @@ public class BOBYQAOptimizer curv = -curv; } if (curv > -gw && - curv < -gw * (ONE + AccurateMath.sqrt(TWO))) { + curv < -gw * (ONE + JdkMath.sqrt(TWO))) { final double scale = -gw / curv; for (int i = 0; i < n; i++) { final double tmp = trustRegionCenterOffset.getEntry(i) + scale * work1.getEntry(i); - alternativeNewPoint.setEntry(i, AccurateMath.max(lowerDifference.getEntry(i), - AccurateMath.min(upperDifference.getEntry(i), tmp))); + alternativeNewPoint.setEntry(i, JdkMath.max(lowerDifference.getEntry(i), + JdkMath.min(upperDifference.getEntry(i), tmp))); } // Computing 2nd power final double d1 = HALF * gw * scale; @@ -1649,11 +1649,11 @@ public class BOBYQAOptimizer stepa = interpolationPoints.getEntry(nfx, nfxm); stepb = -initialTrustRegionRadius; if (lowerDifference.getEntry(nfxm) == ZERO) { - stepb = AccurateMath.min(TWO * initialTrustRegionRadius, upperDifference.getEntry(nfxm)); + stepb = JdkMath.min(TWO * initialTrustRegionRadius, upperDifference.getEntry(nfxm)); // throw new PathIsExploredException(); // XXX } if (upperDifference.getEntry(nfxm) == ZERO) { - stepb = AccurateMath.max(-TWO * initialTrustRegionRadius, lowerDifference.getEntry(nfxm)); + stepb = JdkMath.max(-TWO * initialTrustRegionRadius, lowerDifference.getEntry(nfxm)); // throw new PathIsExploredException(); // XXX } interpolationPoints.setEntry(nfm, nfxm, stepb); @@ -1678,7 +1678,7 @@ public class BOBYQAOptimizer // its index are required. for (int j = 0; j < n; j++) { - currentBest.setEntry(j, AccurateMath.min(AccurateMath.max(lowerBound[j], + currentBest.setEntry(j, JdkMath.min(JdkMath.max(lowerBound[j], originShift.getEntry(j) + interpolationPoints.getEntry(nfm, j)), upperBound[j])); if (interpolationPoints.getEntry(nfm, j) == lowerDifference.getEntry(j)) { @@ -1737,9 +1737,9 @@ public class BOBYQAOptimizer bMatrix.setEntry(nfm, nfxm, -HALF / interpolationPoints.getEntry(nfm - n, nfxm)); bMatrix.setEntry(nfm - n, nfxm, -bMatrix.getEntry(0, nfxm) - bMatrix.getEntry(nfm, nfxm)); - zMatrix.setEntry(0, nfxm, AccurateMath.sqrt(TWO) / (stepa * stepb)); - zMatrix.setEntry(nfm, nfxm, AccurateMath.sqrt(HALF) / rhosq); - // zMatrix.setEntry(nfm, nfxm, AccurateMath.sqrt(HALF) * recip); // XXX "testAckley" and "testDiffPow" fail. + zMatrix.setEntry(0, nfxm, JdkMath.sqrt(TWO) / (stepa * stepb)); + zMatrix.setEntry(nfm, nfxm, JdkMath.sqrt(HALF) / rhosq); + // zMatrix.setEntry(nfm, nfxm, JdkMath.sqrt(HALF) * recip); // XXX "testAckley" and "testDiffPow" fail. zMatrix.setEntry(nfm - n, nfxm, -zMatrix.getEntry(0, nfxm) - zMatrix.getEntry(nfm, nfxm)); } @@ -1937,7 +1937,7 @@ public class BOBYQAOptimizer if (resid <= ZERO) { state = 90; break; } - temp = AccurateMath.sqrt(stepsq * resid + ds * ds); + temp = JdkMath.sqrt(stepsq * resid + ds * ds); if (ds < ZERO) { blen = (temp - ds) / stepsq; } else { @@ -1946,7 +1946,7 @@ public class BOBYQAOptimizer stplen = blen; if (shs > ZERO) { // Computing MIN - stplen = AccurateMath.min(blen, gredsq / shs); + stplen = JdkMath.min(blen, gredsq / shs); } // Reduce STPLEN if necessary in order to preserve the simple bounds, @@ -1975,7 +1975,7 @@ public class BOBYQAOptimizer ++iterc; temp = shs / stepsq; if (iact == -1 && temp > ZERO) { - crvmin = AccurateMath.min(crvmin,temp); + crvmin = JdkMath.min(crvmin,temp); if (crvmin == MINUS_ONE) { crvmin = temp; } @@ -1993,7 +1993,7 @@ public class BOBYQAOptimizer } // Computing MAX final double d1 = stplen * (ggsav - HALF * stplen * shs); - sdec = AccurateMath.max(d1, ZERO); + sdec = JdkMath.max(d1, ZERO); qred += sdec; } @@ -2071,7 +2071,7 @@ public class BOBYQAOptimizer if (temp <= qred * 1e-4 * qred) { state = 190; break; } - temp = AccurateMath.sqrt(temp); + temp = JdkMath.sqrt(temp); for (int i = 0; i < n; i++) { if (xbdi.getEntry(i) == ZERO) { s.setEntry(i, (dredg * trialStepPoint.getEntry(i) - dredsq * gnew.getEntry(i)) / temp); @@ -2110,7 +2110,7 @@ public class BOBYQAOptimizer d1 = trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i); temp = ssq - d1 * d1; if (temp > ZERO) { - temp = AccurateMath.sqrt(temp) - s.getEntry(i); + temp = JdkMath.sqrt(temp) - s.getEntry(i); if (angbd * temp > tempa) { angbd = tempa / temp; iact = i; @@ -2121,7 +2121,7 @@ public class BOBYQAOptimizer d1 = upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i); temp = ssq - d1 * d1; if (temp > ZERO) { - temp = AccurateMath.sqrt(temp) + s.getEntry(i); + temp = JdkMath.sqrt(temp) + s.getEntry(i); if (angbd * temp > tempb) { angbd = tempb / temp; iact = i; @@ -2226,9 +2226,9 @@ public class BOBYQAOptimizer for (int i = 0; i < n; i++) { // Computing MAX // Computing MIN - final double min = AccurateMath.min(trustRegionCenterOffset.getEntry(i) + trialStepPoint.getEntry(i), + final double min = JdkMath.min(trustRegionCenterOffset.getEntry(i) + trialStepPoint.getEntry(i), upperDifference.getEntry(i)); - newPoint.setEntry(i, AccurateMath.max(min, lowerDifference.getEntry(i))); + newPoint.setEntry(i, JdkMath.max(min, lowerDifference.getEntry(i))); if (xbdi.getEntry(i) == MINUS_ONE) { newPoint.setEntry(i, lowerDifference.getEntry(i)); } @@ -2317,7 +2317,7 @@ public class BOBYQAOptimizer for (int k = 0; k < npt; k++) { for (int j = 0; j < nptm; j++) { // Computing MAX - ztest = AccurateMath.max(ztest, AccurateMath.abs(zMatrix.getEntry(k, j))); + ztest = JdkMath.max(ztest, JdkMath.abs(zMatrix.getEntry(k, j))); } } ztest *= 1e-20; @@ -2326,12 +2326,12 @@ public class BOBYQAOptimizer for (int j = 1; j < nptm; j++) { final double d1 = zMatrix.getEntry(knew, j); - if (AccurateMath.abs(d1) > ztest) { + if (JdkMath.abs(d1) > ztest) { // Computing 2nd power final double d2 = zMatrix.getEntry(knew, 0); // Computing 2nd power final double d3 = zMatrix.getEntry(knew, j); - final double d4 = AccurateMath.sqrt(d2 * d2 + d3 * d3); + final double d4 = JdkMath.sqrt(d2 * d2 + d3 * d3); final double d5 = zMatrix.getEntry(knew, 0) / d4; final double d6 = zMatrix.getEntry(knew, j) / d4; for (int i = 0; i < npt; i++) { @@ -2355,7 +2355,7 @@ public class BOBYQAOptimizer // Complete the updating of ZMAT. - final double sqrtDenom = AccurateMath.sqrt(denom); + final double sqrtDenom = JdkMath.sqrt(denom); final double d1 = tau / sqrtDenom; final double d2 = zMatrix.getEntry(knew, 0) / sqrtDenom; for (int i = 0; i < npt; i++) { @@ -2414,7 +2414,7 @@ public class BOBYQAOptimizer double minDiff = Double.POSITIVE_INFINITY; for (int i = 0; i < dimension; i++) { boundDifference[i] = upperBound[i] - lowerBound[i]; - minDiff = AccurateMath.min(minDiff, boundDifference[i]); + minDiff = JdkMath.min(minDiff, boundDifference[i]); } if (minDiff < requiredMinDiff) { initialTrustRegionRadius = minDiff / 3.0; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java index eb92f7b41..d6573306a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java @@ -39,7 +39,7 @@ import org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimi import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.statistics.distribution.ContinuousDistribution; import org.apache.commons.statistics.distribution.NormalDistribution; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * An implementation of the active Covariance Matrix Adaptation Evolution Strategy (CMA-ES) @@ -412,7 +412,7 @@ public class CMAESOptimizer updateCovarianceDiagonalOnly(hsig, bestArz); } // Adapt step size sigma - Eq. (5) - sigma *= AccurateMath.exp(AccurateMath.min(1, (normps/chiN - 1) * cs / damps)); + sigma *= JdkMath.exp(JdkMath.min(1, (normps/chiN - 1) * cs / damps)); final double bestFitness = fitness[arindex[0]]; final double worstFitness = fitness[arindex[arindex.length - 1]]; if (bestValue > bestFitness) { @@ -433,7 +433,7 @@ public class CMAESOptimizer final double[] sqrtDiagC = sqrt(diagC).getColumn(0); final double[] pcCol = pc.getColumn(0); for (int i = 0; i < dimension; i++) { - if (sigma * AccurateMath.max(AccurateMath.abs(pcCol[i]), sqrtDiagC[i]) > stopTolX) { + if (sigma * JdkMath.max(JdkMath.abs(pcCol[i]), sqrtDiagC[i]) > stopTolX) { break; } if (i >= dimension - 1) { @@ -448,8 +448,8 @@ public class CMAESOptimizer final double historyBest = min(fitnessHistory); final double historyWorst = max(fitnessHistory); if (iterations > 2 && - AccurateMath.max(historyWorst, worstFitness) - - AccurateMath.min(historyBest, bestFitness) < stopTolFun) { + JdkMath.max(historyWorst, worstFitness) - + JdkMath.min(historyBest, bestFitness) < stopTolFun) { break generationLoop; } if (iterations > fitnessHistory.length && @@ -473,11 +473,11 @@ public class CMAESOptimizer } // Adjust step size in case of equal function values (flat fitness) if (bestValue == fitness[arindex[(int)(0.1+lambda/4.)]]) { - sigma *= AccurateMath.exp(0.2 + cs / damps); + sigma *= JdkMath.exp(0.2 + cs / damps); } - if (iterations > 2 && AccurateMath.max(historyWorst, bestFitness) - - AccurateMath.min(historyBest, bestFitness) == 0) { - sigma *= AccurateMath.exp(0.2 + cs / damps); + if (iterations > 2 && JdkMath.max(historyWorst, bestFitness) - + JdkMath.min(historyBest, bestFitness) == 0) { + sigma *= JdkMath.exp(0.2 + cs / damps); } // store best in history push(fitnessHistory,bestFitness); @@ -569,7 +569,7 @@ public class CMAESOptimizer // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination - logMu2 = AccurateMath.log(mu + 0.5); + logMu2 = JdkMath.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; @@ -585,16 +585,16 @@ public class CMAESOptimizer cc = (4 + mueff / dimension) / (dimension + 4 + 2 * mueff / dimension); cs = (mueff + 2) / (dimension + mueff + 3.); - damps = (1 + 2 * AccurateMath.max(0, AccurateMath.sqrt((mueff - 1) / + damps = (1 + 2 * JdkMath.max(0, JdkMath.sqrt((mueff - 1) / (dimension + 1)) - 1)) * - AccurateMath.max(0.3, + JdkMath.max(0.3, 1 - dimension / (1e-6 + maxIterations)) + cs; // minor increment ccov1 = 2 / ((dimension + 1.3) * (dimension + 1.3) + mueff); - ccovmu = AccurateMath.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / + ccovmu = JdkMath.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / ((dimension + 2) * (dimension + 2) + mueff)); - ccov1Sep = AccurateMath.min(1, ccov1 * (dimension + 1.5) / 3); - ccovmuSep = AccurateMath.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); - chiN = AccurateMath.sqrt(dimension) * + ccov1Sep = JdkMath.min(1, ccov1 * (dimension + 1.5) / 3); + ccovmuSep = JdkMath.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); + chiN = JdkMath.sqrt(dimension) * (1 - 1 / ((double) 4 * dimension) + 1 / ((double) 21 * dimension * dimension)); // initialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective variables @@ -626,14 +626,14 @@ public class CMAESOptimizer private boolean updateEvolutionPaths(RealMatrix zmean, RealMatrix xold) { ps = ps.scalarMultiply(1 - cs).add( B.multiply(zmean).scalarMultiply( - AccurateMath.sqrt(cs * (2 - cs) * mueff))); + JdkMath.sqrt(cs * (2 - cs) * mueff))); normps = ps.getFrobeniusNorm(); final boolean hsig = normps / - AccurateMath.sqrt(1 - AccurateMath.pow(1 - cs, 2 * iterations)) / + JdkMath.sqrt(1 - JdkMath.pow(1 - cs, 2 * iterations)) / chiN < 1.4 + 2 / ((double) dimension + 1); pc = pc.scalarMultiply(1 - cc); if (hsig) { - pc = pc.add(xmean.subtract(xold).scalarMultiply(AccurateMath.sqrt(cc * (2 - cc) * mueff) / sigma)); + pc = pc.add(xmean.subtract(xold).scalarMultiply(JdkMath.sqrt(cc * (2 - cc) * mueff) / sigma)); } return hsig; } @@ -691,7 +691,7 @@ public class CMAESOptimizer if (isActiveCMA) { // Adapt covariance matrix C active CMA negccov = (1 - ccovmu) * 0.25 * mueff / - (AccurateMath.pow(dimension + 2.0, 1.5) + 2 * mueff); + (JdkMath.pow(dimension + 2.0, 1.5) + 2 * mueff); // keep at least 0.66 in all directions, small popsize are most // critical final double negminresidualvariance = 0.66; @@ -975,7 +975,7 @@ public class CMAESOptimizer private double penalty(final double[] x, final double[] repaired) { double penalty = 0; for (int i = 0; i < x.length; i++) { - double diff = AccurateMath.abs(x[i] - repaired[i]); + double diff = JdkMath.abs(x[i] - repaired[i]); penalty += diff; } return isMinimize ? penalty : -penalty; @@ -992,7 +992,7 @@ public class CMAESOptimizer final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()]; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { - d[r][c] = AccurateMath.log(m.getEntry(r, c)); + d[r][c] = JdkMath.log(m.getEntry(r, c)); } } return new Array2DRowRealMatrix(d, false); @@ -1006,7 +1006,7 @@ public class CMAESOptimizer final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()]; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { - d[r][c] = AccurateMath.sqrt(m.getEntry(r, c)); + d[r][c] = JdkMath.sqrt(m.getEntry(r, c)); } } return new Array2DRowRealMatrix(d, false); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java index 5c185a6d5..b09032f99 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.LineSearch; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimizer; import org.apache.commons.math4.legacy.optim.univariate.UnivariatePointValuePair; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Powell's algorithm. @@ -59,7 +59,7 @@ public class PowellOptimizer /** * Minimum relative tolerance. */ - private static final double MIN_RELATIVE_TOLERANCE = 2 * AccurateMath.ulp(1d); + private static final double MIN_RELATIVE_TOLERANCE = 2 * JdkMath.ulp(1d); /** * Relative threshold. */ @@ -90,7 +90,7 @@ public class PowellOptimizer public PowellOptimizer(double rel, double abs, ConvergenceChecker checker) { - this(rel, abs, AccurateMath.sqrt(rel), AccurateMath.sqrt(abs), checker); + this(rel, abs, JdkMath.sqrt(rel), JdkMath.sqrt(abs), checker); } /** @@ -210,7 +210,7 @@ public class PowellOptimizer // Default convergence check. boolean stop = 2 * (fX - fVal) <= - (relativeThreshold * (AccurateMath.abs(fX) + AccurateMath.abs(fVal)) + + (relativeThreshold * (JdkMath.abs(fX) + JdkMath.abs(fVal)) + absoluteThreshold); final PointValuePair previous = new PointValuePair(x1, fX); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java index 7dd4c2e3c..a0ecd50f3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java @@ -21,7 +21,7 @@ import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.IntegerSequence.Incrementor; /** @@ -143,7 +143,7 @@ public class BracketFinder { double tmp2 = (xB - xC) * (fB - fA); double val = tmp2 - tmp1; - double denom = AccurateMath.abs(val) < EPS_MIN ? 2 * EPS_MIN : 2 * val; + double denom = JdkMath.abs(val) < EPS_MIN ? 2 * EPS_MIN : 2 * val; double w = xB - ((xB - xC) * tmp2 - (xB - xA) * tmp1) / denom; double wLim = xB + growLimit * (xC - xB); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java index 8bfdf9bba..7ed3e5e1e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.optim.ConvergenceChecker; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -44,11 +44,11 @@ public class BrentOptimizer extends UnivariateOptimizer { /** * Golden section. */ - private static final double GOLDEN_SECTION = 0.5 * (3 - AccurateMath.sqrt(5)); + private static final double GOLDEN_SECTION = 0.5 * (3 - JdkMath.sqrt(5)); /** * Minimum relative tolerance. */ - private static final double MIN_RELATIVE_TOLERANCE = 2 * AccurateMath.ulp(1d); + private static final double MIN_RELATIVE_TOLERANCE = 2 * JdkMath.ulp(1d); /** * Relative threshold. */ @@ -151,18 +151,18 @@ public class BrentOptimizer extends UnivariateOptimizer { while (true) { final double m = 0.5 * (a + b); - final double tol1 = relativeThreshold * AccurateMath.abs(x) + absoluteThreshold; + final double tol1 = relativeThreshold * JdkMath.abs(x) + absoluteThreshold; final double tol2 = 2 * tol1; // Default stopping criterion. - final boolean stop = AccurateMath.abs(x - m) <= tol2 - 0.5 * (b - a); + final boolean stop = JdkMath.abs(x - m) <= tol2 - 0.5 * (b - a); if (!stop) { double p = 0; double q = 0; double r = 0; double u = 0; - if (AccurateMath.abs(e) > tol1) { // Fit parabola. + if (JdkMath.abs(e) > tol1) { // Fit parabola. r = (x - w) * (fx - fv); q = (x - v) * (fx - fw); p = (x - v) * q - (x - w) * r; @@ -179,7 +179,7 @@ public class BrentOptimizer extends UnivariateOptimizer { if (p > q * (a - x) && p < q * (b - x) && - AccurateMath.abs(p) < AccurateMath.abs(0.5 * q * r)) { + JdkMath.abs(p) < JdkMath.abs(0.5 * q * r)) { // Parabolic interpolation step. d = p / q; u = x + d; @@ -212,7 +212,7 @@ public class BrentOptimizer extends UnivariateOptimizer { } // Update by at least "tol1". - if (AccurateMath.abs(d) < tol1) { + if (JdkMath.abs(d) < tol1) { if (d >= 0) { u = x + tol1; } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java index b23b172f6..6dd7c4848 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.optim.univariate; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.optim.AbstractConvergenceChecker; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Simple implementation of the @@ -119,8 +119,8 @@ public class SimpleUnivariateValueChecker final double p = previous.getValue(); final double c = current.getValue(); - final double difference = AccurateMath.abs(p - c); - final double size = AccurateMath.max(AccurateMath.abs(p), AccurateMath.abs(c)); + final double difference = JdkMath.abs(p - c); + final double size = JdkMath.max(JdkMath.abs(p), JdkMath.abs(c)); return difference <= size * getRelativeThreshold() || difference <= getAbsoluteThreshold(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/CorrelatedVectorFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/CorrelatedVectorFactory.java index 2fc3a600c..9b681d7d4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/CorrelatedVectorFactory.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/CorrelatedVectorFactory.java @@ -24,7 +24,7 @@ import org.apache.commons.rng.sampling.distribution.ContinuousSampler; import org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler; import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.RectangularCholeskyDecomposition; @@ -62,7 +62,7 @@ import org.apache.commons.math4.legacy.linear.RectangularCholeskyDecomposition; */ public class CorrelatedVectorFactory { /** Square root of three. */ - private static final double SQRT3 = AccurateMath.sqrt(3); + private static final double SQRT3 = JdkMath.sqrt(3); /** Mean vector. */ private final double[] mean; /** Root of the covariance matrix. */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java index 8269eec95..cf64e8bf8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.exception.MathInternalError; import org.apache.commons.math4.legacy.exception.MathParseException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Implementation of a Sobol sequence. @@ -58,7 +58,7 @@ public class SobolSequenceGenerator implements Supplier { private static final int BITS = 52; /** The scaling factor. */ - private static final double SCALE = AccurateMath.pow(2, BITS); + private static final double SCALE = JdkMath.pow(2, BITS); /** The maximum supported space dimension. */ private static final int MAX_DIMENSION = 21201; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java index 1356986e6..f0941f6a0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.exception.ConvergenceException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * This class provides computation methods related to Bessel @@ -165,7 +165,7 @@ public class BesselJ return res.vals[n]; } else if (res.nVals < 0) { throw new MathIllegalArgumentException(LocalizedFormats.BESSEL_FUNCTION_BAD_ARGUMENT,order, x); - } else if (AccurateMath.abs(res.vals[res.nVals - 1]) < 1e-100) { + } else if (JdkMath.abs(res.vals[res.nVals - 1]) < 1e-100) { return res.vals[n]; // underflow; return value (will be zero) } throw new ConvergenceException(LocalizedFormats.BESSEL_FUNCTION_FAILED_CONVERGENCE, order, x); @@ -283,7 +283,7 @@ public class BesselJ halfx = 0.5 * x; } if (alpha != 0) { - tempa = AccurateMath.pow(halfx, alpha) / + tempa = JdkMath.pow(halfx, alpha) / (alpha * Gamma.value(alpha)); } tempb = 0; @@ -323,7 +323,7 @@ public class BesselJ // --------------------------------------------------------------------- // Asymptotic series for X > 25 // --------------------------------------------------------------------- - final double xc = AccurateMath.sqrt(PI2 / x); + final double xc = JdkMath.sqrt(PI2 / x); final double mul = 0.125 / x; final double xin = mul * mul; int m = 0; @@ -341,8 +341,8 @@ public class BesselJ // --------------------------------------------------------------------- double t = (double) ((int) ((x / TWOPI) + 0.5)); final double z = x - t * TOWPI1 - t * TWOPI2 - (alpha + 0.5) / PI2; - double vsin = AccurateMath.sin(z); - double vcos = AccurateMath.cos(z); + double vsin = JdkMath.sin(z); + double vcos = JdkMath.cos(z); double gnu = 2 * alpha; double capq; double capp; @@ -457,7 +457,7 @@ public class BesselJ p = plast * tover; n -= 1; en -= 2.0; - nend = AccurateMath.min(nb, n); + nend = JdkMath.min(nb, n); for (int l = nstart; l <= nend; l++) { pold = psavel; psavel = psave; @@ -479,8 +479,8 @@ public class BesselJ // --------------------------------------------------------------------- // Calculate special significance test for NBMX > 2. // --------------------------------------------------------------------- - test = AccurateMath.max(test, AccurateMath.sqrt(plast * ENSIG) * - AccurateMath.sqrt(2 * p)); + test = JdkMath.max(test, JdkMath.sqrt(plast * ENSIG) * + JdkMath.sqrt(2 * p)); } } // --------------------------------------------------------------------- @@ -620,8 +620,8 @@ public class BesselJ // Normalize. Divide all B(N) by sum. // --------------------------------------------------------------------- - if (AccurateMath.abs(alpha) > 1e-16) { - sum *= Gamma.value(alpha) * AccurateMath.pow(x * 0.5, -alpha); + if (JdkMath.abs(alpha) > 1e-16) { + sum *= Gamma.value(alpha) * JdkMath.pow(x * 0.5, -alpha); } tempa = ENMTEN; if (sum > 1) { @@ -629,7 +629,7 @@ public class BesselJ } for (n = 0; n < nb; n++) { - if (AccurateMath.abs(b[n]) < tempa) { + if (JdkMath.abs(b[n]) < tempa) { b[n] = 0; } b[n] /= sum; @@ -642,7 +642,7 @@ public class BesselJ if (b.length > 0) { b[0] = 0; } - ncalc = AccurateMath.min(nb, 0) - 1; + ncalc = JdkMath.min(nb, 0) - 1; } return new BesselJResult(Arrays.copyOf(b, b.length), ncalc); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java index 24bc4ef77..3f212d6c6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.linear.BlockRealMatrix; import org.apache.commons.math4.legacy.linear.MatrixUtils; import org.apache.commons.math4.legacy.linear.RealMatrix; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.Pair; /** @@ -208,9 +208,9 @@ public class KendallsCorrelation { for (int segmentSize = 1; segmentSize < n; segmentSize <<= 1) { for (int offset = 0; offset < n; offset += 2 * segmentSize) { int i = offset; - final int iEnd = AccurateMath.min(i + segmentSize, n); + final int iEnd = JdkMath.min(i + segmentSize, n); int j = iEnd; - final int jEnd = AccurateMath.min(j + segmentSize, n); + final int jEnd = JdkMath.min(j + segmentSize, n); int copyLocation = offset; while (i < iEnd || j < jEnd) { @@ -257,7 +257,7 @@ public class KendallsCorrelation { final long concordantMinusDiscordant = numPairs - tiedXPairs - tiedYPairs + tiedXYPairs - 2 * swaps; final double nonTiedPairsMultiplied = (numPairs - tiedXPairs) * (double) (numPairs - tiedYPairs); - return concordantMinusDiscordant / AccurateMath.sqrt(nonTiedPairsMultiplied); + return concordantMinusDiscordant / JdkMath.sqrt(nonTiedPairsMultiplied); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java index eda73a64d..3790e04fe 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.linear.BlockRealMatrix; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.stat.regression.SimpleRegression; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Computes Pearson's product-moment correlation coefficients for pairs of arrays @@ -165,7 +165,7 @@ public class PearsonsCorrelation { for (int i = 0; i < nVars; i++) { for (int j = 0; j < nVars; j++) { double r = correlationMatrix.getEntry(i, j); - out[i][j] = AccurateMath.sqrt((1 - r * r) /(nObs - 2)); + out[i][j] = JdkMath.sqrt((1 - r * r) /(nObs - 2)); } } return new BlockRealMatrix(out); @@ -201,7 +201,7 @@ public class PearsonsCorrelation { out[i][j] = 0d; } else { double r = correlationMatrix.getEntry(i, j); - double t = AccurateMath.abs(r * AccurateMath.sqrt((nObs - 2)/(1 - r * r))); + double t = JdkMath.abs(r * JdkMath.sqrt((nObs - 2)/(1 - r * r))); out[i][j] = 2 * tDistribution.cumulativeProbability(-t); } } @@ -300,11 +300,11 @@ public class PearsonsCorrelation { int nVars = covarianceMatrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { - double sigma = AccurateMath.sqrt(covarianceMatrix.getEntry(i, i)); + double sigma = JdkMath.sqrt(covarianceMatrix.getEntry(i, i)); outMatrix.setEntry(i, i, 1d); for (int j = 0; j < i; j++) { double entry = covarianceMatrix.getEntry(i, j) / - (sigma * AccurateMath.sqrt(covarianceMatrix.getEntry(j, j))); + (sigma * JdkMath.sqrt(covarianceMatrix.getEntry(j, j))); outMatrix.setEntry(i, j, entry); outMatrix.setEntry(j, i, entry); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java index ae7def13e..b418c3ec2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java @@ -34,7 +34,7 @@ import org.apache.commons.math4.legacy.stat.descriptive.rank.Min; import org.apache.commons.math4.legacy.stat.descriptive.rank.Percentile; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfSquares; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** @@ -272,7 +272,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { double stdDev = Double.NaN; if (getN() > 0) { if (getN() > 1) { - stdDev = AccurateMath.sqrt(getVariance()); + stdDev = JdkMath.sqrt(getVariance()); } else { stdDev = 0.0; } @@ -289,7 +289,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { */ public double getQuadraticMean() { final long n = getN(); - return n > 0 ? AccurateMath.sqrt(getSumsq() / n) : Double.NaN; + return n > 0 ? JdkMath.sqrt(getSumsq() / n) : Double.NaN; } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java index 128bf9bba..10a4883e1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java @@ -31,7 +31,7 @@ import org.apache.commons.math4.legacy.stat.descriptive.rank.Min; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfSquares; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; @@ -255,7 +255,7 @@ public class MultivariateSummaryStatistics } else { RealMatrix matrix = covarianceImpl.getResult(); for (int i = 0; i < k; ++i) { - stdDev[i] = AccurateMath.sqrt(matrix.getEntry(i, i)); + stdDev[i] = JdkMath.sqrt(matrix.getEntry(i, i)); } } return stdDev; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java index de33db3ce..5f5c2a95c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -540,16 +540,16 @@ class ResizableDoubleArray implements DoubleArray, Serializable { // Not in publ * after expansion will be {@code internalArray.length + expansionFactor}. */ protected void expand() { - // notice the use of AccurateMath.ceil(), this guarantees that we will always + // notice the use of JdkMath.ceil(), this guarantees that we will always // have an array of at least currentSize + 1. Assume that the // current initial capacity is 1 and the expansion factor // is 1.000000000000000001. The newly calculated size will be // rounded up to 2 after the multiplication is performed. int newSize = 0; if (expansionMode == ExpansionMode.MULTIPLICATIVE) { - newSize = (int) AccurateMath.ceil(internalArray.length * expansionFactor); + newSize = (int) JdkMath.ceil(internalArray.length * expansionFactor); } else { - newSize = (int) (internalArray.length + AccurateMath.round(expansionFactor)); + newSize = (int) (internalArray.length + JdkMath.round(expansionFactor)); } final double[] tempArray = new double[newSize]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java index 23fae650a..6e454d1f8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.stat.descriptive; import java.io.Serializable; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -115,7 +115,7 @@ public class StatisticalSummaryValues implements Serializable, */ @Override public double getStandardDeviation() { - return AccurateMath.sqrt(variance); + return JdkMath.sqrt(variance); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java index c3b9c5df9..c0935c613 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.stat.descriptive.rank.Min; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfSquares; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.numbers.core.Precision; /** @@ -219,7 +219,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { double stdDev = Double.NaN; if (getN() > 0) { if (getN() > 1) { - stdDev = AccurateMath.sqrt(getVariance()); + stdDev = JdkMath.sqrt(getVariance()); } else { stdDev = 0.0; } @@ -236,7 +236,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { */ public double getQuadraticMean() { final long size = getN(); - return size > 0 ? AccurateMath.sqrt(getSumsq() / size) : Double.NaN; + return size > 0 ? JdkMath.sqrt(getSumsq() / size) : Double.NaN; } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java index 09e683c78..7c6d0755c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfLogs; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Returns the @@ -108,7 +108,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen @Override public double getResult() { if (sumOfLogs.getN() > 0) { - return AccurateMath.exp(sumOfLogs.getResult() / sumOfLogs.getN()); + return JdkMath.exp(sumOfLogs.getResult() / sumOfLogs.getN()); } else { return Double.NaN; } @@ -141,7 +141,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen @Override public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { - return AccurateMath.exp(sumOfLogs.evaluate(values, begin, length) / length); + return JdkMath.exp(sumOfLogs.evaluate(values, begin, length) / length); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java index 367a22353..a6f021d19 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; @@ -171,15 +171,15 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S Variance variance = new Variance(); variance.incrementAll(values, begin, length); double mean = variance.moment.m1; - double stdDev = AccurateMath.sqrt(variance.getResult()); + double stdDev = JdkMath.sqrt(variance.getResult()); // Sum the ^4 of the distance from the mean divided by the // standard deviation double accum3 = 0.0; for (int i = begin; i < begin + length; i++) { - accum3 += AccurateMath.pow(values[i] - mean, 4.0); + accum3 += JdkMath.pow(values[i] - mean, 4.0); } - accum3 /= AccurateMath.pow(stdDev, 4.0d); + accum3 /= JdkMath.pow(stdDev, 4.0d); // Get N double n0 = length; @@ -187,7 +187,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S double coefficientOne = (n0 * (n0 + 1)) / ((n0 - 1) * (n0 - 2) * (n0 - 3)); double termTwo = - (3 * AccurateMath.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3)); + (3 * JdkMath.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3)); // Calculate kurtosis kurt = (coefficientOne * accum3) - termTwo; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java index 05eb18908..9fd057921 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -123,7 +123,7 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se } else { double n0 = moment.getN(); return (n0 * moment.m3) / - ((n0 - 1) * (n0 -2) * AccurateMath.sqrt(variance) * variance); + ((n0 - 1) * (n0 -2) * JdkMath.sqrt(variance) * variance); } } @@ -191,7 +191,7 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se final double d = values[i] - m; accum3 += d * d * d; } - accum3 /= variance * AccurateMath.sqrt(variance); + accum3 /= variance * JdkMath.sqrt(variance); // Get N double n0 = length; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java index cd9483f58..26ecef220 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * Computes the sample standard deviation. The standard deviation @@ -125,7 +125,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ @Override public double getResult() { - return AccurateMath.sqrt(variance.getResult()); + return JdkMath.sqrt(variance.getResult()); } /** @@ -152,7 +152,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ @Override public double evaluate(final double[] values) throws MathIllegalArgumentException { - return AccurateMath.sqrt(variance.evaluate(values)); + return JdkMath.sqrt(variance.evaluate(values)); } /** @@ -176,7 +176,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic @Override public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { - return AccurateMath.sqrt(variance.evaluate(values, begin, length)); + return JdkMath.sqrt(variance.evaluate(values, begin, length)); } /** @@ -205,7 +205,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ public double evaluate(final double[] values, final double mean, final int begin, final int length) throws MathIllegalArgumentException { - return AccurateMath.sqrt(variance.evaluate(values, mean, begin, length)); + return JdkMath.sqrt(variance.evaluate(values, mean, begin, length)); } /** @@ -231,7 +231,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException { - return AccurateMath.sqrt(variance.evaluate(values, mean)); + return JdkMath.sqrt(variance.evaluate(values, mean)); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java index fd9d351b9..3211154a7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java @@ -20,7 +20,7 @@ import java.io.Serializable; import java.util.Arrays; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; /** * A Simple Kth selector implementation to pick up the @@ -101,11 +101,11 @@ public class KthSelector implements Serializable { } else if (k < pivot) { // the element is in the left partition end = pivot; - node = AccurateMath.min(2 * node + 1, usePivotsHeap ? pivotsHeap.length : end); + node = JdkMath.min(2 * node + 1, usePivotsHeap ? pivotsHeap.length : end); } else { // the element is in the right partition begin = pivot + 1; - node = AccurateMath.min(2 * node + 2, usePivotsHeap ? pivotsHeap.length : end); + node = JdkMath.min(2 * node + 2, usePivotsHeap ? pivotsHeap.length : end); } } Arrays.sort(work, begin, end); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java index 8d2ac8883..e6cc453bb 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractUnivariateStatistic; import org.apache.commons.math4.legacy.stat.ranking.NaNStrategy; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -965,7 +965,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa protected double estimate(final double[] values, final int[] pivotsHeap, final double pos, final int length, final KthSelector selector) { - return super.estimate(values, pivotsHeap, AccurateMath.ceil(pos - 0.5), length, selector); + return super.estimate(values, pivotsHeap, JdkMath.ceil(pos - 0.5), length, selector); } @Override public double evaluate(final double[] work, final double[] sampleWeights, @@ -1002,9 +1002,9 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa final int[] pivotsHeap, final double pos, final int length, final KthSelector selector) { final double low = - super.estimate(values, pivotsHeap, AccurateMath.ceil(pos - 0.5), length, selector); + super.estimate(values, pivotsHeap, JdkMath.ceil(pos - 0.5), length, selector); final double high = - super.estimate(values, pivotsHeap,AccurateMath.floor(pos + 0.5), length, selector); + super.estimate(values, pivotsHeap,JdkMath.floor(pos + 0.5), length, selector); return (low + high) / 2; } @Override @@ -1026,7 +1026,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa protected double index(final double p, final int length) { final double minLimit = 1d/2 / length; return Double.compare(p, minLimit) <= 0 ? - 0 : AccurateMath.rint(length * p); + 0 : JdkMath.rint(length * p); } @Override public double evaluate(final double[] work, final double[] sampleWeights, @@ -1272,7 +1272,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa final double pos, final int length, final KthSelector selector) { - final double fpos = AccurateMath.floor(pos); + final double fpos = JdkMath.floor(pos); final int intPos = (int) fpos; final double dif = pos - fpos; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java index 54aae6d89..570101676 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.WeightedEvaluation; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -165,7 +165,7 @@ public class Product extends AbstractStorelessUnivariateStatistic implements Ser if (MathArrays.verifyValues(values, weights, begin, length, true)) { product = 1.0; for (int i = begin; i < begin + length; i++) { - product *= AccurateMath.pow(values[i], weights[i]); + product *= JdkMath.pow(values[i], weights[i]); } } return product; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java index 6d77f7cb1..fd0e571aa 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java @@ -21,13 +21,13 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.core.jdkmath.JdkMath; import org.apache.commons.math4.legacy.core.MathArrays; /** * Returns the sum of the natural logs for this collection of values. *

- * Uses {@link org.apache.commons.math4.legacy.core.jdkmath.AccurateMath#log(double)} to compute the logs. + * Uses {@link org.apache.commons.math4.core.jdkmath.JdkMath#log(double)} to compute the logs. * Therefore, *