{ "$schema": "https://raw.githubusercontent.com/guitaripod/wwdc-sessions/master/schema/session.schema.json", "schemaVersion": 1, "id": "wwdc2026-328", "event": "wwdc2026", "eventName": "WWDC26", "year": 2026, "eventContentId": 328, "title": "Explore numerical computing in Swift with MLX", "description": "Bring NumPy-style computing natively to Swift with MLX Swift. Discover how to eliminate cross-language friction in your machine learning workflows by handling image processing, tensor operations, and neural network training in a single, type-safe environment. Explore the APIs that let you leverage GPU acceleration while enjoying the compiler, tooling, and debugging experience you already know.", "url": "https://developer.apple.com/videos/play/wwdc2026/328", "sosumiURL": "https://sosumi.ai/videos/play/wwdc2026/328", "type": "Video", "publishedAt": "2026-06-08T14:00:00-07:00", "platforms": [ "macOS" ], "keywords": [], "topics": [ "AI & Machine Learning", "Swift" ], "primaryTopic": "Swift", "duration": 871, "hasTranscript": true, "transcriptWordCount": 2168, "availableLanguages": [ "eng", "fra", "jpn", "kor", "por", "spa", "zho" ], "media": { "hls": "https://devstreaming-cdn.apple.com/videos/wwdc/2026/328/5/51d0ab0a-f401-4514-9f04-6b211897d3e8/cmaf.m3u8", "downloadHLS": "https://devstreaming-cdn.apple.com/videos/wwdc/2026/328/5/51d0ab0a-f401-4514-9f04-6b211897d3e8/cmaf-download.m3u8", "downloadSD": "https://devstreaming-cdn.apple.com/videos/wwdc/2026/328/5/51d0ab0a-f401-4514-9f04-6b211897d3e8/downloads/wwdc2026-328_sd.mp4", "downloadHD": "https://devstreaming-cdn.apple.com/videos/wwdc/2026/328/5/51d0ab0a-f401-4514-9f04-6b211897d3e8/downloads/wwdc2026-328_hd.mp4", "duration": 871 }, "codeSnippets": [ { "title": "Power iteration with MLX Swift arrays", "language": "swift", "startTimeSeconds": 184, "code": "import MLX\nlet n = 100\nlet steps = 10\nlet B = MLXRandom.normal([n, n])\nvar v = MLXRandom.normal([n])\n\n// get symmetric matrix A = Bᵀ + B\nlet A = B.T + B\n\n// Power iteration → top eigenvector of A.\n// v ← A v / ‖A v‖\nfor _ in 0 ..< steps {\n let Av = matmul(A, v)\n v = Av / norm(Av)\n eval(v)\n}\n\n// recover the eigenvalue.\n// λ = vᵀ A v\nlet lambda = matmul(matmul(v.T, A), v)\n\nprint(lambda)" }, { "title": "Mandelbrot set in plain Swift (scalar)", "language": "swift", "startTimeSeconds": 309, "code": "// Plain Swift, scalar-at-a-time\nvar counts = Array2D(width: w, height: h)\n\nfor y in 0 ..< h {\n for x in 0 ..< w {\n let c = Complex(xMin + Float(x) * xStep, yMin + Float(y) * yStep)\n var z = Complex.zero\n var limit = maxIterations\n for i in 0 ..< maxIterations {\n z = z * z + c\n if z.lengthSquared > radiusSquared {\n limit = i\n break\n }\n }\n counts[x, y] = limit\n }\n}" }, { "title": "Mandelbrot set in MLX Swift (array)", "language": "swift", "startTimeSeconds": 327, "code": "// Compute the Mandelbrot set on a grid of complex numbers\nimport MLX\n\nlet x = linspace(Float(-2.0), 0.5, count: w)\nlet y = linspace(Float(-1.25), 1.25, count: h).reshaped(h, 1)\nlet c = x + y.asImaginary()\n\nvar z = MLXArray.zeros(like: c)\nvar counts = MLXArray.zeros(c.shape, dtype: .int16)\n\nfor _ in 0 ..< maxIterations {\n z = z * z + c // iterate z ← z² + c\n counts = counts + (abs(z) .< 2) // count bounded iterations\n}" }, { "title": "Jacobi iteration with conv2d", "language": "swift", "startTimeSeconds": 447, "code": "// Jacobi iteration: average the four neighbors\n\n// Convolution weights\nlet kernel = MLXArray(converting: [\n 0, 0.25, 0,\n 0.25, 0, 0.25,\n 0, 0.25, 0,\n]).reshaped(1, 3, 3, 1)\n\n// Initial value\nvar temperature = heatSources\n\n// Run this in a loop until convergence\nlet next = conv2d(temperature, kernel, padding: 1)\ntemperature = which(heatMask, heatSources, next)" }, { "title": "Successive Over-Relaxation (SOR)", "language": "swift", "startTimeSeconds": 557, "code": "// Successive Over-Relaxation: blend the previous and next state\nlet ω: Float = 2.0 / (1.0 + sin(Float.pi / Float(max(M, N))))\n\nlet redMask = checkerboard(rows: M, cols: N, phase: 0)\nlet blackMask = checkerboard(rows: M, cols: N, phase: 1)\n\n// Update red cells using black neighbors\nlet sorRed = ω * conv2d(temperature, kernel, padding: 1) + (1 - ω) * temperature\ntemperature = which(redMask, sorRed, temperature)\ntemperature = which(heatMask, heatSources, temperature)\n\n// Update black cells using (now-updated) red neighbors\nlet sorBlack = ω * conv2d(temperature, kernel, padding: 1) + (1 - ω) * temperature\ntemperature = which(blackMask, sorBlack, temperature)\ntemperature = which(heatMask, heatSources, temperature)" }, { "title": "Curve fitting with automatic differentiation", "language": "swift", "startTimeSeconds": 673, "code": "// Define a loss, then optimize it with autodiff\n// x, y: data points as MLXArrays\nfunc f(_ θ: MLXArray) -> MLXArray {\n θ[0] + θ[1] * x + θ[2] * x ** 2\n}\n\nfunc loss(_ θ: MLXArray) -> MLXArray {\n mean((f(θ) - y) ** 2)\n}\n\nvar θ = zeros([numParams])\nlet gradLoss = grad(loss)\n\nfor _ in 0 ..< steps {\n let g = gradLoss(θ) // ∇L(θ)\n θ = θ - learningRate * g // parameter update\n eval(θ) // force evaluation\n}" } ], "resources": [ { "title": "MLX Swift LM on GitHub", "url": "https://github.com/ml-explore/mlx-swift-lm", "type": "documentation", "description": null }, { "title": "MLX Swift Examples", "url": "https://github.com/ml-explore/mlx-swift-examples", "type": "samplecode", "description": "MLX Swift Examples" }, { "title": "MLX Examples", "url": "https://github.com/ml-explore/mlx-examples", "type": "samplecode", "description": "This repo contains a variety of standalone examples using the MLX framework." }, { "title": "MLX Swift", "url": "https://github.com/ml-explore/mlx-swift", "type": "documentation", "description": "MLX Swift is a Swift API for MLX." }, { "title": "MLX LM - Python API", "url": "https://github.com/ml-explore/mlx-lm", "type": "documentation", "description": "MLX LM is a Python package for generating text and fine-tuning large language models on Apple silicon with MLX." }, { "title": "MLX Explore - Python API", "url": "https://github.com/ml-explore/mlx", "type": "documentation", "description": "MLX is an array framework for machine learning on Apple silicon, brought to you by Apple machine learning research." }, { "title": "MLX Framework", "url": "https://mlx-framework.org", "type": "documentation", "description": null }, { "title": "MLX", "url": "https://ml-explore.github.io/mlx/", "type": "documentation", "description": "MLX is an array framework for machine learning on Apple silicon, brought to you by Apple machine learning research." } ], "path": "sessions/wwdc2026/328-explore-numerical-computing-in-swift-with-mlx/", "files": { "metadata": "sessions/wwdc2026/328-explore-numerical-computing-in-swift-with-mlx/metadata.json", "readme": "sessions/wwdc2026/328-explore-numerical-computing-in-swift-with-mlx/README.md", "transcript": "sessions/wwdc2026/328-explore-numerical-computing-in-swift-with-mlx/transcript.md", "transcriptJSON": "sessions/wwdc2026/328-explore-numerical-computing-in-swift-with-mlx/transcript.json" } }