Documentation
¶
Overview ¶
Package oracle drives NumPy/SciPy as a reference implementation from Go.
The only Python is the small dispatcher in Program: it resolves a dotted name (np.polyfit, np.polynomial.chebyshev.chebval, ...) or a method (".deriv" on the result of an earlier call), calls it with the decoded JSON arguments and encodes the result as JSON. Everything else - the requests, the comparison, the fixtures - is Go.
Transport is injected so that the package is fully testable without Python; the real "uv run" transport lives behind the "oracle" build tag (uv.go).
Index ¶
Constants ¶
const ( NumPyVersion = "2.5.4" SciPyVersion = "1.18.1" )
Versions pinned for the oracle.
const Program = `` /* 1637-byte string literal not displayed */
Program is the Python dispatcher given to "python -c". It reads one JSON request (a list of calls) per line on stdin and answers one JSON line.
Variables ¶
var ErrVersion = errors.New("oracle: version mismatch")
ErrVersion is returned by HealthCheck when the oracle's libraries differ from the pinned versions.
Functions ¶
Types ¶
type Call ¶
type Call struct {
Fn string
Args []any
Kw map[string]any
// Rep, when > 1, makes the oracle run the call Rep times and report the
// mean time per call (Result.Time).
Rep int
}
Call is a function call; Fn is a dotted name rooted at np, sp or ex, or ".method" to call a method on the first argument. Args may be nested Calls.
func (Call) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type Client ¶
type Client struct{ T Transport }
Client talks to the oracle through a Transport.
func (Client) Batch ¶
Batch sends the items (Call or Set values) as one request and returns one Result per item.
func (Client) HealthCheck ¶
HealthCheck verifies the oracle answers and runs numpy NumPyVersion and scipy SciPyVersion.
type Float ¶
type Float float64
Float is a float64 with the same JSON convention as Floats.
func (Float) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Float) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Floats ¶
type Floats []float64
Floats is a []float64 whose JSON form keeps NaN and +-Inf as the strings "nan", "inf", "-inf" and every finite value as a shortest round-trip number.
func (Floats) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Floats) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Result ¶
type Result struct {
Err string // non-empty when NumPy raised: "ValueError: ..."
Val Value // the result
Time float64 // seconds spent in the call itself (time.perf_counter)
}
Result is the answer to one item of a batch.
type Set ¶
Set stores the value V in the oracle process under Name.
func (Set) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type Value ¶
type Value struct {
Shape []int
Re, Im []float64
Complex bool
Tuple []Value
Str string
IsStr bool
IsTuple bool
}
Value is a decoded result: a (possibly 0-d) array, a tuple, or a string.
func (Value) Complexes ¶
func (v Value) Complexes() []complex128
Complexes returns the value as a complex slice (imaginary parts 0 for a real array).