public static bool HasLength <T>(object JaggedArray, params int[] lengths) { var array = (Array)JaggedArray; if (array.GetType().GetElementType() == typeof(T)) { ExceptionHelpers.Ensure <ArgumentException>(lengths.Length == 1); return(array.Length >= lengths[0]); } else { if (array.Length < lengths[0]) { return(false); } var newLen = new int[lengths.Length - 1]; Array.Copy(lengths, 1, newLen, 0, newLen.Length); foreach (var i in array) { if (HasLength <T>(i, newLen) == false) { return(false); } } return(true); } }
public int NearestIndex(double slope) { int index = Numbers.RoundToInt((slope - items[0]) / 0.1); ExceptionHelpers.Ensure <ArgumentOutOfRangeException>( index >= 0 && index < items.Length); return(index); }
public static Table1D TruncateInvalidXValues(this Table1D table) { var oldX = table.x; ExceptionHelpers.Ensure <ArgumentException>(oldX.Length > 0); var increasing = oldX.Length == 1 || (oldX[1] > oldX[0]); var count = increasing ? oldX.StrictlyIncreasingCount() : oldX.StrictlyDecreasingCount(); var x = oldX.Take(count).ToArray(); var f = table.f.Take(count).ToArray(); return(new Table1D(x, f)); }
public void SetItems(double min, double max) { ExceptionHelpers.Ensure <ArgumentException>(max >= min); int start = (int)Math.Round(min * 10); int end = (int)Math.Round(max * 10); items = new double[end - start + 1]; for (int i = start; i <= end; i++) { items[i - start] = i * 0.1; } }
/// <exception cref="ArgumentException"></exception> public void Validate() { bool hasLen = LengthChecker.HasLength <double>(f, x.Length, y.Length, z.Length); ExceptionHelpers.Ensure <ArgumentException>(hasLen); }
/// <exception cref="ArgumentException"></exception> public void Validate() { ExceptionHelpers.Ensure <ArgumentException>( LengthChecker.HasLength <double>(f, x.Length, y.Length)); }
/// <exception cref="ArgumentException"></exception> public void Validate() { ExceptionHelpers.Ensure <ArgumentException>(f.Length >= x.Length); }
/// <exception cref="ArgumentException">Array length cannot be 0.</exception> public static bool IsStrictlyIncreasing(this double[] item) { ExceptionHelpers.Ensure <ArgumentException>(item.Length != 0); return(item.StrictlyIncreasingCount() == item.Length); }