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).

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1384905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2012-09-14 20:16:05 +00:00
parent 1c032ee454
commit 8bac3361f2
1 changed files with 6 additions and 4 deletions

View File

@ -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];