Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/21 21:15:16 (3 years ago)
Author:
gkronber
Message:

#3087: updated native dlls for NativeInterpreter to a version that runs on Hive infrastructure. Some smaller changes because of deviations in the independently developed implementations (in particular enum types).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs

    r17844 r17989  
    2828using HeuristicLab.Data;
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     30using HeuristicLab.NativeInterpreter;
    3031using HeuristicLab.Parameters;
    3132using HEAL.Attic;
     
    7071      var code = new NativeInstruction[root.GetLength()];
    7172      if (root.SubtreeCount > ushort.MaxValue) throw new ArgumentException("Number of subtrees is too big (>65.535)");
    72       code[0] = new NativeInstruction { narg = (ushort)root.SubtreeCount, opcode = opCodeMapper(root) };
    73       int c = 1, i = 0;
    74       foreach (var node in root.IterateNodesBreadth()) {
    75         for (int j = 0; j < node.SubtreeCount; ++j) {
    76           var s = node.GetSubtree(j);
    77           if (s.SubtreeCount > ushort.MaxValue) throw new ArgumentException("Number of subtrees is too big (>65.535)");
    78           code[c + j] = new NativeInstruction { narg = (ushort)s.SubtreeCount, opcode = opCodeMapper(s) };
     73      int i = code.Length - 1;
     74      foreach (var n in root.IterateNodesPrefix()) {
     75        code[i] = new NativeInstruction { Arity = (ushort)n.SubtreeCount, OpCode = opCodeMapper(n), Length = 1, Optimize = false };
     76        if (n is VariableTreeNode variable) {
     77          code[i].Value = variable.Weight;
     78          code[i].Data = cachedData[variable.VariableName].AddrOfPinnedObject();
     79        } else if (n is ConstantTreeNode constant) {
     80          code[i].Value = constant.Value;
    7981        }
     82        --i;
     83      }
     84      // second pass to calculate lengths
     85      for (i = 0; i < code.Length; i++) {
     86        var c = i - 1;
     87        for (int j = 0; j < code[i].Arity; ++j) {
     88          code[i].Length += code[c].Length;
     89          c -= code[c].Length;
     90        }
     91      }
    8092
    81         if (node is VariableTreeNode variable) {
    82           code[i].weight = variable.Weight;
    83           code[i].data = cachedData[variable.VariableName].AddrOfPinnedObject();
    84         } else if (node is ConstantTreeNode constant) {
    85           code[i].value = constant.Value;
    86         }
    87 
    88         code[i].childIndex = c;
    89         c += node.SubtreeCount;
    90         ++i;
    91       }
    9293      return code;
    9394    }
     
    114115      (byte)OpCode.Tan,
    115116      (byte)OpCode.Tanh,
    116       (byte)OpCode.Power,
    117       (byte)OpCode.Root,
     117      // (byte)OpCode.Power,
     118      // (byte)OpCode.Root,
    118119      (byte)OpCode.SquareRoot,
    119120      (byte)OpCode.Square,
     
    131132      }
    132133
    133       byte mapSupportedSymbols(ISymbolicExpressionTreeNode node) {       
     134      byte mapSupportedSymbols(ISymbolicExpressionTreeNode node) {
    134135        var opCode = OpCodes.MapSymbolToOpCode(node);
    135136        if (supportedOpCodes.Contains(opCode)) return opCode;
     
    140141      var rowsArray = rows.ToArray();
    141142      var result = new double[rowsArray.Length];
    142 
    143       NativeWrapper.GetValuesVectorized(code, code.Length, rowsArray, rowsArray.Length, result);
     143      // prevent optimization of parameters
     144      var options = new SolverOptions {
     145        Iterations = 0
     146      };
     147      NativeWrapper.GetValues(code, rowsArray, options, result, target: null, optSummary: out var optSummary); // target is only used when optimizing parameters
    144148
    145149      // when evaluation took place without any error, we can increment the counter
Note: See TracChangeset for help on using the changeset viewer.