Add UnsafeMemory abstraction (#77)
This simplifies the code dealing with unsafe pointers and allows using existing functions with other collections. Also update the copyright notices.
This commit is contained in:
parent
e600211d32
commit
a3f3153c3c
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
||||||
Copyright © 2014 Mattt Thompson (http://mattt.me/)
|
Copyright © 2014-2018 the Surge contributors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// swift-tools-version:4.0
|
// swift-tools-version:4.0
|
||||||
//
|
//
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -22,21 +22,21 @@ import Accelerate
|
||||||
|
|
||||||
// MARK: Sum
|
// MARK: Sum
|
||||||
|
|
||||||
public func sum<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func sum<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count -> Void in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_sve(x, 1, pointer, vDSP_Length(count))
|
vDSP_sve(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sum<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func sum<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_sveD(x, 1, pointer, vDSP_Length(count))
|
vDSP_sveD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -44,41 +44,35 @@ public func sum<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Elem
|
||||||
|
|
||||||
// MARK: Sum of Absolute Values
|
// MARK: Sum of Absolute Values
|
||||||
|
|
||||||
public func asum<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func asum<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
return x.withUnsafeBufferPointer { bufferPointer in
|
return x.withUnsafeMemory { xm in
|
||||||
guard let x = bufferPointer.baseAddress else {
|
cblas_sasum(numericCast(xm.count), xm.pointer, numericCast(xm.stride))
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return cblas_sasum(Int32(bufferPointer.count), x, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func asum<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func asum<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
return x.withUnsafeBufferPointer { bufferPointer in
|
return x.withUnsafeMemory { xm in
|
||||||
guard let x = bufferPointer.baseAddress else {
|
cblas_dasum(numericCast(xm.count), xm.pointer, numericCast(xm.stride))
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return cblas_dasum(Int32(bufferPointer.count), x, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Sum of Square Values
|
// MARK: Sum of Square Values
|
||||||
|
|
||||||
public func sumsq<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func sumsq<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0
|
var result: Float = 0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_svesq(x, 1, pointer, vDSP_Length(count))
|
vDSP_svesq(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sumsq<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func sumsq<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0
|
var result: Double = 0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_svesqD(x, 1, pointer, vDSP_Length(count))
|
vDSP_svesqD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -86,21 +80,21 @@ public func sumsq<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.El
|
||||||
|
|
||||||
// MARK: Maximum
|
// MARK: Maximum
|
||||||
|
|
||||||
public func max<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func max<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_maxv(x, 1, pointer, vDSP_Length(count))
|
vDSP_maxv(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func max<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func max<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_maxvD(x, 1, pointer, vDSP_Length(count))
|
vDSP_maxvD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -108,21 +102,21 @@ public func max<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Elem
|
||||||
|
|
||||||
// MARK: Minimum
|
// MARK: Minimum
|
||||||
|
|
||||||
public func min<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func min<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_minv(x, 1, pointer, vDSP_Length(count))
|
vDSP_minv(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func min<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func min<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_minvD(x, 1, pointer, vDSP_Length(count))
|
vDSP_minvD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -130,21 +124,21 @@ public func min<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Elem
|
||||||
|
|
||||||
// MARK: Mean
|
// MARK: Mean
|
||||||
|
|
||||||
public func mean<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func mean<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_meanv(x, 1, pointer, vDSP_Length(count))
|
vDSP_meanv(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func mean<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func mean<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_meanvD(x, 1, pointer, vDSP_Length(count))
|
vDSP_meanvD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -152,21 +146,21 @@ public func mean<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Ele
|
||||||
|
|
||||||
// MARK: Mean Magnitude
|
// MARK: Mean Magnitude
|
||||||
|
|
||||||
public func meamg<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func meamg<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_meamgv(x, 1, pointer, vDSP_Length(count))
|
vDSP_meamgv(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func meamg<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func meamg<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_meamgvD(x, 1, pointer, vDSP_Length(count))
|
vDSP_meamgvD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -174,21 +168,21 @@ public func meamg<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.El
|
||||||
|
|
||||||
// MARK: Mean Square Value
|
// MARK: Mean Square Value
|
||||||
|
|
||||||
public func measq<C: ContinuousCollection>(_ x: C) -> Float where C.Iterator.Element == Float {
|
public func measq<C: UnsafeMemoryAccessible>(_ x: C) -> Float where C.Element == Float {
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_measqv(x, 1, pointer, vDSP_Length(count))
|
vDSP_measqv(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public func measq<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.Element == Double {
|
public func measq<C: UnsafeMemoryAccessible>(_ x: C) -> Double where C.Element == Double {
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
x.withUnsafeMemory { xm in
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_measqvD(x, 1, pointer, vDSP_Length(count))
|
vDSP_measqvD(xm.pointer, xm.stride, pointer, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -196,21 +190,21 @@ public func measq<C: ContinuousCollection>(_ x: C) -> Double where C.Iterator.El
|
||||||
|
|
||||||
// MARK: Add
|
// MARK: Add
|
||||||
|
|
||||||
public func add<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
public func add<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
var results = [Float](y)
|
var results = [Float](y)
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
cblas_saxpy(Int32(xbp.count), 1.0, xbp.baseAddress, 1, rbp.baseAddress, 1)
|
cblas_saxpy(numericCast(xm.count), 1.0, xm.pointer, numericCast(xm.stride), rbp.baseAddress, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func add<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
public func add<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
var results = [Double](y)
|
var results = [Double](y)
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
cblas_daxpy(Int32(xbp.count), 1.0, xbp.baseAddress, 1, rbp.baseAddress, 1)
|
cblas_daxpy(numericCast(xm.count), 1.0, xm.pointer, numericCast(xm.stride), rbp.baseAddress, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -218,21 +212,21 @@ public func add<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y
|
||||||
|
|
||||||
// MARK: Subtraction
|
// MARK: Subtraction
|
||||||
|
|
||||||
public func sub<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
public func sub<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
var results = [Float](y)
|
var results = [Float](y)
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
catlas_saxpby(Int32(xbp.count), 1.0, xbp.baseAddress, 1, -1, rbp.baseAddress, 1)
|
catlas_saxpby(numericCast(xm.count), 1.0, xm.pointer, numericCast(xm.stride), -1, rbp.baseAddress, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sub<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
public func sub<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
var results = [Double](y)
|
var results = [Double](y)
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
catlas_daxpby(Int32(xbp.count), 1.0, xbp.baseAddress, 1, -1, rbp.baseAddress, 1)
|
catlas_daxpby(numericCast(xm.count), 1.0, xm.pointer, numericCast(xm.stride), -1, rbp.baseAddress, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -240,281 +234,283 @@ public func sub<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y
|
||||||
|
|
||||||
// MARK: Multiply
|
// MARK: Multiply
|
||||||
|
|
||||||
public func mul<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
public func mul<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vDSP_vmul(xp, 1, yp, 1, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
vDSP_vmul(xm.pointer, xm.stride, ym.pointer, ym.stride, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func mul<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
public func mul<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vDSP_vmulD(xp, 1, yp, 1, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
vDSP_vmulD(xm.pointer, xm.stride, ym.pointer, ym.stride, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Divide
|
// MARK: Divide
|
||||||
|
|
||||||
public func div<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
/// Elemen-wise vector division.
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
public func div<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
return
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
}
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vvdivf(rbp.baseAddress!, xp, yp, [Int32(xbp.count)])
|
vvdivf(rbp.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func div<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
/// Elemen-wise vector division.
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
public func div<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
return
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
}
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vvdiv(rbp.baseAddress!, xp, yp, [Int32(xbp.count)])
|
vvdiv(rbp.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Modulo
|
// MARK: Modulo
|
||||||
|
|
||||||
public func mod<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
/// Elemen-wise modulo.
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
public func mod<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
return
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
}
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vvfmodf(rbp.baseAddress!, xp, yp, [Int32(xbp.count)])
|
vvfmodf(rbp.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func mod<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
/// Elemen-wise modulo.
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
public func mod<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
return
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
}
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vvfmod(rbp.baseAddress!, xp, yp, [Int32(xbp.count)])
|
vvfmod(rbp.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Remainder
|
// MARK: Remainder
|
||||||
|
|
||||||
public func remainder<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
/// Elemen-wise remainder.
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
public func remainder<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
return
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
}
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vvremainderf(rbp.baseAddress!, xp, yp, [Int32(xbp.count)])
|
vvremainderf(rbp.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func remainder<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
/// Elemen-wise remainder.
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
public func remainder<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
return
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
}
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
vvremainder(rbp.baseAddress!, xp, yp, [Int32(xbp.count)])
|
vvremainder(rbp.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Square Root
|
// MARK: Square Root
|
||||||
|
|
||||||
public func sqrt<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// Elemen-wise square root.
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func sqrt<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.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(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { bufferPointer in
|
results.withUnsafeMutableBufferPointer { bufferPointer in
|
||||||
vvsqrtf(bufferPointer.baseAddress!, x, [Int32(count)])
|
vvsqrtf(bufferPointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func sqrt<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// Elemen-wise square root.
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
///
|
||||||
withUnsafePointersAndCountsTo(x) { x, count in
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func sqrt<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.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(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { bufferPointer in
|
results.withUnsafeMutableBufferPointer { bufferPointer in
|
||||||
vvsqrt(bufferPointer.baseAddress!, x, [Int32(count)])
|
vvsqrt(bufferPointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Dot Product
|
// MARK: Dot Product
|
||||||
|
|
||||||
public func dot<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> Float where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
public func dot<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> Float where X.Element == Float, Y.Element == Float {
|
||||||
precondition(x.count == y.count, "Vectors must have equal count")
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
|
precondition(xm.count == ym.count, "Vectors must have equal count")
|
||||||
|
|
||||||
var result: Float = 0.0
|
var result: Float = 0.0
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_dotpr(xp, 1, yp, 1, pointer, vDSP_Length(xbp.count))
|
vDSP_dotpr(xm.pointer, xm.stride, ym.pointer, ym.stride, pointer, numericCast(xm.count))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func dot<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> Double where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
public func dot<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> Double where X.Element == Double, Y.Element == Double {
|
||||||
precondition(x.count == y.count, "Vectors must have equal count")
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
|
precondition(xm.count == ym.count, "Vectors must have equal count")
|
||||||
|
|
||||||
var result: Double = 0.0
|
var result: Double = 0.0
|
||||||
withUnsafeBufferPointersTo(x, y) { xbp, ybp in
|
|
||||||
guard let xp = xbp.baseAddress, let yp = ybp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
withUnsafeMutablePointer(to: &result) { pointer in
|
withUnsafeMutablePointer(to: &result) { pointer in
|
||||||
vDSP_dotprD(xp, 1, yp, 1, pointer, vDSP_Length(xbp.count))
|
vDSP_dotprD(xm.pointer, xm.stride, ym.pointer, ym.stride, pointer, numericCast(xm.count))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Distance
|
// MARK: - Distance
|
||||||
|
|
||||||
public func dist<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> Float where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
public func dist<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> Float where X.Element == Float, Y.Element == Float {
|
||||||
precondition(x.count == y.count, "Vectors must have equal count")
|
precondition(x.count == y.count, "Vectors must have equal count")
|
||||||
let sub = x - y
|
let sub = x - y
|
||||||
var squared = [Float](repeating: 0.0, count: numericCast(x.count))
|
var squared = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
squared.withUnsafeMutableBufferPointer { bufferPointer in
|
squared.withUnsafeMutableBufferPointer { bufferPointer in
|
||||||
vDSP_vsq(sub, 1, bufferPointer.baseAddress!, 1, vDSP_Length(x.count))
|
vDSP_vsq(sub, 1, bufferPointer.baseAddress!, 1, numericCast(x.count))
|
||||||
}
|
}
|
||||||
return sqrt(sum(squared))
|
return sqrt(sum(squared))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func dist<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> Double where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
public func dist<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> Double where X.Element == Double, Y.Element == Double {
|
||||||
precondition(x.count == y.count, "Vectors must have equal count")
|
precondition(x.count == y.count, "Vectors must have equal count")
|
||||||
let sub = x - y
|
let sub = x - y
|
||||||
var squared = [Double](repeating: 0.0, count: numericCast(x.count))
|
var squared = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
squared.withUnsafeMutableBufferPointer { bufferPointer in
|
squared.withUnsafeMutableBufferPointer { bufferPointer in
|
||||||
vDSP_vsqD(sub, 1, bufferPointer.baseAddress!, 1, vDSP_Length(x.count))
|
vDSP_vsqD(sub, 1, bufferPointer.baseAddress!, 1, numericCast(x.count))
|
||||||
}
|
}
|
||||||
return sqrt(sum(squared))
|
return sqrt(sum(squared))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Operators
|
// MARK: - Operators
|
||||||
|
|
||||||
public func + <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Float] where L.Iterator.Element == Float, R.Iterator.Element == Float {
|
public func + <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Float] where L.Element == Float, R.Element == Float {
|
||||||
return add(lhs, rhs)
|
return add(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func + <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Double] where L.Iterator.Element == Double, R.Iterator.Element == Double {
|
public func + <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Double] where L.Element == Double, R.Element == Double {
|
||||||
return add(lhs, rhs)
|
return add(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func + <L: ContinuousCollection>(lhs: L, rhs: Float) -> [Float] where L.Iterator.Element == Float {
|
public func + <L: UnsafeMemoryAccessible>(lhs: L, rhs: Float) -> [Float] where L.Element == Float {
|
||||||
return add(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
return add(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func + <L: ContinuousCollection>(lhs: L, rhs: Double) -> [Double] where L.Iterator.Element == Double {
|
public func + <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where L.Element == Double {
|
||||||
return add(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
return add(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func - <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Float] where L.Iterator.Element == Float, R.Iterator.Element == Float {
|
public func - <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Float] where L.Element == Float, R.Element == Float {
|
||||||
return sub(lhs, rhs)
|
return sub(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func - <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Double] where L.Iterator.Element == Double, R.Iterator.Element == Double {
|
public func - <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Double] where L.Element == Double, R.Element == Double {
|
||||||
return sub(lhs, rhs)
|
return sub(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func - <L: ContinuousCollection>(lhs: L, rhs: Float) -> [Float] where L.Iterator.Element == Float {
|
public func - <L: UnsafeMemoryAccessible>(lhs: L, rhs: Float) -> [Float] where L.Element == Float {
|
||||||
return sub(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
return sub(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func - <L: ContinuousCollection>(lhs: L, rhs: Double) -> [Double] where L.Iterator.Element == Double {
|
public func - <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where L.Element == Double {
|
||||||
return sub(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
return sub(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func / <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Float] where L.Iterator.Element == Float, R.Iterator.Element == Float {
|
public func / <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Float] where L.Element == Float, R.Element == Float {
|
||||||
return div(lhs, rhs)
|
return div(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func / <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Double] where L.Iterator.Element == Double, R.Iterator.Element == Double {
|
public func / <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Double] where L.Element == Double, R.Element == Double {
|
||||||
return div(lhs, rhs)
|
return div(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func / <L: ContinuousCollection>(lhs: L, rhs: Float) -> [Float] where L.Iterator.Element == Float {
|
public func / <L: UnsafeMemoryAccessible>(lhs: L, rhs: Float) -> [Float] where L.Element == Float {
|
||||||
return div(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
return div(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func / <L: ContinuousCollection>(lhs: L, rhs: Double) -> [Double] where L.Iterator.Element == Double {
|
public func / <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where L.Element == Double {
|
||||||
return div(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
return div(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func * <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Float] where L.Iterator.Element == Float, R.Iterator.Element == Float {
|
public func * <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Float] where L.Element == Float, R.Element == Float {
|
||||||
return mul(lhs, rhs)
|
return mul(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func * <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Double] where L.Iterator.Element == Double, R.Iterator.Element == Double {
|
public func * <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Double] where L.Element == Double, R.Element == Double {
|
||||||
return mul(lhs, rhs)
|
return mul(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func * <L: ContinuousCollection>(lhs: L, rhs: Float) -> [Float] where L.Iterator.Element == Float {
|
public func * <L: UnsafeMemoryAccessible>(lhs: L, rhs: Float) -> [Float] where L.Element == Float {
|
||||||
return mul(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
return mul(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func * <L: ContinuousCollection>(lhs: L, rhs: Double) -> [Double] where L.Iterator.Element == Double {
|
public func * <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where L.Element == Double {
|
||||||
return mul(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
return mul(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func % <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Float] where L.Iterator.Element == Float, R.Iterator.Element == Float {
|
public func % <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Float] where L.Element == Float, R.Element == Float {
|
||||||
return mod(lhs, rhs)
|
return mod(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func % <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> [Double] where L.Iterator.Element == Double, R.Iterator.Element == Double {
|
public func % <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> [Double] where L.Element == Double, R.Element == Double {
|
||||||
return mod(lhs, rhs)
|
return mod(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func % <L: ContinuousCollection>(lhs: L, rhs: Float) -> [Float] where L.Iterator.Element == Float {
|
public func % <L: UnsafeMemoryAccessible>(lhs: L, rhs: Float) -> [Float] where L.Element == Float {
|
||||||
return mod(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
return mod(lhs, [Float](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func % <L: ContinuousCollection>(lhs: L, rhs: Double) -> [Double] where L.Iterator.Element == Double {
|
public func % <L: UnsafeMemoryAccessible>(lhs: L, rhs: Double) -> [Double] where L.Element == Double {
|
||||||
return mod(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
return mod(lhs, [Double](repeating: rhs, count: numericCast(lhs.count)))
|
||||||
}
|
}
|
||||||
|
|
||||||
infix operator •
|
infix operator •
|
||||||
public func • <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> Double where L.Iterator.Element == Double, R.Iterator.Element == Double {
|
public func • <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> Double where L.Element == Double, R.Element == Double {
|
||||||
return dot(lhs, rhs)
|
return dot(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func • <L: ContinuousCollection, R: ContinuousCollection>(lhs: L, rhs: R) -> Float where L.Iterator.Element == Float, R.Iterator.Element == Float {
|
public func • <L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(lhs: L, rhs: R) -> Float where L.Element == Float, R.Element == Float {
|
||||||
return dot(lhs, rhs)
|
return dot(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
// 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 Foundation
|
||||||
|
|
||||||
|
extension ArraySlice: UnsafeMemoryAccessible, UnsafeMutableMemoryAccessible {
|
||||||
|
public func withUnsafeMemory<Result>(_ action: (UnsafeMemory<Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try withUnsafeBufferPointer { ptr in
|
||||||
|
guard let base = ptr.baseAddress else {
|
||||||
|
fatalError("ArraySlice is missing its pointer")
|
||||||
|
}
|
||||||
|
let memory = UnsafeMemory(pointer: base, stride: 1, count: ptr.count)
|
||||||
|
return try action(memory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public mutating func withUnsafeMutableMemory<Result>(_ action: (UnsafeMutableMemory<Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try withUnsafeMutableBufferPointer { ptr in
|
||||||
|
guard let base = ptr.baseAddress else {
|
||||||
|
fatalError("ArraySlice is missing its pointer")
|
||||||
|
}
|
||||||
|
let memory = UnsafeMutableMemory(pointer: base, stride: 1, count: ptr.count)
|
||||||
|
return try action(memory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
// 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 Foundation
|
||||||
|
|
||||||
|
extension Array: UnsafeMemoryAccessible, UnsafeMutableMemoryAccessible {
|
||||||
|
public func withUnsafeMemory<Result>(_ action: (UnsafeMemory<Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try withUnsafeBufferPointer { ptr in
|
||||||
|
guard let base = ptr.baseAddress else {
|
||||||
|
fatalError("Array is missing its pointer")
|
||||||
|
}
|
||||||
|
let memory = UnsafeMemory(pointer: base, stride: 1, count: ptr.count)
|
||||||
|
return try action(memory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public mutating func withUnsafeMutableMemory<Result>(_ action: (UnsafeMutableMemory<Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try withUnsafeMutableBufferPointer { ptr in
|
||||||
|
guard let base = ptr.baseAddress else {
|
||||||
|
fatalError("Array is missing its pointer")
|
||||||
|
}
|
||||||
|
let memory = UnsafeMutableMemory(pointer: base, stride: 1, count: ptr.count)
|
||||||
|
return try action(memory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -22,27 +22,29 @@ import Accelerate
|
||||||
|
|
||||||
// MARK: Absolute Value
|
// MARK: Absolute Value
|
||||||
|
|
||||||
public func abs<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// Elemen-wise absolute value.
|
||||||
|
///
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func abs<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvfabs(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvfabs(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func abs<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// Elemen-wise absolute value.
|
||||||
|
///
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func abs<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvfabsf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvfabsf(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -50,27 +52,29 @@ public func abs<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Ele
|
||||||
|
|
||||||
// MARK: Ceiling
|
// MARK: Ceiling
|
||||||
|
|
||||||
public func ceil<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// Elemen-wise ceiling.
|
||||||
|
///
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func ceil<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvceilf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvceilf(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func ceil<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// Elemen-wise ceiling.
|
||||||
|
///
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func ceil<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvceil(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvceil(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -78,34 +82,28 @@ public func ceil<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.E
|
||||||
|
|
||||||
// MARK: Clip
|
// MARK: Clip
|
||||||
|
|
||||||
public func clip<C: ContinuousCollection>(_ x: C, low: Float, high: Float) -> [Float] where C.Iterator.Element == Float {
|
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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var y = low
|
var y = low
|
||||||
var z = high
|
var z = high
|
||||||
withUnsafePointersTo(&y, &z) { y, z in
|
withUnsafePointers(&y, &z) { y, z in
|
||||||
vDSP_vclip(xp, 1, y, z, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
vDSP_vclip(xm.pointer, xm.stride, y, z, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func clip<C: ContinuousCollection>(_ x: C, low: Double, high: Double) -> [Double] where C.Iterator.Element == Double {
|
public func clip<C: UnsafeMemoryAccessible>(_ x: C, low: Double, high: Double) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var y = low
|
var y = low
|
||||||
var z = high
|
var z = high
|
||||||
withUnsafePointersTo(&y, &z) { y, z in
|
withUnsafePointers(&y, &z) { y, z in
|
||||||
vDSP_vclipD(xp, 1, y, z, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
vDSP_vclipD(xm.pointer, xm.stride, y, z, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,27 +112,25 @@ public func clip<C: ContinuousCollection>(_ x: C, low: Double, high: Double) ->
|
||||||
|
|
||||||
// MARK: Copy Sign
|
// MARK: Copy Sign
|
||||||
|
|
||||||
public func copysign<S: ContinuousCollection, M: ContinuousCollection>(sign: S, magnitude: M) -> [Float] where S.Iterator.Element == Float, M.Iterator.Element == Float {
|
/// - 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 {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(sign.count))
|
var results = [Float](repeating: 0.0, count: numericCast(sign.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafeBufferPointersTo(sign, magnitude) { sbp, mbp in
|
withUnsafeMemory(sign, magnitude) { sm, mm in
|
||||||
guard let sp = sbp.baseAddress, let mp = mbp.baseAddress else {
|
precondition(sm.stride == 1 && mm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvcopysignf(rbp.baseAddress!, mm.pointer, sm.pointer, [numericCast(sm.count)])
|
||||||
}
|
|
||||||
vvcopysignf(rbp.baseAddress!, mp, sp, [Int32(sbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func copysign<S: ContinuousCollection, M: ContinuousCollection>(sign: S, magnitude: M) -> [Double] where S.Iterator.Element == Double, M.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func copysign<S: UnsafeMemoryAccessible, M: UnsafeMemoryAccessible>(sign: S, magnitude: M) -> [Double] where S.Element == Double, M.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(sign.count))
|
var results = [Double](repeating: 0.0, count: numericCast(sign.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafeBufferPointersTo(sign, magnitude) { sbp, mbp in
|
withUnsafeMemory(sign, magnitude) { sm, mm in
|
||||||
guard let sp = sbp.baseAddress, let mp = mbp.baseAddress else {
|
precondition(sm.stride == 1 && mm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvcopysign(rbp.baseAddress!, mm.pointer, sm.pointer, [numericCast(sm.count)])
|
||||||
}
|
|
||||||
vvcopysign(rbp.baseAddress!, mp, sp, [Int32(sbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -142,27 +138,29 @@ public func copysign<S: ContinuousCollection, M: ContinuousCollection>(sign: S,
|
||||||
|
|
||||||
// MARK: Floor
|
// MARK: Floor
|
||||||
|
|
||||||
public func floor<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// Elemen-wise floor.
|
||||||
|
///
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func floor<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvfloorf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvfloorf(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func floor<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// Elemen-wise floor.
|
||||||
|
///
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func floor<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvfloor(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvfloor(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -170,27 +168,21 @@ public func floor<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.
|
||||||
|
|
||||||
// MARK: Negate
|
// MARK: Negate
|
||||||
|
|
||||||
public func neg<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
public func neg<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
vDSP_vneg(xm.pointer, xm.stride, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
return
|
|
||||||
}
|
|
||||||
vDSP_vneg(xp, 1, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func neg<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
public func neg<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
vDSP_vnegD(xm.pointer, xm.stride, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
return
|
|
||||||
}
|
|
||||||
vDSP_vnegD(xp, 1, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -198,27 +190,25 @@ public func neg<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.El
|
||||||
|
|
||||||
// MARK: Reciprocal
|
// MARK: Reciprocal
|
||||||
|
|
||||||
public func rec<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func rec<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvrecf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvrecf(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func rec<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func rec<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvrec(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvrec(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -226,27 +216,25 @@ public func rec<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.El
|
||||||
|
|
||||||
// MARK: Round
|
// MARK: Round
|
||||||
|
|
||||||
public func round<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func round<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvnintf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvnintf(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func round<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func round<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvnint(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvnint(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
@ -254,32 +242,26 @@ public func round<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.
|
||||||
|
|
||||||
// MARK: Threshold
|
// MARK: Threshold
|
||||||
|
|
||||||
public func threshold<C: ContinuousCollection>(_ x: C, low: Float) -> [Float] where C.Iterator.Element == Float {
|
public func threshold<C: UnsafeMemoryAccessible>(_ x: C, low: Float) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var y = low
|
var y = low
|
||||||
withUnsafePointer(to: &y) { y in
|
withUnsafePointer(to: &y) { y in
|
||||||
vDSP_vthr(xp, 1, y, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
vDSP_vthr(xm.pointer, xm.stride, y, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func threshold<C: ContinuousCollection>(_ x: C, low: Double) -> [Double] where C.Iterator.Element == Double {
|
public func threshold<C: UnsafeMemoryAccessible>(_ x: C, low: Double) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var y = low
|
var y = low
|
||||||
withUnsafePointer(to: &y) { y in
|
withUnsafePointer(to: &y) { y in
|
||||||
vDSP_vthrD(xp, 1, y, rbp.baseAddress!, 1, vDSP_Length(xbp.count))
|
vDSP_vthrD(xm.pointer, xm.stride, y, rbp.baseAddress!, 1, numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,27 +270,25 @@ public func threshold<C: ContinuousCollection>(_ x: C, low: Double) -> [Double]
|
||||||
|
|
||||||
// MARK: Truncate
|
// MARK: Truncate
|
||||||
|
|
||||||
public func trunc<C: ContinuousCollection>(_ x: C) -> [Float] where C.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func trunc<C: UnsafeMemoryAccessible>(_ x: C) -> [Float] where C.Element == Float {
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvintf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvintf(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func trunc<C: ContinuousCollection>(_ x: C) -> [Double] where C.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func trunc<C: UnsafeMemoryAccessible>(_ x: C) -> [Double] where C.Element == Double {
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
x.withUnsafeBufferPointer { xbp in
|
x.withUnsafeMemory { xm in
|
||||||
guard let xp = xbp.baseAddress else {
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
return
|
vvint(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
|
||||||
vvint(rbp.baseAddress!, xp, [Int32(xbp.count)])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
// Copyright © 2017 Alejandro Isaza
|
|
||||||
//
|
|
||||||
// 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 Foundation
|
|
||||||
|
|
||||||
/// A collection that has a C array representation: a continuous block of memory.
|
|
||||||
public protocol ContinuousCollection: Collection {
|
|
||||||
/// Calls a closure with a pointer to the array's contiguous storage.
|
|
||||||
///
|
|
||||||
/// The pointer passed as an argument to `body` is valid only during the execution of
|
|
||||||
/// `withUnsafeBufferPointer(_:)`. Do not store or return the pointer for later use.
|
|
||||||
///
|
|
||||||
/// - Parameter body: A closure with an `UnsafeBufferPointer` parameter that points to the contiguous storage for
|
|
||||||
/// the array. If `body` has a return value, that value is also used as the return value for the
|
|
||||||
/// `withUnsafeBufferPointer(_:)` method. The pointer argument is valid only for the duration of the method's
|
|
||||||
/// execution.
|
|
||||||
/// - Returns: The return value, if any, of the `body` closure parameter.
|
|
||||||
func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A mutable collection that has a C array representation: a continuous block of memory.
|
|
||||||
public protocol ContinuousMutableCollection: ContinuousCollection {
|
|
||||||
/// Calls the given closure with a pointer to the array's mutable contiguous storage.
|
|
||||||
///
|
|
||||||
/// The pointer passed as an argument to `body` is valid only during the execution of
|
|
||||||
/// `withUnsafeMutableBufferPointer(_:)`. Do not store or return the pointer for later use.
|
|
||||||
///
|
|
||||||
/// - Parameter body: A closure with an `UnsafeMutableBufferPointer` parameter that points to the contiguous
|
|
||||||
/// storage for the array. If `body` has a return value, that value is also used as the return value for the
|
|
||||||
/// `withUnsafeMutableBufferPointer(_:)` method. The pointer argument is valid only for the duration of the
|
|
||||||
/// method's execution.
|
|
||||||
/// - Returns: The return value, if any, of the `body` closure parameter.
|
|
||||||
mutating func withUnsafeMutableBufferPointer<R>(_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R) rethrows -> R
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Array: ContinuousMutableCollection {}
|
|
||||||
extension ContiguousArray: ContinuousMutableCollection {}
|
|
||||||
extension ArraySlice: ContinuousMutableCollection {}
|
|
|
@ -1,5 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
// Copyright © 2015-2016 Remy Prechelt
|
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -23,16 +22,16 @@ 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.
|
/// Convolution of a signal [x], with a kernel [k]. The signal must be at least as long as the kernel.
|
||||||
public func conv<X: ContinuousCollection, K: ContinuousCollection>(_ x: X, _ k: K) -> [Float] where X.Iterator.Element == Float, K.Iterator.Element == Float {
|
public func conv<X: UnsafeMemoryAccessible, K: UnsafeMemoryAccessible>(_ x: X, _ k: K) -> [Float] where X.Element == Float, K.Element == Float {
|
||||||
precondition(x.count >= k.count, "Input vector [x] must have at least as many elements as the kernel, [k]")
|
precondition(x.count >= k.count, "Input vector [x] must have at least as many elements as the kernel, [k]")
|
||||||
|
|
||||||
let resultSize = numericCast(x.count) + numericCast(k.count) - 1
|
let resultSize = numericCast(x.count) + numericCast(k.count) - 1
|
||||||
var result = [Float](repeating: 0, count: resultSize)
|
var result = [Float](repeating: 0, count: resultSize)
|
||||||
result.withUnsafeMutableBufferPointer { rbp in
|
result.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(k) { kp, kc in
|
k.withUnsafeMemory { km in
|
||||||
let kEnd = kp.advanced(by: kc - 1)
|
let kEnd = km.pointer.advanced(by: km.count * km.stride - 1)
|
||||||
let xPad = repeatElement(0 as Float, count: kc - 1)
|
let xPad = repeatElement(0 as Float, count: km.count - 1)
|
||||||
|
|
||||||
var xPadded = [Float]()
|
var xPadded = [Float]()
|
||||||
xPadded.reserveCapacity(xPad.count + numericCast(x.count) + xPad.count)
|
xPadded.reserveCapacity(xPad.count + numericCast(x.count) + xPad.count)
|
||||||
|
@ -40,22 +39,22 @@ public func conv<X: ContinuousCollection, K: ContinuousCollection>(_ x: X, _ k:
|
||||||
xPadded.append(contentsOf: x)
|
xPadded.append(contentsOf: x)
|
||||||
xPadded.append(contentsOf: xPad)
|
xPadded.append(contentsOf: xPad)
|
||||||
|
|
||||||
vDSP_conv(xPadded, 1, kEnd, -1, rbp.baseAddress!, 1, vDSP_Length(resultSize), vDSP_Length(kc))
|
vDSP_conv(xPadded, 1, kEnd, -km.stride, rbp.baseAddress!, 1, numericCast(resultSize), numericCast(km.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convolution of a signal [x], with a kernel [k]. The signal must be at least as long as the kernel.
|
/// Convolution of a signal [x], with a kernel [k]. The signal must be at least as long as the kernel.
|
||||||
public func conv<X: ContinuousCollection, K: ContinuousCollection>(_ x: X, _ k: K) -> [Double] where X.Iterator.Element == Double, K.Iterator.Element == Double {
|
public func conv<X: UnsafeMemoryAccessible, K: UnsafeMemoryAccessible>(_ x: X, _ k: K) -> [Double] where X.Element == Double, K.Element == Double {
|
||||||
precondition(x.count >= k.count, "Input vector [x] must have at least as many elements as the kernel, [k]")
|
precondition(x.count >= k.count, "Input vector [x] must have at least as many elements as the kernel, [k]")
|
||||||
|
|
||||||
let resultSize = numericCast(x.count) + numericCast(k.count) - 1
|
let resultSize = numericCast(x.count) + numericCast(k.count) - 1
|
||||||
var result = [Double](repeating: 0, count: resultSize)
|
var result = [Double](repeating: 0, count: resultSize)
|
||||||
result.withUnsafeMutableBufferPointer { rbp in
|
result.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(k) { kp, kc in
|
k.withUnsafeMemory { km in
|
||||||
let kEnd = kp.advanced(by: kc - 1)
|
let kEnd = km.pointer.advanced(by: km.count * km.stride - 1)
|
||||||
let xPad = repeatElement(0 as Double, count: kc - 1)
|
let xPad = repeatElement(0 as Double, count: km.count - 1)
|
||||||
|
|
||||||
var xPadded = [Double]()
|
var xPadded = [Double]()
|
||||||
xPadded.reserveCapacity(xPad.count + numericCast(x.count) + xPad.count)
|
xPadded.reserveCapacity(xPad.count + numericCast(x.count) + xPad.count)
|
||||||
|
@ -63,7 +62,7 @@ public func conv<X: ContinuousCollection, K: ContinuousCollection>(_ x: X, _ k:
|
||||||
xPadded.append(contentsOf: x)
|
xPadded.append(contentsOf: x)
|
||||||
xPadded.append(contentsOf: xPad)
|
xPadded.append(contentsOf: xPad)
|
||||||
|
|
||||||
vDSP_convD(xPadded, 1, kEnd, -1, rbp.baseAddress!, 1, vDSP_Length(resultSize), vDSP_Length(kc))
|
vDSP_convD(xPadded, 1, kEnd, -km.stride, rbp.baseAddress!, 1, numericCast(resultSize), numericCast(km.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -71,9 +70,9 @@ public func conv<X: ContinuousCollection, K: ContinuousCollection>(_ x: X, _ k:
|
||||||
|
|
||||||
// MARK: Cross-Correlation
|
// MARK: Cross-Correlation
|
||||||
|
|
||||||
// Cross-correlation of a signal [x], with another signal [y]. The signal [y]
|
/// Cross-correlation of a signal [x], with another signal [y]. The signal [y]
|
||||||
// is padded so that it is the same length as [x].
|
/// is padded so that it is the same length as [x].
|
||||||
public func xcorr<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
public func xcorr<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
precondition(x.count >= y.count, "Input vector [x] must have at least as many elements as [y]")
|
precondition(x.count >= y.count, "Input vector [x] must have at least as many elements as [y]")
|
||||||
var yPadded = [Float](y)
|
var yPadded = [Float](y)
|
||||||
if x.count > y.count {
|
if x.count > y.count {
|
||||||
|
@ -92,15 +91,15 @@ public func xcorr<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y:
|
||||||
xPadded.append(contentsOf: xPad)
|
xPadded.append(contentsOf: xPad)
|
||||||
|
|
||||||
result.withUnsafeMutableBufferPointer { rbp in
|
result.withUnsafeMutableBufferPointer { rbp in
|
||||||
vDSP_conv(xPadded, 1, yPadded, 1, rbp.baseAddress!, 1, vDSP_Length(resultSize), vDSP_Length(yPadded.count))
|
vDSP_conv(xPadded, 1, yPadded, 1, rbp.baseAddress!, 1, numericCast(resultSize), numericCast(yPadded.count))
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cross-correlation of a signal [x], with another signal [y]. The signal [y]
|
/// Cross-correlation of a signal [x], with another signal [y]. The signal [y]
|
||||||
// is padded so that it is the same length as [x].
|
/// is padded so that it is the same length as [x].
|
||||||
public func xcorr<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
public func xcorr<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
precondition(x.count >= y.count, "Input vector [x] must have at least as many elements as [y]")
|
precondition(x.count >= y.count, "Input vector [x] must have at least as many elements as [y]")
|
||||||
var yPadded = [Double](y)
|
var yPadded = [Double](y)
|
||||||
if x.count > y.count {
|
if x.count > y.count {
|
||||||
|
@ -119,7 +118,7 @@ public func xcorr<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y:
|
||||||
xPadded.append(contentsOf: xPad)
|
xPadded.append(contentsOf: xPad)
|
||||||
|
|
||||||
result.withUnsafeMutableBufferPointer { rbp in
|
result.withUnsafeMutableBufferPointer { rbp in
|
||||||
vDSP_convD(xPadded, 1, yPadded, 1, rbp.baseAddress!, 1, vDSP_Length(resultSize), vDSP_Length(yPadded.count))
|
vDSP_convD(xPadded, 1, yPadded, 1, rbp.baseAddress!, 1, numericCast(resultSize), numericCast(yPadded.count))
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -127,8 +126,8 @@ public func xcorr<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y:
|
||||||
|
|
||||||
// MARK: Auto-correlation
|
// MARK: Auto-correlation
|
||||||
|
|
||||||
// Auto-correlation of a signal [x]
|
/// Auto-correlation of a signal [x]
|
||||||
public func xcorr<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
public func xcorr<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
let resultSize = 2*numericCast(x.count) - 1
|
let resultSize = 2*numericCast(x.count) - 1
|
||||||
var result = [Float](repeating: 0, count: resultSize)
|
var result = [Float](repeating: 0, count: resultSize)
|
||||||
let xPad = repeatElement(0 as Float, count: numericCast(x.count) - 1)
|
let xPad = repeatElement(0 as Float, count: numericCast(x.count) - 1)
|
||||||
|
@ -139,17 +138,17 @@ public func xcorr<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.E
|
||||||
xPadded.append(contentsOf: x)
|
xPadded.append(contentsOf: x)
|
||||||
xPadded.append(contentsOf: xPad)
|
xPadded.append(contentsOf: xPad)
|
||||||
|
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
x.withUnsafeMemory { xm in
|
||||||
result.withUnsafeMutableBufferPointer { rbp in
|
result.withUnsafeMutableBufferPointer { rbp in
|
||||||
vDSP_conv(xPadded, 1, xp, 1, rbp.baseAddress!, 1, vDSP_Length(resultSize), vDSP_Length(xc))
|
vDSP_conv(xPadded, 1, xm.pointer, xm.stride, rbp.baseAddress!, 1, numericCast(resultSize), numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-correlation of a signal [x]
|
/// Auto-correlation of a signal [x]
|
||||||
public func xcorr<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
public func xcorr<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
let resultSize = 2*numericCast(x.count) - 1
|
let resultSize = 2*numericCast(x.count) - 1
|
||||||
var result = [Double](repeating: 0, count: resultSize)
|
var result = [Double](repeating: 0, count: resultSize)
|
||||||
let xPad = repeatElement(0 as Double, count: numericCast(x.count) - 1)
|
let xPad = repeatElement(0 as Double, count: numericCast(x.count) - 1)
|
||||||
|
@ -160,9 +159,9 @@ public func xcorr<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.
|
||||||
xPadded.append(contentsOf: x)
|
xPadded.append(contentsOf: x)
|
||||||
xPadded.append(contentsOf: xPad)
|
xPadded.append(contentsOf: xPad)
|
||||||
|
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
x.withUnsafeMemory { xm in
|
||||||
result.withUnsafeMutableBufferPointer { rbp in
|
result.withUnsafeMutableBufferPointer { rbp in
|
||||||
vDSP_convD(xPadded, 1, xp, 1, rbp.baseAddress!, 1, vDSP_Length(resultSize), vDSP_Length(xc))
|
vDSP_convD(xPadded, 1, xm.pointer, xm.stride, rbp.baseAddress!, 1, numericCast(resultSize), numericCast(xm.count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -22,132 +22,156 @@ import Accelerate
|
||||||
|
|
||||||
// MARK: Exponentiation
|
// MARK: Exponentiation
|
||||||
|
|
||||||
public func exp<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - 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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvexpf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvexpf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func exp<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - 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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvexp(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvexp(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Square Exponentiation
|
// MARK: Square Exponentiation
|
||||||
|
|
||||||
public func exp2<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - 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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvexp2f(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvexp2f(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func exp2<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - 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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvexp2(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvexp2(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Natural Logarithm
|
// MARK: Natural Logarithm
|
||||||
|
|
||||||
public func log<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func log<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](x)
|
var results = [Float](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlogf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlogf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func log<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func log<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](x)
|
var results = [Double](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlog(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlog(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Base-2 Logarithm
|
// MARK: Base-2 Logarithm
|
||||||
|
|
||||||
public func log2<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func log2<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](x)
|
var results = [Float](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlog2f(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlog2f(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func log2<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func log2<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](x)
|
var results = [Double](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlog2(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlog2(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Base-10 Logarithm
|
// MARK: Base-10 Logarithm
|
||||||
|
|
||||||
public func log10<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func log10<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](x)
|
var results = [Float](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlog10f(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlog10f(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func log10<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func log10<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](x)
|
var results = [Double](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlog10(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlog10(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Logarithmic Exponentiation
|
// MARK: Logarithmic Exponentiation
|
||||||
|
|
||||||
public func logb<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func logb<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](x)
|
var results = [Float](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlogbf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlogbf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func logb<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func logb<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](x)
|
var results = [Double](x)
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvlogb(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvlogb(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -22,144 +22,156 @@ import Accelerate
|
||||||
|
|
||||||
// MARK: Hyperbolic Sine
|
// MARK: Hyperbolic Sine
|
||||||
|
|
||||||
public func sinh<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func sinh<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvsinhf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvsinhf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func sinh<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func sinh<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Iterator.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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvsinh(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvsinh(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Hyperbolic Cosine
|
// MARK: Hyperbolic Cosine
|
||||||
|
|
||||||
public func cosh<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func cosh<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvcoshf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvcoshf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func cosh<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func cosh<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Iterator.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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvcosh(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvcosh(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Hyperbolic Tangent
|
// MARK: Hyperbolic Tangent
|
||||||
|
|
||||||
public func tanh<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func tanh<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvtanhf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvtanhf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func tanh<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func tanh<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Iterator.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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvtanh(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvtanh(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Inverse Hyperbolic Sine
|
// MARK: Inverse Hyperbolic Sine
|
||||||
|
|
||||||
public func asinh<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func asinh<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvasinhf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvasinhf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func asinh<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func asinh<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Iterator.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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvasinh(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvasinh(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Inverse Hyperbolic Cosine
|
// MARK: Inverse Hyperbolic Cosine
|
||||||
|
|
||||||
public func acosh<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func acosh<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvacoshf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvacoshf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func acosh<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func acosh<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Iterator.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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvacosh(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvacosh(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Inverse Hyperbolic Tangent
|
// MARK: Inverse Hyperbolic Tangent
|
||||||
|
|
||||||
public func atanh<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func atanh<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Iterator.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))
|
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvatanhf(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvatanhf(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func atanh<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func atanh<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Iterator.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))
|
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
||||||
results.withUnsafeMutableBufferPointer { rbp in
|
results.withUnsafeMutableBufferPointer { rbp in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvatanh(rbp.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvatanh(rbp.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -318,10 +318,10 @@ public func inv(_ x: Matrix<Float>) -> Matrix<Float> {
|
||||||
var error: __CLPK_integer = 0
|
var error: __CLPK_integer = 0
|
||||||
var nc = __CLPK_integer(x.columns)
|
var nc = __CLPK_integer(x.columns)
|
||||||
|
|
||||||
withUnsafeMutableBufferPointersTo(&ipiv, &work, &(results.grid)) { ipiv, work, grid in
|
withUnsafeMutablePointers(&nc, &lwork, &error) { nc, lwork, error in
|
||||||
withUnsafeMutablePointersTo(&nc, &lwork, &error) { nc, lwork, error in
|
withUnsafeMutableMemory(&ipiv, &work, &(results.grid)) { ipiv, work, grid in
|
||||||
sgetrf_(nc, nc, grid.baseAddress!, nc, ipiv.baseAddress!, error)
|
sgetrf_(nc, nc, grid.pointer, nc, ipiv.pointer, error)
|
||||||
sgetri_(nc, grid.baseAddress!, nc, ipiv.baseAddress!, work.baseAddress!, lwork, error)
|
sgetri_(nc, grid.pointer, nc, ipiv.pointer, work.pointer, lwork, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,10 +341,10 @@ public func inv(_ x: Matrix<Double>) -> Matrix<Double> {
|
||||||
var error: __CLPK_integer = 0
|
var error: __CLPK_integer = 0
|
||||||
var nc = __CLPK_integer(x.columns)
|
var nc = __CLPK_integer(x.columns)
|
||||||
|
|
||||||
withUnsafeMutableBufferPointersTo(&ipiv, &work, &(results.grid)) { ipiv, work, grid in
|
withUnsafeMutablePointers(&nc, &lwork, &error) { nc, lwork, error in
|
||||||
withUnsafeMutablePointersTo(&nc, &lwork, &error) { nc, lwork, error in
|
withUnsafeMutableMemory(&ipiv, &work, &(results.grid)) { ipiv, work, grid in
|
||||||
dgetrf_(nc, nc, grid.baseAddress!, nc, ipiv.baseAddress!, error)
|
dgetrf_(nc, nc, grid.pointer, nc, ipiv.pointer, error)
|
||||||
dgetri_(nc, grid.baseAddress!, nc, ipiv.baseAddress!, work.baseAddress!, lwork, error)
|
dgetri_(nc, grid.pointer, nc, ipiv.pointer, work.pointer, lwork, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,9 +378,9 @@ public func det(_ x: Matrix<Float>) -> Float? {
|
||||||
var info = __CLPK_integer()
|
var info = __CLPK_integer()
|
||||||
var m = __CLPK_integer(x.rows)
|
var m = __CLPK_integer(x.rows)
|
||||||
var n = __CLPK_integer(x.columns)
|
var n = __CLPK_integer(x.columns)
|
||||||
withUnsafeMutableBufferPointersTo(&pivots, &(decomposed.grid)) { ipiv, grid in
|
_ = withUnsafeMutableMemory(&pivots, &(decomposed.grid)) { ipiv, grid in
|
||||||
withUnsafeMutablePointersTo(&m, &n, &info) { m, n, info in
|
withUnsafeMutablePointers(&m, &n, &info) { m, n, info in
|
||||||
sgetrf_(m, n, grid.baseAddress!, m, ipiv.baseAddress!, info)
|
sgetrf_(m, n, grid.pointer, m, ipiv.pointer, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,9 +406,9 @@ public func det(_ x: Matrix<Double>) -> Double? {
|
||||||
var info = __CLPK_integer()
|
var info = __CLPK_integer()
|
||||||
var m = __CLPK_integer(x.rows)
|
var m = __CLPK_integer(x.rows)
|
||||||
var n = __CLPK_integer(x.columns)
|
var n = __CLPK_integer(x.columns)
|
||||||
withUnsafeMutableBufferPointersTo(&pivots, &(decomposed.grid)) { ipiv, grid in
|
_ = withUnsafeMutableMemory(&pivots, &(decomposed.grid)) { ipiv, grid in
|
||||||
withUnsafeMutablePointersTo(&m, &n, &info) { m, n, info in
|
withUnsafeMutablePointers(&m, &n, &info) { m, n, info in
|
||||||
dgetrf_(m, n, grid.baseAddress!, m, ipiv.baseAddress!, info)
|
dgetrf_(m, n, grid.pointer, m, ipiv.pointer, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2017 Alejandro Isaza
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -18,47 +18,13 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
// MARK: 1 Parameter
|
|
||||||
|
|
||||||
/// Invokes the given closure with buffer pointers to the given arrays (1 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeBufferPointer(_:)`
|
|
||||||
@discardableResult
|
|
||||||
public func withUnsafeBufferPointersTo<A: ContinuousCollection, Result>(_ a: A, body: (UnsafeBufferPointer<A.Element>) throws -> Result) rethrows -> Result {
|
|
||||||
return try a.withUnsafeBufferPointer { (a: UnsafeBufferPointer<A.Element>) throws -> Result in
|
|
||||||
try body(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invokes the given closure with pointers to the given arrays (1 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeBufferPointer(_:)`
|
|
||||||
public func withUnsafePointersAndCountsTo<A: ContinuousCollection>(_ a: A, body: (UnsafePointer<A.Element>, Int) throws -> Void) rethrows {
|
|
||||||
try a.withUnsafeBufferPointer { (a: UnsafeBufferPointer<A.Element>) throws -> Void in
|
|
||||||
if let ab = a.baseAddress {
|
|
||||||
try body(ab, a.count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invokes the given closure with mutable pointers to the given arrays (1 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeMutableBufferPointer(_:)`
|
|
||||||
public func withUnsafeMutablePointersAndCountsTo<A: ContinuousMutableCollection>(_ a: inout A, body: (UnsafeMutablePointer<A.Element>, Int) throws -> Void) rethrows {
|
|
||||||
try a.withUnsafeMutableBufferPointer { (a: inout UnsafeMutableBufferPointer<A.Element>) throws -> Void in
|
|
||||||
if let ab = a.baseAddress {
|
|
||||||
try body(ab, a.count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: 2 Parameter
|
// MARK: 2 Parameter
|
||||||
|
|
||||||
/// Invokes the given closure with pointers to the given arguments (2 parameter version).
|
/// Invokes the given closure with pointers to the given arguments (2 parameter version).
|
||||||
///
|
///
|
||||||
/// - See: `withUnsafePointer(to:body:)`
|
/// - See: `withUnsafePointer(to:body:)`
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func withUnsafePointersTo<A, B, Result>(_ a: inout A, _ b: inout B, body: (UnsafePointer<A>, UnsafePointer<B>) throws -> Result) rethrows -> Result {
|
public func withUnsafePointers<A, B, Result>(_ a: inout A, _ b: inout B, body: (UnsafePointer<A>, UnsafePointer<B>) throws -> Result) rethrows -> Result {
|
||||||
return try withUnsafePointer(to: &a) { (a: UnsafePointer<A>) throws -> Result in
|
return try withUnsafePointer(to: &a) { (a: UnsafePointer<A>) throws -> Result in
|
||||||
return try withUnsafePointer(to: &b) { (b: UnsafePointer<B>) throws -> Result in
|
return try withUnsafePointer(to: &b) { (b: UnsafePointer<B>) throws -> Result in
|
||||||
return try body(a, b)
|
return try body(a, b)
|
||||||
|
@ -70,7 +36,7 @@ public func withUnsafePointersTo<A, B, Result>(_ a: inout A, _ b: inout B, body:
|
||||||
///
|
///
|
||||||
/// - See: `withUnsafeMutablePointer(to:body:)`
|
/// - See: `withUnsafeMutablePointer(to:body:)`
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func withUnsafeMutablePointersTo<A, B, Result>(_ a: inout A, _ b: inout B, body: (UnsafeMutablePointer<A>, UnsafeMutablePointer<B>) throws -> Result) rethrows -> Result {
|
public func withUnsafeMutablePointers<A, B, Result>(_ a: inout A, _ b: inout B, body: (UnsafeMutablePointer<A>, UnsafeMutablePointer<B>) throws -> Result) rethrows -> Result {
|
||||||
return try withUnsafeMutablePointer(to: &a) { (a: UnsafeMutablePointer<A>) throws -> Result in
|
return try withUnsafeMutablePointer(to: &a) { (a: UnsafeMutablePointer<A>) throws -> Result in
|
||||||
return try withUnsafeMutablePointer(to: &b) { (b: UnsafeMutablePointer<B>) throws -> Result in
|
return try withUnsafeMutablePointer(to: &b) { (b: UnsafeMutablePointer<B>) throws -> Result in
|
||||||
return try body(a, b)
|
return try body(a, b)
|
||||||
|
@ -78,63 +44,13 @@ public func withUnsafeMutablePointersTo<A, B, Result>(_ a: inout A, _ b: inout B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invokes the given closure with pointers to the given arrays (2 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeBufferPointer(_:)`
|
|
||||||
@discardableResult
|
|
||||||
public func withUnsafeBufferPointersTo<A: ContinuousCollection, B: ContinuousCollection, Result>(_ a: A, _ b: B, body: (UnsafeBufferPointer<A.Element>, UnsafeBufferPointer<B.Element>) throws -> Result) rethrows -> Result {
|
|
||||||
return try a.withUnsafeBufferPointer { (a: UnsafeBufferPointer<A.Element>) throws -> Result in
|
|
||||||
try b.withUnsafeBufferPointer { (b: UnsafeBufferPointer<B.Element>) throws -> Result in
|
|
||||||
try body(a, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invokes the given closure with mutable pointers to the given arrays (2 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeMutableBufferPointer(_:)`
|
|
||||||
@discardableResult
|
|
||||||
public func withUnsafeMutableBufferPointersTo<A: ContinuousMutableCollection, B: ContinuousMutableCollection, Result>(_ a: inout A, _ b: inout B, body: (UnsafeMutableBufferPointer<A.Element>, UnsafeMutableBufferPointer<B.Element>) throws -> Result) rethrows -> Result {
|
|
||||||
return try a.withUnsafeMutableBufferPointer { (a: inout UnsafeMutableBufferPointer<A.Element>) throws -> Result in
|
|
||||||
try b.withUnsafeMutableBufferPointer { (b: inout UnsafeMutableBufferPointer<B.Element>) throws -> Result in
|
|
||||||
try body(a, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invokes the given closure with pointers to the given arrays (2 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeBufferPointer(_:)`
|
|
||||||
public func withUnsafePointersAndCountsTo<A: ContinuousCollection, B: ContinuousCollection>(_ a: A, _ b: B, body: (UnsafePointer<A.Element>, Int, UnsafePointer<B.Element>, Int) throws -> Void) rethrows {
|
|
||||||
try a.withUnsafeBufferPointer { (a: UnsafeBufferPointer<A.Element>) throws -> Void in
|
|
||||||
try b.withUnsafeBufferPointer { (b: UnsafeBufferPointer<B.Element>) throws -> Void in
|
|
||||||
if let ab = a.baseAddress, let bb = b.baseAddress {
|
|
||||||
try body(ab, a.count, bb, b.count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invokes the given closure with mutable pointers to the given arrays (2 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeMutableBufferPointer(_:)`
|
|
||||||
public func withUnsafeMutablePointersAndCountsTo<A: ContinuousMutableCollection, B: ContinuousMutableCollection>(_ a: inout A, _ b: inout B, body: (UnsafeMutablePointer<A.Element>, Int, UnsafeMutablePointer<B.Element>, Int) throws -> Void) rethrows {
|
|
||||||
try a.withUnsafeMutableBufferPointer { (a: inout UnsafeMutableBufferPointer<A.Element>) throws -> Void in
|
|
||||||
try b.withUnsafeMutableBufferPointer { (b: inout UnsafeMutableBufferPointer<B.Element>) throws -> Void in
|
|
||||||
if let ab = a.baseAddress, let bb = b.baseAddress {
|
|
||||||
try body(ab, a.count, bb, b.count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: 3 Parameter
|
// MARK: 3 Parameter
|
||||||
|
|
||||||
/// Invokes the given closure with pointers to the given arguments (3 parameter version).
|
/// Invokes the given closure with pointers to the given arguments (3 parameter version).
|
||||||
///
|
///
|
||||||
/// - See: `withUnsafePointer(to:body:)`
|
/// - See: `withUnsafePointer(to:body:)`
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func withUnsafePointersTo<A, B, C, Result>(_ a: inout A, _ b: inout B, _ c: inout C, body: (UnsafePointer<A>, UnsafePointer<B>, UnsafePointer<C>) throws -> Result) rethrows -> Result {
|
public func withUnsafePointers<A, B, C, Result>(_ a: inout A, _ b: inout B, _ c: inout C, body: (UnsafePointer<A>, UnsafePointer<B>, UnsafePointer<C>) throws -> Result) rethrows -> Result {
|
||||||
return try withUnsafePointer(to: &a) { (a: UnsafePointer<A>) throws -> Result in
|
return try withUnsafePointer(to: &a) { (a: UnsafePointer<A>) throws -> Result in
|
||||||
return try withUnsafePointer(to: &b) { (b: UnsafePointer<B>) throws -> Result in
|
return try withUnsafePointer(to: &b) { (b: UnsafePointer<B>) throws -> Result in
|
||||||
return try withUnsafePointer(to: &c) { (c: UnsafePointer<C>) throws -> Result in
|
return try withUnsafePointer(to: &c) { (c: UnsafePointer<C>) throws -> Result in
|
||||||
|
@ -148,7 +64,7 @@ public func withUnsafePointersTo<A, B, C, Result>(_ a: inout A, _ b: inout B, _
|
||||||
///
|
///
|
||||||
/// - See: `withUnsafeMutablePointer(to:body:)`
|
/// - See: `withUnsafeMutablePointer(to:body:)`
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func withUnsafeMutablePointersTo<A, B, C, Result>(_ a: inout A, _ b: inout B, _ c: inout C, body: (UnsafeMutablePointer<A>, UnsafeMutablePointer<B>, UnsafeMutablePointer<C>) throws -> Result) rethrows -> Result {
|
public func withUnsafeMutablePointers<A, B, C, Result>(_ a: inout A, _ b: inout B, _ c: inout C, body: (UnsafeMutablePointer<A>, UnsafeMutablePointer<B>, UnsafeMutablePointer<C>) throws -> Result) rethrows -> Result {
|
||||||
return try withUnsafeMutablePointer(to: &a) { (a: UnsafeMutablePointer<A>) throws -> Result in
|
return try withUnsafeMutablePointer(to: &a) { (a: UnsafeMutablePointer<A>) throws -> Result in
|
||||||
return try withUnsafeMutablePointer(to: &b) { (b: UnsafeMutablePointer<B>) throws -> Result in
|
return try withUnsafeMutablePointer(to: &b) { (b: UnsafeMutablePointer<B>) throws -> Result in
|
||||||
return try withUnsafeMutablePointer(to: &c) { (c: UnsafeMutablePointer<C>) throws -> Result in
|
return try withUnsafeMutablePointer(to: &c) { (c: UnsafeMutablePointer<C>) throws -> Result in
|
||||||
|
@ -157,31 +73,3 @@ public func withUnsafeMutablePointersTo<A, B, C, Result>(_ a: inout A, _ b: inou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invokes the given closure with pointers to the given arrays (3 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeBufferPointer(_:)`
|
|
||||||
@discardableResult
|
|
||||||
public func withUnsafeBufferPointersTo<A: ContinuousCollection, B: ContinuousCollection, C: ContinuousCollection, Result>(_ a: A, _ b: B, _ c: inout C, body: (UnsafeBufferPointer<A.Element>, UnsafeBufferPointer<B.Element>, UnsafeBufferPointer<C.Element>) throws -> Result) rethrows -> Result {
|
|
||||||
return try a.withUnsafeBufferPointer { (a: UnsafeBufferPointer<A.Element>) throws -> Result in
|
|
||||||
try b.withUnsafeBufferPointer { (b: UnsafeBufferPointer<B.Element>) throws -> Result in
|
|
||||||
try c.withUnsafeBufferPointer { (c: UnsafeBufferPointer<C.Element>) throws -> Result in
|
|
||||||
try body(a, b, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invokes the given closure with mutable pointers to the given arrays (3 parameter version).
|
|
||||||
///
|
|
||||||
/// - See: `Array.withUnsafeMutableBufferPointer(_:)`
|
|
||||||
@discardableResult
|
|
||||||
public func withUnsafeMutableBufferPointersTo<A: ContinuousMutableCollection, B: ContinuousMutableCollection, C: ContinuousMutableCollection, Result>(_ a: inout A, _ b: inout B, _ c: inout C, body: (UnsafeMutableBufferPointer<A.Element>, UnsafeMutableBufferPointer<B.Element>, UnsafeMutableBufferPointer<C.Element>) throws -> Result) rethrows -> Result {
|
|
||||||
return try a.withUnsafeMutableBufferPointer { (a: inout UnsafeMutableBufferPointer<A.Element>) throws -> Result in
|
|
||||||
try b.withUnsafeMutableBufferPointer { (b: inout UnsafeMutableBufferPointer<B.Element>) throws -> Result in
|
|
||||||
try c.withUnsafeMutableBufferPointer { (c: inout UnsafeMutableBufferPointer<C.Element>) throws -> Result in
|
|
||||||
try body(a, b, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -22,32 +22,36 @@ import Accelerate
|
||||||
|
|
||||||
// MARK: Power
|
// MARK: Power
|
||||||
|
|
||||||
public func pow<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Float] where X.Iterator.Element == Float, Y.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func pow<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Float] where X.Element == Float, Y.Element == Float {
|
||||||
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x, y) { xp, xc, yp, _ in
|
vvpowf(pointer.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
vvpowf(pointer.baseAddress!, xp, yp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pow<X: ContinuousCollection, Y: ContinuousCollection>(_ x: X, _ y: Y) -> [Double] where X.Iterator.Element == Double, Y.Iterator.Element == Double {
|
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
|
||||||
withUnsafePointersAndCountsTo(x, y) { xp, xc, yp, _ in
|
|
||||||
vvpow(pointer.baseAddress!, xp, yp, [Int32(xc)])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
|
public func pow<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible>(_ x: X, _ y: Y) -> [Double] where X.Element == Double, Y.Element == Double {
|
||||||
|
return withUnsafeMemory(x, y) { xm, ym in
|
||||||
|
precondition(xm.stride == 1 && ym.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
|
vvpow(pointer.baseAddress!, xm.pointer, ym.pointer, [numericCast(xm.count)])
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func pow<X: ContinuousCollection>(_ x: X, _ y: Float) -> [Float] where X.Iterator.Element == Float {
|
public func pow<X: UnsafeMemoryAccessible>(_ x: X, _ y: Float) -> [Float] where X.Element == Float {
|
||||||
let yVec = [Float](repeating: y, count: numericCast(x.count))
|
let yVec = [Float](repeating: y, count: numericCast(x.count))
|
||||||
return pow(yVec, x)
|
return pow(yVec, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pow<X: ContinuousCollection>(_ x: X, _ y: Double) -> [Double] where X.Iterator.Element == Double {
|
public func pow<X: UnsafeMemoryAccessible>(_ x: X, _ y: Double) -> [Double] where X.Element == Double {
|
||||||
let yVec = [Double](repeating: y, count: numericCast(x.count))
|
let yVec = [Double](repeating: y, count: numericCast(x.count))
|
||||||
return pow(yVec, x)
|
return pow(yVec, x)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -22,206 +22,242 @@ import Accelerate
|
||||||
|
|
||||||
// MARK: Sine-Cosine
|
// MARK: Sine-Cosine
|
||||||
|
|
||||||
public func sincos<X: ContinuousCollection>(_ x: X) -> (sin: [Float], cos: [Float]) where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var sin = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func sincos<X: UnsafeMemoryAccessible>(_ x: X) -> (sin: [Float], cos: [Float]) where X.Element == Float {
|
||||||
var cos = [Float](repeating: 0.0, count: numericCast(x.count))
|
return withUnsafeMemory(x) { xm in
|
||||||
withUnsafeMutableBufferPointersTo(&sin, &cos) { sin, cos in
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
var sin = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
vvsincosf(sin.baseAddress!, cos.baseAddress!, xp, [Int32(xc)])
|
var cos = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
}
|
withUnsafeMutableMemory(&sin, &cos) { sinm, cosm in
|
||||||
|
vvsincosf(sinm.pointer, cosm.pointer, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
}
|
||||||
return (sin, cos)
|
return (sin, cos)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func sincos<X: ContinuousCollection>(_ x: X) -> (sin: [Double], cos: [Double]) where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var sin = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func sincos<X: UnsafeMemoryAccessible>(_ x: X) -> (sin: [Double], cos: [Double]) where X.Element == Double {
|
||||||
var cos = [Double](repeating: 0.0, count: numericCast(x.count))
|
return withUnsafeMemory(x) { xm in
|
||||||
withUnsafeMutableBufferPointersTo(&sin, &cos) { sin, cos in
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
var sin = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
vvsincos(sin.baseAddress!, cos.baseAddress!, xp, [Int32(xc)])
|
var cos = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
}
|
withUnsafeMutableMemory(&sin, &cos) { sinm, cosm in
|
||||||
|
vvsincos(sinm.pointer, cosm.pointer, xm.pointer, [numericCast(xm.count)])
|
||||||
}
|
}
|
||||||
return (sin, cos)
|
return (sin, cos)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Sine
|
// MARK: Sine
|
||||||
|
|
||||||
public func sin<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func sin<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvsinf(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvsinf(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func sin<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func sin<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvsin(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvsin(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Cosine
|
// MARK: Cosine
|
||||||
|
|
||||||
public func cos<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func cos<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvcosf(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvcosf(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func cos<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func cos<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvcos(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvcos(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Tangent
|
// MARK: Tangent
|
||||||
|
|
||||||
public func tan<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func tan<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvtanf(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvtanf(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func tan<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func tan<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvtan(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvtan(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Arcsine
|
// MARK: Arcsine
|
||||||
|
|
||||||
public func asin<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func asin<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvasinf(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvasinf(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func asin<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func asin<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvasin(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvasin(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Arccosine
|
// MARK: Arccosine
|
||||||
|
|
||||||
public func acos<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func acos<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvacosf(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvacosf(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func acos<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func acos<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvacos(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvacos(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Arctangent
|
// MARK: Arctangent
|
||||||
|
|
||||||
public func atan<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
public func atan<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvatanf(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvatanf(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func atan<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
public func atan<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvatan(pointer.baseAddress!, xm.pointer, [numericCast(xm.count)])
|
||||||
vvatan(pointer.baseAddress!, xp, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
||||||
// MARK: Radians to Degrees
|
// MARK: Radians to Degrees
|
||||||
|
|
||||||
func rad2deg<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
func rad2deg<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
let divisor = [Float](repeating: Float.pi / 180.0, count: numericCast(x.count))
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
|
let divisor = [Float](repeating: Float.pi / 180.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvdivf(pointer.baseAddress!, xm.pointer, divisor, [numericCast(xm.count)])
|
||||||
vvdivf(pointer.baseAddress!, xp, divisor, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func rad2deg<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
func rad2deg<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
let divisor = [Double](repeating: Double.pi / 180.0, count: numericCast(x.count))
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
|
let divisor = [Double](repeating: Double.pi / 180.0, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvdiv(pointer.baseAddress!, xm.pointer, divisor, [numericCast(xm.count)])
|
||||||
vvdiv(pointer.baseAddress!, xp, divisor, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Degrees to Radians
|
// MARK: Degrees to Radians
|
||||||
|
|
||||||
func deg2rad<X: ContinuousCollection>(_ x: X) -> [Float] where X.Iterator.Element == Float {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Float](repeating: 0.0, count: numericCast(x.count))
|
func deg2rad<X: UnsafeMemoryAccessible>(_ x: X) -> [Float] where X.Element == Float {
|
||||||
let divisor = [Float](repeating: 180.0 / Float.pi, count: numericCast(x.count))
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Float](repeating: 0.0, count: numericCast(xm.count))
|
||||||
|
let divisor = [Float](repeating: 180.0 / Float.pi, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvdivf(pointer.baseAddress!, xm.pointer, divisor, [numericCast(xm.count)])
|
||||||
vvdivf(pointer.baseAddress!, xp, divisor, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func deg2rad<X: ContinuousCollection>(_ x: X) -> [Double] where X.Iterator.Element == Double {
|
/// - Warning: does not support memory stride (assumes stride is 1).
|
||||||
var results = [Double](repeating: 0.0, count: numericCast(x.count))
|
func deg2rad<X: UnsafeMemoryAccessible>(_ x: X) -> [Double] where X.Element == Double {
|
||||||
let divisor = [Double](repeating: 180.0 / Double.pi, count: numericCast(x.count))
|
return withUnsafeMemory(x) { xm in
|
||||||
|
precondition(xm.stride == 1, "\(#function) does not support strided memory access")
|
||||||
|
var results = [Double](repeating: 0.0, count: numericCast(xm.count))
|
||||||
|
let divisor = [Double](repeating: 180.0 / Double.pi, count: numericCast(xm.count))
|
||||||
results.withUnsafeMutableBufferPointer { pointer in
|
results.withUnsafeMutableBufferPointer { pointer in
|
||||||
withUnsafePointersAndCountsTo(x) { xp, xc in
|
vvdiv(pointer.baseAddress!, xm.pointer, divisor, [numericCast(xm.count)])
|
||||||
vvdiv(pointer.baseAddress!, xp, divisor, [Int32(xc)])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
// 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 Foundation
|
||||||
|
|
||||||
|
/// Memory region.
|
||||||
|
public struct UnsafeMemory<Element>: Sequence {
|
||||||
|
/// Pointer to the first element
|
||||||
|
public var pointer: UnsafePointer<Element>
|
||||||
|
|
||||||
|
/// Pointer stride between elements
|
||||||
|
public var stride: Int
|
||||||
|
|
||||||
|
/// Number of elements
|
||||||
|
public var count: Int
|
||||||
|
|
||||||
|
public func makeIterator() -> UnsafeMemoryIterator<Element> {
|
||||||
|
return UnsafeMemoryIterator(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct UnsafeMemoryIterator<Element>: IteratorProtocol {
|
||||||
|
let base: UnsafeMemory<Element>
|
||||||
|
var index: Int?
|
||||||
|
|
||||||
|
public init(_ base: UnsafeMemory<Element>) {
|
||||||
|
self.base = base
|
||||||
|
}
|
||||||
|
|
||||||
|
public mutating func next() -> Element? {
|
||||||
|
let newIndex: Int
|
||||||
|
if let index = index {
|
||||||
|
newIndex = index + 1
|
||||||
|
} else {
|
||||||
|
newIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if newIndex >= base.count {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.index = newIndex
|
||||||
|
return base.pointer[newIndex * base.stride]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Protocol for collections that can be accessed via `UnsafeMemory`
|
||||||
|
public protocol UnsafeMemoryAccessible: Collection {
|
||||||
|
func withUnsafeMemory<Result>(_ body: (UnsafeMemory<Element>) throws -> Result) rethrows -> Result
|
||||||
|
}
|
||||||
|
|
||||||
|
public func withUnsafeMemory<X: UnsafeMemoryAccessible, Result>(_ x: X, _ body: (UnsafeMemory<X.Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try x.withUnsafeMemory(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func withUnsafeMemory<X: UnsafeMemoryAccessible, Y: UnsafeMemoryAccessible, Result>(_ x: X, _ y: Y, _ body: (UnsafeMemory<X.Element>, UnsafeMemory<Y.Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try x.withUnsafeMemory { xm in
|
||||||
|
try y.withUnsafeMemory { ym in
|
||||||
|
try body(xm, ym)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
// 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 Foundation
|
||||||
|
|
||||||
|
/// Mutable memory region.
|
||||||
|
public struct UnsafeMutableMemory<Element> {
|
||||||
|
/// Pointer to the first element
|
||||||
|
var pointer: UnsafeMutablePointer<Element>
|
||||||
|
|
||||||
|
/// Pointer stride between elements
|
||||||
|
var stride: Int
|
||||||
|
|
||||||
|
/// Number of elements
|
||||||
|
var count: Int
|
||||||
|
|
||||||
|
public func makeIterator() -> UnsafeMutableMemoryIterator<Element> {
|
||||||
|
return UnsafeMutableMemoryIterator(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct UnsafeMutableMemoryIterator<Element>: IteratorProtocol {
|
||||||
|
let base: UnsafeMutableMemory<Element>
|
||||||
|
var index: Int?
|
||||||
|
|
||||||
|
public init(_ base: UnsafeMutableMemory<Element>) {
|
||||||
|
self.base = base
|
||||||
|
}
|
||||||
|
|
||||||
|
public mutating func next() -> Element? {
|
||||||
|
let newIndex: Int
|
||||||
|
if let index = index {
|
||||||
|
newIndex = index + 1
|
||||||
|
} else {
|
||||||
|
newIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if newIndex >= base.count {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.index = newIndex
|
||||||
|
return base.pointer[newIndex * base.stride]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Protocol for mutable collections that can be accessed via `UnsafeMutableMemory`
|
||||||
|
public protocol UnsafeMutableMemoryAccessible: UnsafeMemoryAccessible {
|
||||||
|
mutating func withUnsafeMutableMemory<Result>(_ body: (UnsafeMutableMemory<Element>) throws -> Result) rethrows -> Result
|
||||||
|
}
|
||||||
|
|
||||||
|
public func withUnsafeMutableMemory<X: UnsafeMutableMemoryAccessible, Result>(_ x: inout X, _ body: (UnsafeMutableMemory<X.Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try x.withUnsafeMutableMemory(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func withUnsafeMutableMemory<X: UnsafeMutableMemoryAccessible, Y: UnsafeMutableMemoryAccessible, Result>(_ x: inout X, _ y: inout Y, _ body: (UnsafeMutableMemory<X.Element>, UnsafeMutableMemory<Y.Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try x.withUnsafeMutableMemory { xm in
|
||||||
|
try y.withUnsafeMutableMemory { ym in
|
||||||
|
try body(xm, ym)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func withUnsafeMutableMemory<X: UnsafeMutableMemoryAccessible, Y: UnsafeMutableMemoryAccessible, Z: UnsafeMutableMemoryAccessible, Result>(_ x: inout X, _ y: inout Y, _ z: inout Z, _ body: (UnsafeMutableMemory<X.Element>, UnsafeMutableMemory<Y.Element>, UnsafeMutableMemory<Z.Element>) throws -> Result) rethrows -> Result {
|
||||||
|
return try x.withUnsafeMutableMemory { xm in
|
||||||
|
try y.withUnsafeMutableMemory { ym in
|
||||||
|
try z.withUnsafeMutableMemory { zm in
|
||||||
|
try body(xm, ym, zm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -29,7 +29,7 @@ let sum = Surge.sum(n)
|
||||||
|
|
||||||
let a = [1.0, 3.0, 5.0, 7.0]
|
let a = [1.0, 3.0, 5.0, 7.0]
|
||||||
let b = [2.0, 4.0, 6.0, 8.0]
|
let b = [2.0, 4.0, 6.0, 8.0]
|
||||||
let product = Surge.mul(a, y: b)
|
let product = mul(a, b)
|
||||||
|
|
||||||
// MARK: - Matrix
|
// MARK: - Matrix
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
614AD33F1FC0AF72002BFE1C /* Pointers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394521F762B58002A4AD2 /* Pointers.swift */; };
|
614AD33F1FC0AF72002BFE1C /* Pointers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394521F762B58002A4AD2 /* Pointers.swift */; };
|
||||||
614AD3401FC0AF72002BFE1C /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
614AD3401FC0AF72002BFE1C /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
||||||
614AD3411FC0AF72002BFE1C /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
614AD3411FC0AF72002BFE1C /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
||||||
614AD3421FC0AF72002BFE1C /* ContinuousCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394E31F76D3ED002A4AD2 /* ContinuousCollection.swift */; };
|
|
||||||
614AD3431FC0AF77002BFE1C /* ArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */; };
|
614AD3431FC0AF77002BFE1C /* ArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */; };
|
||||||
614AD3441FC0AF77002BFE1C /* AuxiliaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */; };
|
614AD3441FC0AF77002BFE1C /* AuxiliaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */; };
|
||||||
614AD3451FC0AF77002BFE1C /* ConvolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */; };
|
614AD3451FC0AF77002BFE1C /* ConvolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */; };
|
||||||
|
@ -41,7 +40,6 @@
|
||||||
614AD3701FC0B0CC002BFE1C /* Pointers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394521F762B58002A4AD2 /* Pointers.swift */; };
|
614AD3701FC0B0CC002BFE1C /* Pointers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394521F762B58002A4AD2 /* Pointers.swift */; };
|
||||||
614AD3711FC0B0CC002BFE1C /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
614AD3711FC0B0CC002BFE1C /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
||||||
614AD3721FC0B0CC002BFE1C /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
614AD3721FC0B0CC002BFE1C /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
||||||
614AD3731FC0B0CC002BFE1C /* ContinuousCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394E31F76D3ED002A4AD2 /* ContinuousCollection.swift */; };
|
|
||||||
614AD3741FC0B0D2002BFE1C /* ArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */; };
|
614AD3741FC0B0D2002BFE1C /* ArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */; };
|
||||||
614AD3751FC0B0D2002BFE1C /* AuxiliaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */; };
|
614AD3751FC0B0D2002BFE1C /* AuxiliaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */; };
|
||||||
614AD3761FC0B0D2002BFE1C /* ConvolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */; };
|
614AD3761FC0B0D2002BFE1C /* ConvolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */; };
|
||||||
|
@ -62,7 +60,6 @@
|
||||||
614AD3921FC0B134002BFE1C /* Pointers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394521F762B58002A4AD2 /* Pointers.swift */; };
|
614AD3921FC0B134002BFE1C /* Pointers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394521F762B58002A4AD2 /* Pointers.swift */; };
|
||||||
614AD3931FC0B134002BFE1C /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
614AD3931FC0B134002BFE1C /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
||||||
614AD3941FC0B134002BFE1C /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
614AD3941FC0B134002BFE1C /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
||||||
614AD3951FC0B134002BFE1C /* ContinuousCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394E31F76D3ED002A4AD2 /* ContinuousCollection.swift */; };
|
|
||||||
615394561F762B59002A4AD2 /* Arithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6153944B1F762B58002A4AD2 /* Arithmetic.swift */; };
|
615394561F762B59002A4AD2 /* Arithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6153944B1F762B58002A4AD2 /* Arithmetic.swift */; };
|
||||||
615394571F762B59002A4AD2 /* Auxiliary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6153944C1F762B58002A4AD2 /* Auxiliary.swift */; };
|
615394571F762B59002A4AD2 /* Auxiliary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6153944C1F762B58002A4AD2 /* Auxiliary.swift */; };
|
||||||
615394581F762B59002A4AD2 /* Convolution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6153944D1F762B58002A4AD2 /* Convolution.swift */; };
|
615394581F762B59002A4AD2 /* Convolution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6153944D1F762B58002A4AD2 /* Convolution.swift */; };
|
||||||
|
@ -74,7 +71,6 @@
|
||||||
6153945E1F762B59002A4AD2 /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
6153945E1F762B59002A4AD2 /* Power.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394531F762B58002A4AD2 /* Power.swift */; };
|
||||||
6153945F1F762B59002A4AD2 /* Surge.h in Headers */ = {isa = PBXBuildFile; fileRef = 615394541F762B58002A4AD2 /* Surge.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
6153945F1F762B59002A4AD2 /* Surge.h in Headers */ = {isa = PBXBuildFile; fileRef = 615394541F762B58002A4AD2 /* Surge.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
615394601F762B59002A4AD2 /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
615394601F762B59002A4AD2 /* Trigonometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394551F762B58002A4AD2 /* Trigonometric.swift */; };
|
||||||
615394E41F76D3ED002A4AD2 /* ContinuousCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 615394E31F76D3ED002A4AD2 /* ContinuousCollection.swift */; };
|
|
||||||
61A0AD761F70D22600B99FFB /* ArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */; };
|
61A0AD761F70D22600B99FFB /* ArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */; };
|
||||||
61A0AD771F70D22600B99FFB /* AuxiliaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */; };
|
61A0AD771F70D22600B99FFB /* AuxiliaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */; };
|
||||||
61A0AD781F70D22600B99FFB /* ConvolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */; };
|
61A0AD781F70D22600B99FFB /* ConvolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */; };
|
||||||
|
@ -84,6 +80,22 @@
|
||||||
61A0AD7C1F70D22600B99FFB /* PowerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD731F70D22600B99FFB /* PowerTests.swift */; };
|
61A0AD7C1F70D22600B99FFB /* PowerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD731F70D22600B99FFB /* PowerTests.swift */; };
|
||||||
61A0AD7D1F70D22600B99FFB /* TrigonometricTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD741F70D22600B99FFB /* TrigonometricTests.swift */; };
|
61A0AD7D1F70D22600B99FFB /* TrigonometricTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD741F70D22600B99FFB /* TrigonometricTests.swift */; };
|
||||||
61A0AD7E1F70D22600B99FFB /* XCTestCase+Surge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD751F70D22600B99FFB /* XCTestCase+Surge.swift */; };
|
61A0AD7E1F70D22600B99FFB /* XCTestCase+Surge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A0AD751F70D22600B99FFB /* XCTestCase+Surge.swift */; };
|
||||||
|
61E930B8207002EA00694FCB /* UnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930B7207002EA00694FCB /* UnsafeMemory.swift */; };
|
||||||
|
61E930B9207002EA00694FCB /* UnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930B7207002EA00694FCB /* UnsafeMemory.swift */; };
|
||||||
|
61E930BA207002EA00694FCB /* UnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930B7207002EA00694FCB /* UnsafeMemory.swift */; };
|
||||||
|
61E930BB207002EA00694FCB /* UnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930B7207002EA00694FCB /* UnsafeMemory.swift */; };
|
||||||
|
61E930BD2070104600694FCB /* ArrayUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930BC2070104600694FCB /* ArrayUnsafeMemory.swift */; };
|
||||||
|
61E930BE2070104600694FCB /* ArrayUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930BC2070104600694FCB /* ArrayUnsafeMemory.swift */; };
|
||||||
|
61E930BF2070104600694FCB /* ArrayUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930BC2070104600694FCB /* ArrayUnsafeMemory.swift */; };
|
||||||
|
61E930C02070104600694FCB /* ArrayUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930BC2070104600694FCB /* ArrayUnsafeMemory.swift */; };
|
||||||
|
61E930C22070B69300694FCB /* UnsafeMutableMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C12070B69300694FCB /* UnsafeMutableMemory.swift */; };
|
||||||
|
61E930C32070B69300694FCB /* UnsafeMutableMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C12070B69300694FCB /* UnsafeMutableMemory.swift */; };
|
||||||
|
61E930C42070B69300694FCB /* UnsafeMutableMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C12070B69300694FCB /* UnsafeMutableMemory.swift */; };
|
||||||
|
61E930C52070B69300694FCB /* UnsafeMutableMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C12070B69300694FCB /* UnsafeMutableMemory.swift */; };
|
||||||
|
61E930C82070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C72070BCCD00694FCB /* ArraySliceUnsafeMemory.swift */; };
|
||||||
|
61E930C92070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C72070BCCD00694FCB /* ArraySliceUnsafeMemory.swift */; };
|
||||||
|
61E930CA2070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C72070BCCD00694FCB /* ArraySliceUnsafeMemory.swift */; };
|
||||||
|
61E930CB2070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E930C72070BCCD00694FCB /* ArraySliceUnsafeMemory.swift */; };
|
||||||
F8A1E1D519917C25009735E2 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8A1E1D219917C0B009735E2 /* Accelerate.framework */; };
|
F8A1E1D519917C25009735E2 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8A1E1D219917C0B009735E2 /* Accelerate.framework */; };
|
||||||
F8A1E1D719917C2B009735E2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8A1E1D619917C2B009735E2 /* Foundation.framework */; };
|
F8A1E1D719917C2B009735E2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8A1E1D619917C2B009735E2 /* Foundation.framework */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
@ -132,7 +144,6 @@
|
||||||
615394531F762B58002A4AD2 /* Power.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Power.swift; sourceTree = "<group>"; };
|
615394531F762B58002A4AD2 /* Power.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Power.swift; sourceTree = "<group>"; };
|
||||||
615394541F762B58002A4AD2 /* Surge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Surge.h; sourceTree = "<group>"; };
|
615394541F762B58002A4AD2 /* Surge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Surge.h; sourceTree = "<group>"; };
|
||||||
615394551F762B58002A4AD2 /* Trigonometric.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Trigonometric.swift; sourceTree = "<group>"; };
|
615394551F762B58002A4AD2 /* Trigonometric.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Trigonometric.swift; sourceTree = "<group>"; };
|
||||||
615394E31F76D3ED002A4AD2 /* ContinuousCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContinuousCollection.swift; sourceTree = "<group>"; };
|
|
||||||
61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArithmeticTests.swift; sourceTree = "<group>"; };
|
61A0AD6D1F70D22600B99FFB /* ArithmeticTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArithmeticTests.swift; sourceTree = "<group>"; };
|
||||||
61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuxiliaryTests.swift; sourceTree = "<group>"; };
|
61A0AD6E1F70D22600B99FFB /* AuxiliaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuxiliaryTests.swift; sourceTree = "<group>"; };
|
||||||
61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionTests.swift; sourceTree = "<group>"; };
|
61A0AD6F1F70D22600B99FFB /* ConvolutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionTests.swift; sourceTree = "<group>"; };
|
||||||
|
@ -145,6 +156,10 @@
|
||||||
61A0AD7F1F70D99B00B99FFB /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
61A0AD7F1F70D99B00B99FFB /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||||
61A0AD801F70D99B00B99FFB /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
|
61A0AD801F70D99B00B99FFB /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
|
||||||
61A0AD811F70D99B00B99FFB /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
|
61A0AD811F70D99B00B99FFB /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
|
||||||
|
61E930B7207002EA00694FCB /* UnsafeMemory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsafeMemory.swift; sourceTree = "<group>"; };
|
||||||
|
61E930BC2070104600694FCB /* ArrayUnsafeMemory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayUnsafeMemory.swift; sourceTree = "<group>"; };
|
||||||
|
61E930C12070B69300694FCB /* UnsafeMutableMemory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsafeMutableMemory.swift; sourceTree = "<group>"; };
|
||||||
|
61E930C72070BCCD00694FCB /* ArraySliceUnsafeMemory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArraySliceUnsafeMemory.swift; sourceTree = "<group>"; };
|
||||||
F84A6AAE19A9A72F007B53E1 /* SurgeTests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SurgeTests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
F84A6AAE19A9A72F007B53E1 /* SurgeTests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SurgeTests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
F8A1E1AA19917A79009735E2 /* Surge.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Surge.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
F8A1E1AA19917A79009735E2 /* Surge.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Surge.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
F8A1E1D219917C0B009735E2 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
|
F8A1E1D219917C0B009735E2 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
|
||||||
|
@ -221,6 +236,8 @@
|
||||||
children = (
|
children = (
|
||||||
615394541F762B58002A4AD2 /* Surge.h */,
|
615394541F762B58002A4AD2 /* Surge.h */,
|
||||||
6153944B1F762B58002A4AD2 /* Arithmetic.swift */,
|
6153944B1F762B58002A4AD2 /* Arithmetic.swift */,
|
||||||
|
61E930C72070BCCD00694FCB /* ArraySliceUnsafeMemory.swift */,
|
||||||
|
61E930BC2070104600694FCB /* ArrayUnsafeMemory.swift */,
|
||||||
6153944C1F762B58002A4AD2 /* Auxiliary.swift */,
|
6153944C1F762B58002A4AD2 /* Auxiliary.swift */,
|
||||||
6153944D1F762B58002A4AD2 /* Convolution.swift */,
|
6153944D1F762B58002A4AD2 /* Convolution.swift */,
|
||||||
6153944E1F762B58002A4AD2 /* Exponential.swift */,
|
6153944E1F762B58002A4AD2 /* Exponential.swift */,
|
||||||
|
@ -230,7 +247,8 @@
|
||||||
615394521F762B58002A4AD2 /* Pointers.swift */,
|
615394521F762B58002A4AD2 /* Pointers.swift */,
|
||||||
615394531F762B58002A4AD2 /* Power.swift */,
|
615394531F762B58002A4AD2 /* Power.swift */,
|
||||||
615394551F762B58002A4AD2 /* Trigonometric.swift */,
|
615394551F762B58002A4AD2 /* Trigonometric.swift */,
|
||||||
615394E31F76D3ED002A4AD2 /* ContinuousCollection.swift */,
|
61E930B7207002EA00694FCB /* UnsafeMemory.swift */,
|
||||||
|
61E930C12070B69300694FCB /* UnsafeMutableMemory.swift */,
|
||||||
);
|
);
|
||||||
path = Surge;
|
path = Surge;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -660,6 +678,8 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
614AD33E1FC0AF72002BFE1C /* Matrix.swift in Sources */,
|
614AD33E1FC0AF72002BFE1C /* Matrix.swift in Sources */,
|
||||||
|
61E930C32070B69300694FCB /* UnsafeMutableMemory.swift in Sources */,
|
||||||
|
61E930C92070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */,
|
||||||
614AD3391FC0AF72002BFE1C /* Auxiliary.swift in Sources */,
|
614AD3391FC0AF72002BFE1C /* Auxiliary.swift in Sources */,
|
||||||
614AD3411FC0AF72002BFE1C /* Trigonometric.swift in Sources */,
|
614AD3411FC0AF72002BFE1C /* Trigonometric.swift in Sources */,
|
||||||
614AD3381FC0AF72002BFE1C /* Arithmetic.swift in Sources */,
|
614AD3381FC0AF72002BFE1C /* Arithmetic.swift in Sources */,
|
||||||
|
@ -667,9 +687,10 @@
|
||||||
614AD33A1FC0AF72002BFE1C /* Convolution.swift in Sources */,
|
614AD33A1FC0AF72002BFE1C /* Convolution.swift in Sources */,
|
||||||
614AD33F1FC0AF72002BFE1C /* Pointers.swift in Sources */,
|
614AD33F1FC0AF72002BFE1C /* Pointers.swift in Sources */,
|
||||||
614AD33C1FC0AF72002BFE1C /* FFT.swift in Sources */,
|
614AD33C1FC0AF72002BFE1C /* FFT.swift in Sources */,
|
||||||
|
61E930BE2070104600694FCB /* ArrayUnsafeMemory.swift in Sources */,
|
||||||
|
61E930B9207002EA00694FCB /* UnsafeMemory.swift in Sources */,
|
||||||
614AD3401FC0AF72002BFE1C /* Power.swift in Sources */,
|
614AD3401FC0AF72002BFE1C /* Power.swift in Sources */,
|
||||||
614AD33B1FC0AF72002BFE1C /* Exponential.swift in Sources */,
|
614AD33B1FC0AF72002BFE1C /* Exponential.swift in Sources */,
|
||||||
614AD3421FC0AF72002BFE1C /* ContinuousCollection.swift in Sources */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -694,6 +715,8 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
614AD36F1FC0B0CC002BFE1C /* Matrix.swift in Sources */,
|
614AD36F1FC0B0CC002BFE1C /* Matrix.swift in Sources */,
|
||||||
|
61E930C42070B69300694FCB /* UnsafeMutableMemory.swift in Sources */,
|
||||||
|
61E930CA2070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */,
|
||||||
614AD36A1FC0B0CC002BFE1C /* Auxiliary.swift in Sources */,
|
614AD36A1FC0B0CC002BFE1C /* Auxiliary.swift in Sources */,
|
||||||
614AD3721FC0B0CC002BFE1C /* Trigonometric.swift in Sources */,
|
614AD3721FC0B0CC002BFE1C /* Trigonometric.swift in Sources */,
|
||||||
614AD3691FC0B0CC002BFE1C /* Arithmetic.swift in Sources */,
|
614AD3691FC0B0CC002BFE1C /* Arithmetic.swift in Sources */,
|
||||||
|
@ -701,9 +724,10 @@
|
||||||
614AD36B1FC0B0CC002BFE1C /* Convolution.swift in Sources */,
|
614AD36B1FC0B0CC002BFE1C /* Convolution.swift in Sources */,
|
||||||
614AD3701FC0B0CC002BFE1C /* Pointers.swift in Sources */,
|
614AD3701FC0B0CC002BFE1C /* Pointers.swift in Sources */,
|
||||||
614AD36D1FC0B0CC002BFE1C /* FFT.swift in Sources */,
|
614AD36D1FC0B0CC002BFE1C /* FFT.swift in Sources */,
|
||||||
|
61E930BF2070104600694FCB /* ArrayUnsafeMemory.swift in Sources */,
|
||||||
|
61E930BA207002EA00694FCB /* UnsafeMemory.swift in Sources */,
|
||||||
614AD3711FC0B0CC002BFE1C /* Power.swift in Sources */,
|
614AD3711FC0B0CC002BFE1C /* Power.swift in Sources */,
|
||||||
614AD36C1FC0B0CC002BFE1C /* Exponential.swift in Sources */,
|
614AD36C1FC0B0CC002BFE1C /* Exponential.swift in Sources */,
|
||||||
614AD3731FC0B0CC002BFE1C /* ContinuousCollection.swift in Sources */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -728,6 +752,8 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
614AD3911FC0B134002BFE1C /* Matrix.swift in Sources */,
|
614AD3911FC0B134002BFE1C /* Matrix.swift in Sources */,
|
||||||
|
61E930C52070B69300694FCB /* UnsafeMutableMemory.swift in Sources */,
|
||||||
|
61E930CB2070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */,
|
||||||
614AD38C1FC0B134002BFE1C /* Auxiliary.swift in Sources */,
|
614AD38C1FC0B134002BFE1C /* Auxiliary.swift in Sources */,
|
||||||
614AD3941FC0B134002BFE1C /* Trigonometric.swift in Sources */,
|
614AD3941FC0B134002BFE1C /* Trigonometric.swift in Sources */,
|
||||||
614AD38B1FC0B134002BFE1C /* Arithmetic.swift in Sources */,
|
614AD38B1FC0B134002BFE1C /* Arithmetic.swift in Sources */,
|
||||||
|
@ -735,9 +761,10 @@
|
||||||
614AD38D1FC0B134002BFE1C /* Convolution.swift in Sources */,
|
614AD38D1FC0B134002BFE1C /* Convolution.swift in Sources */,
|
||||||
614AD3921FC0B134002BFE1C /* Pointers.swift in Sources */,
|
614AD3921FC0B134002BFE1C /* Pointers.swift in Sources */,
|
||||||
614AD38F1FC0B134002BFE1C /* FFT.swift in Sources */,
|
614AD38F1FC0B134002BFE1C /* FFT.swift in Sources */,
|
||||||
|
61E930C02070104600694FCB /* ArrayUnsafeMemory.swift in Sources */,
|
||||||
|
61E930BB207002EA00694FCB /* UnsafeMemory.swift in Sources */,
|
||||||
614AD3931FC0B134002BFE1C /* Power.swift in Sources */,
|
614AD3931FC0B134002BFE1C /* Power.swift in Sources */,
|
||||||
614AD38E1FC0B134002BFE1C /* Exponential.swift in Sources */,
|
614AD38E1FC0B134002BFE1C /* Exponential.swift in Sources */,
|
||||||
614AD3951FC0B134002BFE1C /* ContinuousCollection.swift in Sources */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -762,6 +789,8 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
6153945C1F762B59002A4AD2 /* Matrix.swift in Sources */,
|
6153945C1F762B59002A4AD2 /* Matrix.swift in Sources */,
|
||||||
|
61E930C22070B69300694FCB /* UnsafeMutableMemory.swift in Sources */,
|
||||||
|
61E930C82070BCCD00694FCB /* ArraySliceUnsafeMemory.swift in Sources */,
|
||||||
615394571F762B59002A4AD2 /* Auxiliary.swift in Sources */,
|
615394571F762B59002A4AD2 /* Auxiliary.swift in Sources */,
|
||||||
615394601F762B59002A4AD2 /* Trigonometric.swift in Sources */,
|
615394601F762B59002A4AD2 /* Trigonometric.swift in Sources */,
|
||||||
615394561F762B59002A4AD2 /* Arithmetic.swift in Sources */,
|
615394561F762B59002A4AD2 /* Arithmetic.swift in Sources */,
|
||||||
|
@ -769,9 +798,10 @@
|
||||||
615394581F762B59002A4AD2 /* Convolution.swift in Sources */,
|
615394581F762B59002A4AD2 /* Convolution.swift in Sources */,
|
||||||
6153945D1F762B59002A4AD2 /* Pointers.swift in Sources */,
|
6153945D1F762B59002A4AD2 /* Pointers.swift in Sources */,
|
||||||
6153945A1F762B59002A4AD2 /* FFT.swift in Sources */,
|
6153945A1F762B59002A4AD2 /* FFT.swift in Sources */,
|
||||||
|
61E930BD2070104600694FCB /* ArrayUnsafeMemory.swift in Sources */,
|
||||||
|
61E930B8207002EA00694FCB /* UnsafeMemory.swift in Sources */,
|
||||||
6153945E1F762B59002A4AD2 /* Power.swift in Sources */,
|
6153945E1F762B59002A4AD2 /* Power.swift in Sources */,
|
||||||
615394591F762B59002A4AD2 /* Exponential.swift in Sources */,
|
615394591F762B59002A4AD2 /* Exponential.swift in Sources */,
|
||||||
615394E41F76D3ED002A4AD2 /* ContinuousCollection.swift in Sources */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
codeCoverageEnabled = "YES"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
<TestableReference
|
<TestableReference
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Workspace
|
<Workspace
|
||||||
version = "1.0">
|
version = "1.0">
|
||||||
<FileRef
|
|
||||||
location = "group:Surge.playground">
|
|
||||||
</FileRef>
|
|
||||||
<FileRef
|
<FileRef
|
||||||
location = "group:Surge.xcodeproj">
|
location = "group:Surge.xcodeproj">
|
||||||
</FileRef>
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:Surge.playground">
|
||||||
|
</FileRef>
|
||||||
</Workspace>
|
</Workspace>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2016 Remy Prechelt, Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2016 Wenbin Zhang, Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// Created by Wenbin Zhang on 2/13/16.
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2014–2015 Mattt Thompson (http://mattt.me)
|
// Copyright © 2014-2018 the Surge contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
Loading…
Reference in New Issue