Surge is a Swift library that uses the Accelerate framework to provide high-performance functions for matrix math, digital signal processing, and image manipulation.
Accelerate exposes SIMD instructions available in modern CPUs to significantly improve performance of certain calculations. Because of its relative obscurity and inconvenient APIs, Accelerate is not commonly used by developers, which is a shame, since many applications could benefit from these performance optimizations.
Surge aims to bring Accelerate to the mainstream, making it as easy (and nearly as fast, in most cases) to perform computation over a set of numbers as for a single member.
Though, keep in mind: Accelerate is not a silver bullet. Under certain conditions, such as performing simple calculations over a small data set, Accelerate can be out-performed by conventional algorithms. Always benchmark to determine the performance characteristics of each potential approach.
Curious about the name Surge? (And Jounce?)
Back in the mid 90’s, Apple, IBM, and Motorola teamed up to create
AltiVec (a.k.a the Velocity Engine),
which provided a SIMD instruction set for the PowerPC architecture.
When Apple made the switch to Intel CPUs,
AltiVec was ported to the x86 architecture and rechristened
Accelerate.
The derivative of Accelerate (and second derivative of Velocity)
is known as either jerk, jolt, surge, or lurch;
if you take the derivative of surge,
you get the jounce —
hence the name of this library and its parent organization.
Installation
The infrastructure and best practices for distributing Swift libraries are currently in flux during this beta period of Swift & Xcode. In the meantime, you can add Surge as a git submodule, drag the Surge.xcodeproj file into your Xcode project, and add Surge.framework as a dependency for your target.
Surge uses Swift 5. This means that your code has to be written in Swift 5 due to current binary compatibility limitations.
License
Surge is available under the MIT license. See the LICENSE file for more info.
Surge
Surge is a Swift library that uses the Accelerate framework to provide high-performance functions for matrix math, digital signal processing, and image manipulation.
Accelerate exposes SIMD instructions available in modern CPUs to significantly improve performance of certain calculations. Because of its relative obscurity and inconvenient APIs, Accelerate is not commonly used by developers, which is a shame, since many applications could benefit from these performance optimizations.
Surge aims to bring Accelerate to the mainstream, making it as easy (and nearly as fast, in most cases) to perform computation over a set of numbers as for a single member.
Though, keep in mind: Accelerate is not a silver bullet. Under certain conditions, such as performing simple calculations over a small data set, Accelerate can be out-performed by conventional algorithms. Always benchmark to determine the performance characteristics of each potential approach.
Installation
The infrastructure and best practices for distributing Swift libraries are currently in flux during this beta period of Swift & Xcode. In the meantime, you can add Surge as a git submodule, drag the
Surge.xcodeproj
file into your Xcode project, and addSurge.framework
as a dependency for your target.Surge uses Swift 5. This means that your code has to be written in Swift 5 due to current binary compatibility limitations.
License
Surge is available under the MIT license. See the LICENSE file for more info.
Swift Package Manager
To use Swift Package Manager add Surge to your
Package.swift
file:Then run
swift build
.CocoaPods
To use CocoaPods add Surge to your
Podfile
:Then run
pod install
.Carthage
To use Carthage add Surge to your
Cartfile
:Then run
carthage update
and use the framework inCarthage/Build/<platform>
.Usage
Computing Sum of
[Double]
Computing Product of Two
[Double]
sInventory
[Double]
[Double]
sGeneral Arithmetic Operations
Addition
Addition functions & operators
(Array, Array)
add
.+
(infix).+=
(infix)(Array, Scalar)
add
+
(infix)+=
(infix)(Matrix, Matrix)
add
+
(infix)+=
(infix)(Matrix, Scalar)
(Vector, Vector)
add
+
(infix)+=
(infix)(Vector, Scalar)
add
+
(infix)+=
(infix)Subtraction
Subtraction functions & operators
(Array, Array)
sub
.-
(infix).-=
(infix)(Array, Scalar)
sub
-
(infix)-=
(infix)(Matrix, Matrix)
sub
-
(infix)-=
(infix)(Matrix, Scalar)
(Vector, Vector)
sub
-
(infix)-=
(infix)(Vector, Scalar)
sub
-
(infix)-=
(infix)Multiplication
Multiplication functions & operators
(Array, Array)
mul
.*
(infix).*=
(infix)(Array, Scalar)
mul
*
(infix)*=
(infix)(Matrix, Matrix)
mul
*
(infix)(Matrix, Vector)
mul
*
(infix)(Matrix, Scalar)
mul
*
(infix)(Vector, Matrix)
mul
*
(infix)(Vector, Scalar)
mul
*
(infix)*=
(infix)(Scalar, Array)
mul
*
(infix)(Scalar, Matrix)
mul
*
(infix)(Scalar, Vector)
mul
*
(infix)Element-wise multiplication
Element-wise multiplication functions & operators
(Matrix, Matrix)
elmul
(Vector, Vector)
elmul
.*
(infix).*=
(infix)Division
Division functions & operators
(Array, Array)
div
./
(infix)./=
(infix)(Array, Scalar)
div
/
(infix)/=
(infix)(Matrix, Matrix)
div
/
(infix)(Matrix, Scalar)
/
(infix)(Vector, Scalar)
div
/
(infix)/=
(infix)Element-wise Division
Element-wise multiplication functions & operators
(Vector, Vector)
eldiv
./
(infix)./=
(infix)Modulo
Modulo functions & operators
(Array, Array)
mod
.%
(infix)(Array, Scalar)
mod
%
(infix)Remainder
Remainder functions & operators
(Array, Array)
remainder
(Array, Scalar)
remainder
Square Root
Square root functions & operators
(Array)
sqrt
Summation
Sum functions & operators
(Array)
sum
(Matrix)
sum
Dot Product
Dot product functions & operators
(Array, Array)
dot
•
(infix)(Vector, Vector)
dot
•
(infix)Distance
Distance functions & operators
(Array, Array)
dist
(Vector, Vector)
dist
Squared Distance
Squared distance functions & operators
(Array, Array)
distSq
(Vector, Vector)
distSq
Power
Power functions & operators
(Array, Array)
pow
.**
(infix).**=
(infix)(Array, Scalar)
pow
**
(infix)**=
(infix)(Matrix, Scalar)
pow
(Vector, Vector)
pow
(Serial exponentiation:
a ** b ** c == a ** (b ** c)
)Exponential
Exponential functions & operators
(Array)
exp
(Matrix)
exp
(Vector)
exp
Trigonometric Operations
Trigonometric functions & operators
Sine/Cosine/Tangent
(Array)
sin
(Array)
cos
(Array)
tan
(Array)
sincos
Arc Sine/Cosine/Tangent
(Array)
asin
(Array)
acos
(Array)
atan
Hyperbolic Sine/Cosine/Tangent
(Array)
sinh
(Array)
cosh
(Array)
tanh
Inverse Hyperbolic Sine/Cosine/Tangent
(Array)
asinh
(Array)
acosh
(Array)
atanh
Radians ↔︎ Degrees
(Array)
rad2deg
(Array)
deg2rad
Exponential Function
Exponential functions & operators
(Array)
exp
(Array)
exp2
Logarithm
Exponential functions & operators
(Array)
log
(Array)
log2
(Array)
log10
(Array)
logb
Statistical Operations
Statistical functions & operators
Summation
(Array)
sum
(Array)
asum
Minimum/Maximum
(Array)
min
(Array)
max
Mean/Variance
(Array)
mean
(Array)
meamg
(Array)
measq
(Array)
variance
(Array)
std
Auxiliary Functions
Auxiliary functions & operators
Rounding Functions
(Array)
ceil
(Array)
floor
(Array)
round
(Array)
trunc
Absolute value
(Array)
abs
Signum function
(Array)
copysign
Multiplicative inverse
(Array)
rec
Matrix-specific Operations
Matrix-specific functions & operators
Matrix Inversion
(Matrix)
inv
Matrix Transposition
(Matrix)
transpose
′
(postfix)Matrix Determinant
(Matrix)
det
Eigen Decomposition
(Matrix)
eigenDecompose
DSP-specific Operations
Fast fourier transform functions & operators
Fast Fourier Transform
(Array)
fft
Convolution
(Array, Array)
conv
Cross-Correlation
(Array, Array)
xcorr
(Array)
xcorr