commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject [4/7] [math] Fix DerivativeStructure.pow for 0 argument and power less than 1.
Date Fri, 05 Aug 2016 15:06:52 GMT
Fix DerivativeStructure.pow for 0 argument and power less than 1.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/540564e1
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/540564e1
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/540564e1

Branch: refs/heads/develop
Commit: 540564e190662e6617d8c8974854ded6ff2b365a
Parents: c64856f
Author: Luc Maisonobe <luc@orekit.org>
Authored: Fri Aug 5 15:05:33 2016 +0200
Committer: Emmanuel Bourg <ebourg@apache.org>
Committed: Fri Aug 5 15:05:33 2016 +0200

----------------------------------------------------------------------
 .../math4/analysis/differentiation/DSCompiler.java      |  6 ++++++
 .../differentiation/DerivativeStructureTest.java        | 12 ++++++++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/540564e1/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
b/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
index 7d5c163..8e07838 100644
--- a/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
+++ b/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
@@ -893,6 +893,12 @@ public class DSCompiler {
             return;
         }
 
+        if (operand[operandOffset] == 0) {
+            // special case, 0^p = 0 for all p
+            Arrays.fill(result, resultOffset, resultOffset + getSize(), 0);
+            return;
+        }
+
         // create the function value and derivatives
         // [x^p, px^(p-1), p(p-1)x^(p-2), ... ]
         double[] function = new double[1 + order];

http://git-wip-us.apache.org/repos/asf/commons-math/blob/540564e1/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
index 8d0c733..1bb7718 100644
--- a/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
@@ -345,6 +345,18 @@ public class DerivativeStructureTest extends ExtendedFieldElementAbstractTest<De
                     Assert.assertEquals(0.0, d, Precision.SAFE_MIN);
                 }
             }
+
+            // 0^p with p smaller than 1.0
+            DerivativeStructure u = new DerivativeStructure(3, maxOrder, 1, -0.0).pow(0.25);
+            for (int i0 = 0; i0 <= maxOrder; ++i0) {
+                for (int i1 = 0; i1 <= maxOrder; ++i1) {
+                    for (int i2 = 0; i2 <= maxOrder; ++i2) {
+                        if (i0 + i1 + i2 <= maxOrder) {
+                            Assert.assertEquals(0.0, u.getPartialDerivative(i0, i1, i2),
1.0e-10);
+                        }
+                    }
+                }
+            }
         }
 
     }


Mime
View raw message