LICENSE=BSD-3-ClauseCGO_ENABLED=0go-approx is the approximation layer of the Go scientific stack: interpolation and splines with the semantics of scipy.interpolate, and polynomials with those of numpy.polyfit, numpy.roots and numpy.polynomial. Both libraries run SciPy and NumPy as oracles from their tests and record where they differ. No cgo.
s, _ := interp.NewCubicSpline(x, y, "not-a-knot") // scipy CubicSpline v := s.At(2.5) d := s.Derivative(1).At(2.5) area := s.Integrate(0, 4) fit, _ := poly.Polyfit(x, y, 3, nil) // np.polyfit r, _ := poly.Roots(fit.Coef) // np.roots
Each Go function names the SciPy, NumPy or MATLAB call it corresponds to, and the deliberate differences are listed in each library's README.
interp1d kinds, cubic splines with not-a-knot, natural, clamped and periodic conditions, Hermite, PCHIP, Akima and makima.
make_interp_spline of any degree, make_lsq_spline, FITPACK smoothing splines, design matrices, derivatives, antiderivatives and integrals.
Regular-grid interpolation (linear to quintic), tensor-product splines and bicubic interpolation.
Evaluation by Horner or compensated Horner, arithmetic, derivatives, integrals, companion-matrix roots.
Polyfit with weights, rcond and covariance, and fits in the Chebyshev, Legendre, Hermite, HermiteE and Laguerre bases.
No cgo. poly's CI runs Linux, macOS, Windows, arm64, and qemu riscv64, loong64, ppc64le, s390x and arm.
Chebyshev approximation and AAA rational approximation are not written yet.
Every repository of the organization. Ported code keeps its attribution in place.
The fixtures are written by tests that call the reference — SciPy 1.18.1 and NumPy 2.5.4 — committed, and compared in the ordinary tests. What differs, and why, is in each library's documentation.
SciPy 1.18.1 and NumPy 2.5.4 are run from Go by a tag-gated harness that writes the fixtures; the ordinary tests read them and need no Python. Where SciPy raises, the Go constructor returns an error and the fixture says so. (interp)
1, 2 and 3 points, duplicate and unsorted x, NaN and Inf, nodes clustered over 14 orders of magnitude, offsets of 1e8, spans of 1e-9, values of 1e150 and 1e-290, and n = 1e5 and 1e6. (interp)
Polyval, Polyder, Polyint, Polyadd, Polysub, Deconv and PolyFromRoots: 3434 of 3434 values bit-identical to NumPy; each of the five bases: 10016 of 10016. (poly)
PolyvalComp: worst error over the theoretical bound is 0.00095, and it is more accurate than Horner at 677 of 780 points. (poly)
When our sum of squared residuals and NumPy’s differ by more than 1000 eps y², both are judged against the exact residual (normal equations at 256 bits). (poly)
poly holds 100.0% statement coverage and its CI runs Linux, macOS, Windows, arm64, qemu riscv64, loong64, ppc64le, s390x and arm, 386, and compiles every GOOS/GOARCH. (poly)
Interpolation, splines and smoothing: interp1d, cubic splines with every boundary condition, PCHIP, Akima and makima, B-splines of any degree, FITPACK smoothing splines and the legacy splrep, least-squares splines, regular-grid and tensor-product interpolation.
Polynomials: evaluation (Horner and compensated), arithmetic, least-squares fitting, roots, and the Chebyshev, Legendre, Hermite, HermiteE and Laguerre bases, with the semantics of numpy.polyfit, numpy.roots and numpy.polynomial.
The documentation (Hugo + Hextra): one section per library, made of its own README, with its verification and performance. Source →
Logos and icons for the organization, in SVG / PNG / JPG / ICO / ICNS across colour, white and black variants.
go-approx belongs to the family of go-numerics (optimisation, quadrature, special functions) and go-statistics. What is not there yet — scattered-data interpolation, periodic and parametric smoothing splines, Chebyshev and AAA approximation — is listed in the documentation.
Read the source on GitHub →