public void Sort_ArrayAndAscMaxAbsolutValueComparer_ArraySortedByMaxAbsoluteValueByAsc() { int[][] array = new int[][] { new int[] { -1, 2 }, new int[] { 0, 1, 1, 0 }, new int[] { 0, 0, 0, 0 }, new int[] { 3, -5, 2, 0 }, new int[] { 2, 4, 1 } }; int[][] expected = new int[][] { new int[] { 0, 0, 0, 0 }, new int[] { 0, 1, 1, 0 }, new int[] { -1, 2 }, new int[] { 2, 4, 1 }, new int[] { 3, -5, 2, 0 } }; JaggedArray.Sort(array, new AscMaxAbsoluteValueComparer()); IStructuralEquatable actual = array; Assert.IsTrue(actual.Equals(expected, StructuralComparisons.StructuralEqualityComparer)); }
public static double[][] MatrixInversion(double[][] matrix) { int matrixLength = matrix.Length; double[][] matrixTemp = JaggedArray.CreateJaggedArray <double[][]>(matrixLength, 2 * matrixLength); double[][] result = JaggedArray.CreateJaggedArray <double[][]>(matrixLength, matrixLength); for (int i = 0; i < matrixLength; i++) { for (int j = 0; j < matrixLength; j++) { matrixTemp[i][j] = matrix[i][j]; } } for (int k = 0; k < matrixLength; k++) { for (int t = matrixLength; t < matrixLength * 2; t++) { matrixTemp[k][t] = t - k == matrixLength ? 1.0 : 0; } } for (int k = 0; k < matrixLength; k++) { if (matrixTemp[k][k] != 1) { double bs = matrixTemp[k][k]; matrixTemp[k][k] = 1; for (int p = k; p < matrixLength * 2; p++) { matrixTemp[k][p] /= bs; } } for (int q = 0; q < matrixLength; q++) { if (q == k) { continue; } double bs = matrixTemp[q][k]; for (int p = 0; p < matrixLength * 2; p++) { matrixTemp[q][p] -= bs * matrixTemp[k][p]; } } } for (int x = 0; x < matrixLength; x++) { for (int y = matrixLength; y < matrixLength * 2; y++) { result[x][y - matrixLength] = matrixTemp[x][y]; } } return(result); }
public void JaggedRanks() { int[] ranks = JaggedArray.GetRanks(jagged.GetType(), typeof(int)); Assert.Equal(4, ranks.Length); Assert.Equal(2, ranks[0]); Assert.Equal(1, ranks[1]); Assert.Equal(2, ranks[2]); Assert.Equal(1, ranks[3]); }
public void JaggedTypes() { Type[] types = JaggedArray.GetTypes(jagged.GetType(), typeof(int)); Assert.Equal(5, types.Length); Assert.Equal(types[0], jagged.GetType()); Assert.Equal(types[1], jagged[0, 0].GetType()); Assert.Equal(types[2], jagged[0, 0][0].GetType()); Assert.Equal(types[3], jagged[0, 0][0][0, 0].GetType()); Assert.Equal(types[4], jagged[0, 0][0][0, 0][0].GetType()); }
public void HasLengthHigherDimensionTest() { Assert.IsTrue(LengthChecker.HasLength <double>( JaggedArray.Create <double[][]>(8, 9), 8, 9)); Assert.IsTrue(LengthChecker.HasLength <double>( JaggedArray.Create <double[][][]>(3, 4, 5), 3, 4, 5)); }
public void Sort_CompareArrayMin() { var array = new int[5][] { new int[] { 3, 5, 6 }, new int[] { -3, 5, 6, 7 }, new int[] { -43, 5 }, new int[] { -53, 5, 6, 7, 9 }, new int[] { 8 } }; var JG = new JaggedArray(array); var expected = new int[5][] { new int[] { -53, 5, 6, 7, 9 }, new int[] { -43, 5 }, new int[] { -3, 5, 6, 7 }, new int[] { 3, 5, 6 }, new int[] { 8 } }; SortByMinimumOfTheElements.GetCompareElements(JG); CollectionAssert.AreEqual(expected, array); }
public void TestMethod_Sort_by_Min_Decrease() { int[][] actual = JaggedArray.Sort_by_Min_Decrease(jaggedArray); int[][] expected = { new int[] { 11, 22 }, new int[] { 1,3, 5, 7, 9 }, new int[] { 0,2, 4, 6 }, }; Assert.AreEqual(expected, actual); }
private static double[][] Calc(IReadOnlyList <double> segment, double d, IReadOnlyList <double> segment2) { double[][] ret = JaggedArray.CreateJaggedArray <double[][]>(segment.Count, 1); for (int i = 0; i < segment.Count; i++) { ret[i][0] = segment[i] - d * segment2[i]; } return(ret); }
public void Array2DArrayEstimatorTest() { // Create the estimator // element type is double[] //Estimator<GaussianArray2DArray> est = null; int length1 = ga2aArrayOfDist.GetLength(0); int length2 = ga2aArrayOfDist.GetLength(1); Array2DEstimator <GaussianArrayEstimator, GaussianArray2DArray, GaussianArray, double[]> est = new Array2DEstimator <GaussianArrayEstimator, GaussianArray2DArray, GaussianArray, double[]>( Utilities.Util.ArrayInit(length1, length2, (i, j) => new GaussianArrayEstimator(Utilities.Util.ArrayInit(ga2aArrayOfDist[i, j].Length, k => new GaussianEstimator())) )); // Add some samples to the estimator int nSamples = 5; // Create a sample an mean variable of the right structure double[, ][] mean = (double[, ][]) JaggedArray.ConvertToNew( ga2aArrayOfDist, typeof(double), delegate(object elt) { return(0.0); }); double[, ][] sample = (double[, ][]) JaggedArray.ConvertToNew( ga2aArrayOfDist, typeof(double), delegate(object elt) { return(0.0); }); // Create samples and add them to the estimator. Accumulate sum of samples at the same time for (int nSamp = 0; nSamp < nSamples; nSamp++) { JaggedArray.ConvertElements2( sample, ga2aArrayOfDist, delegate(object smp, object dst) { return(((Gaussian)dst).Sample()); }); est.Add(sample); JaggedArray.ConvertElements2( mean, sample, delegate(object mn, object smp) { return((double)mn + (double)smp); }); } // Hand calculate the sample mean JaggedArray.ConvertElements( mean, delegate(object mn) { return(((double)mn) / ((double)nSamples)); }); // Let the estimator do the work GaussianArray2DArray result = new GaussianArray2DArray(length1, length2, (i, j) => new GaussianArray(ga2aArrayOfDist[i, j].Length)); result = est.GetDistribution(result); // The results should be identical to a very high precision for (int i = 0; i < dim1; i++) { for (int j = 0; j < dim2; j++) { for (int k = 0; k < result[i, j].Count; k++) { Assert.True(System.Math.Abs(result[i, j][k].GetMean() - mean[i, j][k]) < 1e-9); } } } }
public void SortMaxTestInvert() { int[][] expend = new int[4][] { new int[] { 100 }, new int[] { 12, 22, 32, 42, 52, 62 }, new int[] { 10, 20, 30, 40, 50, 60 }, new int[] { 11, 21, 31 }, }; JaggedArray.SortMax(_test, true); Assert.AreEqual(_test, expend); }
public Board(List <Stone> stones, int height, int width, User blackPlayer, User whitePlayer) { StoneMap = JaggedArray.InitalizeStoneMap(height, width, stones); KoInfo = new Stone(); Height = height; Width = width; Capture = new Dictionary <bool, int> { { true, 0 }, { false, 0 } }; Player = new Dictionary <User, bool> { { whitePlayer, true }, { blackPlayer, false } }; }
public BoeingPerfTable GetItem(XDocument doc) { var root = doc.Root; var para = root.Element("Parameters"); bool lenUnitIsMeter = para.GetString("LengthUnit") == "M"; double wtRefKg = para.GetDouble("WeightRef"); double wtStepKg = para.GetDouble("WeightStep"); var brks = para.Element("Brakes"); var brkSettingDry = brks.GetString("Dry").Split(';'); var brkSettingWet = brks.GetString("Wet").Split(';'); var reversers = para.GetString("Reversers").Split(';'); var data = root.Elements("Data").ToArray(); int flapsCount = data.Length; string[] flaps = new string[flapsCount]; var tableDry = JaggedArray.Create <double[][][]> (flapsCount, brkSettingDry.Length, ColumnCount); var tableWet = JaggedArray.Create <double[][][][]> (flapsCount, SurfaceCondCount, brkSettingWet.Length, ColumnCount); for (int i = 0; i < flapsCount; i++) { flaps[i] = data[i].Element("Flaps").Value; ReadTableDry(tableDry, i, data[i].GetString("Dry")); ReadTableWet(tableWet, i, 0, data[i].GetString("Good")); ReadTableWet(tableWet, i, 1, data[i].GetString("Medium")); ReadTableWet(tableWet, i, 2, data[i].GetString("Poor")); } if (lenUnitIsMeter == false) { tableDry.Multiply(FtMeterRatio); tableWet.Multiply(FtMeterRatio); } return(new BoeingPerfTable( wtRefKg, wtStepKg, brkSettingDry, brkSettingWet, flaps, reversers, new TableDry(tableDry), new TableWet(tableWet))); }
public void JaggedConvertToNewTypeGeneric() { Array jaggedGaussian = JaggedArray.ConvertToNew <int, Gaussian>( jagged, delegate(int elt) { return(new Gaussian(0.5, 1.0)); }); Assert.Equal( JaggedArray.GetLength(jaggedGaussian, typeof(Gaussian)), JaggedArray.GetLength(jagged, typeof(int))); foreach (Gaussian g in JaggedArray.ElementIterator <Gaussian>(jaggedGaussian)) { Assert.Equal(0.5, g.GetMean()); } }
// Tests that visitor works when one jagged is a distribution array and the // other is a jagged array public void Array2DArrayVisitor() { int count = JaggedArray.GetLength(ga2aArrayOfDist); // We must use the expanded form of VisitElements2 here because the element type of // ga2aDistArray will be wrongly determined by the shorter version JaggedArray.VisitElements2( ga2aDistArray, ga2aArrayOfDist, typeof(Gaussian), typeof(Gaussian), delegate(object a, object b) { Assert.True(((Gaussian)a).Equals((Gaussian)b)); count--; }); Assert.Equal(0, count); }
public void JaggedIntIterator() { List <int> listActual = new List <int>(); foreach (int i in JaggedArray.ElementIterator <int>(jagged)) { listActual.Add(i); } int[] arrActual = listActual.ToArray(); Assert.Equal(arrActual.Length, arrExpected.Length); for (int i = 0; i < arrActual.Length; i++) { Assert.Equal(arrActual[i], arrExpected[i]); } }
public void JaggedVisitor() { Array jaggedDir = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Dirichlet), delegate(object elt) { return(new Dirichlet(2.0, 3.0, 4.0)); }); double[] newPseudoCount = { 3.0, 4.0, 5.0 }; JaggedArray.VisitElements( jaggedDir, typeof(Dirichlet), delegate(object elt) { ((Dirichlet)elt).PseudoCount.SetTo(newPseudoCount); }); foreach (Dirichlet d in JaggedArray.ElementIterator(jaggedDir, typeof(Dirichlet))) { Assert.Equal(3.0, d.PseudoCount[0]); } }
public static double[][] MatrixMultiplication(double[][] a, double[][] b) { int hang = a.Length; int lie = b[0].Length; double[][] result = JaggedArray.CreateJaggedArray <double[][]>(hang, lie); for (int i = 0; i < hang; i++) { for (int j = 0; j < lie; j++) { result[i][j] = b.Select((t, k) => a[i][k] * t[j]).Sum(); } } return(result); }
public static float[][] RandomPartitioning(float[][] records, int k) { Debug.Assert(k > 0); var rng = new Random((int)DateTime.Now.Ticks); var centroids = JaggedArray.Init <float>(k, records[0].Length); var labels = new int[records.Length]; // Assign each record to random cluster for (var i = 0; i < records.Length; ++i) { labels[i] = rng.Next(k); } Compute(centroids, records, labels); return(centroids); }
public void JaggedArrayTest_SortInnerArrayNull_ExeptionResult() { int[][] jaggedArray = new int[5][]; jaggedArray[0] = new int[3] { -1, 5, 6 }; jaggedArray[1] = null; jaggedArray[2] = new int[3] { 11, 25, 16 }; jaggedArray[3] = new int[3] { 0, -4, 0 }; jaggedArray[4] = new int[3] { 1, 8, 6 }; JaggedArray.Sort(jaggedArray, (x, y) => x.Sum() > y.Sum()); }
public void JaggedSetValues() { Array jaggedGaussian = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Gaussian), delegate(object elt) { return(new Gaussian(0.0, 1.0)); }); Assert.Equal( JaggedArray.GetLength(jaggedGaussian, typeof(Gaussian)), JaggedArray.GetLength(jagged, typeof(int))); JaggedArray.ConvertElements( jaggedGaussian, typeof(Gaussian), delegate(object elt) { return(Gaussian.FromMeanAndPrecision(1.0, 2.0)); }); foreach (Gaussian g in JaggedArray.ElementIterator(jaggedGaussian, typeof(Gaussian))) { Assert.Equal(1.0, g.GetMean()); } }
public void SortByMinimumOfTheElementsTest() { int[][] b = new int[3][]; b[0] = new int[2] { 3, 5 }; b[1] = new int[3] { 2, 9, 1 }; b[2] = new int[4] { 8, 5, 3, 2 }; JaggedArray a = new JaggedArray(b); int[][] f = new int[3][]; b[2] = new int[2] { 3, 5 }; b[0] = new int[3] { 2, 9, 1 }; b[1] = new int[4] { 8, 5, 3, 2 }; JaggedArray expect = new JaggedArray(f); a.SortByMinimumOfTheElements(); for (int i = 0; i < expect.Array.Length; i++) { for (int j = 0; j < expect.Array[i].Length; j++) { Assert.AreEqual(expect.Array[i][j], a.Array[i][j]); } } }
private List <Stone> GetLiberties(Stone stone) { if (!Has(stone) || Get(stone) is null) { return(null); } List <Stone> chain = GetChain(stone); List <Stone> liberties = new List <Stone>(); bool?[][] added = JaggedArray.InitalizeStoneMap(Width, Height); foreach (Stone libertie in chain) { List <Stone> freeNeighbors = GetNeighbors(libertie).Where(n => Get(n) is null).ToList(); freeNeighbors.ForEach(n => added[n.Column][n.Row] = true); liberties.AddRange(freeNeighbors.Where(n => !(added[n.Column][n.Row] is null))); } return(liberties); }
public static int[] Clusterize(float[][] records, int k, float error = 1e-5f, int maxIter = 10) { var distances = new float[k, records.Length]; var labels = new int[records.Length]; var centroidsPrev = KMeansCentroid.RandomPartitioning(records, k); var centroidsNext = JaggedArray.InitAndCopy(centroidsPrev, k); var iteration = 0; float e; do { CalculateDistancesBetweenRecordsAndCentroids(distances, records, centroidsNext); ComputeLabels(labels, distances, k); KMeansCentroid.Compute(centroidsNext, records, labels); e = ComputeError(centroidsPrev, centroidsNext); JaggedArray.Copy(centroidsNext, centroidsPrev, k); } while (iteration++ < maxIter && e > error); return(labels); }
public void JaggedVisitor2() { Dirichlet d1 = new Dirichlet(2.0, 3.0, 4.0); Dirichlet d2 = new Dirichlet(3.0, 4.0, 5.0); Dirichlet d3 = d1 * d2; Array jaggedDir1 = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Dirichlet), delegate(object elt) { return(new Dirichlet(d1)); }); Array jaggedDir2 = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Dirichlet), delegate(object elt) { return(new Dirichlet(d2)); }); JaggedArray.VisitElements2( jaggedDir1, jaggedDir2, typeof(Dirichlet), typeof(Dirichlet), delegate(object elt1, object elt2) { ((Dirichlet)elt1).PseudoCount.SetTo((((Dirichlet)elt1) * ((Dirichlet)elt2)).PseudoCount); }); foreach (Dirichlet d in JaggedArray.ElementIterator(jaggedDir1, typeof(Dirichlet))) { Assert.Equal(d.PseudoCount, d3.PseudoCount); } }
public void Sort_NullAndDescSumElementsComparer_ArgumentNullException() { JaggedArray.Sort(null, new DescSumElementsComparer()); }
public void BubbleSortByMinElementDecrease_NullArray_Exception() { int[][] jArray = null; JaggedArray.BubbleSortByMinElementDecrease(jArray); }
public void JaggedArrayTest_SortNull_ExeptionResult() { int[][] jaggedArray = null; JaggedArray.Sort(jaggedArray, (x, y) => x.Sum() > y.Sum()); }
private static void RandomExercises() { int[] numValues = { 8, 1, 2, 2, 3 }; ArrayExercises.SmallerNumbersThanCurrent(numValues); int[] FirstDuplicate = { 2, 1, 3, 5, 3, 2 }; Console.WriteLine(string.Format("{0} is the first duplicate.", ArrayExercises.FindFirstDuplicate(FirstDuplicate))); BinaryTree <int> MyTree = new BinaryTree <int>(); MyTree.Insert(6); MyTree.Insert(7); MyTree.Insert(8); MyTree.Insert(2); MyTree.Insert(7); MyTree.Insert(1); MyTree.Insert(3); MyTree.Insert(9); MyTree.Insert(1); MyTree.Insert(4); MyTree.Insert(5); MyTree.SumEvenGrandparent(MyTree.Find(6)); long binary_val = 100100111000000; BitManipulator x = new BitManipulator(); Console.WriteLine(x.GetDecimalValue(binary_val)); int[] luis = ManyExercises.BeautifulArray(4); int[] arri = { 1, 1, 2, 3, 3, 4, 4, 8, 8 }; int UniqueVal = ManyExercises.SingleNonDuplicate(arri); if (UniqueVal > -1) { Console.WriteLine(string.Format("Unique value is {0}.", UniqueVal)); } else { Console.WriteLine("No unique value is found in given array."); } Console.WriteLine("\n"); string a = "kqep"; string b = "pekeq"; CustomSortString.SortString(a, b); int[] Pancakes = { 3, 2, 4, 1 }; ArrayExercises.PancakeSort(Pancakes); // [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]] int[][] matrix = new int[5][] { new int[] { 11, 25, 66, 1, 69, 7 }, new int[] { 23, 55, 17, 45, 15, 52 }, new int[] { 75, 31, 36, 44, 58, 8 }, new int[] { 22, 27, 33, 25, 68, 4 }, new int[] { 84, 28, 14, 11, 5, 50 } }; Console.WriteLine("Original Matrix:"); PrintMatrix(matrix); JaggedArray.DiagonalSort(matrix); Console.WriteLine("\nDiagonally Sorted Matrix:"); PrintMatrix(matrix); Console.ReadLine(); int[] arr = { 8, 3, 2, 7, 9, 1, 4, 1 }; Console.WriteLine("\n"); Console.WriteLine("Before SelectionSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.ReadLine(); SelectionSortAlgorithm.SelectionSort(arr); Console.WriteLine("\n"); Console.WriteLine("After SelectionSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.WriteLine("\n"); Console.ReadLine(); Console.Write("Binary Search. Enter number to search for: "); int.TryParse(Console.ReadLine(), out int key); BinarySearchAlgorithm.BinarySearch(arr, key); arr = Sorting(); int[] G = { 1, 2, 3, 3, 4, 5 }; Console.WriteLine(OneDimensionalArray.FindDuplicate(G)); Console.ReadLine(); int[] arrX1 = { 3, 4, -7, 1, 3, 3, 1, -4 }; OneDimensionalArray.FindSubarrayForGivenSum(arrX1, 7); var y1 = new int[] { 3, 1, 7, 5, 4, 9, 2 }; InsertionSortAlgorithm.InsertionSortBitWise(y1); PrintResults(y1); //ArrayExercises.StoreElementsInArray(); var x1 = new int[] { 1, 2, 3 }; var x2 = new int[] { 1, 2, 3 }; ArrayExercises.MergeToArraysSameSizeSorted(x1, x2); LeetCode lc = new LeetCode(); var groupSizes = new int[] { 3, 3, 3, 3, 3, 1, 3 }; var List111 = OneDimensionalArray.GroupThePeople(groupSizes); int[][] indices = new int[3][] { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } }; lc.OddCells(2, 3, indices); }
public static List <double> DoFiltfilt(List <double> b, List <double> a, List <double> x) { if (b == null) { throw new ArgumentNullException(nameof(b)); } if (a == null) { throw new ArgumentNullException(nameof(a)); } if (x == null) { throw new ArgumentNullException(nameof(x)); } int len = x.Count; int na = a.Count; int nb = b.Count; int nFilt = nb > na ? nb : na; int nFact = 3 * (nFilt - 1); if (len <= nFact) { throw new Exception("Length X is too small"); } Resize(b, nFilt, 0); Resize(a, nFilt, 0); List <int> rows = new List <int>(); List <int> cols = new List <int>(); AddIndexRange(rows, 0, nFilt - 2, 1); if (nFilt > 2) { AddIndexRange(rows, 1, nFilt - 2, 1); AddIndexRange(rows, 0, nFilt - 3, 1); } AddIndexConst(cols, 0, nFilt - 1); if (nFilt > 2) { AddIndexRange(cols, 1, nFilt - 2, 1); AddIndexRange(cols, 1, nFilt - 2, 1); } int kLen = rows.Count; List <double> data = new List <double>(); Resize(data, kLen, 0); data[0] = 1 + a[1]; int j = 1; if (nFilt > 2) { for (int i = 2; i < nFilt; i++) { data[j++] = a[i]; } for (int i = 0; i < nFilt - 2; i++) { data[j++] = 1.0; } for (int i = 0; i < nFilt - 2; i++) { data[j++] = -1.0; } } List <double> leftPad = SubvectorReverse(x, nFact, 1); leftPad = leftPad.Select(q => 2 * x[0] - q).ToList(); List <double> rightPad = SubvectorReverse(x, len - 2, len - nFact - 1); rightPad = rightPad.Select(q => 2 * x[len - 1] - q).ToList(); List <double> signal1 = new List <double>(); List <double> signal2 = new List <double>(); List <double> zi = new List <double>(); signal1.AddRange(leftPad); signal1.AddRange(x); signal1.AddRange(rightPad); double[][] sp = JaggedArray.CreateJaggedArray <double[][]>(rows.Max() + 1, cols.Max() + 1); for (int k = 0; k < kLen; ++k) { sp[rows[k]][cols[k]] = data[k]; } double[][] zZi = MatrixMultiplication(MatrixInversion(sp), Calc(Segment(b.ToArray(), 1, nFilt - 1), b.ToArray()[0], Segment(a.ToArray(), 1, nFilt - 1))); Resize(zi, zZi.Length, 1); ChangeZi(zZi, zi, signal1[0]); Filter(b, a, signal1, signal2, zi); signal2.Reverse(); ChangeZi(zZi, zi, signal2[0]); Filter(b, a, signal2, signal1, zi); List <double> y = SubvectorReverse(signal1, signal1.Count - nFact - 1, nFact); return(y); }
private static void CalculatePartialDerivatives(float[][] dedy, float[][] d2edy2, float[][] dds, float[][] yds, float[][] ys) { var c = 0.0f; Parallel.For(0, ys.Length, row => { var slots = Vector <float> .Count; var accum = Vector <float> .Zero; var col = row + 1; for (; col + slots < ys[row].Length - row; ++col) { var v = new Vector <float>(dds[row], col); accum += v; } c += Vector.Dot(accum, Vector <float> .One); for (; col < ys[row].Length; ++col) { c += dds[row][col]; } }); Parallel.For(0, ys.Length, i => { var ysColumns = new float[ys[0].Length][]; for (var k = 0; k < ys[0].Length; ++k) { ysColumns[k] = JaggedArray.GetColumn(ys, k); } for (var j = 0; j < ys[i].Length; ++j) { var slots = Vector <float> .Count; var dedyAccum = Vector <float> .Zero; var d2edy2Accum = Vector <float> .Zero; var dedySum = 0.0f; var d2edy2Sum = 0.0f; var s = 0; for (; s + slots < ys.Length; s += slots) { var dis = new Vector <float>(dds[i], s); var disStar = new Vector <float>(yds[i], s); var yij = new Vector <float>(ys[i][j]); var ysj = new Vector <float>(ysColumns[j], s); var disMinusDisStar = dis - disStar; var disMulDisStar = dis * disStar; var yijMinusYsj = yij - ysj; var one = Vector <float> .One; dedyAccum += disMinusDisStar / disMulDisStar * yijMinusYsj; d2edy2Accum += one / disMulDisStar * ( disMinusDisStar - (yijMinusYsj * yijMinusYsj) / disStar * (one + disMinusDisStar / dis) ); } dedySum += Vector.Dot(dedyAccum, Vector <float> .One); d2edy2Sum += Vector.Dot(d2edy2Accum, Vector <float> .One); for (; s < ys.Length; ++s) { var disMinusDisStar = dds[i][s] - yds[i][s]; var disMulDisStar = dds[i][s] * yds[i][s]; var yijMinusYsj = ys[i][j] - ys[s][j]; var one = 1.0f; dedySum += disMinusDisStar / disMulDisStar * yijMinusYsj; d2edy2Sum += one / disMulDisStar * ( disMinusDisStar - (yijMinusYsj * yijMinusYsj) / yds[i][s] * (one + disMinusDisStar / dds[i][s]) ); } dedy[i][j] = dedySum * -2.0f / c; d2edy2[i][j] = d2edy2Sum * -2.0f / c; } ; }); }