reference

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Epsilon = 0x1p-52

Epsilon is the gap between 1.0 and the next float64 (2^-52) used to express relative error in ULPs it can undercount by up to 2x, since the relative gap between neighbouring float64s varies between 2^-53 and 2^-52 within each power of two

Variables

This section is empty.

Functions

func AssertClose

func AssertClose[T Number](t testing.TB, name string, got, want []T, tol Tolerance)

AssertClose fails t for every element of got outside tol of want

func Run

func Run[T any](t *testing.T, category string, check func(t *testing.T, v T))

Run loads category's reference vectors and runs check on each as a subtest named after its file

Types

type Comparison

type Comparison struct {
	// Worst is the largest |got-want| relative to the comparison's scale:
	// the measured error that tolerances are set from
	Worst      float64
	Mismatches []Mismatch
}

Comparison is the outcome of comparing got against want

func Compare

func Compare[T Number](got, want []T, tol Tolerance) (c Comparison, err error)

Compare measures got against want element by element, with errors relative to max|want| (see Tolerance) NaN in the same position of both counts as a match, as in numpy.allclose(equal_nan=True) NaN in only one is always a mismatch

func CompareScaled

func CompareScaled[T Number](got, want []T, tol Tolerance, floor float64) (c Comparison, err error)

CompareScaled is Compare with errors measured relative to max(max|want|, floor) use it when want can legitimately be ~0 while the computation that produced it handled much larger values, such as a filter rejecting its input: rounding error then scales with those values, and relative to ~0 alone it would look enormous

type Complex added in v0.2.0

type Complex struct {
	Re []float64 `json:"re"`
	Im []float64 `json:"im"`
}

Complex is a vector of complex values as stored in reference vector JSON {"re":[...], "im":[...]}

func (Complex) Values added in v0.2.0

func (c Complex) Values() (values []complex128, err error)

Values combines Re and Im into complex values

type File

type File[T any] struct {
	Name   string // file name, e.g. "butter2_1p0.3_step.json"
	Vector T
}

File is one decoded reference vector file

func Load

func Load[T any](category string) (files []File[T], err error)

Load decodes every testdata/<category>/*.json into a T, in file-name order unknown JSON fields are an error, so a mistyped struct tag fails loudly instead of silently decoding as an empty field

type Meta

type Meta struct {
	Description  string `json:"description"`
	SciPyVersion string `json:"scipy_version"`
	NumPyVersion string `json:"numpy_version"`
}

Meta is the header every reference vector file carries: embed it in each vector type

type Mismatch

type Mismatch struct {
	Index         int
	Diff, Allowed float64
}

Mismatch is one element outside tolerance

type Number

type Number interface {
	float64 | complex128
}

Number is the element types Compare can handle

type Tolerance

type Tolerance struct {
	Rel    float64 // relative to each expected value
	Scaled float64 // relative to the comparison's scale, so small but valid slices are still checked
}

Tolerance says how close got must be to want for a slice comparison a value passes if |got-want| <= Scaled*scale + Rel*|want|, where scale is max|want|, or the floor given to CompareScaled if that's larger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL