Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIndexOfExpressions.cs
- Timestamp:
- 05/10/17 11:23:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIndexOfExpressions.cs
r14834 r14952 2 2 3 3 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 4 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 5 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 10 11 /// </summary> 11 12 /// <typeparam name="T"></typeparam> 13 [StorableClass] 12 14 public abstract class VectorIndexOfExpression<T> : StatelessExpression { 13 protected bool Eval( 15 protected VectorIndexOfExpression() { } 16 [StorableConstructor] 17 protected VectorIndexOfExpression(bool deserializing) : base(deserializing) { } 18 19 protected bool IsNoop(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) { 20 return vectorStack.IsEmpty || literalStack.IsEmpty; 21 } 22 23 protected void Eval( 14 24 IInternalPushInterpreter interpreter, 15 25 IPushStack<List<T>> vectorStack, 16 26 IPushStack<T> literalStack, 17 27 bool canOverride = false) { 18 if (vectorStack.IsEmpty || literalStack.IsEmpty)19 return false;20 21 28 var vector = vectorStack.Pop(); 22 29 var literal = canOverride ? literalStack.Top : literalStack.Pop(); … … 25 32 if (canOverride) interpreter.IntegerStack.SetTop(result); 26 33 else interpreter.IntegerStack.Push(result); 27 return true;28 34 } 29 35 } 30 36 37 [StorableClass] 31 38 [PushExpression(StackTypes.IntegerVector, "INTEGER[].INDEXOF", StackTypes.Integer)] 32 39 public class IntegerVectorIndexOfExpression : VectorIndexOfExpression<long> { 33 public override bool Eval(IInternalPushInterpreter interpreter) { 34 return Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true); 40 public IntegerVectorIndexOfExpression() { } 41 [StorableConstructor] 42 protected IntegerVectorIndexOfExpression(bool deserializing) : base(deserializing) { } 43 44 public override bool IsNoop(IInternalPushInterpreter interpreter) { 45 return IsNoop(interpreter.IntegerVectorStack, interpreter.IntegerStack); 46 } 47 48 public override void Eval(IInternalPushInterpreter interpreter) { 49 Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true); 35 50 } 36 51 } 37 52 53 [StorableClass] 38 54 [PushExpression(StackTypes.FloatVector, "FLOAT[].INDEXOF", StackTypes.Float | StackTypes.Integer)] 39 55 public class FloatVectorIndexOfExpression : VectorIndexOfExpression<double> { 40 public override bool Eval(IInternalPushInterpreter interpreter) { 41 return Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); 56 public FloatVectorIndexOfExpression() { } 57 [StorableConstructor] 58 protected FloatVectorIndexOfExpression(bool deserializing) : base(deserializing) { } 59 60 public override bool IsNoop(IInternalPushInterpreter interpreter) { 61 return IsNoop(interpreter.FloatVectorStack, interpreter.FloatStack); 62 } 63 64 public override void Eval(IInternalPushInterpreter interpreter) { 65 Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); 42 66 } 43 67 } 44 68 69 [StorableClass] 45 70 [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].INDEXOF", StackTypes.Boolean | StackTypes.Integer)] 46 71 public class BooleanVectorIndexOfExpression : VectorIndexOfExpression<bool> { 47 public override bool Eval(IInternalPushInterpreter interpreter) { 48 return Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); 72 public BooleanVectorIndexOfExpression() { } 73 [StorableConstructor] 74 protected BooleanVectorIndexOfExpression(bool deserializing) : base(deserializing) { } 75 76 public override bool IsNoop(IInternalPushInterpreter interpreter) { 77 return IsNoop(interpreter.BooleanVectorStack, interpreter.BooleanStack); 78 } 79 80 public override void Eval(IInternalPushInterpreter interpreter) { 81 Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); 49 82 } 50 83 } 51 84 85 [StorableClass] 52 86 [PushExpression(StackTypes.StringVector, "STRING[].INDEXOF", StackTypes.String | StackTypes.String)] 53 87 public class StringVectorIndexOfExpression : VectorIndexOfExpression<string> { 54 public override bool Eval(IInternalPushInterpreter interpreter) { 55 return Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack); 88 public StringVectorIndexOfExpression() { } 89 [StorableConstructor] 90 protected StringVectorIndexOfExpression(bool deserializing) : base(deserializing) { } 91 92 public override bool IsNoop(IInternalPushInterpreter interpreter) { 93 return IsNoop(interpreter.StringVectorStack, interpreter.StringStack); 94 } 95 96 public override void Eval(IInternalPushInterpreter interpreter) { 97 Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack); 56 98 } 57 99 }
Note: See TracChangeset
for help on using the changeset viewer.