Quiver: Statistics, linear algebra, and machine learning in plain Swift

Hi everyone,

I’d like to share Quiver, an open-source Swift package for statistics, linear algebra, and machine learning.

I came to machine learning through courses built on Python, NumPy, scikit-learn, and Jupyter. They were excellent tools, and they gave me a real appreciation for that ecosystem. As a longtime Swift developer, though, I wanted to explore what numerical computing and machine learning could look like when built around Swift’s strengths.

Two questions guide the project:

  1. How can data science and machine learning take better advantage of Swift?
  2. What would it take to teach these subjects in Swift, including in schools and universities?

It’s just an Array

Quiver adds numerical methods directly to Swift’s standard Array through extensions. A plain [Double] gains mathematical operations without becoming a separate vector type, so it still works naturally with SwiftUI, Swift Charts, and SwiftData.

import Quiver

let position = [3.0, 4.0]
position.magnitude  // 5.0

Swift’s type system then does more of the work:

  • Operations are constrained to compatible types. Constrained extensions catch many mistakes at compile time. Vector and matrix dimensions are checked at runtime.

  • Models are trained on creation. fit returns a trained model, so asking an untrained model for a prediction cannot compile.

  • Learned parameters are immutable. Fitted models are Sendable, so they can cross task boundaries without locking. They are also Codable, making it straightforward to save a trained model as JSON and load it later without retraining.

  • Results are readable by default. Models and result types print useful summaries, while vectors and matrices can render in textbook form.

Prototype in Quiver Notebook

The Quiver Notebook is a browser-based Swift IDE for testing and evaluating Quiver models before moving them into an app.

It runs locally on a Mac, with no accounts, telemetry, or analytics. Quiver and Foundation are already imported, teaching datasets are bundled, and documentation, autocomplete, and signature help are available inline.

Code written in the Notebook is ordinary Swift. Because each Notebook release builds against a published Quiver release, examples can move into an Xcode project using that same package version.

The Notebook currently runs on macOS. On Linux, Quiver can be used directly as a package in apps and server-side Swift projects.

From prototype to app

Quiver has zero dependencies. Adding it to a project requires only a Swift Package Manager dependency, with no additional runtime or packages to keep in sync.

The same package runs on iPhone, Apple Watch, Mac, and Vision Pro, and inside server-side Swift applications such as Vapor on Linux. Quiver runs on the CPU and supports Swift concurrency, allowing expensive training work to stay off the main thread and immutable models to be shared safely across tasks.

One worked example is True Effort Score. Its model learns each runner’s baseline from their recent runs, using signals such as heart rate, pace, cadence, grade, altitude, and vertical oscillation to score running effort on Apple Watch. It demonstrates how a model can be trained directly on the device that collects the data.

Built to teach and ship

Quiver is designed to keep the mathematics visible. Models expose what they learned as plain Swift values, including regression coefficients, standard errors, cluster centroids, and principal components.

The package currently includes 971 tests, and its numerical results have been checked against NumPy, SciPy, and scikit-learn.

For students and educators, the Notebook provides a self-contained environment with examples and teaching datasets. For developers, the same package and models can move into production apps.

The project resources include:

  • Quiver Framework: the core package, source code, issues, and contributions.
  • Quiver Notebook: the local prototyping environment described above.
  • Quiver Cookbook: interactive recipes for common tasks and models.
  • Quiver Documentation: guides, API reference material, and beginner-friendly explanations of the underlying mathematics.
  • True Effort Score: a transparent, multi-signal model of running load on Apple Watch.
  • Swift Package Index: package and release information.

What’s next

Four pieces of work are currently underway:

  • Quiver Agent Skill: a Claude Code plugin that provides release-specific knowledge of Quiver’s actual API, helping Claude write correct code instead of guessing. Its review mode will also flag breaking changes when a project upgrades to a newer release.

  • Quiver CLI: a terminal assistant for people learning Quiver. It will use Quiver itself to retrieve relevant documentation passages and assemble context, then use Apple’s on-device Foundation Models to generate a plain-language answer—with no account and no usage fee.

  • Quiver Notebook for Linux: bringing the local Notebook experience to Linux, so the same prototyping environment can be used beyond macOS.

  • True Effort Score refinements: calibration for walking and hiking, followed by effort zones personalized to each runner.

Beyond those projects, my roadmap is focused on expanding Quiver’s statistics and data science capabilities. Hypothesis tests such as t-tests and ANOVA, along with cross-validation, are planned for release 1.8.0. Decision trees and additional classifiers are planned after that.

Thanks for reading. If Quiver looks useful for a project or classroom, I’d be glad to connect.

8 Likes

Very Cool thanks for sharing

Thanks @Lin! Just let me know if I can answer any questions.

1 Like