Documentation
¶
Overview ¶
Package floats provides SIMD-accelerated reductions over float32 and float64 slices — the dot product, sum, min, max, Euclidean (L2) distance and cosine similarity that sit at the heart of vector search, embeddings and numerics. It is pure Go (CGO_ENABLED=0, stable Go, no GOEXPERIMENT): the hot reduction loops are SIMD assembly generated by go-asmgen on all six of Go's 64-bit SIMD targets — amd64 (AVX2+FMA), arm64 (NEON FMLA), ppc64le (VSX), s390x (vector facility), riscv64 (RVV) and loong64 (LSX) — with a portable scalar fallback everywhere else, all on a plain `go build`.
Operations ¶
For both []float32 (the Float32 functions) and []float64:
Dot(a, b) a·b = Σ aᵢbᵢ Sum(a) Σ aᵢ Min(a) / Max(a) the minimum / maximum element Distance(a, b) ‖a−b‖₂ = √Σ(aᵢ−bᵢ)² CosineSimilarity(a, b) a·b / (‖a‖₂‖b‖₂)
Dot, Distance and CosineSimilarity require len(a) == len(b) and panic otherwise. Min and Max panic on an empty slice. Sum of an empty slice is 0.
For []float64, the in-place elementwise updates (BLAS level 1) behind iterative solvers, QR and LU:
Axpy(α, x, y) yᵢ = fma(α, xᵢ, yᵢ) (y += αx) Xpby(x, β, y) yᵢ = fma(β, yᵢ, xᵢ) (y = x + βy) AxpyDot(α, x, y, w) y += αx, then returns Σ yᵢwᵢ (one pass) Scale(α, x) xᵢ = α·xᵢ
They operate on the first len(x) elements and panic if y (or w) is shorter. Unlike the reductions, the updated slices are bit-identical on every architecture: each element is rounded once, exactly as math.FMA rounds it (AVX2 FMA on amd64, NEON FMLA on arm64, the math.FMA loop elsewhere). Only AxpyDot's returned sum is a reduction and follows the rules below.
SumPairwise(a) is NumPy's np.sum(a) for a contiguous float64 array, bit for bit on every architecture (scalar, pairwise, block 128, eight accumulators); unlike Sum it does not follow the lane order below.
Floating-point determinism ¶
A SIMD reduction does not add its terms left-to-right: it keeps several independent accumulator lanes (for instruction-level parallelism) and folds them together at the end, so the rounding differs from a naïve scalar loop. To stay deterministic and architecture-independent, the scalar reference used internally and by the tests (sumLanes / dotLanes / …) reduces in the *same* lane-blocked order the kernels use (laneCount lanes), and the SIMD result is required to agree with it to a tight, documented ULP bound across every architecture (the differential tests and FuzzDot/FuzzDistance enforce this). For the similarity use case (cosine / Euclidean distance) bit-exact equality with a naïve scalar loop is neither required nor meaningful; correctness to a few ULP is.
Index ¶
- func Abs(dst, src []float64)
- func Add(dst, a, b []float64)
- func Add32(dst, a, b []float32)
- func AllPass3(out, in []complex128, t *AllPassRows, old, cur *[3][]complex128)
- func AllPass3Split32(out, in Split32, t *AllPassRows32, old, cur *[3]Split32)
- func Axpby3(dst []float64, alpha float64, a []float64, beta float64, b []float64, ...)
- func Axpby3NoFMA(dst []float64, alpha float64, a []float64, beta float64, b []float64, ...)
- func Axpy(alpha float64, x, y []float64)
- func AxpyDiffNoFMA(dst, a []float64, f float64, b, c []float64)
- func AxpyDot(alpha float64, x, y, w []float64) float64
- func AxpyGather(alpha float64, a []float64, idx []int, d []float64)
- func AxpyNoFMA(alpha float64, x, y []float64)
- func AxpyRowsNoFMA(a []float64, x []float64, ldx int, y []float64)
- func CDotC(a, b []float64) (re, im float64)
- func CMulGather(dst, x, tw []float64)
- func CMulGatherFrom32(dst []float64, x []float32, tw []float64)
- func CMulScatter(dst, c, tw []float64, f float64)
- func CMulScatterTo32(dst []float32, c, tw []float64, f float64)
- func CMulTo(dst, a, b []complex128)
- func CMulZipRev(dst, x, y, w []float64)
- func Ceil(dst, src []float64)
- func Chebval(dst, x, c []float64)
- func Clamp(dst, v, lo, hi []float64)
- func ClampScalar(dst, v []float64, lo, hi float64)
- func ConjReverse(dst, src []float64)
- func CosineSimilarity(a, b []float64) float64
- func Distance(a, b []float64) float64
- func Div(dst, a, b []float64)
- func Div32(dst, a, b []float32)
- func Dot(a, b []float64) float64
- func DotGather(a []float64, idx []int, d []float64) float64
- func DotIdx(a, b []float64, idx []int) float64
- func Exp(dst, src []float64)
- func Float32CosineSimilarity(a, b []float32) float32
- func Float32Distance(a, b []float32) float32
- func Float32Dot(a, b []float32) float32
- func Float32Exp(dst, src []float32)
- func Float32Log(dst, src []float32)
- func Float32Max(a []float32) float32
- func Float32Min(a []float32) float32
- func Float32OverlapWindow(dst, a, b, win []float32)
- func Float32Sum(a []float32) float32
- func Floor(dst, src []float64)
- func Log(dst, src []float64)
- func MDCTFold(dst, x []float64)
- func MDCTFoldFrom32(dst []float64, x []float32)
- func MDCTUnfold(dst, u []float64)
- func MDCTUnfoldTo32(dst []float32, u []float64)
- func Max(a []float64) float64
- func MaxAbs(v []float64) float64
- func MaxAbsMul(v, w []float64) float64
- func Maximum(dst, a, b []float64)
- func Min(a []float64) float64
- func Minimum(dst, a, b []float64)
- func MirrorCombine(dst, z, w1, w2 []float64)
- func MirrorCombineSplit(dst, z, w1, w2 []float64)
- func Mul(dst, a, b []float64)
- func Mul32(dst, a, b []float32)
- func MulAddRows(dst, a []float64, lda int, b []float64, ldb int, rows int)
- func MulAddRows32(dst, a []float32, lda int, b []float32, ldb int, rows int)
- func Neg(dst, src []float64)
- func OverlapWindow(dst, a, b, win []float64)
- func Polyval(dst, x, c []float64)
- func RoundEven(dst, src []float64)
- func Scale(alpha float64, x []float64)
- func Sqrt(dst, src []float64)
- func Sqrt32(dst, src []float32)
- func Square(dst, src []float64)
- func SquaredMagnitude(dst, c []float64, s float64)
- func Sub(dst, a, b []float64)
- func Sub32(dst, a, b []float32)
- func Sum(a []float64) float64
- func SumPairwise(a []float64) float64
- func Trunc(dst, src []float64)
- func Xpby(x []float64, beta float64, y []float64)
- func XpbyNoFMA(x []float64, beta float64, y []float64)
- type AllPass3Plan
- type AllPass3Plan32
- type AllPassRows
- type AllPassRows32
- type PSMixPlan32
- type PSMixRun
- type Split32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶ added in v0.23.0
func Abs(dst, src []float64)
Abs computes dst[i] = math.Abs(src[i]) for i < len(src). It panics if len(dst) < len(src).
func Add ¶ added in v0.8.0
func Add(dst, a, b []float64)
Add computes dst[i] = a[i] + b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func Add32 ¶ added in v0.30.0
func Add32(dst, a, b []float32)
Add32 computes dst[i] = a[i] + b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func AllPass3 ¶ added in v0.29.0
func AllPass3(out, in []complex128, t *AllPassRows, old, cur *[3][]complex128)
AllPass3 computes the decorrelator rows described above for k < len(out). It panics if an operand is shorter than len(out) or a written slice overlaps another operand.
func AllPass3Split32 ¶ added in v0.43.0
func AllPass3Split32(out, in Split32, t *AllPassRows32, old, cur *[3]Split32)
AllPass3Split32 computes the decorrelator rows described above for k < len(out.Re). It panics if an operand is shorter than that or a written slice overlaps another operand.
func Axpby3 ¶ added in v0.5.0
func Axpby3(dst []float64, alpha float64, a []float64, beta float64, b []float64, gamma float64, c []float64)
Axpby3 computes the three-term combination
dst[i] = alpha*a[i] + beta*b[i] + gamma*c[i]
for i < len(a), fused: dst[i] = math.FMA(gamma, c[i], math.FMA(beta, b[i], alpha*a[i])) — see the package notes above. It panics if len(b), len(c) or len(dst) is less than len(a).
func Axpby3NoFMA ¶ added in v0.7.0
func Axpby3NoFMA(dst []float64, alpha float64, a []float64, beta float64, b []float64, gamma float64, c []float64)
Axpby3NoFMA computes dst[i] = alpha*a[i] + beta*b[i] + gamma*c[i] for i < len(a), unfused and left to right, as NumPy evaluates alpha*a + beta*b + gamma*c: ((alpha*a[i]) + (beta*b[i])) + (gamma*c[i]), five roundings. It is the unfused counterpart of Axpby3. It panics if len(b), len(c) or len(dst) is less than len(a).
func Axpy ¶ added in v0.4.0
Axpy computes y[i] += alpha*x[i] for i < len(x), fused: y[i] = math.FMA(alpha, x[i], y[i]). Elements of y past len(x) are left untouched. It panics if len(y) < len(x).
func AxpyDiffNoFMA ¶ added in v0.7.0
AxpyDiffNoFMA computes dst[i] = a[i] + f*(b[i] - c[i]) for i < len(a): the difference, the product and the sum each rounded in turn, as NumPy evaluates a + F*(b - c). It is the mutation step of differential evolution (rand/1, best/1 and the second half of rand-to-best/1; for b += F*(x - b) pass dst = a = c = b). It panics if len(b), len(c) or len(dst) is less than len(a).
func AxpyDot ¶ added in v0.4.0
AxpyDot computes y[i] += alpha*x[i] for i < len(x) exactly as Axpy does and returns Σ y[i]*w[i] over the updated elements, in one pass over the three slices — the residual update and its norm in conjugate gradient (r -= αAp; rr = r·r is AxpyDot(-α, Ap, r, r)). It panics if len(y) < len(x) or len(w) < len(x).
func AxpyGather ¶ added in v0.17.0
AxpyGather does d[k] = fma(alpha, a[idx[k]], d[k]) for every k (each element rounded once, bit-identical on every architecture). It panics if an index is out of range or len(d) < len(idx).
func AxpyNoFMA ¶ added in v0.7.0
AxpyNoFMA computes y[i] = y[i] + alpha*x[i] for i < len(x) with two roundings, the product first: NumPy's y + alpha*x. Elements of y past len(x) are left untouched. It panics if len(y) < len(x).
func AxpyRowsNoFMA ¶ added in v0.13.0
AxpyRowsNoFMA applies len(a) unfused AXPY updates to y in one pass: for j < len(y),
y[j] = (((y[j] + a[0]*x[0*ldx+j]) + a[1]*x[1*ldx+j]) + ...) + a[r-1]*x[(r-1)*ldx+j]
with r = len(a), every product rounded before its addition and the rows added in increasing order. The result is bit-identical to r successive AxpyNoFMA(a[k], x[k*ldx:k*ldx+len(y)], y) calls, but a block of y stays in registers across all r rows, so y is loaded and stored once instead of r times. It is the row of an exact matrix product C = A*B in i-k-j order: pass a = A[i,:], x = B (row-major, ldx = its row stride), y = C[i,:], and the entry is the left-to-right sum in increasing k that NumPy's matmul loop (and any reference that does not fuse) computes.
x holds row k at x[k*ldx:]; it must not overlap y. It panics if ldx < 0 or if x is shorter than (len(a)-1)*ldx + len(y). With len(a) == 0 or len(y) == 0 it does nothing (and checks nothing).
func CDotC ¶ added in v0.24.0
CDotC returns the real and imaginary parts of Σ conj(a_k)·b_k for the n = len(a)/2 complex numbers a_k = (a[2k], a[2k+1]), b_k = (b[2k], b[2k+1]). It panics if len(a) is odd or len(b) < len(a).
func CMulGather ¶ added in v0.18.0
func CMulGather(dst, x, tw []float64)
CMulGather writes the pre-twiddle of a DCT-IV: see the formulas above.
func CMulGatherFrom32 ¶ added in v0.18.0
CMulGatherFrom32 is CMulGather with x read as float32 and widened.
func CMulScatter ¶ added in v0.18.0
CMulScatter writes the post-twiddle of a DCT-IV: see the formulas above.
func CMulScatterTo32 ¶ added in v0.18.0
CMulScatterTo32 is CMulScatter with each output rounded to float32.
func CMulTo ¶ added in v0.31.0
func CMulTo(dst, a, b []complex128)
CMulTo writes dst[i] = a[i]*b[i] for i < len(dst). It panics, before writing anything, if len(a) or len(b) is less than len(dst).
func CMulZipRev ¶ added in v0.28.0
func CMulZipRev(dst, x, y, w []float64)
CMulZipRev writes dst[j] = w[j] * (x[j] - i y[m-1-j]) for j < m = len(dst)/2.
func Ceil ¶ added in v0.23.0
func Ceil(dst, src []float64)
Ceil computes dst[i] = math.Ceil(src[i]) for i < len(src): the smallest integer not below the value; Ceil(-0.5) is -0 (np.ceil). It panics if len(dst) < len(src).
func Chebval ¶ added in v0.12.0
func Chebval(dst, x, c []float64)
Chebval computes dst[i] = sum c[k]*T_k(x[i]) for i < len(x) by Clenshaw's recurrence in NumPy's order (numpy.polynomial.chebyshev.chebval). It panics if len(dst) < len(x) or len(c) == 0. Elements of dst past len(x) are left untouched.
func Clamp ¶ added in v0.5.0
func Clamp(dst, v, lo, hi []float64)
Clamp projects v onto the box [lo, hi] elementwise, min(max(v[i], lo[i]), hi[i]), for i < len(v):
r := v[i]; if lo[i] > r { r = lo[i] }; if hi[i] < r { r = hi[i] }; dst[i] = r
Exact semantics, identical on every architecture:
- a NaN v[i] propagates unchanged (same bits, whatever its sign);
- a NaN bound is ignored, as if that side were infinite;
- lo[i] > hi[i] gives hi[i] (the upper bound wins);
- signed zeros are compared as equal, so Clamp(-0, +0, hi) keeps -0 and Clamp(+0, -0, hi) keeps +0: the result is v[i] unless a strict bound replaces it.
It panics if len(lo), len(hi) or len(dst) is less than len(v). For one-sided bounds pass ±Inf.
func ClampScalar ¶ added in v0.8.0
ClampScalar limits every element of v to [lo, hi], like np.clip with scalar bounds and like Clamp with the same bounds at every index:
r := v[i]; if lo > r { r = lo }; if hi < r { r = hi }; dst[i] = r
A NaN v[i] passes through unchanged (same bits); a NaN bound is ignored (that side is unbounded); lo > hi gives hi; signed zeros compare equal, so the result is v[i] unless a strict bound replaces it. It panics if len(dst) < len(v).
func ConjReverse ¶ added in v0.21.0
func ConjReverse(dst, src []float64)
ConjReverse writes the n = len(dst)/2 complex numbers (src[2k], src[2k+1]) conjugated and in reverse order into dst.
func CosineSimilarity ¶
CosineSimilarity returns a·b / (‖a‖₂‖b‖₂), a value in [-1, 1] measuring the angle between a and b — the standard relevance score for embedding vectors. It panics if len(a) != len(b). If either vector has zero magnitude the result is NaN (0/0), matching the mathematical definition.
func Distance ¶
Distance returns the Euclidean (L2) distance ‖a−b‖₂ = √Σ(aᵢ−bᵢ)². It panics if len(a) != len(b).
func Div ¶ added in v0.8.0
func Div(dst, a, b []float64)
Div computes dst[i] = a[i] / b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func Div32 ¶ added in v0.30.0
func Div32(dst, a, b []float32)
Div32 computes dst[i] = a[i] / b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func DotGather ¶ added in v0.17.0
DotGather returns Σ a[idx[k]]·d[k] (d is contiguous, a is gathered). It panics if an index is out of range or len(d) < len(idx).
func DotIdx ¶ added in v0.17.0
DotIdx returns Σ a[idx[k]]·b[idx[k]]. It panics if an index is out of range.
func Exp ¶ added in v0.9.0
func Exp(dst, src []float64)
Exp writes exp(src[i]) into dst[i] for i < len(src), accurate to 0.511 ULP (Arm documents 0.509 with FMA): a ULP-bounded exp, not NumPy's bits (tolerance parity). It panics if len(dst) < len(src). Moved here from go-ndarray's internal/kernels (K1 of the go-scikit performance campaign). exp1 is too large to inline, and a call per element cost half the time, so the common case (2^-54 <= |x| < 512) is exp1's main path written out in the loop; everything else calls exp1. TestExpLoopMatchesExp1 holds the two to the same bits.
func Float32CosineSimilarity ¶
Float32CosineSimilarity returns a·b / (‖a‖₂‖b‖₂) over float32 slices — the relevance score for float32 embedding vectors. It panics if len(a) != len(b). If either vector has zero magnitude the result is NaN.
func Float32Distance ¶
Float32Distance returns the Euclidean (L2) distance ‖a−b‖₂ over float32 slices. The squared-difference sum is accumulated in float32 and the square root taken in float64 for accuracy. It panics if len(a) != len(b).
func Float32Dot ¶
Float32Dot returns the dot product a·b = Σ aᵢbᵢ over float32 slices, accumulated in float32. It panics if len(a) != len(b).
func Float32Exp ¶ added in v0.9.0
func Float32Exp(dst, src []float32)
Float32Exp writes the correctly rounded float32 exp(src[i]) into dst[i] for i < len(src) (every float32 input rounds as the exact value does: proven over all 2^32 by TestExp32CorrectlyRounded, which is env-gated). Both operations are computed in float64 and rounded once: expCR, Arm's correctly rounded expf (optimized-routines, MIT), on an AVX2+FMA kernel on amd64 and a NEON kernel on arm64, in Go elsewhere. Nothing is allocated. Moved here from go-ndarray's internal/kernels with the AVX2 kernel of go-ndarray#94 and the NEON kernel of go-ndarray#95. It panics if len(dst) < len(src).
func Float32Log ¶ added in v0.9.0
func Float32Log(dst, src []float32)
Float32Log writes the correctly rounded float32 log(src[i]) into dst[i] for i < len(src) (proven over all 2^32 inputs by TestLog32CorrectlyRounded, which is env-gated): logCR, CORE-MATH's correctly rounded logf (MIT), on an AVX2 kernel on amd64 and a NEON kernel on arm64, in Go elsewhere. log(±0) = -Inf, log(+Inf) = +Inf, negative and NaN inputs give NaN. Nothing is allocated. Moved here from go-ndarray's internal/kernels with the kernels of go-ndarray#94 and #95. It panics if len(dst) < len(src).
func Float32Max ¶
Float32Max returns the largest element of a. It panics if a is empty. If a contains a NaN the result is NaN, and +0 orders above -0, as numpy.max. Same kernels as Float32Min.
func Float32Min ¶
Float32Min returns the smallest element of a. It panics if a is empty. If a contains a NaN the result is NaN, and -0 orders below +0, as numpy.min. SIMD kernels on amd64 (SSE2), arm64 (NEON), loong64 (LSX), ppc64le (VSX), riscv64 (RVV) and s390x (VXE); the four-chain loop elsewhere. The result is bit-for-bit the sequential loop's.
func Float32OverlapWindow ¶ added in v0.16.0
func Float32OverlapWindow(dst, a, b, win []float32)
Float32OverlapWindow is OverlapWindow on float32 values, computed in float32.
func Float32Sum ¶
Float32Sum returns Σ aᵢ over a float32 slice, accumulated in float32. The sum of an empty slice is 0.
func Floor ¶ added in v0.23.0
func Floor(dst, src []float64)
Floor computes dst[i] = math.Floor(src[i]) for i < len(src): the largest integer not above the value, ±0, ±Inf and NaN unchanged (np.floor). It panics if len(dst) < len(src).
func Log ¶ added in v0.9.0
func Log(dst, src []float64)
Log writes log(src[i]) into dst[i] for i < len(src), accurate to 0.519 ULP (0.507 near 1): a ULP-bounded log, not NumPy's bits (tolerance parity): on the AVX2 kernel where there is one (explog_amd64.go), on logScalar otherwise and for the blocks the kernel hands back. It panics if len(dst) < len(src). Moved here from go-ndarray's internal/kernels, with the AVX2 kernel of go-ndarray#96.
func MDCTFold ¶ added in v0.19.0
func MDCTFold(dst, x []float64)
MDCTFold writes the fold of the N = len(x) samples of x into dst[:N/2].
func MDCTFoldFrom32 ¶ added in v0.19.0
MDCTFoldFrom32 is MDCTFold with x read as float32 and widened.
func MDCTUnfold ¶ added in v0.19.0
func MDCTUnfold(dst, u []float64)
MDCTUnfold writes the unfolding of the M = len(u) values of u into dst[:2M].
func MDCTUnfoldTo32 ¶ added in v0.19.0
MDCTUnfoldTo32 is MDCTUnfold with each output rounded to float32.
func Max ¶
Max returns the largest element of a. It panics if a is empty. If a contains a NaN the result is NaN. Signed zeros are ordered -0 < +0, as NumPy's np.max and Go's builtin max: the maximum of any mix containing a +0 is +0.
func MaxAbs ¶ added in v0.5.0
MaxAbs returns the infinity norm max |v[i]|, and 0 for an empty slice. If any element is NaN (of either sign) it returns NaN (math.NaN()); ±Inf elements give +Inf.
func MaxAbsMul ¶ added in v0.25.0
MaxAbsMul returns max over i of |v[i]|*w[i], folded with C's fmax from +0:
- a NaN product (a NaN element, or Inf*0) is ignored, as fmax ignores a NaN argument; the result is NaN never (unlike MaxAbs, which propagates it);
- the fold starts at +0 and a product replaces the running maximum when it is greater or equal, so a negative product (w < 0) never wins over the seed and the sign of a zero result is that of the last zero product seen, +0 if there is none: exactly the loop `m = fmax(m, |v[i]|*w[i])` with m = +0;
- it returns +0 for an empty slice.
It panics if len(w) < len(v). Only the first len(v) elements of w are read.
func Maximum ¶ added in v0.26.0
func Maximum(dst, a, b []float64)
Maximum computes dst[i] = max(a[i], b[i]) for i < len(a), the Go builtin max: NaN-propagating, +0 above -0, np.maximum up to the choice of NaN and the order of a (-0, +0) pair. With a vector kernel a NaN operand is returned unchanged and, if both are NaNs, b[i]'s; where no kernel runs it is the builtin loop, whose NaN choice is target-dependent (see README). It panics if len(b) < len(a) or len(dst) < len(a).
func Min ¶
Min returns the smallest element of a. It panics if a is empty. If a contains a NaN the result is NaN. Signed zeros are ordered -0 < +0, as NumPy's np.min and Go's builtin min: the minimum of any mix containing a -0 is -0.
func Minimum ¶ added in v0.26.0
func Minimum(dst, a, b []float64)
Minimum computes dst[i] = min(a[i], b[i]) for i < len(a), the Go builtin min: NaN-propagating, -0 below +0, np.minimum up to the choice of NaN and the order of a (-0, +0) pair. With a vector kernel a NaN operand is returned unchanged and, if both are NaNs, b[i]'s; where no kernel runs it is the builtin loop, whose NaN choice is target-dependent (see README). It panics if len(b) < len(a) or len(dst) < len(a).
func MirrorCombine ¶ added in v0.27.0
func MirrorCombine(dst, z, w1, w2 []float64)
MirrorCombine writes r[k], k = 1 .. n-1, as complex numbers into dst[2k], dst[2k+1].
func MirrorCombineSplit ¶ added in v0.27.0
func MirrorCombineSplit(dst, z, w1, w2 []float64)
MirrorCombineSplit writes Re r[k] to dst[k] and -Im r[k] to dst[2n-k], k = 1 .. n-1.
func Mul ¶ added in v0.5.0
func Mul(dst, a, b []float64)
Mul computes dst[i] = a[i]*b[i] for i < len(a). Elements of dst and b past len(a) are left untouched. It panics if len(b) < len(a) or len(dst) < len(a).
func Mul32 ¶ added in v0.30.0
func Mul32(dst, a, b []float32)
Mul32 computes dst[i] = a[i] * b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func MulAddRows ¶ added in v0.22.0
MulAddRows computes dst[j] += Σ_{k<rows} a[k*lda+j]*b[k*ldb+j] for every j < len(dst), each term a fused multiply-add in increasing k. rows = 0 or an empty dst do nothing. It panics if rows, lda or ldb is negative, if a or b is shorter than the contract says or the index would overflow, or if dst overlaps the elements read of a or b.
func MulAddRows32 ¶ added in v0.33.0
MulAddRows32 computes dst[j] += Σ_{k<rows} a[k*lda+j]*b[k*ldb+j] for every j < len(dst), in float32. rows = 0 or an empty dst do nothing. It panics if rows, lda or ldb is negative, if a or b is shorter than the contract says or the index would overflow, or if dst overlaps the elements read of a or b.
func Neg ¶ added in v0.23.0
func Neg(dst, src []float64)
Neg computes dst[i] = -src[i] for i < len(src): the sign bit is flipped, also for zeros, infinities and NaNs. It panics if len(dst) < len(src).
func OverlapWindow ¶ added in v0.16.0
func OverlapWindow(dst, a, b, win []float64)
OverlapWindow computes the windowed overlap-add of a and b under win into dst for n = len(a): dst has at least 2n elements, b at least n and win at least 2n. It writes dst[:2n] and panics if a slice is too short.
func Polyval ¶ added in v0.12.0
func Polyval(dst, x, c []float64)
Polyval computes dst[i] = p(x[i]) for i < len(x), where p is the polynomial c[0] + c[1]*t + ... + c[len(c)-1]*t^(len(c)-1) evaluated by Horner's rule in NumPy's order (numpy.polynomial.polynomial.polyval). It panics if len(dst) < len(x) or len(c) == 0 (NumPy raises IndexError). Elements of dst past len(x) are left untouched.
func RoundEven ¶ added in v0.23.0
func RoundEven(dst, src []float64)
RoundEven computes dst[i] = math.RoundToEven(src[i]) for i < len(src): the nearest integer, halfway cases to the even one (np.rint, and np.round with no decimals). It panics if len(dst) < len(src).
func Sqrt ¶ added in v0.8.0
func Sqrt(dst, src []float64)
Sqrt computes dst[i] = math.Sqrt(src[i]) for i < len(src): the correctly rounded square root, sqrt(-x) = NaN, sqrt(-0) = -0, sqrt(+Inf) = +Inf. It panics if len(dst) < len(src).
func Sqrt32 ¶ added in v0.30.0
func Sqrt32(dst, src []float32)
Sqrt32 computes dst[i] = float32(math.Sqrt(float64(src[i]))) for i < len(src): the correctly rounded square root, sqrt(-x) = NaN, sqrt(-0) = -0, sqrt(+Inf) = +Inf. It panics if len(dst) < len(src).
func Square ¶ added in v0.23.0
func Square(dst, src []float64)
Square computes dst[i] = src[i] * src[i] for i < len(src), one rounding per element (np.square). It panics if len(dst) < len(src).
func SquaredMagnitude ¶ added in v0.20.0
SquaredMagnitude writes dst[k] = (re_k² + im_k²)·s for the n = len(dst) complex numbers (re_k, im_k) = (c[2k], c[2k+1]).
func Sub ¶ added in v0.8.0
func Sub(dst, a, b []float64)
Sub computes dst[i] = a[i] - b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func Sub32 ¶ added in v0.30.0
func Sub32(dst, a, b []float32)
Sub32 computes dst[i] = a[i] - b[i] for i < len(a). It panics if len(b) < len(a) or len(dst) < len(a).
func SumPairwise ¶ added in v0.6.0
SumPairwise returns Σ aᵢ computed exactly as NumPy computes np.sum(a) for a contiguous one-dimensional float64 array: the same pairwise summation, with the same block size, the same eight-accumulator unrolling and the same order of partial sums. The result is bit-identical to np.sum(a) — on every architecture, because the order is fixed by this code rather than by the width of a vector register, and no step is a fused multiply-add.
It is the function to use when a result must be reproducible against NumPy (for instance a stopping test that compares np.std of a population with a tolerance). It is not the same as Sum, whose lane-blocked order trades reproducibility for speed on the SIMD kernels.
The sum of an empty slice is +0, and so is the sum of a slice holding only -0 (the reduction starts from +0), as in NumPy. NaN and ±Inf propagate by IEEE 754 rules; when several NaNs are summed which payload survives is, as in NumPy, up to the hardware.
The 8..128-element blocks at the leaves of the recursion run in SIMD on amd64 (AVX2: the eight accumulators r[0..7] are two 4-lane YMM registers) and arm64 (NEON: four 2-lane registers); every lane receives exactly the additions NumPy's scalar code performs on the matching r[j], so the bits do not change. Elsewhere the portable Go block (pairwiseBlockRef) runs; it is also the reference the tests compare the SIMD blocks against.
func Trunc ¶ added in v0.23.0
func Trunc(dst, src []float64)
Trunc computes dst[i] = math.Trunc(src[i]) for i < len(src): the integer part, rounding toward zero, with the sign of the value (Trunc(-0.5) is -0) (np.trunc). It panics if len(dst) < len(src).
Types ¶
type AllPass3Plan ¶ added in v0.33.0
type AllPass3Plan struct {
// contains filtered or unexported fields
}
AllPass3Plan is a set of memory proved for AllPass3. It is not safe for concurrent use.
func NewAllPass3Plan ¶ added in v0.33.0
func NewAllPass3Plan(t *AllPassRows, out, in []complex128, inStride int, w [3][]complex128, wStride [3]int) (*AllPass3Plan, error)
NewAllPass3Plan proves the memory of n = len(t.Phi) rows and returns the plan. It returns an error, and no plan, if
- any table of t does not hold n elements, or n is 0,
- out holds fewer than n elements,
- a stride is below n, or a ring holds fewer than one slot (the input) or two slots (a link ring: one slot to read and another to write),
- any of out and the three link rings (the written memory) overlaps any other of them, the input ring or a table. The tables and the input ring may overlap one another: they are only read.
The slices are kept: the caller must not reslice them elsewhere to write the proved memory while a plan uses it through another name; the plan guarantees that its own calls never write outside out and the link rings.
func NewAllPass3TickPlan ¶ added in v0.41.0
func NewAllPass3TickPlan(t *AllPassRows, out, in []complex128, inStride int, w [3][]complex128, wStride [3]int, inDelay int) (*AllPass3Plan, error)
NewAllPass3TickPlan is NewAllPass3Plan for a decorrelator driven by a tick counter: the plan keeps inDelay, the age in ticks of the input slot that RunTick reads. It refuses, besides the cases of NewAllPass3Plan, an inDelay that is negative or not below the number of slots of the input ring.
func (*AllPass3Plan) Out ¶ added in v0.33.0
func (p *AllPass3Plan) Out() []complex128
Out is the output of the last Run: n elements, owned by the plan's caller.
func (*AllPass3Plan) Rows ¶ added in v0.33.0
func (p *AllPass3Plan) Rows() int
Rows is the number of rows n of the plan.
func (*AllPass3Plan) Run ¶ added in v0.33.0
func (p *AllPass3Plan) Run(inSlot int, oldSlot, curSlot [3]int)
Run computes the rows of one slot: the input is slot inSlot of the input ring, link l reads its state in slot oldSlot[l] of its ring and writes the new one to slot curSlot[l], and the result goes to Out. It panics, before reading or writing anything, if a slot number is out of range or a link reads the slot it writes.
func (*AllPass3Plan) RunTick ¶ added in v0.41.0
func (p *AllPass3Plan) RunTick(t int)
RunTick is Run for tick t: link l, whose ring holds m slots, reads slot (t+1) mod m and writes slot t mod m; the input is slot (t - inDelay) mod s of the input ring of s slots (inDelay is 0 for a plan from NewAllPass3Plan). The slots follow from t and from sizes proved at construction (every ring of a link holds at least two slots, so no link reads the slot it writes, and every slot is in range), so a call checks nothing and cannot panic for any t, negative or not. For t >= 0 the result is bit-identical to Run on those slots; a negative t reduces as uint(t) does, memory-safe but not continuous.
type AllPass3Plan32 ¶ added in v0.43.0
type AllPass3Plan32 struct {
// contains filtered or unexported fields
}
AllPass3Plan32 is a set of memory proved for AllPass3Split32. It is not safe for concurrent use.
func NewAllPass3TickPlan32 ¶ added in v0.43.0
func NewAllPass3TickPlan32(t *AllPassRows32, out, in Split32, inStride int, w [3]Split32, wStride [3]int, inDelay int) (*AllPass3Plan32, error)
NewAllPass3TickPlan32 proves the memory of n = len(t.PhiRe) rows for a decorrelator driven by a tick counter, and returns the plan. It returns an error, and no plan, if
- any table of t does not hold n elements, or n is 0,
- a plane of out holds fewer than n elements,
- the two planes of a ring differ in length, a stride is below n, or a ring holds fewer than one slot (the input) or two slots (a link ring: one to read and another to write),
- inDelay is negative or not below the number of slots of the input ring,
- any of out and the three link rings (the written memory, every plane) overlaps any other of them, the input ring or a table. The tables and the input ring may overlap one another: they are only read.
The slices are kept: the caller must not reslice them elsewhere to write the proved memory while a plan uses it through another name; the plan guarantees that its own calls never write outside out and the link rings.
func (*AllPass3Plan32) Out ¶ added in v0.43.0
func (p *AllPass3Plan32) Out() Split32
Out is the output of the last RunTick: n elements per plane, owned by the plan's caller.
func (*AllPass3Plan32) Rows ¶ added in v0.43.0
func (p *AllPass3Plan32) Rows() int
Rows is the number of rows n of the plan.
func (*AllPass3Plan32) RunTick ¶ added in v0.43.0
func (p *AllPass3Plan32) RunTick(t int)
RunTick computes the rows of tick t: link l, whose ring holds m slots, reads slot (t+1) mod m and writes slot t mod m; the input is slot (t - inDelay) mod s of the input ring of s slots; the result goes to Out. The slots follow from t and from sizes proved at construction (every ring of a link holds at least two slots, so no link reads the slot it writes, and every slot is in range), so a call checks nothing and cannot panic for any t, negative or not; a negative t reduces as uint(t) does, memory-safe but not continuous.
type AllPassRows ¶ added in v0.29.0
type AllPassRows struct {
Phi, Q0, Q1, Q2 []complex128
C0, C1, C2 []float64
}
AllPassRows holds the constants of the rows of a layout: Phi the rotation of the pre-delay, Q_l the rotation of link l, C_l its real coefficient.
type AllPassRows32 ¶ added in v0.43.0
type AllPassRows32 struct {
PhiRe, PhiIm, Q0Re, Q0Im, Q1Re, Q1Im, Q2Re, Q2Im []float32
C0, C1, C2 []float32
}
AllPassRows32 holds the constants of the rows of a layout: Phi the rotation of the pre-delay, Q_l the rotation of link l (each as two planes), C_l its real coefficient.
type PSMixPlan32 ¶ added in v0.44.0
type PSMixPlan32 struct {
// contains filtered or unexported fields
}
PSMixPlan32 is a list of runs proved once, for Run. It is immutable and may be shared by goroutines, as long as the planes they pass are not.
func NewPSMixPlan32 ¶ added in v0.44.0
func NewPSMixPlan32(runs []PSMixRun, nBands int) (*PSMixPlan32, error)
NewPSMixPlan32 checks the runs for nBands bands and returns the plan. It returns an error, and no plan, if there is no run, nBands is not positive, a run is empty or negative, has a band outside [0, nBands) or a source outside [0, 3), or starts before the end of the run that precedes it (the runs must be in increasing row order and must not overlap), or a row number is 2^30 or more.
func (*PSMixPlan32) Run ¶ added in v0.44.0
func (p *PSMixPlan32) Run(gains, tg []float32, s Split32, d *[3]Split32, l, r Split32)
Run mixes the runs of the plan: gains holds four values per band (gLs, gLd, gRs, gRd of band b at 4b..4b+3), tg one transient gain per band, s the mono rows, d the three decorrelated sources and l and r the outputs. It panics if gains or tg is shorter than the plan's bands need, or a plane shorter than maxEnd+7 elements (a source that no run uses may be empty).
func (*PSMixPlan32) Runs ¶ added in v0.44.0
func (p *PSMixPlan32) Runs() int
Runs is the number of runs of the plan.
Source Files
¶
- allpass.go
- allpass32.go
- allpass32_amd64.go
- allpass32_plan.go
- allpass_amd64.go
- allpass_plan.go
- axpy.go
- binop.go
- binop32.go
- binop32_amd64.go
- binop_amd64.go
- cdot.go
- cdot_amd64.go
- cmulto.go
- cmulto_amd64.go
- cmulziprev.go
- cmulziprev_amd64.go
- conjrev.go
- conjrev_amd64.go
- elem.go
- exp32.go
- exp64.go
- explog_amd64.go
- extrema32.go
- extrema32_amd64.go
- extrema_amd64.go
- floats.go
- floats32.go
- fold.go
- fold_amd64.go
- gather.go
- kernels_amd64.go
- log32.go
- log64.go
- maxabsmul.go
- maxabsmul_amd64.go
- maxmin.go
- maxmin_amd64.go
- mirror.go
- mirror_amd64.go
- mulrows.go
- mulrows32.go
- mulrows32_amd64.go
- mulrows_amd64.go
- nofma.go
- nofma_amd64.go
- overlap.go
- overlap_amd64.go
- polyval.go
- polyval_amd64.go
- psmix32.go
- psmix32_amd64.go
- reference.go
- round.go
- round_amd64.go
- sqmag.go
- sqmag_amd64.go
- sumpairwise.go
- twiddle.go
- twiddle_amd64.go
