# `TFLiteElixir`
[🔗](https://github.com/cocoa-xu/tflite_elixir/blob/main/lib/tflite_elixir.ex#L1)

This module contains some helper functions from the `tflite`
namespace in TensorFlow Lite's codebase.

# `print_interpreter_state`

```elixir
@spec print_interpreter_state(reference()) :: nil | {:error, String.t()}
```

Prints a dump of what tensors and what nodes are in the interpreter.

Note that this function directly prints to stdout. It answers `nil` once it
has, or `{:error, reason}` when another process is using the interpreter or
it belongs to one, which used to be swallowed and reported as `nil`.

# `reset_variable_tensor`

```elixir
@spec reset_variable_tensor(
  %TFLiteElixir.TFLiteTensor{
    index: term(),
    name: term(),
    quantization_params: term(),
    reference: term(),
    shape: term(),
    shape_signature: term(),
    sparsity_params: term(),
    type: term()
  }
  | reference()
) :: :ok | {:error, String.t()}
```

Resets a variable tensor to the default value.

# `source_tree`

```elixir
@spec source_tree() :: :litert
```

Which source tree the loaded shared object was built from. Answers `:litert`.

There is no other answer: the C++ behind it names a type only LiteRT's schema
defines, so a binary built from anything else does not compile, and a release
from before the move has no such function at all. Worth asking in a test rather
than trusting the build, because a stale precompiled artifact looks exactly
like a fresh one from the outside.

# `tensorflow_version`

```elixir
@spec tensorflow_version() :: String.t()
```

The TensorFlow release this build pulled in, for example `"2.21.0-rc0"`.

TensorFlow is not where the runtime comes from any more: LiteRT reaches into it
for `compiler/mlir/lite`, TSL and XLA. Worth having when something reads wrong,
not for matching a plugin against.

# `tflite_extension_apis_version`

```elixir
@spec tflite_extension_apis_version() :: String.t()
```

The version of the extension APIs: `c_api_opaque.h`, `common.h`,
`builtin_op_data.h` and `builtin_ops.h`.

Narrower in scope than `tflite_runtime_version/0` but derived from the same
stale number, so the same caveat applies.

# `tflite_runtime_version`

```elixir
@spec tflite_runtime_version() :: String.t()
```

The runtime version string `lite/version.h` carries.

Hand-maintained upstream and forgotten: the 2.21.0 tree still says `"2.19.0"`.
It only applies when the build system injects nothing, which Bazel does and
CMake does not, so two builds from different releases are indistinguishable
through this value. `tflite_version/0` is the one to match a plugin against.

# `tflite_schema_version`

```elixir
@spec tflite_schema_version() :: integer()
```

The major schema version this runtime reads model files at.

Unlike the version strings this one is real: it is defined next to the schema
it describes. A model serialised at a different schema version may not load.

# `tflite_version`

```elixir
@spec tflite_version() :: String.t()
```

The version of the TfLite sources this was built from, for example `"2.2.0"`.

Since the runtime moved to LiteRT's `tflite` subtree this is LiteRT's version,
not TensorFlow's. The two are separate version lines and the numbers are not
comparable: LiteRT's 2.2.0 is newer than TensorFlow's 2.21.0, not older. For
the TensorFlow release the build borrowed from, see `tensorflow_version/0`.

**This is the number a delegate plugin has to match.** A plugin loaded through
`TFLiteElixir.Delegate.external/1` must have been built from the same release;
upstream offers no binary stable delegate interface, so a mismatch is undefined
behaviour rather than an error.

# `xnnpack_max_tensor_dims`

```elixir
@spec xnnpack_max_tensor_dims() :: integer() | nil
```

How many dimensions XNNPACK will delegate a tensor with, or `nil` where this
build carries no XNNPACK.

A tensor already wider than this was refused by the delegate to begin with, was
therefore never delegated, and can still be reshaped freely. The armv6 and
armv7l builds answer `nil`, where nothing is refused.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
