La

License Release CI

一个用 Swift 编写的具有类型安全的线性代数库。

动机

示例

La 在编译时拒绝未定义的操作

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`.

您可以根据环境变量或文件等输入,通过惰性求值在运行时决定大小

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 matrix

安装

Swift 包管理器

LaLaAccelerate 添加到依赖项

// 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

将以下行添加到您的 Podfile

source 'https://github.com/mitsuse/pods-la.git'

Pod 'La', '~> 0.6.1'
Pod 'LaAccelerate', '~> 0.6.1'

矩阵运算

La 不提供矩阵运算的实现。此包仅提供矩阵类型和运算接口。

您需要导入矩阵运算的其中一个实现

许可

本仓库的内容在 MIT 许可证下获得许可,除非另有说明。请阅读 LICENSE 以了解详情。