La
A library for linear algebra with type-safety written in Swift.
Motivations
- Type-safety: Detect undefined operations in compile time.
- Performance: Use highly-optimized implementations for the backend.
Examples
La rejects undefined operations in compile-time:
import La
import LaAccelerate
enum _2: Size { static let value: Int32 = 2 }
enum _3: Size { static let value: Int32 = 3 }
let a = Matrix<_2, _3, Double>([
0, 1, 2,
3, 4, 5,
])!
let b = Matrix<_2, _3, Double>([
0, 1, 2,
3, 4, 5,
])!
let c = Matrix<_3, _2, Double>([
0, 1,
2, 3,
4, 5,
])!
_ = a + b // OK.
_ = a + c // This casuese a compile-tim error because the size of `a` is not same as the one of `c`.You can decide sizes in run-time with lazy-evaluation based on input such as environment variables or files:
import Foundation
import La
enum N: Size {
// Constants defined with `statc let` are lazily-evaluated in Swift.
static let value: Int32 = Int(ProcessInfo.processInfo.environment["MATRIX_SIZE_M"])!
}
// `N.value` is decided here in run-time.
_ = Matrix<_1, N, Double>.zeros() // 1 x N zero matrixInstallation
Swift Pacakge Manager
Add La and LaAccelerate into dependencies:
// Package.swift
import PackageDescription
let package = Package(
name: "YourPackage",
dependencies: [
.Package(url: "https://github.com/mitsuse/la", majorVersion: 0, minor: 6),
.Package(url: "https://github.com/mitsuse/la-accelerate", majorVersion: 0, minor: 6),
]
)CocoaPods
Add the following lines into your Podfile:
source 'https://github.com/mitsuse/pods-la.git'
Pod 'La', '~> 0.6.1'
Pod 'LaAccelerate', '~> 0.6.1'Matrix Operations
La doesn't provide the implementation of matrix operations. This package just provides a matrix type and the interface of operations.
You need to import one of implementations for matrix operations:
- la-accelerate: Accelerate (Apple's BLAS)
- la-openblas (under development): OpenBLAS
License
The content of this repository are licensed under the MIT License unless otherwise noted. Please read LICENSE for the detail.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
