Vettore.Interop.Nx (Vettore v0.3.5)

Copy Markdown View Source

Optional interoperability with Nx.Tensor values.

Vettore does not use Nx for its vector kernels. This module deliberately resolves Nx at runtime so applications that only use lists or little-endian f32 binaries do not need to install or start Nx.

Add {:nx, "~> 0.11"} to the host application's dependencies when tensor conversion is required.

Summary

Functions

Returns whether a compatible Nx module is available in the host application.

Creates an f32 Nx tensor, optionally with a shape and host-provided backend.

Returns an Nx tensor's original shape.

Returns whether the value is an Nx tensor without requiring Nx at compile time.

Flattens an Nx tensor into an ordinary Elixir list.

Transfers an Nx tensor to a host-provided backend such as EXLA.

Returns an Nx tensor's element type.

Functions

available?()

@spec available?() :: boolean()

Returns whether a compatible Nx module is available in the host application.

from_list(vector, opts \\ [])

@spec from_list(
  [number()],
  keyword()
) ::
  {:ok, term()}
  | {:error,
     :invalid_options | :invalid_shape | :invalid_vector | :nx_not_available}

Creates an f32 Nx tensor, optionally with a shape and host-provided backend.

shape(tensor)

@spec shape(term()) :: {:ok, tuple()} | {:error, :invalid_vector | :nx_not_available}

Returns an Nx tensor's original shape.

tensor?(arg1)

@spec tensor?(term()) :: boolean()

Returns whether the value is an Nx tensor without requiring Nx at compile time.

to_list(tensor)

@spec to_list(term()) ::
  {:ok, [number()]} | {:error, :invalid_vector | :nx_not_available}

Flattens an Nx tensor into an ordinary Elixir list.

transfer(tensor, backend)

@spec transfer(term(), term()) ::
  {:ok, term()} | {:error, :invalid_vector | :nx_not_available}

Transfers an Nx tensor to a host-provided backend such as EXLA.

type(tensor)

@spec type(term()) :: {:ok, term()} | {:error, :invalid_vector | :nx_not_available}

Returns an Nx tensor's element type.