Documentation
¶
Overview ¶
Package testutil provides utilities for testing a compute.Backend. It is used by the gobackend package to implement the "go" backend, but shared here as it could be used by other backends as well.
It includes helpers for:
- Comparison: IsEqual, IsInDelta and IsInRelativeDelta, implemented for various types, including the half-precision float16 and bfloat16.
- Buffer manipulation: ToBuffer and FromBuffer are not efficient, but convenient conversion of values to Go for testing.
Index ¶
- func Exec(backend compute.Backend, inputs []any, ...) ([]any, error)
- func Exec1(backend compute.Backend, inputs []any, ...) (any, error)
- func Exec2(backend compute.Backend, inputs []any, ...) (any, any, error)
- func Exec3(backend compute.Backend, inputs []any, ...) (any, any, any, error)
- func FlattenSlice(v any) any
- func FromBuffer(backend compute.Backend, buf compute.Buffer) (any, error)
- func IsEqual(want, got any) (ok bool, diff string)
- func IsInDelta(want, got any, delta float64) (ok bool, diff string)
- func IsInRelativeDelta(want, got any, relDelta float64) (ok bool, diff string)
- func Must(err error)
- func Must1[T any](value T, err error) T
- func SkipIfMissing(t *testing.T, b compute.Backend, op compute.OpType)
- func SkipIfMissingDType(t *testing.T, b compute.Backend, dtype dtypes.DType)
- func SkipIfMissingFunctions(t *testing.T, b compute.Backend)
- func ToBuffer(backend compute.Backend, v any) (compute.Buffer, error)
- func ToFlatAndShape(v any) (any, shapes.Shape)
- func Try(f func()) (panicked bool, reason any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
func Exec(backend compute.Backend, inputs []any, buildFn func(f compute.Function, params []compute.Value) ([]compute.Value, error), ) ([]any, error)
Exec builds, compiles, and executes graph with multiple inputs and outputs.
Each of the inputs are converted using ToBuffer, and the results are converted back to Go using FromBuffer.
func Exec1 ¶
func Exec1(backend compute.Backend, inputs []any, buildFn func(f compute.Function, params []compute.Value) (compute.Value, error), ) (any, error)
Exec1 is like Exec, but it has only 1 output.
func Exec2 ¶
func Exec2(backend compute.Backend, inputs []any, buildFn func(f compute.Function, params []compute.Value) (compute.Value, compute.Value, error), ) (any, any, error)
Exec2 is like Exec, but it has only 2 outputs.
func Exec3 ¶
func Exec3(backend compute.Backend, inputs []any, buildFn func(f compute.Function, params []compute.Value) (compute.Value, compute.Value, compute.Value, error), ) (any, any, any, error)
Exec3 is like Exec, but it has only 3 outputs.
func FlattenSlice ¶
FlattenSlice is a helper to convert a nested slice of any into a flat slice.
func FromBuffer ¶
FromBuffer converts a compute.Buffer into a nested slice of the corresponding Go type.
func IsEqual ¶
IsEqual returns whether want and got are equal using go-cmp. If they are not equal, it returns the diff using the format "-want +got").
func IsInDelta ¶
IsInDelta reports if want and got are equal within a given absolute delta. If they are not equal, it returns the diff using the format "-want +got").
func IsInRelativeDelta ¶
IsInRelativeDelta reports if want and got are equal within a given relative delta. If they are not equal, it returns the diff using the format "-want +got").
func SkipIfMissing ¶
SkipIfMissing skips the current test if the backend doesn't support the given operation.
func SkipIfMissingDType ¶
SkipIfMissingDType skips the current test if the backend doesn't support the given data type.
func SkipIfMissingFunctions ¶
SkipIfMissingFunctions skips the current test if the backend doesn't support functions (closures).
func ToFlatAndShape ¶
ToFlatAndShape converts a nested slice of any into a flat slice and a shape that can be fed into testBackend (or a BufferFromFlatData).
Types ¶
This section is empty.