reference

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 10 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

This section is empty.

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, source Source, category string, check func(t *testing.T, v T))

Run loads source's reference vectors for category, 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|, as Tolerance describes. NaN in the same position of both counts as a match, same as numpy.allclose(equal_nan=True), and 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 rightly be about 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 about 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_lp0.3_step.json"
	Vector T
}

File is one decoded reference vector file.

func Load

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

Load decodes every testdata/<source>/<category>/*.json into a T, in file-name order. An unknown JSON field is an error, so a mistyped struct tag fails loudly, rather than silently decoding as an empty field.

type Floats added in v0.5.0

type Floats []float64

Floats is a vector of floats, as stored in reference vector JSON, where NaN, which JSON can't represent, is null.

func (*Floats) UnmarshalJSON added in v0.5.0

func (f *Floats) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON decodes a JSON array of numbers and nulls, nulls as NaN.

type Meta

type Meta struct {
	Description string            `json:"description"`
	Versions    map[string]string `json:"versions"` // e.g. {"scipy": "1.18.1", "numpy": "2.5.3"}
}

Meta is the header every reference vector file carries, to embed 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 Source added in v0.4.0

type Source string

Source is the tool a set of reference vectors comes from, and the testdata directory they're in.

const (
	SourceSciPy  Source = "scipy"
	SourceMATLAB Source = "matlab"
)

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