# Changeset 16600 for branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Vector.cs

Ignore:
Timestamp:
02/12/19 13:59:15 (4 years ago)
Message:

#2925: made some simplifications (Vector) to aid debugging.

File:
1 edited

Unmodified
Added
Removed
• ## branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Vector.cs

 r16599 } public static Vector AddTo(Vector a, Vector b) { if (b == Zero) return a; if (a == Zero) { var vArr = new double[b.Length]; b.CopyTo(vArr); return new Vector(vArr); } else { Trace.Assert(a.arr.Length == b.arr.Length); for (int i = 0; i < a.arr.Length; i++) a.arr[i] += b.arr[i]; return a; } } // public static Vector AddTo(Vector a, Vector b) { //   if (b == Zero) return a; //   if (a == Zero) { //     var vArr = new double[b.Length]; //     b.CopyTo(vArr); //     return new Vector(vArr); //   } else { //     Trace.Assert(a.arr.Length == b.arr.Length); //     for (int i = 0; i < a.arr.Length; i++) //       a.arr[i] += b.arr[i]; //     return a; //   } // } } Trace.Assert(a.arr.Length == b.arr.Length); var res = new double[a.arr.Length]; for (int i = 0; i < a.arr.Length; i++) a.arr[i] -= b.arr[i]; return a; res[i] = a.arr[i] - b.arr[i]; return new Vector(res); } public static Vector operator -(Vector a, Vector b) { if (b == Zero) return a; if (a == Zero) return -b; Trace.Assert(a.arr.Length == b.arr.Length); var res = new double[a.arr.Length]; for (int i = 0; i < res.Length; i++) res[i] = a.arr[i] - b.arr[i]; return new Vector(res); return Subtract(a, b); } public static Vector operator -(Vector v) { if (v == Zero) return Zero; for (int i = 0; i < v.arr.Length; i++) v.arr[i] = -v.arr[i]; return v; return v.Scale(-1.0); } public static Vector operator *(double s, Vector v) { if (v == Zero) return Zero; if (s == 0.0) return Zero; var res = new double[v.arr.Length]; for (int i = 0; i < res.Length; i++) res[i] = s * v.arr[i]; return new Vector(res); return v.Scale(s); } public Vector Scale(double s) { if (this != Zero) { for (int i = 0; i < arr.Length; i++) { arr[i] *= s; } if (this == Zero) return Zero; var res = new double[arr.Length]; for (int i = 0; i < arr.Length; i++) { res[i] = arr[i] * s; } return new Vector(res); return this; } return s * v; } public static Vector operator *(Vector u, Vector v) { if (v == Zero) return Zero; return new Vector(res); } public static Vector operator /(double s, Vector v) { if (s == 0.0) return Zero; var res = new double[v.arr.Length]; for (int i = 0; i < res.Length; i++) res[i] = 1.0 / v.arr[i]; res[i] = s / v.arr[i]; return new Vector(res); } public static Vector operator /(Vector v, double s) { return v * 1.0 / s; return v.Scale(1.0 / s); }
Note: See TracChangeset for help on using the changeset viewer.