All Projects → alejandro-isaza → Upsurge

alejandro-isaza / Upsurge

Licence: MIT license
Multi-dimensional Swift math

Labels

Projects that are alternatives of or similar to Upsurge

btc-bash-ng
math and bitcoin tools in gnu bc and bash
Stars: ✭ 25 (-86.11%)
Mutual labels:  math
Math
考研数学,数学一,包括高等数学、线性代数、概率统计
Stars: ✭ 300 (+66.67%)
Mutual labels:  math
manim
A community-maintained Python framework for creating mathematical animations.
Stars: ✭ 12,657 (+6931.67%)
Mutual labels:  math
matrixgl
Yet another matrix library for WebGL
Stars: ✭ 25 (-86.11%)
Mutual labels:  math
dart-more
More Dart — Literally.
Stars: ✭ 81 (-55%)
Mutual labels:  math
speedy-math
An application which allows user (small kids) to practice basic Mathematics operations
Stars: ✭ 28 (-84.44%)
Mutual labels:  math
mathcore
Advanced .NET math library (.NET Standard).
Stars: ✭ 24 (-86.67%)
Mutual labels:  math
langtons-ant
Langton’s Ant macOS screen saver written in Swift
Stars: ✭ 12 (-93.33%)
Mutual labels:  math
good-reads
List of inspiring articles, blogs, tutorials and books. Tech stuff.
Stars: ✭ 14 (-92.22%)
Mutual labels:  math
noteworthy
Markdown editor with bidirectional links and excellent math support, powered by ProseMirror. (In Development!)
Stars: ✭ 178 (-1.11%)
Mutual labels:  math
TensorFlow
Swift high-level API for TensorFlow.
Stars: ✭ 49 (-72.78%)
Mutual labels:  math
30secondchallenge
Inspired by the newspaper puzzle my wife's grandma tests me with each time I visit.
Stars: ✭ 19 (-89.44%)
Mutual labels:  math
d rive
c++17 compile time math(derivation/integration)
Stars: ✭ 16 (-91.11%)
Mutual labels:  math
HLML
Auto-generated maths library for C and C++ based on HLSL/Cg
Stars: ✭ 23 (-87.22%)
Mutual labels:  math
commons-statistics
Statistics
Stars: ✭ 35 (-80.56%)
Mutual labels:  math
python-baseconv
Python module to convert numbers from base 10 integers to base X strings and back again.
Stars: ✭ 40 (-77.78%)
Mutual labels:  math
mml-book-chinese
mml-book-chinese《Mathematics For Machine Learning》机器学习中的数学 中文版
Stars: ✭ 113 (-37.22%)
Mutual labels:  math
alokmenghrajani.github.com
Alok Menghrajani's Blog
Stars: ✭ 64 (-64.44%)
Mutual labels:  math
SCNMathExtensions
Math extensions for SCNVector3, SCNQuaternion, SCNMatrix4
Stars: ✭ 32 (-82.22%)
Mutual labels:  math
topologic
Visualiser for basic geometric primitives and fractals in arbitrary-dimensional spaces
Stars: ✭ 39 (-78.33%)
Mutual labels:  math

Upsurge

Upsurge implements multi-dimensional data structures and operations. It brings numpy-like operations to Swift.

Upsurge no longer supports DSP and other linear operations, please use Surge for that. Surge and Upsurge play nice together.

Features

  • Tensor and tensor slicing: tensor.asMatrix(1, 1, 0...4, 0...4)
  • Matrix and matrix operations: let result = A * B′
  • ValueArrays with explicit copying and numeric operators: let result = A • B

Installation

Upsurge supports both CocoaPods (pod 'Upsurge') and Carthage (github "aleph7/Upsurge"). For macOS apps you can use the Swift Package Manager to install Upsurge by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/aleph7/Upsurge.git", Version(0,8,.max)),
    ]
)

Usage

Arrays and vector operations

All of Upsurge's linear (1-dimensional) operations can be performed on anything that conforms to LinearType. Swift's built-in arrays and array slices conform to LinearType, of course. But Upsurge also defines the ValueArray class to store a one-dimensional collection of values. ValueArray is very similar to Swift's Array but it is optimized to reduce unnecessary memory allocation. These are the most important differences:

  • Its instances have a fixed size defined on creation. When you create a ValueArray you can define a capacity var a = ValueArray<Double>(capacity: 100) and then append elements up to that capacity. Or you can create it with specific elements var a: ValueArray = [1.0, 2.0, 3.0] but then you can't add any more elements after.
  • It is a class. That means that creating a new variable will only create a reference and modifying the reference will also modify the original. For instance doing var a: ValueArray = [1, 2, 3]; var b = a and then b[0] = 5 will result in a being [5, 2, 3]. If you want to create a copy you need to do var b = ValueArray(a) or var b = a.copy().
  • You can create an uninitialized ValueArray by doing var a = ValueArray<Double>(capacity: n) or var a = ValueArray<Doube>(count: n). This is good for when you are going to fill up the array yourself. But you can also use var a = ValueArray(count: n, repeatedValue: 0.0) if you do want to initialize all the values.

Creating arrays

Create a ValueArray with specific literal elements when you know ahead of time what the contents are, and you don't need to add more elements at a later time:

let a: ValueArray = [1.0, 3.0, 5.0, 7.0]

Create a ValueArray with a capacity and then fill it in when you are loading the contents from an external source or have a very large array:

let a = ValueArray<Double>(capacity: 100)
for v in intputSource {
    a.append(v)
}

Finally there is a way of initializing both the capacity and the count of a ValueArray. You should rarely need this but it's there for when you are doing operations on existing arrays using low-level APIs that take pointers:

func operation(a: ValueArray<Double>) {
    let N = a.count
    let b = ValueArray<Double>(count: N)
    // ...
}

Vector arithmetic

You can perform operations on ValueArray in an intuitive manner:

let a: ValueArray = [1.0, 3.0, 5.0, 7.0]
let b: ValueArray = [2.0, 4.0, 6.0, 8.0]
let addition = a + b // [3.0, 7.0, 11.0, 15.0]
let product  = a  b // 100.0

Matrix operations

import Upsurge

let A = Matrix<Double>([
    [1,  1],
    [1, -1]
])
let C = Matrix<Double>([
    [3],
    [1]
])

// find B such that A*B=C
let B = inv(A) * C // [2.0, 1.0]′

// Verify result
let r = A*B - C    // zero   

Tiling

A block Matrix can be formed by repeating a 1-D ValueArray or 2-D Matrix mxn times.

import Upsurge

let a = ValueArray = [1.0, 2.0]
// Tile source array 2 times in each directon,
// returning a 2X4 block matrix
let A = a.tile(2, 2)

let B = Matrix<Double>([
    [1.0,  2.0],
    [3.0,  4.0]
)]
// Tile source matrix 2 times in each directon,
// returning a 4x4 block matrix
let r = B.tile(2, 2)

Tensors

The Tensor class makes it easy to manipulate multi-dimensional data. You can easily slice or flatten a tensor to get matrices and vectors that you can operate on.


License

Upsurge is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].