Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6755 for trunk


Ignore:
Timestamp:
09/13/11 17:38:29 (13 years ago)
Author:
gkronber
Message:

#1480 implemented code to handle root symbols for the il emitting interpreter and fixed code for power symbol.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r6741 r6755  
    4444    private static MethodInfo log = typeof(Math).GetMethod("Log", new Type[] { typeof(double) });
    4545    private static MethodInfo power = typeof(Math).GetMethod("Pow", new Type[] { typeof(double), typeof(double) });
     46    private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) });
    4647
    4748    internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns);
     
    340341            CompileInstructions(il, state);
    341342            CompileInstructions(il, state);
     343            il.Emit(System.Reflection.Emit.OpCodes.Call, round);
    342344            il.Emit(System.Reflection.Emit.OpCodes.Call, power);
    343345            return;
    344346          }
    345347        case OpCodes.Root: {
    346             throw new NotImplementedException();
     348            CompileInstructions(il, state);
     349            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // 1 / round(...)
     350            CompileInstructions(il, state);
     351            il.Emit(System.Reflection.Emit.OpCodes.Call, round);
     352            il.Emit(System.Reflection.Emit.OpCodes.Div);
     353            il.Emit(System.Reflection.Emit.OpCodes.Call, power);
     354            return;
    347355          }
    348356        case OpCodes.Exp: {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs

    r6735 r6755  
    276276      Evaluate(interpreter, ds, "(log -3.0)", 0, Math.Log(-3));
    277277
     278      // power
     279      Evaluate(interpreter, ds, "(pow 2.0 3.0)", 0, 8.0);
     280      Evaluate(interpreter, ds, "(pow 4.0 0.5)", 0, 1.0); // interpreter should round to the nearest integer value value (.5 is rounded to the even number)
     281      Evaluate(interpreter, ds, "(pow 4.0 2.5)", 0, 16.0); // interpreter should round to the nearest integer value value (.5 is rounded to the even number)
     282      Evaluate(interpreter, ds, "(pow -2.0 3.0)", 0, -8.0);
     283      Evaluate(interpreter, ds, "(pow 2.0 -3.0)", 0, 1.0 / 8.0);
     284      Evaluate(interpreter, ds, "(pow -2.0 -3.0)", 0, -1.0 / 8.0);
     285
     286      // root
     287      Evaluate(interpreter, ds, "(root 9.0 2.0)", 0, 3.0);
     288      Evaluate(interpreter, ds, "(root 27.0 3.0)", 0, 3.0);
     289      Evaluate(interpreter, ds, "(root 2.0 -3.0)", 0, Math.Pow(2.0, -1.0 / 3.0));
     290
    278291      // mean
    279292      Evaluate(interpreter, ds, "(mean -1.0 1.0 -1.0)", 0, -1.0 / 3.0);
Note: See TracChangeset for help on using the changeset viewer.