- Timestamp:
- 11/22/19 16:31:11 (5 years ago)
- Location:
- branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors/DoubleVector.cs
r17365 r17367 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Windows.Markup; 23 26 using HEAL.Attic; 24 27 … … 35 38 : base(_) { } 36 39 40 public static DoubleVector operator +(DoubleVector lhs, DoubleVector rhs) { 41 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l + r)); 42 } 43 public static DoubleVector operator -(DoubleVector lhs, DoubleVector rhs) { 44 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l - r)); 45 } 46 public static DoubleVector operator *(DoubleVector lhs, DoubleVector rhs) { 47 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l * r)); 48 } 49 public static DoubleVector operator /(DoubleVector lhs, DoubleVector rhs) { 50 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l / r)); 51 } 52 private static IEnumerable<double> VecCalc(IReadOnlyList<double> lhs, IReadOnlyList<double> rhs, Func<double, double, double> resultFunc) { 53 if (lhs.Count != rhs.Count) throw new InvalidOperationException("Vectors are not of equal length."); 54 return lhs.Zip(rhs, resultFunc); 55 } 56 57 public static DoubleVector operator +(DoubleVector lhs, double rhs) { 58 return new DoubleVector(lhs.Select(l => l + rhs)); 59 } 60 public static DoubleVector operator -(DoubleVector lhs, double rhs) { 61 return new DoubleVector(lhs.Select(l => l - rhs)); 62 } 63 public static DoubleVector operator *(DoubleVector lhs, double rhs) { 64 return new DoubleVector(lhs.Select(l => l * rhs)); 65 } 66 public static DoubleVector operator /(DoubleVector lhs, double rhs) { 67 return new DoubleVector(lhs.Select(l => l / rhs)); 68 } 69 70 public double Sum() { 71 return values.Sum(); 72 } 73 74 public double Average() { 75 return values.Average(); 76 } 37 77 } 38 78 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors/Vector.cs
r17365 r17367 28 28 [StorableType("3574E222-1167-4F1B-93D2-01B15A7F1E84")] 29 29 public abstract class Vector<T> : IVector<T> { 30 private readonly List<T> values; 30 [Storable] 31 protected readonly List<T> values; 31 32 32 33 protected Vector(IEnumerable<T> values) {
Note: See TracChangeset
for help on using the changeset viewer.