Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/13 13:58:45 (11 years ago)
Author:
bburlacu
Message:

#2021: Code enhancements: changed the SymbolicExpressionTreeLinearCompiler to use and return an array directly and not a list.ToArray(). Replaced GetPrefixSequence lambda with a standalone method and eliminated SetSkip lambda from the PrepareInstructions method. Updated description of SymbolicDataAnalysisExpressionTreeLinearInterpreter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeLinearCompiler.cs

    r9758 r9815  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2523
    2624namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    2826    public static LinearInstruction[] Compile(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) {
    2927      var root = tree.Root.GetSubtree(0).GetSubtree(0);
    30       var code = new List<LinearInstruction> {
    31           new LinearInstruction { dynamicNode = root, nArguments = (byte)root.SubtreeCount, opCode = opCodeMapper(root) }
    32         };
    33       // iterate breadth-wise over tree nodes and produce an array of instructions
    34       var nodes = root.IterateNodesBreadth().ToArray();
    35       for (int i = 0; i != nodes.Length; ++i) {
    36         code[i].childIndex = (byte)code.Count;
    37         code.AddRange(nodes[i].Subtrees.Select(s => new LinearInstruction { dynamicNode = s, nArguments = (byte)s.SubtreeCount, opCode = opCodeMapper(s) }));
     28      var code = new LinearInstruction[root.GetLength()];
     29      code[0] = new LinearInstruction { dynamicNode = root, nArguments = (byte)root.SubtreeCount, opCode = opCodeMapper(root) };
     30      int c = 1, i = 0;
     31      foreach (var node in root.IterateNodesBreadth()) {
     32        for (int j = 0; j != node.SubtreeCount; ++j) {
     33          var s = node.GetSubtree(j);
     34          code[c + j] = new LinearInstruction { dynamicNode = s, nArguments = (byte)s.SubtreeCount, opCode = opCodeMapper(s) };
     35        }
     36        code[i].childIndex = (byte)c;
     37        c += node.SubtreeCount;
     38        ++i;
    3839      }
    39 
    40       return code.ToArray();
     40      return code;
    4141    }
    4242  }
Note: See TracChangeset for help on using the changeset viewer.