> ## Documentation Index
> Fetch the complete documentation index at: https://docs.muna.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Supported Types

> Value types supported for compiled model inputs and outputs.

Muna supports a [fixed set](https://docs.muna.ai/sdk/predictions.md#using-inference-values) of input and output value
types for compiled models. Below are supported type annotations:

> [accordion] Floating Point Values
>
> Floating-point input and return values should be annotated with the `float` built-in type.
>
> ```py icon="python" theme={null}
> from muna import compile
>
> @compile(...)
> def square(number: float) -> float:
>     return number ** 2
> ```
>
> > [!WARNING]
> >
> > Unlike Python which defaults to 64-bit floats, Muna will always lower a Python `float` to 32 bits.
>
> For control over the binary width of the number, use the `numpy.float[16,32,64]` types:
>
> ```py icon="python" theme={null}
> from muna import compile
> import numpy as np
>
> @compile(...)
> def square(number: np.float64) -> float64:
>     return number ** 2
> ```

> [accordion] Integer Values
>
> Integer input and return values should be annotated with the `int` built-in type.
>
> ```py icon="python" theme={null}
> from muna import compile
>
> @compile(...)
> def square(number: int) -> int:
>     return number ** 2
> ```
>
> > [!WARNING]
> >
> > Unlike Python which supports arbitrary-precision integers, Muna will always lower a Python `int` to 32 bits.
>
> For control over the binary width of the integer, use the `numpy.int[8,16,32,64]` types:
>
> ```py icon="python" theme={null}
> from muna import compile
> import numpy as np
>
> @compile(...)
> def square(number: np.int16) -> np.int16:
>     return number ** 2
> ```

> [accordion] Boolean Values
>
> Boolean input and return values must be annotated with the `bool` built-in type.
>
> ```py icon="python" theme={null}
> from muna import compile
>
> @compile(...)
> def invert(on: bool) -> bool:
>     return not on
> ```

> [accordion] Tensor Values
>
> Tensor input and return values must be annotated with the NumPy `numpy.typing.NDArray[T]` type, where `T` is
> the tensor element type.
>
> ```py icon="python" theme={null}
> from muna import compile
> import numpy as np
> from numpy.typing import NDArray
>
> @compile(...)
> def cholesky_decompose(tensor: NDArray[np.float64]) -> np.ndarray:
>     return np.linalg.cholesky(tensor).astype("float32")
> ```
>
> > [!TIP]
> >
> > You can also annotate with the `np.ndarray` type, but doing so will always assume a `float32` element type (following
> > [PyTorch semantics](https://pytorch.org/docs/stable/generated/torch.get_default_dtype.html)).
>
> Below are the supported element types:
>
> | Numpy data type | Muna data type |
> | :- | :- |
> | `np.float16` | `float16` |
> | `np.float32` | `float32` |
> | `np.float64` | `float64` |
> | `np.int8` | `int8` |
> | `np.int16` | `int16` |
> | `np.int32` | `int32` |
> | `np.int64` | `int64` |
> | `np.uint8` | `uint8` |
> | `np.uint16` | `uint16` |
> | `np.uint32` | `uint32` |
> | `np.uint64` | `uint64` |
> | `bool` | `bool` |
>
> > [!WARNING]
> >
> > Muna does not yet support complex numbers or tensors.
>
> > [!WARNING]
> >
> > Muna only supports, and will always assume, little-endian ordering for multi-byte element types.

> [accordion] String Values
>
> String input and return values must be annotated with the `str` built-in type.
>
> ```py icon="python" theme={null}
> from muna import compile
>
> @compile(...)
> def uppercase(text: str) -> str:
>     return text.upper()
> ```

> [accordion] List Values
>
> List input and return values must be annotated with the `list[T]` built-in type, where `T` is the element type.
>
> ```py icon="python" theme={null}
> from muna import compile
>
> @compile(...)
> def slice(items: list[str]) -> list[str]:
>     return items[:3]
> ```
>
> > [!TIP]
> >
> > When the list element type `T` is a Pydantic `BaseModel`, a full JSON schema will be generated.
>
> > [!NOTE]
> >
> > Providing an element type `T` is optional but strongly recommended because it is used to generate a schema for the parameter or
> > return value.

> [accordion] Dictionary Values
>
> Dictionary input and return values can be annotated in one of two ways:
>
> 1. Using a Pydantic [`BaseModel`](https://docs.pydantic.dev/latest/concepts/models) subclass.
> 2. Using the `dict[str, T]` built-in type.
>
> ```py icon="python" theme={null}
> from muna import compile
> from pydantic import BaseModel
> from typing import Literal
>
> class Person(BaseModel):
>     city: str
>     age: int
>
> class Pet(BaseModel):
>     sound: Literal["bark", "meow"]
>     legs: int
>
> @compile(...)
> def choose_favorite_pet(person: Person) -> Pet:
>     return Pet(sound="meow", legs=6)
> ```
>
> > [!TIP]
> >
> > We strongly recommend the Pydantic `BaseModel` annotation, as it allows us to generate a full JSON schema.
>
> > [!WARNING]
> >
> > When using the `dict` annotation, they key type **must** be `str`. The value type `T` can be any arbitrary type.

> [accordion] Image Values
>
> Image input and return values must be annotated with the Pillow
> [`PIL.Image.Image`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image) type.
>
> ```py icon="python" theme={null}
> from muna import compile
> from PIL import Image
>
> @compile(...)
> def resize(image: Image.Image) -> Image.Image:
>     return image.resize((512, 512))
> ```

> [accordion] Binary Values
>
> Binary input and return values can be annotated in one of three ways:
>
> 1. Using the `bytes` built-in type.
> 2. Using the `bytearray` built-in type.
> 3. Using the `io.BytesIO` type.
>
> ```py icon="python" theme={null}
> from muna import compile
> from PIL import Image
>
> def resize_pixels(pixels: bytes) -> bytes
>     return Image.frombytes("L", (4,4), pixels).resize((8,8)).tobytes()
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.