Nx.Backend behaviour (Nx v0.1.0) View Source
The behaviour for tensor backends.
Each backend is module that defines a struct and implements the callbacks
defined in this module. The callbacks are mostly implementations of the
functions in the Nx
module with the tensor output shape given as first
argument.
Nx
backends come in two flavors: opaque backends, of which you should
not access its data directly except through the functions in the Nx
module, and public ones, of which its data can be directly accessed and
traversed. The former typically have the Backend
suffix.
Nx
ships with the following backends:
Nx.BinaryBackend
- an opaque backend written in pure Elixir that stores the data in Elixir's binaries. This is the default backend used by theNx
module. The backend itself (and its data) is private and must not be accessed directly.Nx.TemplateBackend
- an opaque backend written that works as a template in APIs to declare the type, shape, and names of tensors to be expected in the future.Nx.Defn.Expr
- a public backend used bydefn
to build expression trees that are traversed by custom compilers.
This module also includes functions that are meant to be shared across backends.
Link to this section Summary
Functions
Inspects the given tensor given by binary
.
Link to this section Types
Specs
axes() :: Nx.Tensor.axes()
Specs
axis() :: Nx.Tensor.axis()
Specs
backend_options() :: term()
Specs
shape() :: Nx.Tensor.shape()
Specs
t() :: %{__struct__: atom()}
Specs
tensor() :: Nx.Tensor.t()
Link to this section Callbacks
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
backend_copy(tensor(), module(), backend_options()) :: tensor()
Specs
backend_deallocate(tensor()) :: :ok | :already_deallocated
Specs
backend_transfer(tensor(), module(), backend_options()) :: tensor()
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
constant(out :: tensor(), binary(), backend_options()) :: tensor()
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
eye(tensor(), backend_options()) :: tensor()
Specs
Specs
from_binary(out :: tensor(), binary(), backend_options()) :: tensor()
Specs
Specs
Specs
Specs
Specs
inspect(tensor(), Inspect.Opts.t()) :: tensor()
Specs
iota(tensor(), axis() | nil, backend_options()) :: tensor()
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
random_normal(tensor(), mu :: tensor(), sigma :: tensor(), backend_options()) :: tensor()
Specs
random_uniform(tensor(), tensor(), tensor(), backend_options()) :: tensor()
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
to_binary(tensor(), limit :: non_neg_integer()) :: binary()
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Specs
Link to this section Functions
Inspects the given tensor given by binary
.
Note the binary
may have fewer elements than the
tensor size but, in such cases, it must strictly have
more elements than inspect_opts.limit