> ## 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](/sdk/predictions#using-inference-values) of input and output value
types for compiled models. Below are supported type annotations:

<AccordionGroup>
  <Accordion title="Floating Point Values" icon="pi">
    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.
    </Warning>

    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>

  <Accordion title="Integer Values" icon="hundred-points">
    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.
    </Warning>

    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>

  <Accordion title="Boolean Values" icon="toggle-on">
    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>

  <Accordion title="Tensor Values" icon="fire-flame-curved">
    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)).
    </Tip>

    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>

    <Warning>
      Muna only supports, and will always assume, little-endian ordering for multi-byte element types.
    </Warning>
  </Accordion>

  <Accordion title="String Values" icon="quote-right" iconType="solid">
    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>

  <Accordion title="List Values" icon="brackets-square">
    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.
    </Tip>

    <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.
    </Note>
  </Accordion>

  <Accordion title="Dictionary Values" icon="brackets-curly">
    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.
    </Tip>

    <Warning>
      When using the `dict` annotation, they key type **must** be `str`. The value type `T` can be any arbitrary type.
    </Warning>
  </Accordion>

  <Accordion title="Image Values" icon="image">
    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>

  <Accordion title="Binary Values" icon="binary">
    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()
    ```
  </Accordion>
</AccordionGroup>


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