testutil

package
v0.0.0-...-af68625 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

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

func FlattenSlice(v any) any

FlattenSlice is a helper to convert a nested slice of any into a flat slice.

func FromBuffer

func FromBuffer(backend compute.Backend, buf compute.Buffer) (any, error)

FromBuffer converts a compute.Buffer into a nested slice of the corresponding Go type.

func IsEqual

func IsEqual(want, got any) (ok bool, diff string)

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

func IsInDelta(want, got any, delta float64) (ok bool, diff string)

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

func IsInRelativeDelta(want, got any, relDelta float64) (ok bool, diff string)

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 Must

func Must(err error)

Must panics if there is an error.

func Must1

func Must1[T any](value T, err error) T

Must1 panics if there is an error and returns the value.

func SkipIfMissing

func SkipIfMissing(t *testing.T, b compute.Backend, op compute.OpType)

SkipIfMissing skips the current test if the backend doesn't support the given operation.

func SkipIfMissingDType

func SkipIfMissingDType(t *testing.T, b compute.Backend, dtype dtypes.DType)

SkipIfMissingDType skips the current test if the backend doesn't support the given data type.

func SkipIfMissingFunctions

func SkipIfMissingFunctions(t *testing.T, b compute.Backend)

SkipIfMissingFunctions skips the current test if the backend doesn't support functions (closures).

func ToBuffer

func ToBuffer(backend compute.Backend, v any) (compute.Buffer, error)

ToBuffer converts a nested slice of any into a buffer for the given backend.

func ToFlatAndShape

func ToFlatAndShape(v any) (any, shapes.Shape)

ToFlatAndShape converts a nested slice of any into a flat slice and a shape that can be fed into testBackend (or a BufferFromFlatData).

func Try

func Try(f func()) (panicked bool, reason any)

Try whether f panics, and also returns the panic value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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