Builtin Library
- ..
- .metadata17 B
- README.md2.3 KB
- gpu.module
- init.luau43.4 KB
README.md
nx
Numerical-arrays kernel library — fast-math over typed CPU buffers.
Location: src/lua/lib/modules/nx.module
Declared module identity: nx
Quick reference
See man nx (/zero/source/libs/@builtin/docs/topics/nx.guide/guide.md) for the full guide. Short version:
- Constructors:
nx.create / zeros / ones / full / fromTable - Unary in-place:
nx.applySin / Cos / Tan / Sqrt / Abs / Neg / Exp / Log / Log2 / Floor / Ceil / Round / Trunc / Fract / Sign / Square / Recip / RecipSqrt - Binary scalar in-place:
nx.add / mul / sub / div / min / max / pow / scale / fill / clamp(work on (buf, scalar) and (buf, buf)) - Buffer ops:
nx.copy / addBuffer / subBuffer / mulBuffer / divBuffer / minBuffer / maxBuffer - Reductions:
nx.sum / min / max / mean / normL1 / normL2 / dot - Strided:
nx.addStrided / mulStrided / fillStrided / addStridedFrom / copyStridedFrom - Random:
nx.fillRandomUniform / fillRandomNormal - Fused (game-shaped):
nx.wanderYaw / axpby / lerpTo / sinCosTo / quatFromYaw / integratePosition / normalizeVec3 - FFT (CPU substrate buffers):
nx.fft1d / ifft1d / rfft1d / irfft1d / fft2d / ifft2d / rfft2d / irfft2d - Windowing:
nx.window.hann / hamming / blackman,nx.applyWindow - GPU FFT (GPU substrate buffers):
nx.gpu.fft1d / ifft1d / fft2d / ifft2d
FFT & windowing
-- 1D real-input
local re, im = nx.rfft1d(signal)
local back = nx.irfft1d(re, im)
-- Windowed audio spectrum
local sig = nx.zeros(1024) -- fill with PCM samples
local w = nx.window.hann(1024)
nx.applyWindow(sig, w)
local re, im = nx.rfft1d(sig)
-- 2D real-input
local re2, im2 = nx.rfft2d(image, w, h)
local back2 = nx.irfft2d(re2, im2, w, h)
-- GPU 1D (GPU buffer handles, interleaved vec2 layout)
nx.gpu.fft1d({ input = bufIn, output = bufOut, size = 1024 })
A CPU transform takes any length whose plan fits (mixed-radix rustfft). A plan's cost grows with the length and its large prime factors, and a length whose plan could need more than 2147483647 bytes (2^27, for example, or any prime past about 19.17 million), or more than the heap can supply, raises an error naming the length and the bytes. GPU transforms take powers of two. Real-input variants return fresh CPU buffers, which the caller owns and must :destroy().