Begin statistics creation
This commit is contained in:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user