Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs

    r14952 r15017  
    22
    33namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
     4  using System;
     5  using System.Linq;
     6
    47  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    58  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
     9  using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
    610  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    711  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
     
    1721    protected VectorTakeExpression(bool deserializing) : base(deserializing) { }
    1822
    19     protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack) {
     23    protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
    2024      return vectorStack.IsEmpty || interpreter.IntegerStack.IsEmpty;
    2125    }
    2226
    23     protected void Eval(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack) {
    24       var count = (int)interpreter.IntegerStack.Pop();
     27    protected void Eval(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
    2528
    2629      if (vectorStack.Top.Count == 0)
    2730        return;
    2831
    29       count %= vectorStack.Top.Count;
     32      var count = interpreter.IntegerStack.Pop().AsInt(vectorStack.Top.Count);
    3033
    3134      if (count < 0)
    3235        count *= -1;
    3336
    34       var result = vectorStack.Top.GetRange(0, count);
    35       vectorStack.SetTop(result);
     37      var vector = vectorStack.Top;
     38      var list = vector as List<T>;
     39
     40      if (list != null) {
     41        var newTop = new T[count];
     42        list.CopyTo(0, newTop, 0, count);
     43        vectorStack.Top = newTop;
     44        return;
     45      }
     46
     47      var array = vector as T[];
     48      if (array != null) {
     49        var newTop = new T[count];
     50        Array.Copy(array, 0, newTop, 0, count);
     51        vectorStack.Top = newTop;
     52        return;
     53      }
     54
     55      vectorStack.Top = vector.Take(count).ToArray();
    3656    }
    3757  }
Note: See TracChangeset for help on using the changeset viewer.