Surge

一个 Swift 库,使用 Accelerate 框架为矩阵数学、数字信号处理和图像处理提供高性能功能。「A Swift library that uses the Accelerate framework to provide high-performance functions for matrix math, digital signal processing, and image manipulation.」

Github stars Tracking Chart

Surge

Surge 是一个 Swift 库,它使用 Accelerate 框架为矩阵数学、数字信号处理和图像处理提供高性能功能。

Accelerate 公开了现代 CPU 中可用的 SIMD 指令,以显着提高某些计算的性能。由于它的相对模糊性和 API 的不便,开发人员不经常使用 Accelerate,这很可惜,因为许多应用程序可以从这些性能优化中受益。

Surge 旨在将 Accelerate 推向主流,使对一组数字的计算与单个成员一样容易(在大多数情况下,几乎一样快)。

不过,请记住:Accelerate 不是灵丹妙药。在某些条件下,例如对较小的数据集执行简单的计算,Accelerate 可能无法通过常规算法执行。始终以基准确定每种潜在方法的性能特征。

对 Surge 这个名字感到好奇吗? (还有Jounce?)早在90年代中期,苹果,IBM和摩托罗拉就联手创建了AltiVec(又称为Velocity Engine),该引擎为PowerPC架构提供了SIMD指令集。当苹果公司切换到英特尔CPU时,AltiVec被移植到x86架构并改名为Accelerate。 Accelerate的导数(和Velocity的二阶导数)被称为跳动,颠簸,波动或倾斜。如果您使用激增的派生形式,则会产生混乱---因此,该库的名称及其上级组织。

安装

在 Swift 和 Xcode 的测试阶段,用于分发 Swift 库的基础结构和最佳实践目前处于不断变化中。 同时,您可以将 Surge 作为 git 子模块添加,将 Surge.xcodeproj 文件拖到 Xcode 项目中,并将 Surge.framework 添加为目标的依赖项。

Surge 使用 Swift5。这意味着由于当前二进制兼容性限制,您的代码必须用 Swift 5 编写。

许可

根据 MIT 许可,可以使用 Surge。 有关更多信息,请参见 LICENSE 文件。

Overview

Name With OwnerJounce/Surge
Primary LanguageSwift
Program languageSwift (Language Count: 3)
PlatformMac
License:MIT License
Release Count12
Last Release Name2.3.2 (Posted on )
First Release Name0.1.0 (Posted on )
Created At2014-08-08 13:03:42
Pushed At2023-07-20 14:04:23
Last Commit At2023-07-19 22:44:24
Stargazers Count5.2k
Watchers Count157
Fork Count475
Commits Count346
Has Issues Enabled
Issues Count77
Issue Open Count14
Pull Requests Count83
Pull Requests Open Count1
Pull Requests Close Count24
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Surge

Build Status
License
CocoaPods platforms
CocoaPods compatible
Carthage compatible
Swift Package Manager compatible

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.

Swift Package Manager

To use Swift Package Manager add Surge to your Package.swift file:

let package = Package(
    name: "myproject",
    dependencies: [
        .package(url: "https://github.com/Jounce/Surge.git", .upToNextMajor(from: "2.3.2")),
    ],
    targets: [
        .target(
            name: "myproject",
            dependencies: ["Surge"]),
    ]
)

Then run swift build.

CocoaPods

To use CocoaPods add Surge to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Surge', '~> 2.3.2'
end

Then run pod install.

Carthage

To use Carthage add Surge to your Cartfile:

github "Jounce/Surge" ~> 2.3.2

Then run carthage update and use the framework in Carthage/Build/<platform>.


Usage

Computing Sum of [Double]

import Surge

let n = [1.0, 2.0, 3.0, 4.0, 5.0]
let sum = Surge.sum(n) // 15.0

Computing Product of Two [Double]s

import Surge

let a = [1.0, 3.0, 5.0, 7.0]
let b = [2.0, 4.0, 6.0, 8.0]

let product = Surge.elmul(a, b) // [2.0, 12.0, 30.0, 56.0]

Inventory

General Arithmetic Operations

Addition

Arguments Function Operator In-Place Operator
(Array, Array) add .+ (infix) .+= (infix)
(Array, Scalar) add + (infix) += (infix)
(Matrix, Matrix) add + (infix) += (infix)
(Matrix, Scalar) n/a n/a n/a
(Vector, Vector) add + (infix) += (infix)
(Vector, Scalar) add + (infix) += (infix)

Subtraction

Arguments Function Operator In-Place Operator
(Array, Array) sub .- (infix) .-= (infix)
(Array, Scalar) sub - (infix) -= (infix)
(Matrix, Matrix) sub - (infix) -= (infix)
(Matrix, Scalar) n/a n/a n/a
(Vector, Vector) sub - (infix) -= (infix)
(Vector, Scalar) sub - (infix) -= (infix)

Multiplication

Arguments Function Operator In-Place Operator
(Array, Array) mul .* (infix) .*= (infix)
(Array, Scalar) mul * (infix) *= (infix)
(Matrix, Matrix) mul * (infix) n/a
(Matrix, Vector) mul * (infix) n/a
(Matrix, Scalar) mul * (infix) n/a
(Vector, Matrix) mul * (infix) n/a
(Vector, Scalar) mul * (infix) *= (infix)
(Scalar, Array) mul * (infix) n/a
(Scalar, Matrix) mul * (infix) n/a
(Scalar, Vector) mul * (infix) n/a

