Begin statistics creation

This commit is contained in:
Christoph Hagen
2025-08-31 16:27:32 +02:00
parent f972a2c020
commit 96bd07bdb7
33 changed files with 1406 additions and 187 deletions

View File

@@ -9,6 +9,31 @@ private struct Entry<T: BinaryFloatingPoint>: Comparable {
}
extension Sequence {
func firstElement() -> Element? {
for element in self {
return element
}
return nil
}
func minMax<E>(by converting: (Element) -> E) -> (min: E, max: E)? where E: Comparable {
guard let first = firstElement() else {
return nil
}
var minimum = converting(first)
var maximum = minimum
for location in dropFirst() {
let value = converting(location)
if value < minimum {
minimum = value
} else if value > maximum {
maximum = value
}
}
return (minimum, maximum)
}
/// Applies a centered median filter to the sequence.
/// - Parameters:
/// - windowSize: The number of samples in the median filter window (should be odd for symmetric centering).