Replaced `// MARK:` with `// MARK: - ` for nicer visual separation in Xcode
This commit is contained in:
parent
4bc8823311
commit
7f4543704f
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Addition
|
||||
// MARK: - Addition
|
||||
|
||||
public func add<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ 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 + <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where
|
|||
return add(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Addition: In Place
|
||||
// MARK: - Addition: In Place
|
||||
|
||||
func addInPlace<L: UnsafeMutableMemoryAccessible, R: UnsafeMemoryAccessible>(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float {
|
||||
lhs.withUnsafeMutableMemory { lm in
|
||||
|
@ -116,7 +116,7 @@ public func +=<L: UnsafeMutableMemoryAccessible>(lhs: inout L, rhs: Double) wher
|
|||
return addInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Subtraction
|
||||
// MARK: - Subtraction
|
||||
|
||||
public func sub<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ 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 - <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where
|
|||
return sub(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Subtraction: In Place
|
||||
// MARK: - Subtraction: In Place
|
||||
|
||||
func subInPlace<L: UnsafeMutableMemoryAccessible, R: UnsafeMemoryAccessible>(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float {
|
||||
lhs.withUnsafeMutableMemory { lm in
|
||||
|
@ -212,7 +212,7 @@ public func -=<L: UnsafeMutableMemoryAccessible>(lhs: inout L, rhs: Double) wher
|
|||
return subInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Multiplication
|
||||
// MARK: - Multiplication
|
||||
|
||||
public func mul<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ 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 * <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where
|
|||
return mul(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Multiplication: In Place
|
||||
// MARK: - Multiplication: In Place
|
||||
|
||||
func mulInPlace<L: UnsafeMutableMemoryAccessible, R: UnsafeMemoryAccessible>(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float {
|
||||
lhs.withUnsafeMutableMemory { lm in
|
||||
|
@ -308,7 +308,7 @@ public func *=<L: UnsafeMutableMemoryAccessible>(lhs: inout L, rhs: Double) wher
|
|||
return mulInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Division
|
||||
// MARK: - Division
|
||||
|
||||
/// Elemen-wise vector division.
|
||||
public func div<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||
|
@ -358,7 +358,7 @@ public func / <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where
|
|||
return div(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Division: In Place
|
||||
// MARK: - Division: In Place
|
||||
|
||||
func divInPlace<L: UnsafeMutableMemoryAccessible, R: UnsafeMemoryAccessible>(_ lhs: inout L, _ rhs: R) where L.Element == Float, R.Element == Float {
|
||||
lhs.withUnsafeMutableMemory { lm in
|
||||
|
@ -406,7 +406,7 @@ public func /=<L: UnsafeMutableMemoryAccessible>(lhs: inout L, rhs: Double) wher
|
|||
return divInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Modulo
|
||||
// MARK: - Modulo
|
||||
|
||||
/// Elemen-wise modulo.
|
||||
///
|
||||
|
@ -462,7 +462,7 @@ public func % <L: UnsafeMemoryAccessible>(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: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x:
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Square Root
|
||||
// MARK: - Square Root
|
||||
|
||||
/// Elemen-wise square root.
|
||||
///
|
||||
|
@ -540,7 +540,7 @@ public func sqrt<MI: UnsafeMemoryAccessible, MO: UnsafeMutableMemoryAccessible>(
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Dot Product
|
||||
// MARK: - Dot Product
|
||||
|
||||
public func dot<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> Float where X.Element == Float, Y.Element == Float {
|
||||
return withUnsafeMemory(x, y) { xm, ym in
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Absolute Value
|
||||
// MARK: - Absolute Value
|
||||
|
||||
/// Elemen-wise absolute value.
|
||||
///
|
||||
|
@ -50,7 +50,7 @@ public func abs<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element ==
|
|||
return results
|
||||
}
|
||||
|
||||
// MARK: Ceiling
|
||||
// MARK: - Ceiling
|
||||
|
||||
/// Elemen-wise ceiling.
|
||||
///
|
||||
|
@ -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))
|
||||
|
@ -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 {
|
||||
|
@ -136,7 +136,7 @@ public func copysign<S: UnsafeMemoryAccessible, M: UnsafeMemoryAccessible>(sign:
|
|||
return results
|
||||
}
|
||||
|
||||
// MARK: Floor
|
||||
// MARK: - Floor
|
||||
|
||||
/// Elemen-wise floor.
|
||||
///
|
||||
|
@ -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))
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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].
|
||||
|
@ -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 {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Exponentiation
|
||||
// MARK: - Exponentiation
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func exp<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -46,7 +46,7 @@ public func exp<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -72,7 +72,7 @@ public func exp2<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -98,7 +98,7 @@ public func log<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -124,7 +124,7 @@ public func log2<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -150,7 +150,7 @@ public func log10<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Fast Fourier Transform
|
||||
// MARK: - Fast Fourier Transform
|
||||
|
||||
public func fft(_ input: [Float]) -> [Float] {
|
||||
var real = [Float](input)
|
||||
|
|
|
@ -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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
||||
|
@ -46,7 +46,7 @@ public func sinh<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
||||
|
@ -72,7 +72,7 @@ public func cosh<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
||||
|
@ -98,7 +98,7 @@ public func tanh<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
||||
|
@ -124,7 +124,7 @@ public func asinh<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
||||
|
@ -150,7 +150,7 @@ public func acosh<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
||||
|
|
|
@ -260,7 +260,7 @@ public func ==<T> (lhs: Matrix<T>, rhs: Matrix<T>) -> Bool {
|
|||
return lhs.rows == rhs.rows && lhs.columns == rhs.columns && lhs.grid == rhs.grid
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
// MARK: - Addition
|
||||
|
||||
public func add(_ x: Matrix<Float>, _ y: Matrix<Float>) -> Matrix<Float> {
|
||||
precondition(x.rows == y.rows && x.columns == y.columns, "Matrix dimensions not compatible with addition")
|
||||
|
@ -292,6 +292,8 @@ public func + (lhs: Matrix<Double>, rhs: Matrix<Double>) -> Matrix<Double> {
|
|||
return add(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: - Subtraction
|
||||
|
||||
public func sub(_ x: Matrix<Float>, _ y: Matrix<Float>) -> Matrix<Float> {
|
||||
precondition(x.rows == y.rows && x.columns == y.columns, "Matrix dimensions not compatible with subtraction")
|
||||
|
||||
|
@ -322,6 +324,8 @@ public func - (lhs: Matrix<Double>, rhs: Matrix<Double>) -> Matrix<Double> {
|
|||
return sub(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: - Multiplication
|
||||
|
||||
public func mul(_ x: Matrix<Float>, _ y: Matrix<Float>) -> Matrix<Float> {
|
||||
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<Double>, rhs: Vector<Double>) -> Vector<Double> {
|
|||
return mul(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: - Element-wise Multiplication
|
||||
|
||||
public func elmul(_ x: Matrix<Double>, _ y: Matrix<Double>) -> Matrix<Double> {
|
||||
precondition(x.rows == y.rows && x.columns == y.columns, "Matrix must have the same dimensions")
|
||||
var result = Matrix<Double>(rows: x.rows, columns: x.columns, repeatedValue: 0.0)
|
||||
|
@ -408,6 +414,8 @@ public func elmul(_ x: Matrix<Float>, _ y: Matrix<Float>) -> Matrix<Float> {
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: - Division
|
||||
|
||||
public func div(_ x: Matrix<Double>, _ y: Matrix<Double>) -> Matrix<Double> {
|
||||
let yInv = inv(y)
|
||||
precondition(x.columns == yInv.rows, "Matrix dimensions not compatible")
|
||||
|
@ -448,6 +456,8 @@ public func / (lhs: Matrix<Float>, rhs: Float) -> Matrix<Float> {
|
|||
return div(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: - Power
|
||||
|
||||
public func pow(_ x: Matrix<Double>, _ y: Double) -> Matrix<Double> {
|
||||
var result = Matrix<Double>(rows: x.rows, columns: x.columns, repeatedValue: 0.0)
|
||||
result.grid = pow(x.grid, y)
|
||||
|
@ -460,6 +470,8 @@ public func pow(_ x: Matrix<Float>, _ y: Float) -> Matrix<Float> {
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: - Exponential
|
||||
|
||||
public func exp(_ x: Matrix<Double>) -> Matrix<Double> {
|
||||
var result = Matrix<Double>(rows: x.rows, columns: x.columns, repeatedValue: 0.0)
|
||||
result.grid = exp(x.grid)
|
||||
|
@ -472,8 +484,9 @@ public func exp(_ x: Matrix<Float>) -> Matrix<Float> {
|
|||
return result
|
||||
}
|
||||
|
||||
public func sum(_ x: Matrix<Double>, axies: MatrixAxies = .column) -> Matrix<Double> {
|
||||
// MARK: - Summation
|
||||
|
||||
public func sum(_ x: Matrix<Double>, axies: MatrixAxies = .column) -> Matrix<Double> {
|
||||
switch axies {
|
||||
case .column:
|
||||
var result = Matrix<Double>(rows: 1, columns: x.columns, repeatedValue: 0.0)
|
||||
|
@ -481,7 +494,6 @@ public func sum(_ x: Matrix<Double>, axies: MatrixAxies = .column) -> Matrix<Dou
|
|||
result.grid[i] = sum(x[column: i])
|
||||
}
|
||||
return result
|
||||
|
||||
case .row:
|
||||
var result = Matrix<Double>(rows: x.rows, columns: 1, repeatedValue: 0.0)
|
||||
for i in 0..<x.rows {
|
||||
|
@ -492,7 +504,6 @@ public func sum(_ x: Matrix<Double>, axies: MatrixAxies = .column) -> Matrix<Dou
|
|||
}
|
||||
|
||||
public func sum(_ x: Matrix<Float>, axies: MatrixAxies = .column) -> Matrix<Float> {
|
||||
|
||||
switch axies {
|
||||
case .column:
|
||||
var result = Matrix<Float>(rows: 1, columns: x.columns, repeatedValue: 0.0)
|
||||
|
@ -500,7 +511,6 @@ public func sum(_ x: Matrix<Float>, axies: MatrixAxies = .column) -> Matrix<Floa
|
|||
result.grid[i] = sum(x[column: i])
|
||||
}
|
||||
return result
|
||||
|
||||
case .row:
|
||||
var result = Matrix<Float>(rows: x.rows, columns: 1, repeatedValue: 0.0)
|
||||
for i in 0..<x.rows {
|
||||
|
@ -510,6 +520,8 @@ public func sum(_ x: Matrix<Float>, axies: MatrixAxies = .column) -> Matrix<Floa
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Inverse
|
||||
|
||||
public func inv(_ x: Matrix<Float>) -> Matrix<Float> {
|
||||
precondition(x.rows == x.columns, "Matrix must be square")
|
||||
|
||||
|
@ -556,6 +568,8 @@ public func inv(_ x: Matrix<Double>) -> Matrix<Double> {
|
|||
return results
|
||||
}
|
||||
|
||||
// MARK: - Transpose
|
||||
|
||||
public func transpose(_ x: Matrix<Float>) -> Matrix<Float> {
|
||||
var results = Matrix<Float>(rows: x.columns, columns: x.rows, repeatedValue: 0.0)
|
||||
results.grid.withUnsafeMutableBufferPointer { pointer in
|
||||
|
@ -582,6 +596,8 @@ public postfix func ′ (value: Matrix<Double>) -> Matrix<Double> {
|
|||
return transpose(value)
|
||||
}
|
||||
|
||||
// MARK: - Determinant
|
||||
|
||||
/// Computes the matrix determinant.
|
||||
public func det(_ x: Matrix<Float>) -> Float? {
|
||||
var decomposed = x
|
||||
|
@ -638,6 +654,8 @@ public func det(_ x: Matrix<Double>) -> 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:
|
||||
|
|
|
@ -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 ′
|
||||
|
|
|
@ -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, B, Result>(_ 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).
|
||||
///
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Power
|
||||
// MARK: - Power
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func pow<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Multiplication
|
||||
// MARK: - Multiplication
|
||||
|
||||
public func mul<R: UnsafeMemoryAccessible>(_ lhs: Float, _ rhs: R) -> [Float] where R.Element == Float {
|
||||
return mul([Float](repeating: lhs, count: numericCast(rhs.count)), rhs)
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import Accelerate
|
||||
|
||||
// MARK: Sum
|
||||
// MARK: - Sum
|
||||
|
||||
public func sum<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -42,7 +42,7 @@ public func sum<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element ==
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Sum of Absolute Values
|
||||
// MARK: - Sum of Absolute Values
|
||||
|
||||
public func asum<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
return x.withUnsafeMemory { xm in
|
||||
|
@ -56,7 +56,7 @@ public func asum<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element ==
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Sum of Square Values
|
||||
// MARK: - Sum of Square Values
|
||||
|
||||
public func sumsq<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0
|
||||
|
@ -78,7 +78,7 @@ public func sumsq<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element =
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Maximum
|
||||
// MARK: - Maximum
|
||||
|
||||
public func max<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -100,7 +100,7 @@ public func max<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element ==
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Minimum
|
||||
// MARK: - Minimum
|
||||
|
||||
public func min<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -122,7 +122,7 @@ public func min<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element ==
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Mean
|
||||
// MARK: - Mean
|
||||
|
||||
public func mean<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -144,7 +144,7 @@ public func mean<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element ==
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Mean Magnitude
|
||||
// MARK: - Mean Magnitude
|
||||
|
||||
public func meamg<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -166,7 +166,7 @@ public func meamg<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element =
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Mean Square Value
|
||||
// MARK: - Mean Square Value
|
||||
|
||||
public func measq<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -188,7 +188,7 @@ public func measq<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element =
|
|||
return result
|
||||
}
|
||||
|
||||
// MARK: Root Mean Square Value
|
||||
// MARK: - Root Mean Square Value
|
||||
|
||||
public func rmsq<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||
var result: Float = 0.0
|
||||
|
@ -210,7 +210,7 @@ public func rmsq<C: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> Float where X.Element == Float {
|
||||
|
@ -226,7 +226,7 @@ public func std<X: UnsafeMemoryAccessible>(_ x: X) -> Double where X.Element ==
|
|||
return sqrt(variance)
|
||||
}
|
||||
|
||||
// MARK: Linear regression
|
||||
// MARK: - Linear regression
|
||||
|
||||
/// Performs linear regression
|
||||
///
|
||||
|
|
|
@ -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: UnsafeMemoryAccessible>(_ x: X) -> (sin: [Float], cos: [Float]) where X.Element == Float {
|
||||
|
@ -48,7 +48,7 @@ public func sincos<X: UnsafeMemoryAccessible>(_ x: X) -> (sin: [Double], cos: [D
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Sine
|
||||
// MARK: - Sine
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func sin<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -74,7 +74,7 @@ public func sin<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element =
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Cosine
|
||||
// MARK: - Cosine
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func cos<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -100,7 +100,7 @@ public func cos<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element =
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Tangent
|
||||
// MARK: - Tangent
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func tan<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -126,7 +126,7 @@ public func tan<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element =
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Arcsine
|
||||
// MARK: - Arcsine
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func asin<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -152,7 +152,7 @@ public func asin<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Arccosine
|
||||
// MARK: - Arccosine
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func acos<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -178,7 +178,7 @@ public func acos<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Arctangent
|
||||
// MARK: - Arctangent
|
||||
|
||||
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||
public func atan<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -206,7 +206,7 @@ public func atan<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
@ -234,7 +234,7 @@ func rad2deg<X: UnsafeMemoryAccessible>(_ 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: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||
|
|
|
@ -143,7 +143,7 @@ public func + (lhs: Vector<Double>, rhs: Double) -> Vector<Double> {
|
|||
return add(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Addition: In Place
|
||||
// MARK: - Addition: In Place
|
||||
|
||||
public func addInPlace(_ x: inout Vector<Float>, _ y: Vector<Float>) {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with addition")
|
||||
|
@ -181,7 +181,7 @@ public func += (lhs: inout Vector<Double>, rhs: Double) {
|
|||
return addInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Subtraction
|
||||
// MARK: - Subtraction
|
||||
|
||||
public func sub(_ x: Vector<Float>, _ y: Vector<Float>) -> Vector<Float> {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with subtraction")
|
||||
|
@ -219,7 +219,7 @@ public func - (lhs: Vector<Double>, rhs: Double) -> Vector<Double> {
|
|||
return sub(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Subtraction: In Place
|
||||
// MARK: - Subtraction: In Place
|
||||
|
||||
public func subInPlace(_ x: inout Vector<Float>, _ y: Vector<Float>) {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with subtraction")
|
||||
|
@ -257,7 +257,7 @@ public func -= (lhs: inout Vector<Double>, rhs: Double) {
|
|||
return subInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Multiplication
|
||||
// MARK: - Multiplication
|
||||
|
||||
public func mul(_ x: Vector<Float>, _ y: Float) -> Vector<Float> {
|
||||
return Vector(mul(x.scalars, y))
|
||||
|
@ -311,7 +311,7 @@ public func * (lhs: Vector<Double>, rhs: Matrix<Double>) -> Vector<Double> {
|
|||
return mul(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Multiplication: In Place
|
||||
// MARK: - Multiplication: In Place
|
||||
|
||||
public func mulInPlace(_ x: inout Vector<Float>, _ y: Float) {
|
||||
return mulInPlace(&x.scalars, y)
|
||||
|
@ -329,7 +329,7 @@ public func *= (lhs: inout Vector<Double>, rhs: Double) {
|
|||
return mulInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Division
|
||||
// MARK: - Division
|
||||
|
||||
public func div(_ x: Vector<Float>, _ y: Float) -> Vector<Float> {
|
||||
return Vector(div(x.scalars, y))
|
||||
|
@ -347,7 +347,7 @@ public func / (lhs: Vector<Float>, rhs: Float) -> Vector<Float> {
|
|||
return div(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Division: In Place
|
||||
// MARK: - Division: In Place
|
||||
|
||||
public func divInPlace(_ x: inout Vector<Float>, _ y: Float) {
|
||||
return divInPlace(&x.scalars, y)
|
||||
|
@ -365,7 +365,7 @@ public func /= (lhs: inout Vector<Double>, rhs: Double) {
|
|||
return divInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Element-wise Multiplication
|
||||
// MARK: - Element-wise Multiplication
|
||||
|
||||
public func elmul(_ x: Vector<Double>, _ y: Vector<Double>) -> Vector<Double> {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise multiplication")
|
||||
|
@ -387,7 +387,7 @@ public func .* (lhs: Vector<Double>, rhs: Vector<Double>) -> Vector<Double> {
|
|||
return elmul(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Element-wise Multiplication: In Place
|
||||
// MARK: - Element-wise Multiplication: In Place
|
||||
|
||||
public func elmulInPlace(_ x: inout Vector<Double>, _ y: Vector<Double>) {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise multiplication")
|
||||
|
@ -409,7 +409,7 @@ public func .*= (lhs: inout Vector<Double>, rhs: Vector<Double>) {
|
|||
return elmulInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Element-wise Division
|
||||
// MARK: - Element-wise Division
|
||||
|
||||
public func eldiv(_ x: Vector<Double>, _ y: Vector<Double>) -> Vector<Double> {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise division")
|
||||
|
@ -431,7 +431,7 @@ public func ./ (lhs: Vector<Float>, rhs: Vector<Float>) -> Vector<Float> {
|
|||
return eldiv(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Element-wise Division: In Place
|
||||
// MARK: - Element-wise Division: In Place
|
||||
|
||||
public func eldivInPlace(_ x: inout Vector<Double>, _ y: Vector<Double>) {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with element-wise division")
|
||||
|
@ -453,7 +453,7 @@ public func ./= (lhs: inout Vector<Float>, rhs: Vector<Float>) {
|
|||
return eldivInPlace(&lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Dot Product
|
||||
// MARK: - Dot Product
|
||||
|
||||
public func dot(_ x: Vector<Double>, _ y: Vector<Double>) -> Double {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with dot product")
|
||||
|
@ -476,7 +476,7 @@ public func • (lhs: Vector<Float>, rhs: Vector<Float>) -> Float {
|
|||
return dot(lhs, rhs)
|
||||
}
|
||||
|
||||
// MARK: Power
|
||||
// MARK: - Power
|
||||
|
||||
public func pow(_ x: Vector<Double>, _ y: Double) -> Vector<Double> {
|
||||
return Vector(pow(x.scalars, y))
|
||||
|
@ -486,7 +486,7 @@ public func pow(_ x: Vector<Float>, _ y: Float) -> Vector<Float> {
|
|||
return Vector(pow(x.scalars, y))
|
||||
}
|
||||
|
||||
// MARK: Exponential
|
||||
// MARK: - Exponential
|
||||
|
||||
public func exp(_ x: Vector<Double>) -> Vector<Double> {
|
||||
return Vector(exp(x.scalars))
|
||||
|
@ -496,7 +496,7 @@ public func exp(_ x: Vector<Float>) -> Vector<Float> {
|
|||
return Vector(exp(x.scalars))
|
||||
}
|
||||
|
||||
// MARK: Distance
|
||||
// MARK: - Distance
|
||||
|
||||
public func dist(_ x: Vector<Double>, _ y: Vector<Double>) -> Double {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with distance calculation")
|
||||
|
@ -510,7 +510,7 @@ public func dist(_ x: Vector<Float>, _ y: Vector<Float>) -> Float {
|
|||
return dist(x.scalars, y.scalars)
|
||||
}
|
||||
|
||||
// MARK: Distance Squared
|
||||
// MARK: - Distance Squared
|
||||
|
||||
public func distSq(_ x: Vector<Double>, _ y: Vector<Double>) -> Double {
|
||||
precondition(x.dimensions == y.dimensions, "Vector dimensions not compatible with distance calculation")
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue