SOLR-13146: Allow derivatives to be computed for the oscillate Stream Evaluator

This commit is contained in:
Joel Bernstein 2019-01-20 13:18:54 -05:00
parent 571ae2670a
commit 28953a3afc
2 changed files with 12 additions and 3 deletions

View File

@ -44,14 +44,17 @@ public class OscillateEvaluator extends RecursiveNumericEvaluator implements Man
HarmonicOscillator pf = new HarmonicOscillator(amp, om, phase);
double[] x = new double[128];
List list = new ArrayList();
for(int i=0; i<128; i++) {
double yvalue= pf.value(i);
list.add(yvalue);
x[i] = i;
}
return new VectorFunction(pf, list);
VectorFunction func = new VectorFunction(pf, list);
func.addToContext("x", x);
return func;
}
}

View File

@ -2782,7 +2782,8 @@ public class MathExpressionTest extends SolrCloudTestCase {
" e=harmfit(a)," +
" f=getAmplitude(e)," +
" g=getAngularFrequency(e)," +
" h=getPhase(e))";
" h=getPhase(e)," +
" i=derivative(a))";
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
paramsLoc.set("expr", cexpr);
paramsLoc.set("qt", "/stream");
@ -2810,6 +2811,11 @@ public class MathExpressionTest extends SolrCloudTestCase {
assertEquals(amp.doubleValue(), 10, .1);
assertEquals(freq.doubleValue(), .3, .1);
assertEquals(pha.doubleValue(), 2.9, .1);
List<Number> der = (List<Number>)tuples.get(0).get("i");
assertEquals(der.size(), 128);
assertEquals(der.get(0).doubleValue(), -0.7177479876419472, 0);
assertEquals(der.get(127).doubleValue(), 0.47586800641412696, 0);
}
@Test