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 the Nx 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 by defn 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

Callbacks

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

abs(out :: tensor(), tensor()) :: tensor()

Specs

acos(out :: tensor(), tensor()) :: tensor()

Specs

acosh(out :: tensor(), tensor()) :: tensor()
Link to this callback

add(out, tensor, tensor)

View Source

Specs

add(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

all(out, tensor, keyword)

View Source

Specs

all(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

any(out, tensor, keyword)

View Source

Specs

any(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

argmax(out, tensor, keyword)

View Source

Specs

argmax(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

argmin(out, tensor, keyword)

View Source

Specs

argmin(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

argsort(out, tensor, keyword)

View Source

Specs

argsort(out :: tensor(), tensor(), keyword()) :: tensor()

Specs

as_type(out :: tensor(), tensor()) :: tensor()

Specs

asin(out :: tensor(), tensor()) :: tensor()

Specs

asinh(out :: tensor(), tensor()) :: tensor()

Specs

atan(out :: tensor(), tensor()) :: tensor()
Link to this callback

atan2(out, tensor, tensor)

View Source

Specs

atan2(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

atanh(out :: tensor(), tensor()) :: tensor()
Link to this callback

backend_copy(tensor, module, backend_options)

View Source

Specs

backend_copy(tensor(), module(), backend_options()) :: tensor()
Link to this callback

backend_deallocate(tensor)

View Source

Specs

backend_deallocate(tensor()) :: :ok | :already_deallocated
Link to this callback

backend_transfer(tensor, module, backend_options)

View Source

Specs

backend_transfer(tensor(), module(), backend_options()) :: tensor()

Specs

bitcast(out :: tensor(), tensor()) :: tensor()
Link to this callback

bitwise_and(out, tensor, tensor)

View Source

Specs

bitwise_and(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

bitwise_not(out, tensor)

View Source

Specs

bitwise_not(out :: tensor(), tensor()) :: tensor()
Link to this callback

bitwise_or(out, tensor, tensor)

View Source

Specs

bitwise_or(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

bitwise_xor(out, tensor, tensor)

View Source

Specs

bitwise_xor(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

broadcast(out, tensor, shape, axes)

View Source

Specs

broadcast(out :: tensor(), tensor(), shape(), axes()) :: tensor()

Specs

cbrt(out :: tensor(), tensor()) :: tensor()

Specs

ceil(out :: tensor(), tensor()) :: tensor()

Specs

cholesky(out :: tensor(), tensor()) :: tensor()
Link to this callback

clip(out, tensor, min, max)

View Source

Specs

clip(out :: tensor(), tensor(), min :: tensor(), max :: tensor()) :: tensor()
Link to this callback

concatenate(out, tensor, axis)

View Source

Specs

concatenate(out :: tensor(), tensor(), axis()) :: tensor()
Link to this callback

constant(out, binary, backend_options)

View Source

Specs

constant(out :: tensor(), binary(), backend_options()) :: tensor()
Link to this callback

conv(out, tensor, kernel, keyword)

View Source

Specs

conv(out :: tensor(), tensor(), kernel :: tensor(), keyword()) :: tensor()

Specs

cos(out :: tensor(), tensor()) :: tensor()

Specs

cosh(out :: tensor(), tensor()) :: tensor()
Link to this callback

count_leading_zeros(out, tensor)

View Source

Specs

count_leading_zeros(out :: tensor(), tensor()) :: tensor()
Link to this callback

divide(out, tensor, tensor)

View Source

Specs

divide(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

dot(out, tensor, axes, axes, tensor, axes, axes)

View Source

Specs

dot(out :: tensor(), tensor(), axes(), axes(), tensor(), axes(), axes()) ::
  tensor()
Link to this callback

eigh({}, tensor, keyword)

View Source

Specs

eigh({eigenvals :: tensor(), eigenvecs :: tensor()}, tensor(), keyword()) ::
  tensor()
Link to this callback

equal(out, tensor, tensor)

View Source

Specs

equal(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

erf(out :: tensor(), tensor()) :: tensor()

Specs

erf_inv(out :: tensor(), tensor()) :: tensor()

Specs

erfc(out :: tensor(), tensor()) :: tensor()

Specs

exp(out :: tensor(), tensor()) :: tensor()

Specs

expm1(out :: tensor(), tensor()) :: tensor()
Link to this callback

eye(tensor, backend_options)

View Source

Specs

eye(tensor(), backend_options()) :: tensor()

Specs

floor(out :: tensor(), tensor()) :: tensor()
Link to this callback

from_binary(out, binary, backend_options)

View Source

Specs

from_binary(out :: tensor(), binary(), backend_options()) :: tensor()
Link to this callback

gather(out, input, indices)

View Source

Specs

gather(out :: tensor(), input :: tensor(), indices :: tensor()) :: tensor()
Link to this callback

greater(out, tensor, tensor)

View Source

Specs

greater(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

greater_equal(out, tensor, tensor)

View Source

Specs

greater_equal(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

indexed_add(out, tensor, tensor, tensor)

View Source

Specs

indexed_add(out :: tensor(), tensor(), tensor(), tensor()) :: tensor()

Specs

inspect(tensor(), Inspect.Opts.t()) :: tensor()
Link to this callback

iota(tensor, arg2, backend_options)

View Source

Specs

iota(tensor(), axis() | nil, backend_options()) :: tensor()
Link to this callback

left_shift(out, tensor, tensor)

View Source

Specs

left_shift(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

less(out, tensor, tensor)

View Source

Specs

less(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

less_equal(out, tensor, tensor)

View Source

Specs

less_equal(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

log(out :: tensor(), tensor()) :: tensor()

Specs

log1p(out :: tensor(), tensor()) :: tensor()
Link to this callback

logical_and(out, tensor, tensor)

View Source

Specs

logical_and(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

logical_or(out, tensor, tensor)

View Source

Specs

logical_or(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

logical_xor(out, tensor, tensor)

View Source

Specs

logical_xor(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

logistic(out :: tensor(), tensor()) :: tensor()

Specs

lu({p :: tensor(), l :: tensor(), u :: tensor()}, tensor(), keyword()) ::
  tensor()
Link to this callback

map(out, tensor, keyword, function)

View Source

Specs

map(out :: tensor(), tensor(), keyword(), (... -> any())) :: tensor()
Link to this callback

max(out, tensor, tensor)

View Source

Specs

max(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

min(out, tensor, tensor)

View Source

Specs

min(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

multiply(out, tensor, tensor)

View Source

Specs

multiply(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

negate(out :: tensor(), tensor()) :: tensor()
Link to this callback

not_equal(out, tensor, tensor)

View Source

Specs

not_equal(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

pad(out, tensor, pad_value, padding_config)

View Source

Specs

pad(out :: tensor(), tensor(), pad_value :: tensor(), padding_config :: list()) ::
  tensor()
Link to this callback

population_count(out, tensor)

View Source

Specs

population_count(out :: tensor(), tensor()) :: tensor()
Link to this callback

power(out, tensor, tensor)

View Source

Specs

power(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

product(out, tensor, keyword)

View Source

Specs

product(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

put_slice(out, tensor, tensor, list)

View Source

Specs

put_slice(out :: tensor(), tensor(), tensor(), list()) :: tensor()

Specs

qr({q :: tensor(), r :: tensor()}, tensor(), keyword()) :: tensor()
Link to this callback

quotient(out, tensor, tensor)

View Source

Specs

quotient(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

random_normal(tensor, mu, sigma, backend_options)

View Source

Specs

random_normal(tensor(), mu :: tensor(), sigma :: tensor(), backend_options()) ::
  tensor()
Link to this callback

random_uniform(tensor, tensor, tensor, backend_options)

View Source

Specs

random_uniform(tensor(), tensor(), tensor(), backend_options()) :: tensor()
Link to this callback

reduce(out, tensor, acc, keyword, function)

View Source

Specs

reduce(out :: tensor(), tensor(), acc :: tensor(), keyword(), (... -> any())) ::
  tensor()
Link to this callback

reduce_max(out, tensor, keyword)

View Source

Specs

reduce_max(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

reduce_min(out, tensor, keyword)

View Source

Specs

reduce_min(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

remainder(out, tensor, tensor)

View Source

Specs

remainder(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

reshape(out :: tensor(), tensor()) :: tensor()
Link to this callback

reverse(out, tensor, axes)

View Source

Specs

reverse(out :: tensor(), tensor(), axes()) :: tensor()
Link to this callback

right_shift(out, tensor, tensor)

View Source

Specs

right_shift(out :: tensor(), tensor(), tensor()) :: tensor()

Specs

round(out :: tensor(), tensor()) :: tensor()

Specs

rsqrt(out :: tensor(), tensor()) :: tensor()
Link to this callback

select(out, tensor, tensor, tensor)

View Source

Specs

select(out :: tensor(), tensor(), tensor(), tensor()) :: tensor()

Specs

sign(out :: tensor(), tensor()) :: tensor()

Specs

sin(out :: tensor(), tensor()) :: tensor()

Specs

sinh(out :: tensor(), tensor()) :: tensor()
Link to this callback

slice(out, tensor, list, list, list)

View Source

Specs

slice(out :: tensor(), tensor(), list(), list(), list()) :: tensor()
Link to this callback

sort(out, tensor, keyword)

View Source

Specs

sort(out :: tensor(), tensor(), keyword()) :: tensor()

Specs

sqrt(out :: tensor(), tensor()) :: tensor()
Link to this callback

squeeze(out, tensor, axes)

View Source

Specs

squeeze(out :: tensor(), tensor(), axes()) :: tensor()
Link to this callback

subtract(out, tensor, tensor)

View Source

Specs

subtract(out :: tensor(), tensor(), tensor()) :: tensor()
Link to this callback

sum(out, tensor, keyword)

View Source

Specs

sum(out :: tensor(), tensor(), keyword()) :: tensor()
Link to this callback

svd({}, tensor, keyword)

View Source

Specs

svd({u :: tensor(), s :: tensor(), v :: tensor()}, tensor(), keyword()) ::
  tensor()
Link to this callback

take(out, input, indices, axis)

View Source

Specs

take(out :: tensor(), input :: tensor(), indices :: tensor(), axis()) ::
  tensor()
Link to this callback

take_along_axis(out, input, indices, axis)

View Source

Specs

take_along_axis(out :: tensor(), input :: tensor(), indices :: tensor(), axis()) ::
  tensor()

Specs

tan(out :: tensor(), tensor()) :: tensor()

Specs

tanh(out :: tensor(), tensor()) :: tensor()
Link to this callback

to_batched_list(out, tensor, keyword)

View Source

Specs

to_batched_list(out :: tensor(), tensor(), keyword()) :: [tensor()]
Link to this callback

to_binary(tensor, limit)

View Source

Specs

to_binary(tensor(), limit :: non_neg_integer()) :: binary()
Link to this callback

transpose(out, tensor, axes)

View Source

Specs

transpose(out :: tensor(), tensor(), axes()) :: tensor()
Link to this callback

triangular_solve(out, a, b, keyword)

View Source

Specs

triangular_solve(out :: tensor(), a :: tensor(), b :: tensor(), keyword()) ::
  tensor()
Link to this callback

window_max(out, tensor, shape, keyword)

View Source

Specs

window_max(out :: tensor(), tensor(), shape(), keyword()) :: tensor()
Link to this callback

window_min(out, tensor, shape, keyword)

View Source

Specs

window_min(out :: tensor(), tensor(), shape(), keyword()) :: tensor()
Link to this callback

window_product(out, tensor, shape, keyword)

View Source

Specs

window_product(out :: tensor(), tensor(), shape(), keyword()) :: tensor()
Link to this callback

window_reduce(out, tensor, acc, shape, keyword, function)

View Source

Specs

window_reduce(
  out :: tensor(),
  tensor(),
  acc :: tensor(),
  shape(),
  keyword(),
  (... -> any())
) ::
  tensor()
Link to this callback

window_scatter_max(out, tensor, tensor, tensor, shape, keyword)

View Source

Specs

window_scatter_max(
  out :: tensor(),
  tensor(),
  tensor(),
  tensor(),
  shape(),
  keyword()
) :: tensor()
Link to this callback

window_scatter_min(out, tensor, tensor, tensor, shape, keyword)

View Source

Specs

window_scatter_min(
  out :: tensor(),
  tensor(),
  tensor(),
  tensor(),
  shape(),
  keyword()
) :: tensor()
Link to this callback

window_sum(out, tensor, shape, keyword)

View Source

Specs

window_sum(out :: tensor(), tensor(), shape(), keyword()) :: tensor()

Link to this section Functions

Link to this function

inspect(map, binary, inspect_opts)

View Source

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