You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2012/09/14 22:16:05 UTC

svn commit: r1384905 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java

Author: luc
Date: Fri Sep 14 20:16:05 2012
New Revision: 1384905

URL: http://svn.apache.org/viewvc?rev=1384905&view=rev
Log:
Fixed too large memory consumption in DSCompiler.

Prior to this correction, when at one point in a program a user needed a
derivative with 1 parameter and order 5, and at another point needed a
derivative with 30 parameters and order 1, all DSCompilers from 1x1 to
30x5 were created. As the compilation rules for 30 parameters and 5
order are huge, this failed with memory heap errors after several
gigabytes were consumed.

The fix is to simply build the necessary compilers, and let the array
contain null references for the compilers never used (these null
references will be populated later if the user ask for some intermediate
value that need them, of course).

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java?rev=1384905&r1=1384904&r2=1384905&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java Fri Sep 14 20:16:05 2012
@@ -159,8 +159,10 @@ public class DSCompiler {
         // get the cached compilers
         final DSCompiler[][] cache = compilers.get();
         if (cache != null && cache.length > parameters && cache[parameters].length > order) {
-            // the compiler has already been created
-            return cache[parameters][order];
+            if (cache[parameters][order] != null) {
+                // the compiler has already been created
+                return cache[parameters][order];
+            }
         }
 
         // we need to create more compilers
@@ -176,8 +178,8 @@ public class DSCompiler {
         }
 
         // create the array in increasing diagonal order
-        for (int diag = 0; diag <= maxParameters + maxOrder; ++diag) {
-            for (int o = FastMath.max(0, diag - maxParameters); o <= FastMath.min(maxOrder, diag); ++o) {
+        for (int diag = 0; diag <= parameters + order; ++diag) {
+            for (int o = FastMath.max(0, diag - parameters); o <= FastMath.min(order, diag); ++o) {
                 final int p = diag - o;
                 if (newCache[p][o] == null) {
                     final DSCompiler valueCompiler      = (p == 0) ? null : newCache[p - 1][o];