Changeset 18230 for branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 03/07/22 15:45:30 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
r18214 r18230 728 728 } 729 729 case OpCodes.SubVector: { 730 DoubleVector SubVector(DoubleVector v , double start, double end) { 731 int size = v.Count; 732 int startIdx = Math.Abs((int)Math.Round(start * (size - 1)) % size); 733 int endIdx = Math.Abs((int)Math.Round(end * (size - 1)) % size); 734 if (startIdx < endIdx) { 735 return v.SubVector(startIdx, count: endIdx - startIdx); 736 } else { // wrap around 737 var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx)); 738 v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx] 739 v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx); // copy [0:endIdx] to [size-startIdx:size] 740 return resultVector; 730 DoubleVector SubVector(DoubleVector v , double start, double end) { 731 int size = v.Count; 732 int ToIdx(double x) { 733 int idx = (int)Math.Round(x * (size - 1)); 734 return (idx % size + size) % size; // positive mod 735 } 736 int startIdx = ToIdx(start); 737 int endIdx = ToIdx(end); 738 if (startIdx <= endIdx) { 739 return v.SubVector(startIdx, count: endIdx - startIdx + 1); // incl end 740 } else { // wrap around 741 var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx) + 1); 742 v.CopySubVectorTo(resultVector, sourceIndex: startIdx, targetIndex: 0, count: size - startIdx); // copy [startIdx:size] to [0:size-startIdx] 743 v.CopySubVectorTo(resultVector, sourceIndex: 0, targetIndex: size - startIdx, count: endIdx); // copy [0:endIdx] to [size-startIdx:size] 744 return resultVector; 745 } 741 746 } 742 } 743 var cur = Evaluate(dataset, ref row, state, traceDict); 744 TraceEvaluation(currentInstr, cur); 745 return FunctionApply(cur, 746 s => s, 747 v => { 748 var node = (IWindowedSymbolTreeNode)currentInstr.dynamicNode; 749 return SubVector(v, node.Offset, node.Length); 750 }); 747 var cur = Evaluate(dataset, ref row, state, traceDict); 748 TraceEvaluation(currentInstr, cur); 749 return FunctionApply(cur, 750 s => s, 751 v => { 752 var node = (IWindowedSymbolTreeNode)currentInstr.dynamicNode; 753 return SubVector(v, node.Offset, node.Length); 754 }); 751 755 } 752 756 case OpCodes.SubVectorSubtree: { 753 DoubleVector SubVector(DoubleVector v, double start, double end) { 754 int Mod(int x, int m) => (x % m + m) % m; 755 int startIdx = Mod((int)Math.Round(start * v.Count), v.Count); 756 int endIdx = Mod((int)Math.Round(end * v.Count), v.Count); 757 int size = v.Count; 758 if (startIdx < endIdx) { 759 return v.SubVector(startIdx, count: endIdx - startIdx); 760 } else { // wrap around 761 var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx)); 762 v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx] 763 v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx); // copy [0:endIdx] to [size-startIdx:size] 764 return resultVector; 757 DoubleVector SubVector(DoubleVector v, double start, double end) { 758 int Mod(int x, int m) => (x % m + m) % m; 759 int startIdx = Mod((int)Math.Round(start * v.Count), v.Count); 760 int endIdx = Mod((int)Math.Round(end * v.Count), v.Count); 761 int size = v.Count; 762 if (startIdx < endIdx) { 763 return v.SubVector(startIdx, count: endIdx - startIdx); 764 } else { // wrap around 765 var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx)); 766 v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx] 767 v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx); // copy [0:endIdx] to [size-startIdx:size] 768 return resultVector; 769 } 765 770 } 766 } 767 var cur = Evaluate(dataset, ref row, state, traceDict); 768 var offset = Evaluate(dataset, ref row, state, traceDict); 769 var length = Evaluate(dataset, ref row, state, traceDict); 770 TraceEvaluation(currentInstr, cur); 771 return FunctionApply(cur, 772 s => s, 773 v => SubVector(v, offset.Scalar, length.Scalar) 774 ); 775 } 771 var cur = Evaluate(dataset, ref row, state, traceDict); 772 var offset = Evaluate(dataset, ref row, state, traceDict); 773 var length = Evaluate(dataset, ref row, state, traceDict); 774 TraceEvaluation(currentInstr, cur); 775 return FunctionApply(cur, 776 s => s, 777 v => SubVector(v, offset.Scalar, length.Scalar) 778 ); 779 } 776 780 case OpCodes.Variable: { 777 781 if (row < 0 || row >= dataset.Rows) return EvaluationResult.NaN;
Note: See TracChangeset
for help on using the changeset viewer.