Skip to content

Engine

engine

The engine under zeki's collections, built directly for float arithmetic: a DAG of float operations over arrays of one length, compiled once and evaluated in one parallel pass. The engine computes every kind for the collections; this interface to it takes floats only.

import numpy as np
from zeki import engine

length = 1_000_000
graph = engine.Graph(length)
gross = graph.input(np.random.lognormal(10, 1, length))
inflation = graph.input(np.full(length, 1.05))

trended = (gross * inflation) ** 1.03
# `trended` is one node: reusing it shares its computation.
capped = trended.min(1e5) + trended

losses = graph.compile(capped).eval()            # 1-D array
both = graph.compile([trended, capped]).eval()   # one row per output

It skips the collections' lineage, dims and kinds, so a large program of plain float arithmetic builds and evaluates with the least overhead. Most models want the collections.

Compiled

Compiled outputs, evaluated in one pass that releases the GIL.

eval

eval() -> NDArray[float64]

Every output, on all cores.

eval_serial

eval_serial() -> NDArray[float64]

As eval, on one thread.

Expr

A node of a Graph. Reusing one shares its computation.

Graph

Graph(length: int)

A DAG of float operations over arrays of one length.

input

input(values: NDArray[float64]) -> Expr

Add a 1-D C-contiguous float64 array of length values as an input.

compile

compile(outputs: Expr | Iterable[Expr]) -> Compiled

Freeze outputs into one pass: eval() gives a 1-D array for one Expr, and a row per output for a list.