Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/25/17 15:59:39 (7 years ago)
Author:
gkronber
Message:

#2581: merged r13645,r13648,r13650,r13651,r13652,r13654,r13657,r13658,r13659,r13661,r13662,r13669,r13708,r14142 from trunk to stable (to be deleted in the next commit)

Location:
stable
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/ExpressionEvaluator.cs

    r13645 r15060  
    22/* HeuristicLab
    33 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    4  * and the BEACON Center for the Study of Evolution in Action.
    54 *
    65 * This file is part of HeuristicLab.
     
    2928  internal class ExpressionEvaluator {
    3029    // manages it's own vector buffers
    31     private readonly List<double[]> vectorBuffers = new List<double[]>();
    32     private readonly List<double[]> scalarBuffers = new List<double[]>(); // scalars are vectors of length 1 (to allow mixing scalars and vectors on the same stack)
     30    private readonly double[][] vectorBuffers;
     31    private readonly double[][] scalarBuffers; // scalars are vectors of length 1 (to allow mixing scalars and vectors on the same stack)
     32    private int lastVecBufIdx;
     33    private int lastScalarBufIdx;
    3334
    3435
    3536    private double[] GetVectorBuffer() {
    36       var v = vectorBuffers[vectorBuffers.Count - 1];
    37       vectorBuffers.RemoveAt(vectorBuffers.Count - 1);
    38       return v;
     37      return vectorBuffers[--lastVecBufIdx];
    3938    }
    4039    private double[] GetScalarBuffer() {
    41       var v = scalarBuffers[scalarBuffers.Count - 1];
    42       scalarBuffers.RemoveAt(scalarBuffers.Count - 1);
    43       return v;
     40      return scalarBuffers[--lastScalarBufIdx];
    4441    }
    4542
    4643    private void ReleaseBuffer(double[] buf) {
    47       (buf.Length == 1 ? scalarBuffers : vectorBuffers).Add(buf);
     44      if (buf.Length == 1) {
     45        scalarBuffers[lastScalarBufIdx++] = buf;
     46      } else {
     47        vectorBuffers[lastVecBufIdx++] = buf;
     48      }
    4849    }
    4950
     
    7475
    7576      // preallocate buffers
     77      vectorBuffers = new double[MaxStackSize * (1 + MaxParams)][];
     78      scalarBuffers = new double[MaxStackSize * (1 + MaxParams)][];
    7679      for (int i = 0; i < MaxStackSize; i++) {
    7780        ReleaseBuffer(new double[vLen]);
     
    9598      short arg;
    9699      // checked at the end to make sure we do not leak buffers
    97       int initialScalarCount = scalarBuffers.Count;
    98       int initialVectorCount = vectorBuffers.Count;
     100      int initialScalarCount = lastScalarBufIdx;
     101      int initialVectorCount = lastVecBufIdx;
    99102
    100103      while (true) {
     
    180183
    181184                var f = 1.0 / (maxFx * consts[curParamIdx]);
    182                 // adjust c so that maxFx*c = 1
     185                // adjust c so that maxFx*c = 1 TODO: this is not ideal as it enforces positive arguments to exp()
    183186                consts[curParamIdx] *= f;
    184187
     
    212215            }
    213216            ReleaseBuffer(r);
    214             Contract.Assert(vectorBuffers.Count == initialVectorCount);
    215             Contract.Assert(scalarBuffers.Count == initialScalarCount);
     217            Contract.Assert(lastVecBufIdx == initialVectorCount);
     218            Contract.Assert(lastScalarBufIdx == initialScalarCount);
    216219            return;
    217220        }
     
    233236
    234237      // checked at the end to make sure we do not leak buffers
    235       int initialScalarCount = scalarBuffers.Count;
    236       int initialVectorCount = vectorBuffers.Count;
     238      int initialScalarCount = lastScalarBufIdx;
     239      int initialVectorCount = lastVecBufIdx;
    237240
    238241      while (true) {
     
    401404            }
    402405
    403             Contract.Assert(vectorBuffers.Count == initialVectorCount);
    404             Contract.Assert(scalarBuffers.Count == initialScalarCount);
     406            Contract.Assert(lastVecBufIdx == initialVectorCount);
     407            Contract.Assert(lastScalarBufIdx == initialScalarCount);
    405408            return; // break loop
    406409        }
     
    509512      s = 0;
    510513      if (op == (byte)OpCodes.LoadVar) {
    511         s = (short)(((short)code[pc] << 8) | (short)code[pc + 1]);
     514        s = (short)((code[pc] << 8) | code[pc + 1]);
    512515        pc += 2;
    513516      }
Note: See TracChangeset for help on using the changeset viewer.