Utils
This module implements various procs that don't fit in any of the other modules.
Highlights:
- meshgrid to produce meshed points.
- linspace and arange to generate points.
- chi2 to calculate χ²-test on data and fit.
Procs
proc arange(x1, x2, dx: float; includeStart = true; includeEnd = false): seq[ float] {.inline, ...raises: [ValueError], tags: [], forbids: [].}
- Generates points between x1 and x2 with spacing dx. By default, x2 is not included unless it ends up exactly on it. Set includeEnd = true if you want to include it. Source Edit
proc checkVectorSizes(v1, v2: Vector) {.inline.}
- Source Edit
proc findDuplicates[T](x: openArray[T]; isSorted: bool = false): seq[seq[int]]
- Finds and returns the indices of duplicates in an openArray. 1, 1, 2, 1, 4, 5, 4 would yield @@[0, 1, 3], @[4, 6] for the duplicate 1's and 4's Source Edit
proc getIndexTable[T](x: openArray[T]): Table[T, seq[int]]
- Source Edit
proc hermiteInterpolate[T](x: openArray[float]; t: openArray[float]; y, dy: openArray[T]): seq[T] {.inline.}
-
Hermite interpolate data points.
- x is the points to evaluate the spline in
- t, y, dy are the raw input values used to form the spline
proc hermiteSpline[T](x, x1, x2: float; y1, y2, dy1, dy2: T): T {.inline.}
- Source Edit
proc mean_squared_error[T](v1, v2: Vector[T]): float {.inline.}
- Source Edit
proc mean_squared_error[T](y_true, y: T): auto {.inline.}
- Source Edit
proc meshgrid[T](ts: varargs[Tensor[T]]): Tensor[T]
-
Creates a Tensor with the coordinates on a meshgrid defined by the inputs. Each input is expected to be a 1D Tensor with the grid values in that dimension. If N inputs are given, a N-dimensional meshgrid will be created and returned in a (nPoints, N) Tensor.
Note: This is different from for example MATLAB's meshgrid which returns a N-dimensional Tensor instead.
Source Edit proc meshgridFlat[T](x, y: Tensor[T]): (Tensor[T], Tensor[T])
- Returns two flat (rank 1) tensors with the grid coordinates specified by x and y. Source Edit
proc removeDuplicates[Tx, Ty](x: seq[Tx]; y: seq[seq[Ty]]): tuple[x: seq[Tx], y: seq[seq[Ty]]]
- Pure duplicates, ie exactly the same x and y values, are removed. If impure duplicate, same x but different y, exception will be raised. Source Edit
proc sortAndTrimDataset[Tx, Ty](x: seq[Tx]; y: seq[seq[Ty]]; sortOrder: SortOrder = Ascending): tuple[ x: seq[Tx], y: seq[seq[Ty]]]
- Sorts x and y according to x and removes duplicate values. Source Edit
proc sortAndTrimDataset[Tx, Ty](x: seq[Tx]; y: seq[Ty]; sortOrder: SortOrder = Ascending): tuple[ x: seq[Tx], y: seq[Ty]]
- Sorts x and y according to x and removes duplicate values. Source Edit
proc sortDataset[T](X: openArray[float]; Y: openArray[T]): seq[(float, T)] {. inline.}
- Source Edit
proc sortDataset[Tx, Ty](x: seq[Tx]; y: seq[seq[Ty]]; sortOrder: SortOrder = Ascending): tuple[x: seq[Tx], y: seq[seq[Ty]]]
- Sorts seqs of according to the first seq in the openarray. Source Edit
proc sortDataset[Tx, Ty](x: seq[Tx]; y: seq[Ty]; sortOrder: SortOrder = Ascending): tuple[x: seq[Tx], y: seq[Ty]]
- Source Edit
Templates
template benchmarkit[T](s: untyped; n = 100; msg = ""; answer: T; onlyEfficiency = false): untyped
- Source Edit