Tune.Program behaviour (Tune v0.5.0)

Copy Markdown View Source

The contract for a typed Tune program.

A program is either a Tune.Predictor or a struct whose module implements this behaviour. Composition stays in ordinary Elixir functions.

Summary

Functions

Returns the program's declared parameters.

Replaces named parameters and returns the updated program.

Returns true when two signatures have the same field names and schemas.

Returns the program's signature.

Types

parameters()

@type parameters() :: %{
  required(String.t()) => Tune.Predictor.t() | Tune.Parameter.t()
}

t()

@type t() :: Tune.Predictor.t() | struct()

Callbacks

call(program, inputs, t)

@callback call(program :: struct(), inputs :: map(), Tune.Execution.t()) ::
  {:ok, map(), Tune.Execution.t()} | {:error, term(), Tune.Execution.t()}

parameters(program)

@callback parameters(program :: struct()) :: parameters()

put_parameters(program, parameters)

@callback put_parameters(program :: struct(), parameters()) :: struct()

signature(program)

@callback signature(program :: struct()) :: Tune.Signature.t()

Functions

parameters(predictor)

@spec parameters(t()) :: {:ok, parameters()} | {:error, Exception.t()}

Returns the program's declared parameters.

replace_parameters(program, updates)

@spec replace_parameters(t(), parameters()) :: {:ok, t()} | {:error, Exception.t()}

Replaces named parameters and returns the updated program.

Every name must exist. Each replacement must keep its kind and schema.

same_fields?(left, right)

@spec same_fields?(Tune.Signature.t(), Tune.Signature.t()) :: boolean()

Returns true when two signatures have the same field names and schemas.

signature(program)

@spec signature(t()) :: {:ok, Tune.Signature.t()} | {:error, Exception.t()}

Returns the program's signature.