public static NArray CholeskyDecomposition(NArray a)
        {
            var result = a.Clone(MatrixRegion.LowerTriangle);

            ExecutionContext.Executor.CholeskyDecomposition(result);
            return(result);
        }
        public static IEnumerable <double> Percentiles(NArray a, IEnumerable <double> percentiles)
        {
            var clone = a.Clone();

            SortInPlace(clone);
            // the ith element is percentile p = 100 * (i + 0.5) / n
            // i = n * p / 100 - 0.5
            var fractionalIndices = percentiles.Select(p => clone.Length * p / 100.0 - 0.5);

            foreach (var fractionalIndex in fractionalIndices)
            {
                var lower       = (int)fractionalIndex;
                var weightUpper = fractionalIndex - lower;
                yield return(clone.GetValue(lower) * (1 - weightUpper) + weightUpper * clone.GetValue(lower + 1));
            }
        }