Skip to main content

Matft

Numpy-like multi-dimensional array library in Swift

Write Swift like Numpy

Numpy
import numpy as np

a = np.arange(27).reshape(3, 3, 3)
b = a[1:3, :, 0]
c = np.sin(a) + a.T
a[a > 20] = 0
Matft
import Matft

let a = Matft.arange(start: 0, to: 27, by: 1, shape: [3, 3, 3])
let b = a[1~<3, Matft.all, 0]
let c = Matft.math.sin(a) + a.T
a[a > 20] = MfArray([0])

Numpy-like API

Function names, arguments and behaviors follow Numpy, so you can port Python code almost line by line.

Powerful indexing

Slicing with ~<, negative, boolean and fancy indexing, and views sharing memory as in Numpy.

Fast with Accelerate

Math, statistics, linear algebra and FFT are backed by Apple's Accelerate framework.

Complex numbers

Arithmetic, math and indexing on complex arrays.

Image and audio

OpenCV-compatible image processing, PIL / transformers-compatible preprocessing and librosa-compatible audio features.

Works with MLX

Zero-copy conversion between MfArray and MLXArray: preprocess with Matft, infer with MLX.