Element-wise multiplication

Arguments Function Operator In-Place Operator
(Matrix, Matrix) elmul n/a n/a
(Vector, Vector) elmul .* (infix) .*= (infix)

Division

Arguments Function Operator In-Place Operator
(Array, Array) div ./ (infix) ./= (infix)
(Array, Scalar) div / (infix) /= (infix)
(Matrix, Matrix) div / (infix) n/a
(Matrix, Scalar) n/a / (infix) n/a
(Vector, Scalar) div / (infix) /= (infix)

Element-wise Division

Arguments Function Operator In-Place Operator
(Vector, Vector) eldiv ./ (infix) ./= (infix)

Modulo

Arguments Function Operator In-Place Operator
(Array, Array) mod .% (infix) n/a
(Array, Scalar) mod % (infix) n/a

Remainder

Arguments Function Operator In-Place Operator
(Array, Array) remainder n/a n/a
(Array, Scalar) remainder n/a n/a

Square Root

Arguments Function Operator In-Place Operator
(Array) sqrt n/a n/a

Summation

Arguments Function Operator In-Place Operator
(Array) sum n/a n/a
(Matrix) sum n/a n/a

Dot Product

Arguments Function Operator In-Place Operator
(Array, Array) dot (infix) n/a
(Vector, Vector) dot (infix) n/a

Distance

Arguments Function Operator In-Place Operator
(Array, Array) dist n/a n/a
(Vector, Vector) dist n/a n/a

Squared Distance

Arguments Function Operator In-Place Operator
(Array, Array) distSq n/a n/a
(Vector, Vector) distSq n/a n/a

Power

Arguments Function Operator In-Place Operator
(Array, Array) pow .** (infix) .**= (infix)
(Array, Scalar) pow ** (infix) **= (infix)
(Matrix, Scalar) pow n/a n/a
(Vector, Vector) pow n/a n/a

(Serial exponentiation: a ** b ** c == a ** (b ** c))

Exponential

Arguments Function Operator In-Place Operator
(Array) exp n/a n/a
(Matrix) exp n/a n/a
(Vector) exp n/a n/a

Trigonometric Operations

Sine/Cosine/Tangent

Arguments Function Operation
(Array) sin Sine
(Array) cos Cosine
(Array) tan Tangent
(Array) sincos Sine & Cosine

Arc Sine/Cosine/Tangent

Arguments Function Operation
(Array) asin Arc Sine
(Array) acos Arc Cosine
(Array) atan Arc Tangent

Hyperbolic Sine/Cosine/Tangent

Arguments Function Operation
(Array) sinh Hyperbolic Sine
(Array) cosh Hyperbolic Cosine
(Array) tanh Hyperbolic Tangent

Inverse Hyperbolic Sine/Cosine/Tangent

Arguments Function Operation
(Array) asinh Inverse Hyperbolic Sine
(Array) acosh Inverse Hyperbolic Cosine
(Array) atanh Inverse Hyperbolic Tangent

Radians ↔︎ Degrees

Arguments Function Operation
(Array) rad2deg Radians to Degrees
(Array) deg2rad Degrees to Radians

Exponential Function

Arguments Function Operation
(Array) exp Base-e Exponential Function
(Array) exp2 Base-2 Exponential Function

Logarithm

Arguments Function Operation
(Array) log Base-e Logarithm
(Array) log2 Base-2 Logarithm
(Array) log10 Base-10 Logarithm
(Array) logb Base-b Logarithm

Statistical Operations

Summation

Arguments Function Operation
(Array) sum Summation
(Array) asum Absolute Summation

Minimum/Maximum

Arguments Function Operation
(Array) min Minimum
(Array) max Maximum

Mean/Variance

Arguments Function Operation
(Array) mean Mean
(Array) meamg Mean of Magnitudes
(Array) measq Mean of Squares
(Array) variance Variance
(Array) std Standard Deviation

Auxiliary Functions

Rounding Functions

Arguments Function Operation
(Array) ceil Ceiling
(Array) floor Flooring
(Array) round Rounding
(Array) trunc Integer truncation

Absolute value

Arguments Function In-Place Function Operator In-Place Operator
(Array) abs n/a n/a n/a

Signum function

Arguments Function In-Place Function Operator In-Place Operator
(Array) copysign n/a n/a n/a

Multiplicative inverse

Arguments Function In-Place Function Operator In-Place Operator
(Array) rec n/a n/a n/a

Matrix-specific Operations

Matrix Inversion

Arguments Function In-Place Function Operator In-Place Operator
(Matrix) inv n/a n/a n/a

Matrix Transposition

Arguments Function In-Place Function Operator In-Place Operator
(Matrix) transpose n/a (postfix) n/a

Matrix Determinant

Arguments Function In-Place Function Operator In-Place Operator
(Matrix) det n/a n/a n/a

Eigen Decomposition

Arguments Function In-Place Function Operator In-Place Operator
(Matrix) eigenDecompose n/a n/a n/a

DSP-specific Operations

Fast Fourier Transform

Arguments Function In-Place Function Operator In-Place Operator
(Array) fft n/a n/a n/a

Convolution

Arguments Function In-Place Function Operator In-Place Operator
(Array, Array) conv n/a n/a n/a

Cross-Correlation

Arguments Function In-Place Function Operator In-Place Operator
(Array, Array) xcorr n/a n/a n/a
(Array) xcorr n/a n/a n/a
To the top