# `Vix.Tensor`
[🔗](https://github.com/akash-akya/vix/blob/v0.38.0/lib/vix/tensor.ex#L1)

Struct to hold raw pixel data returned by the libvips along with metadata about the binary.

Useful for interoperability between other libraries like [Nx](https://hexdocs.pm/nx/Nx.html), [Evision](https://github.com/cocoa-xu/evision/).

See `Vix.Vips.Image.write_to_tensor/1` to convert an vix image to tensor.

# `t`
[🔗](https://github.com/akash-akya/vix/blob/v0.38.0/lib/vix/tensor.ex#L35)

```elixir
@type t() :: %Vix.Tensor{
  data: binary(),
  names: list(),
  shape: {non_neg_integer(), non_neg_integer(), non_neg_integer()},
  type: tensor_type()
}
```

Struct to hold raw pixel data returned by the Libvips along with metadata about the binary.

`:names` will always be `[:height, :width, :bands]`

# `tensor_type`
[🔗](https://github.com/akash-akya/vix/blob/v0.38.0/lib/vix/tensor.ex#L19)

```elixir
@type tensor_type() ::
  {:u, 8}
  | {:s, 8}
  | {:u, 16}
  | {:s, 16}
  | {:u, 32}
  | {:s, 32}
  | {:f, 32}
  | {:f, 64}
```

Type of the image pixel when image is represented as Tensor.

This type is useful for interoperability between different libraries. Type value is same as [`Nx.Type.t()`](https://hexdocs.pm/nx/Nx.Type.html)

# `type`
[🔗](https://github.com/akash-akya/vix/blob/v0.38.0/lib/vix/tensor.ex#L57)

```elixir
@spec type(image :: Vix.Vips.Image.t()) :: tensor_type() | no_return()
```

Convert Vix image pixel format to [Nx tensor type](https://hexdocs.pm/nx/Nx.Type.html#t:t/0)

Vix internally uses [libvips image
format](https://www.libvips.org/API/current/VipsImage.html#VipsBandFormat). To
ease the interoperability between Vix and other elixir libraries, we
can use this function.

---

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