From 7f4543704f671e1e215ca28be33215060f1539a7 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Fri, 30 Aug 2019 12:32:36 +0200 Subject: [PATCH] Replaced `// MARK:` with `// MARK: - ` for nicer visual separation in Xcode --- Sources/Surge/Arithmetic.swift | 24 +++++++++---------- Sources/Surge/Auxiliary.swift | 20 ++++++++-------- Sources/Surge/Convolution.swift | 6 ++--- Sources/Surge/Exponential.swift | 12 +++++----- Sources/Surge/FFT.swift | 2 +- Sources/Surge/Hyperbolic.swift | 12 +++++----- Sources/Surge/Matrix.swift | 28 ++++++++++++++++++---- Sources/Surge/OperatorPrecedences.swift | 14 +++++------ Sources/Surge/Pointers.swift | 4 ++-- Sources/Surge/Power.swift | 2 +- Sources/Surge/Scalar.swift | 2 +- Sources/Surge/Statistics.swift | 22 ++++++++--------- Sources/Surge/Trigonometric.swift | 18 +++++++------- Sources/Surge/Vector.swift | 32 ++++++++++++------------- Tests/SurgeTests/ConvolutionTests.swift | 16 ++++++------- 15 files changed, 116 insertions(+), 98 deletions(-) diff --git a/Sources/Surge/Arithmetic.swift b/Sources/Surge/Arithmetic.swift index 32bffb5..394ae24 100644 --- a/Sources/Surge/Arithmetic.swift +++ b/Sources/Surge/Arithmetic.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Addition +// MARK: - Addition public func add(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float { precondition(x.count == y.count, "Collections must have the same size") @@ -68,7 +68,7 @@ public func + (lhs: L, rhs: Double) -> [Double] where return add(lhs, rhs) } -// MARK: Addition: In Place +// MARK: - Addition: In Place func addInPlace(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float { lhs.withUnsafeMutableMemory { lm in @@ -116,7 +116,7 @@ public func +=(lhs: inout L, rhs: Double) wher return addInPlace(&lhs, rhs) } -// MARK: Subtraction +// MARK: - Subtraction public func sub(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float { precondition(x.count == y.count, "Collections must have the same size") @@ -164,7 +164,7 @@ public func - (lhs: L, rhs: Double) -> [Double] where return sub(lhs, rhs) } -// MARK: Subtraction: In Place +// MARK: - Subtraction: In Place func subInPlace(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float { lhs.withUnsafeMutableMemory { lm in @@ -212,7 +212,7 @@ public func -=(lhs: inout L, rhs: Double) wher return subInPlace(&lhs, rhs) } -// MARK: Multiplication +// MARK: - Multiplication public func mul(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float { precondition(x.count == y.count, "Collections must have the same size") @@ -260,7 +260,7 @@ public func * (lhs: L, rhs: Double) -> [Double] where return mul(lhs, rhs) } -// MARK: Multiplication: In Place +// MARK: - Multiplication: In Place func mulInPlace(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float { lhs.withUnsafeMutableMemory { lm in @@ -308,7 +308,7 @@ public func *=(lhs: inout L, rhs: Double) wher return mulInPlace(&lhs, rhs) } -// MARK: Division +// MARK: - Division /// Elemen-wise vector division. public func div(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float { @@ -358,7 +358,7 @@ public func / (lhs: L, rhs: Double) -> [Double] where return div(lhs, rhs) } -// MARK: Division: In Place +// MARK: - Division: In Place func divInPlace(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float { lhs.withUnsafeMutableMemory { lm in @@ -406,7 +406,7 @@ public func /=(lhs: inout L, rhs: Double) wher return divInPlace(&lhs, rhs) } -// MARK: Modulo +// MARK: - Modulo /// Elemen-wise modulo. /// @@ -462,7 +462,7 @@ public func % (lhs: L, rhs: Double) -> [Double] where return mod(lhs, rhs) } -// MARK: Remainder +// MARK: - Remainder /// Elemen-wise remainder. /// @@ -494,7 +494,7 @@ public func remainder(_ x: } } -// MARK: Square Root +// MARK: - Square Root /// Elemen-wise square root. /// @@ -540,7 +540,7 @@ public func sqrt( } } -// MARK: Dot Product +// MARK: - Dot Product public func dot(_ x: X, _ y: Y) -> Float where X.Element == Float, Y.Element == Float { return withUnsafeMemory(x, y) { xm, ym in diff --git a/Sources/Surge/Auxiliary.swift b/Sources/Surge/Auxiliary.swift index 0bd217a..09fea3e 100644 --- a/Sources/Surge/Auxiliary.swift +++ b/Sources/Surge/Auxiliary.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Absolute Value +// MARK: - Absolute Value /// Elemen-wise absolute value. /// @@ -50,7 +50,7 @@ public func abs(_ x: C) -> [Float] where C.Element == return results } -// MARK: Ceiling +// MARK: - Ceiling /// Elemen-wise ceiling. /// @@ -80,7 +80,7 @@ public func ceil(_ x: C) -> [Double] where C.Element return results } -// MARK: Clip +// MARK: - Clip public func clip(_ x: C, low: Float, high: Float) -> [Float] where C.Element == Float { var results = [Float](repeating: 0.0, count: numericCast(x.count)) @@ -110,7 +110,7 @@ public func clip(_ 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(sign: S, magnitude: M) -> [Float] where S.Element == Float, M.Element == Float { @@ -136,7 +136,7 @@ public func copysign(sign: return results } -// MARK: Floor +// MARK: - Floor /// Elemen-wise floor. /// @@ -166,7 +166,7 @@ public func floor(_ x: C) -> [Double] where C.Element return results } -// MARK: Negate +// MARK: - Negate public func neg(_ x: C) -> [Float] where C.Element == Float { var results = [Float](repeating: 0.0, count: numericCast(x.count)) @@ -188,7 +188,7 @@ public func neg(_ 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(_ x: C) -> [Float] where C.Element == Float { @@ -214,7 +214,7 @@ public func rec(_ 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(_ x: C) -> [Float] where C.Element == Float { @@ -240,7 +240,7 @@ public func round(_ x: C) -> [Double] where C.Element return results } -// MARK: Threshold +// MARK: - Threshold public func threshold(_ x: C, low: Float) -> [Float] where C.Element == Float { var results = [Float](repeating: 0.0, count: numericCast(x.count)) @@ -268,7 +268,7 @@ public func threshold(_ x: C, low: Double) -> [Double return results } -// MARK: Truncate +// MARK: - Truncate /// - Warning: does not support memory stride (assumes stride is 1). public func trunc(_ x: C) -> [Float] where C.Element == Float { diff --git a/Sources/Surge/Convolution.swift b/Sources/Surge/Convolution.swift index c6aa8ee..7c85ae8 100644 --- a/Sources/Surge/Convolution.swift +++ b/Sources/Surge/Convolution.swift @@ -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: X, _ k: K) -> [Float] where X.Element == Float, K.Element == Float { @@ -68,7 +68,7 @@ public func conv(_ 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]. @@ -124,7 +124,7 @@ public func xcorr(_ x: X, return result } -// MARK: Auto-correlation +// MARK: - Auto-correlation /// Auto-correlation of a signal [x] public func xcorr(_ x: X) -> [Float] where X.Element == Float { diff --git a/Sources/Surge/Exponential.swift b/Sources/Surge/Exponential.swift index 6bc92e7..28964fd 100644 --- a/Sources/Surge/Exponential.swift +++ b/Sources/Surge/Exponential.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Exponentiation +// MARK: - Exponentiation /// - Warning: does not support memory stride (assumes stride is 1). public func exp(_ x: X) -> [Float] where X.Element == Float { @@ -46,7 +46,7 @@ public func exp(_ x: X) -> [Double] where X.Element = } } -// MARK: Square Exponentiation +// MARK: - Square Exponentiation /// - Warning: does not support memory stride (assumes stride is 1). public func exp2(_ x: X) -> [Float] where X.Element == Float { @@ -72,7 +72,7 @@ public func exp2(_ x: X) -> [Double] where X.Element } } -// MARK: Natural Logarithm +// MARK: - Natural Logarithm /// - Warning: does not support memory stride (assumes stride is 1). public func log(_ x: X) -> [Float] where X.Element == Float { @@ -98,7 +98,7 @@ public func log(_ x: X) -> [Double] where X.Element = } } -// MARK: Base-2 Logarithm +// MARK: - Base-2 Logarithm /// - Warning: does not support memory stride (assumes stride is 1). public func log2(_ x: X) -> [Float] where X.Element == Float { @@ -124,7 +124,7 @@ public func log2(_ x: X) -> [Double] where X.Element } } -// MARK: Base-10 Logarithm +// MARK: - Base-10 Logarithm /// - Warning: does not support memory stride (assumes stride is 1). public func log10(_ x: X) -> [Float] where X.Element == Float { @@ -150,7 +150,7 @@ public func log10(_ x: X) -> [Double] where X.Element } } -// MARK: Logarithmic Exponentiation +// MARK: - Logarithmic Exponentiation /// - Warning: does not support memory stride (assumes stride is 1). public func logb(_ x: X) -> [Float] where X.Element == Float { diff --git a/Sources/Surge/FFT.swift b/Sources/Surge/FFT.swift index 6c09b84..85ac242 100644 --- a/Sources/Surge/FFT.swift +++ b/Sources/Surge/FFT.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Fast Fourier Transform +// MARK: - Fast Fourier Transform public func fft(_ input: [Float]) -> [Float] { var real = [Float](input) diff --git a/Sources/Surge/Hyperbolic.swift b/Sources/Surge/Hyperbolic.swift index 30bbca1..76e2a25 100644 --- a/Sources/Surge/Hyperbolic.swift +++ b/Sources/Surge/Hyperbolic.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Hyperbolic Sine +// MARK: - Hyperbolic Sine /// - Warning: does not support memory stride (assumes stride is 1). public func sinh(_ x: X) -> [Float] where X.Iterator.Element == Float { @@ -46,7 +46,7 @@ public func sinh(_ x: X) -> [Double] where X.Iterator } } -// MARK: Hyperbolic Cosine +// MARK: - Hyperbolic Cosine /// - Warning: does not support memory stride (assumes stride is 1). public func cosh(_ x: X) -> [Float] where X.Iterator.Element == Float { @@ -72,7 +72,7 @@ public func cosh(_ x: X) -> [Double] where X.Iterator } } -// MARK: Hyperbolic Tangent +// MARK: - Hyperbolic Tangent /// - Warning: does not support memory stride (assumes stride is 1). public func tanh(_ x: X) -> [Float] where X.Iterator.Element == Float { @@ -98,7 +98,7 @@ public func tanh(_ x: X) -> [Double] where X.Iterator } } -// MARK: Inverse Hyperbolic Sine +// MARK: - Inverse Hyperbolic Sine /// - Warning: does not support memory stride (assumes stride is 1). public func asinh(_ x: X) -> [Float] where X.Iterator.Element == Float { @@ -124,7 +124,7 @@ public func asinh(_ x: X) -> [Double] where X.Iterato } } -// MARK: Inverse Hyperbolic Cosine +// MARK: - Inverse Hyperbolic Cosine /// - Warning: does not support memory stride (assumes stride is 1). public func acosh(_ x: X) -> [Float] where X.Iterator.Element == Float { @@ -150,7 +150,7 @@ public func acosh(_ x: X) -> [Double] where X.Iterato } } -// MARK: Inverse Hyperbolic Tangent +// MARK: - Inverse Hyperbolic Tangent /// - Warning: does not support memory stride (assumes stride is 1). public func atanh(_ x: X) -> [Float] where X.Iterator.Element == Float { diff --git a/Sources/Surge/Matrix.swift b/Sources/Surge/Matrix.swift index 42e0561..bd4d59a 100644 --- a/Sources/Surge/Matrix.swift +++ b/Sources/Surge/Matrix.swift @@ -260,7 +260,7 @@ public func == (lhs: Matrix, rhs: Matrix) -> Bool { return lhs.rows == rhs.rows && lhs.columns == rhs.columns && lhs.grid == rhs.grid } -// MARK: - +// MARK: - Addition public func add(_ x: Matrix, _ y: Matrix) -> Matrix { precondition(x.rows == y.rows && x.columns == y.columns, "Matrix dimensions not compatible with addition") @@ -292,6 +292,8 @@ public func + (lhs: Matrix, rhs: Matrix) -> Matrix { return add(lhs, rhs) } +// MARK: - Subtraction + public func sub(_ x: Matrix, _ y: Matrix) -> Matrix { precondition(x.rows == y.rows && x.columns == y.columns, "Matrix dimensions not compatible with subtraction") @@ -322,6 +324,8 @@ public func - (lhs: Matrix, rhs: Matrix) -> Matrix { return sub(lhs, rhs) } +// MARK: - Multiplication + public func mul(_ x: Matrix, _ y: Matrix) -> Matrix { precondition(x.columns == y.rows, "Matrix dimensions not compatible with multiplication") if x.rows == 0 || x.columns == 0 || y.columns == 0 { @@ -394,6 +398,8 @@ public func * (lhs: Matrix, rhs: Vector) -> Vector { return mul(lhs, rhs) } +// MARK: - Element-wise Multiplication + public func elmul(_ x: Matrix, _ y: Matrix) -> Matrix { precondition(x.rows == y.rows && x.columns == y.columns, "Matrix must have the same dimensions") var result = Matrix(rows: x.rows, columns: x.columns, repeatedValue: 0.0) @@ -408,6 +414,8 @@ public func elmul(_ x: Matrix, _ y: Matrix) -> Matrix { return result } +// MARK: - Division + public func div(_ x: Matrix, _ y: Matrix) -> Matrix { let yInv = inv(y) precondition(x.columns == yInv.rows, "Matrix dimensions not compatible") @@ -448,6 +456,8 @@ public func / (lhs: Matrix, rhs: Float) -> Matrix { return div(lhs, rhs) } +// MARK: - Power + public func pow(_ x: Matrix, _ y: Double) -> Matrix { var result = Matrix(rows: x.rows, columns: x.columns, repeatedValue: 0.0) result.grid = pow(x.grid, y) @@ -460,6 +470,8 @@ public func pow(_ x: Matrix, _ y: Float) -> Matrix { return result } +// MARK: - Exponential + public func exp(_ x: Matrix) -> Matrix { var result = Matrix(rows: x.rows, columns: x.columns, repeatedValue: 0.0) result.grid = exp(x.grid) @@ -472,8 +484,9 @@ public func exp(_ x: Matrix) -> Matrix { return result } -public func sum(_ x: Matrix, axies: MatrixAxies = .column) -> Matrix { +// MARK: - Summation +public func sum(_ x: Matrix, axies: MatrixAxies = .column) -> Matrix { switch axies { case .column: var result = Matrix(rows: 1, columns: x.columns, repeatedValue: 0.0) @@ -481,7 +494,6 @@ public func sum(_ x: Matrix, axies: MatrixAxies = .column) -> Matrix(rows: x.rows, columns: 1, repeatedValue: 0.0) for i in 0.., axies: MatrixAxies = .column) -> Matrix, axies: MatrixAxies = .column) -> Matrix { - switch axies { case .column: var result = Matrix(rows: 1, columns: x.columns, repeatedValue: 0.0) @@ -500,7 +511,6 @@ public func sum(_ x: Matrix, axies: MatrixAxies = .column) -> Matrix(rows: x.rows, columns: 1, repeatedValue: 0.0) for i in 0.., axies: MatrixAxies = .column) -> Matrix) -> Matrix { precondition(x.rows == x.columns, "Matrix must be square") @@ -556,6 +568,8 @@ public func inv(_ x: Matrix) -> Matrix { return results } +// MARK: - Transpose + public func transpose(_ x: Matrix) -> Matrix { var results = Matrix(rows: x.columns, columns: x.rows, repeatedValue: 0.0) results.grid.withUnsafeMutableBufferPointer { pointer in @@ -582,6 +596,8 @@ public postfix func ′ (value: Matrix) -> Matrix { return transpose(value) } +// MARK: - Determinant + /// Computes the matrix determinant. public func det(_ x: Matrix) -> Float? { var decomposed = x @@ -638,6 +654,8 @@ public func det(_ x: Matrix) -> Double? { return det } +// MARK: - Eigen-Decomposition + // Convert the result of dgeev into an array of complex numbers // See Intel's documentation on column-major results for sample code that this // is based on: diff --git a/Sources/Surge/OperatorPrecedences.swift b/Sources/Surge/OperatorPrecedences.swift index c71e97b..227fa8b 100644 --- a/Sources/Surge/OperatorPrecedences.swift +++ b/Sources/Surge/OperatorPrecedences.swift @@ -20,35 +20,35 @@ import Foundation -// MARK: Element-wise Addition +// MARK: - Element-wise Addition infix operator .+: AdditionPrecedence infix operator .+=: AssignmentPrecedence -// MARK: Element-wise Subtraction +// MARK: - Element-wise Subtraction infix operator .-: AdditionPrecedence infix operator .-=: AssignmentPrecedence -// MARK: Element-wise Multiplication +// MARK: - Element-wise Multiplication infix operator .*: MultiplicationPrecedence infix operator .*=: AssignmentPrecedence -// MARK: Element-wise Division +// MARK: - Element-wise Division infix operator ./: MultiplicationPrecedence infix operator ./=: AssignmentPrecedence -// MARK: Element-wise Modulo +// MARK: - Element-wise Modulo infix operator .%: MultiplicationPrecedence infix operator .%=: AssignmentPrecedence -// MARK: Dot product +// MARK: - Dot product infix operator •: MultiplicationPrecedence -// MARK: Matrix Transpose +// MARK: - Matrix Transpose postfix operator ′ diff --git a/Sources/Surge/Pointers.swift b/Sources/Surge/Pointers.swift index 92be6c1..0b6e75d 100644 --- a/Sources/Surge/Pointers.swift +++ b/Sources/Surge/Pointers.swift @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// MARK: 2 Parameter +// MARK: - 2 Parameter /// Invokes the given closure with pointers to the given arguments (2 parameter version). /// @@ -44,7 +44,7 @@ public func withUnsafeMutablePointers(_ a: inout A, _ b: inout B, } } -// MARK: 3 Parameter +// MARK: - 3 Parameter /// Invokes the given closure with pointers to the given arguments (3 parameter version). /// diff --git a/Sources/Surge/Power.swift b/Sources/Surge/Power.swift index ab94acb..6d083a3 100644 --- a/Sources/Surge/Power.swift +++ b/Sources/Surge/Power.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Power +// MARK: - Power /// - Warning: does not support memory stride (assumes stride is 1). public func pow(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float { diff --git a/Sources/Surge/Scalar.swift b/Sources/Surge/Scalar.swift index 4c947c2..d141883 100644 --- a/Sources/Surge/Scalar.swift +++ b/Sources/Surge/Scalar.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Multiplication +// MARK: - Multiplication public func mul(_ lhs: Float, _ rhs: R) -> [Float] where R.Element == Float { return mul([Float](repeating: lhs, count: numericCast(rhs.count)), rhs) diff --git a/Sources/Surge/Statistics.swift b/Sources/Surge/Statistics.swift index 5dae45a..b7cf43c 100644 --- a/Sources/Surge/Statistics.swift +++ b/Sources/Surge/Statistics.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Sum +// MARK: - Sum public func sum(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -42,7 +42,7 @@ public func sum(_ x: C) -> Double where C.Element == return result } -// MARK: Sum of Absolute Values +// MARK: - Sum of Absolute Values public func asum(_ x: C) -> Float where C.Element == Float { return x.withUnsafeMemory { xm in @@ -56,7 +56,7 @@ public func asum(_ x: C) -> Double where C.Element == } } -// MARK: Sum of Square Values +// MARK: - Sum of Square Values public func sumsq(_ x: C) -> Float where C.Element == Float { var result: Float = 0 @@ -78,7 +78,7 @@ public func sumsq(_ x: C) -> Double where C.Element = return result } -// MARK: Maximum +// MARK: - Maximum public func max(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -100,7 +100,7 @@ public func max(_ x: C) -> Double where C.Element == return result } -// MARK: Minimum +// MARK: - Minimum public func min(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -122,7 +122,7 @@ public func min(_ x: C) -> Double where C.Element == return result } -// MARK: Mean +// MARK: - Mean public func mean(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -144,7 +144,7 @@ public func mean(_ x: C) -> Double where C.Element == return result } -// MARK: Mean Magnitude +// MARK: - Mean Magnitude public func meamg(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -166,7 +166,7 @@ public func meamg(_ x: C) -> Double where C.Element = return result } -// MARK: Mean Square Value +// MARK: - Mean Square Value public func measq(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -188,7 +188,7 @@ public func measq(_ x: C) -> Double where C.Element = return result } -// MARK: Root Mean Square Value +// MARK: - Root Mean Square Value public func rmsq(_ x: C) -> Float where C.Element == Float { var result: Float = 0.0 @@ -210,7 +210,7 @@ public func rmsq(_ x: C) -> Double where C.Element == return result } -// MARK: Standard deviation +// MARK: - Standard deviation /// Computes the standard deviation, a measure of the spread of deviation. public func std(_ x: X) -> Float where X.Element == Float { @@ -226,7 +226,7 @@ public func std(_ x: X) -> Double where X.Element == return sqrt(variance) } -// MARK: Linear regression +// MARK: - Linear regression /// Performs linear regression /// diff --git a/Sources/Surge/Trigonometric.swift b/Sources/Surge/Trigonometric.swift index f18f57f..a257dd1 100644 --- a/Sources/Surge/Trigonometric.swift +++ b/Sources/Surge/Trigonometric.swift @@ -20,7 +20,7 @@ import Accelerate -// MARK: Sine-Cosine +// MARK: - Sine-Cosine /// - Warning: does not support memory stride (assumes stride is 1). public func sincos(_ x: X) -> (sin: [Float], cos: [Float]) where X.Element == Float { @@ -48,7 +48,7 @@ public func sincos(_ x: X) -> (sin: [Double], cos: [D } } -// MARK: Sine +// MARK: - Sine /// - Warning: does not support memory stride (assumes stride is 1). public func sin(_ x: X) -> [Float] where X.Element == Float { @@ -74,7 +74,7 @@ public func sin(_ x: X) -> [Double] where X.Element = } } -// MARK: Cosine +// MARK: - Cosine /// - Warning: does not support memory stride (assumes stride is 1). public func cos(_ x: X) -> [Float] where X.Element == Float { @@ -100,7 +100,7 @@ public func cos(_ x: X) -> [Double] where X.Element = } } -// MARK: Tangent +// MARK: - Tangent /// - Warning: does not support memory stride (assumes stride is 1). public func tan(_ x: X) -> [Float] where X.Element == Float { @@ -126,7 +126,7 @@ public func tan(_ x: X) -> [Double] where X.Element = } } -// MARK: Arcsine +// MARK: - Arcsine /// - Warning: does not support memory stride (assumes stride is 1). public func asin(_ x: X) -> [Float] where X.Element == Float { @@ -152,7 +152,7 @@ public func asin(_ x: X) -> [Double] where X.Element } } -// MARK: Arccosine +// MARK: - Arccosine /// - Warning: does not support memory stride (assumes stride is 1). public func acos(_ x: X) -> [Float] where X.Element == Float { @@ -178,7 +178,7 @@ public func acos(_ x: X) -> [Double] where X.Element } } -// MARK: Arctangent +// MARK: - Arctangent /// - Warning: does not support memory stride (assumes stride is 1). public func atan(_ x: X) -> [Float] where X.Element == Float { @@ -206,7 +206,7 @@ public func atan(_ x: X) -> [Double] where X.Element // MARK: - -// MARK: Radians to Degrees +// MARK: - Radians to Degrees /// - Warning: does not support memory stride (assumes stride is 1). func rad2deg(_ x: X) -> [Float] where X.Element == Float { @@ -234,7 +234,7 @@ func rad2deg(_ x: X) -> [Double] where X.Element == D } } -// MARK: Degrees to Radians +// MARK: - Degrees to Radians /// - Warning: does not support memory stride (assumes stride is 1). func deg2rad(_ x: X) -> [Float] where X.Element == Float { diff --git a/Sources/Surge/Vector.swift b/Sources/Surge/Vector.swift index 51d0ccb..beb6e29 100644 --- a/Sources/Surge/Vector.swift +++ b/Sources/Surge/Vector.swift @@ -143,7 +143,7 @@ public func + (lhs: Vector, rhs: Double) -> Vector { return add(lhs, rhs) } -// MARK: Addition: In Place +// MARK: - Addition: In Place public func addInPlace(_ x: inout Vector, _ y: Vector) { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with addition") @@ -181,7 +181,7 @@ public func += (lhs: inout Vector, rhs: Double) { return addInPlace(&lhs, rhs) } -// MARK: Subtraction +// MARK: - Subtraction public func sub(_ x: Vector, _ y: Vector) -> Vector { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with subtraction") @@ -219,7 +219,7 @@ public func - (lhs: Vector, rhs: Double) -> Vector { return sub(lhs, rhs) } -// MARK: Subtraction: In Place +// MARK: - Subtraction: In Place public func subInPlace(_ x: inout Vector, _ y: Vector) { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with subtraction") @@ -257,7 +257,7 @@ public func -= (lhs: inout Vector, rhs: Double) { return subInPlace(&lhs, rhs) } -// MARK: Multiplication +// MARK: - Multiplication public func mul(_ x: Vector, _ y: Float) -> Vector { return Vector(mul(x.scalars, y)) @@ -311,7 +311,7 @@ public func * (lhs: Vector, rhs: Matrix) -> Vector { return mul(lhs, rhs) } -// MARK: Multiplication: In Place +// MARK: - Multiplication: In Place public func mulInPlace(_ x: inout Vector, _ y: Float) { return mulInPlace(&x.scalars, y) @@ -329,7 +329,7 @@ public func *= (lhs: inout Vector, rhs: Double) { return mulInPlace(&lhs, rhs) } -// MARK: Division +// MARK: - Division public func div(_ x: Vector, _ y: Float) -> Vector { return Vector(div(x.scalars, y)) @@ -347,7 +347,7 @@ public func / (lhs: Vector, rhs: Float) -> Vector { return div(lhs, rhs) } -// MARK: Division: In Place +// MARK: - Division: In Place public func divInPlace(_ x: inout Vector, _ y: Float) { return divInPlace(&x.scalars, y) @@ -365,7 +365,7 @@ public func /= (lhs: inout Vector, rhs: Double) { return divInPlace(&lhs, rhs) } -// MARK: Element-wise Multiplication +// MARK: - Element-wise Multiplication public func elmul(_ x: Vector, _ y: Vector) -> Vector { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise multiplication") @@ -387,7 +387,7 @@ public func .* (lhs: Vector, rhs: Vector) -> Vector { return elmul(lhs, rhs) } -// MARK: Element-wise Multiplication: In Place +// MARK: - Element-wise Multiplication: In Place public func elmulInPlace(_ x: inout Vector, _ y: Vector) { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise multiplication") @@ -409,7 +409,7 @@ public func .*= (lhs: inout Vector, rhs: Vector) { return elmulInPlace(&lhs, rhs) } -// MARK: Element-wise Division +// MARK: - Element-wise Division public func eldiv(_ x: Vector, _ y: Vector) -> Vector { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise division") @@ -431,7 +431,7 @@ public func ./ (lhs: Vector, rhs: Vector) -> Vector { return eldiv(lhs, rhs) } -// MARK: Element-wise Division: In Place +// MARK: - Element-wise Division: In Place public func eldivInPlace(_ x: inout Vector, _ y: Vector) { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise division") @@ -453,7 +453,7 @@ public func ./= (lhs: inout Vector, rhs: Vector) { return eldivInPlace(&lhs, rhs) } -// MARK: Dot Product +// MARK: - Dot Product public func dot(_ x: Vector, _ y: Vector) -> Double { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with dot product") @@ -476,7 +476,7 @@ public func • (lhs: Vector, rhs: Vector) -> Float { return dot(lhs, rhs) } -// MARK: Power +// MARK: - Power public func pow(_ x: Vector, _ y: Double) -> Vector { return Vector(pow(x.scalars, y)) @@ -486,7 +486,7 @@ public func pow(_ x: Vector, _ y: Float) -> Vector { return Vector(pow(x.scalars, y)) } -// MARK: Exponential +// MARK: - Exponential public func exp(_ x: Vector) -> Vector { return Vector(exp(x.scalars)) @@ -496,7 +496,7 @@ public func exp(_ x: Vector) -> Vector { return Vector(exp(x.scalars)) } -// MARK: Distance +// MARK: - Distance public func dist(_ x: Vector, _ y: Vector) -> Double { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with distance calculation") @@ -510,7 +510,7 @@ public func dist(_ x: Vector, _ y: Vector) -> Float { return dist(x.scalars, y.scalars) } -// MARK: Distance Squared +// MARK: - Distance Squared public func distSq(_ x: Vector, _ y: Vector) -> Double { precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with distance calculation") diff --git a/Tests/SurgeTests/ConvolutionTests.swift b/Tests/SurgeTests/ConvolutionTests.swift index 2e1d7d4..972db0d 100644 --- a/Tests/SurgeTests/ConvolutionTests.swift +++ b/Tests/SurgeTests/ConvolutionTests.swift @@ -26,7 +26,7 @@ class ConvolutionTests: XCTestCase { let floatAccuracy: Float = 1e-8 let doubleAccuracy: Double = 1e-11 - // MARK: Test Arrays - Float + // MARK: - Test Arrays - Float let a1f: [Float] = [0, 0, 1, 0, 0] let a2f: [Float] = [1, 0, 0] let b1f: [Float] = [0, 2, 3, 1, 5, 6] @@ -38,7 +38,7 @@ class ConvolutionTests: XCTestCase { let e1f: [Float] = [0, 0, 0, 0, 0] let e2f: [Float] = [0, 0, 0] - // MARK: Test Arrays - Double + // MARK: - Test Arrays - Double let a1d: [Double] = [0, 0, 1, 0, 0] let a2d: [Double] = [1, 0, 0] let b1d: [Double] = [0, 2, 3, 1, 5, 6] @@ -50,7 +50,7 @@ class ConvolutionTests: XCTestCase { let e1d: [Double] = [0, 0, 0, 0, 0] let e2d: [Double] = [0, 0, 0] - // MARK: Convolution - Float + // MARK: - Convolution - Float func test_conv_float() { let a3f: [Float] = [0, 0, 1, 0, 0, 0, 0] let b3f: [Float] = [0, 0, 0, -2, -3, -1, -5, -6] @@ -65,7 +65,7 @@ class ConvolutionTests: XCTestCase { XCTAssertEqual(conv(e1f, e2f), e3f, accuracy: floatAccuracy) } - // MARK: Convolution - Double + // MARK: - Convolution - Double func test_conv_double() { let a3d: [Double] = [0, 0, 1, 0, 0, 0, 0] let b3d: [Double] = [0, 0, 0, -2, -3, -1, -5, -6] @@ -80,7 +80,7 @@ class ConvolutionTests: XCTestCase { XCTAssertEqual(conv(e1d, e2d), e3d, accuracy: doubleAccuracy) } - // MARK: Cross-Correlation - Float + // MARK: - Cross-Correlation - Float func test_xcorr_float() { let a3f: [Float] = [0, 0, 0, 0, 0, 0, 1, 0, 0] let b3f: [Float] = [0, 0, 0, 0, -2, -3, -1, -5, -6, 0, 0] @@ -95,7 +95,7 @@ class ConvolutionTests: XCTestCase { XCTAssertEqual(xcorr(e1f, e2f), e3f, accuracy: floatAccuracy) } - // MARK: Cross-Correlation - Double + // MARK: - Cross-Correlation - Double func test_xcorr_double() { let a3d: [Double] = [0, 0, 0, 0, 0, 0, 1, 0, 0] let b3d: [Double] = [0, 0, 0, 0, -2, -3, -1, -5, -6, 0, 0] @@ -110,7 +110,7 @@ class ConvolutionTests: XCTestCase { XCTAssertEqual(xcorr(e1d, e2d), e3d, accuracy: doubleAccuracy) } - // MARK: Auto-Correlation - Float + // MARK: - Auto-Correlation - Float func test_acorr_float() { let a3f: [Float] = [0, 0, 0, 0, 1, 0, 0, 0, 0] let b3f: [Float] = [0, 12, 28, 23, 44, 75, 44, 23, 28, 12, 0] @@ -125,7 +125,7 @@ class ConvolutionTests: XCTestCase { XCTAssertEqual(xcorr(e1f), e3f, accuracy: floatAccuracy) } - // MARK: Auto-Correlation - Double + // MARK: - Auto-Correlation - Double func test_acorr_double() { let a3d: [Double] = [0, 0, 0, 0, 1, 0, 0, 0, 0] let b3d: [Double] = [0, 12, 28, 23, 44, 75, 44, 23, 28, 12, 0]