Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantics-preserving cleanup #114

Merged
merged 9 commits into from
Aug 30, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import Accelerate

// MARK: Absolute Value
// MARK: - Absolute Value

/// Elemen-wise absolute value.
///
Expand Down Expand Up @@ -50,7 +50,7 @@ public func abs<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element ==
return results
}

// MARK: Ceiling
// MARK: - Ceiling

/// Elemen-wise ceiling.
///
Expand Down Expand Up @@ -80,7 +80,7 @@ public func ceil<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element
return results
}

// MARK: Clip
// MARK: - Clip

public func clip<C: UnsafeMemoryAccessible>(_ x: C, low: Float, high: Float) -> [Float] where C.Element == Float {
var results = [Float](repeating: 0.0, count: numericCast(x.count))
Expand Down Expand Up @@ -110,7 +110,7 @@ public func clip<C: UnsafeMemoryAccessible>(_ x: C, low: Double, high: Double) -
return results
}

// MARK: Copy Sign
// MARK: - Copy Sign

/// - Warning: does not support memory stride (assumes stride is 1).
public func copysign<S: UnsafeMemoryAccessible, M: UnsafeMemoryAccessible>(sign: S, magnitude: M) -> [Float] where S.Element == Float, M.Element == Float {
Expand All @@ -136,7 +136,7 @@ public func copysign<S: UnsafeMemoryAccessible, M: UnsafeMemoryAccessible>(sign:
return results
}

// MARK: Floor
// MARK: - Floor

/// Elemen-wise floor.
///
Expand Down Expand Up @@ -166,7 +166,7 @@ public func floor<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element
return results
}

// MARK: Negate
// MARK: - Negate

public func neg<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
var results = [Float](repeating: 0.0, count: numericCast(x.count))
Expand All @@ -188,7 +188,7 @@ public func neg<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element =
return results
}

// MARK: Reciprocal
// MARK: - Reciprocal

/// - Warning: does not support memory stride (assumes stride is 1).
public func rec<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
Expand All @@ -214,7 +214,7 @@ public func rec<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element =
return results
}

// MARK: Round
// MARK: - Round

/// - Warning: does not support memory stride (assumes stride is 1).
public func round<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
Expand All @@ -240,7 +240,7 @@ public func round<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element
return results
}

// MARK: Threshold
// MARK: - Threshold

public func threshold<C: UnsafeMemoryAccessible>(_ x: C, low: Float) -> [Float] where C.Element == Float {
var results = [Float](repeating: 0.0, count: numericCast(x.count))
Expand Down Expand Up @@ -268,7 +268,7 @@ public func threshold<C: UnsafeMemoryAccessible>(_ x: C, low: Double) -> [Double
return results
}

// MARK: Truncate
// MARK: - Truncate

/// - Warning: does not support memory stride (assumes stride is 1).
public func trunc<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import Accelerate

// MARK: Convolution
// MARK: - Convolution

/// Convolution of a signal [x], with a kernel [k]. The signal must be at least as long as the kernel.
public func conv<X: UnsafeMemoryAccessible, K: UnsafeMemoryAccessible>(_ x: X, _ k: K) -> [Float] where X.Element == Float, K.Element == Float {
Expand Down Expand Up @@ -68,7 +68,7 @@ public func conv<X: UnsafeMemoryAccessible, K: UnsafeMemoryAccessible>(_ x: X, _
return result
}

// MARK: Cross-Correlation
// MARK: - Cross-Correlation

/// Cross-correlation of a signal [x], with another signal [y]. The signal [y]
/// is padded so that it is the same length as [x].
Expand Down Expand Up @@ -124,7 +124,7 @@ public func xcorr<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X,
return result
}

// MARK: Auto-correlation
// MARK: - Auto-correlation

/// Auto-correlation of a signal [x]
public func xcorr<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import Accelerate

// MARK: Fast Fourier Transform
// MARK: - Fast Fourier Transform

public func fft(_ input: [Float]) -> [Float] {
var real = [Float](input)
Expand Down
73 changes: 73 additions & 0 deletions Sources/Surge/Exponential/Exponential.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright © 2014-2018 the Surge contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Accelerate

// MARK: - Exponentiation

/// - Warning: does not support memory stride (assumes stride is 1).
public func exp<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
return x.withUnsafeMemory { xm in
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
var results = [Float](repeating: 0.0, count: numericCast(x.count))
results.withUnsafeMutableBufferPointer { rbp in
vvexpf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
}
return results
}
}

/// - Warning: does not support memory stride (assumes stride is 1).
public func exp<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
return x.withUnsafeMemory { xm in
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
var results = [Double](repeating: 0.0, count: numericCast(x.count))
results.withUnsafeMutableBufferPointer { rbp in
vvexp(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
}
return results
}
}

// MARK: - Square Exponentiation

/// - Warning: does not support memory stride (assumes stride is 1).
public func exp2<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
return x.withUnsafeMemory { xm in
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
var results = [Float](repeating: 0.0, count: numericCast(x.count))
results.withUnsafeMutableBufferPointer { rbp in
vvexp2f(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
}
return results
}
}

/// - Warning: does not support memory stride (assumes stride is 1).
public func exp2<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
return x.withUnsafeMemory { xm in
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
var results = [Double](repeating: 0.0, count: numericCast(x.count))
results.withUnsafeMutableBufferPointer { rbp in
vvexp2(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
}
return results
}
}
Loading