# `Dala.ML.CoreML`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/ml/core_ml.ex#L1)

CoreML integration for iOS.

Provides an Elixir API for Apple's CoreML framework via NIF calls.
CoreML uses the Apple Neural Engine (ANE) for hardware-accelerated
ML inference on iOS devices and simulators.

All NIF functions run on the dirty CPU scheduler.

## Prerequisites

- iOS device or simulator
- CoreML model file (.mlmodel or .mlpackage)

## Usage

    # Load a model
    :ok = Dala.ML.CoreML.load_model("/path/to/model.mlmodel", "my_model")

    # Check if loaded
    true = Dala.ML.CoreML.loaded?("my_model")

    # Make prediction
    {:ok, result_json} = Dala.ML.CoreML.predict("my_model", %{
      "input": [1.0, 2.0, 3.0]
    })

    # Unload when done
    :ok = Dala.ML.CoreML.unload_model("my_model")

# `load_model`

```elixir
@spec load_model(String.t(), String.t()) :: :ok | {:error, term()} | :not_supported
```

Loads a CoreML model from the given path.

## Parameters

- `model_path`: Path to the .mlmodel or .mlpackage file
- `identifier`: A unique identifier for this model

## Returns

- `:ok` on success
- `{:error, reason}` on failure
- `:not_supported` on non-iOS platforms

# `loaded?`

```elixir
@spec loaded?(String.t()) :: boolean()
```

Checks if a model is loaded.

Returns `true` if loaded, `false` otherwise.
Returns `false` on non-iOS platforms.

# `loaded_models`

```elixir
@spec loaded_models() :: [String.t()]
```

Lists all loaded model identifiers.

# `predict`

```elixir
@spec predict(String.t(), map()) ::
  {:ok, String.t()} | {:error, term()} | :not_supported
```

Makes a prediction using a loaded model.

## Parameters

- `identifier`: The model identifier
- `inputs`: A map of input names to values (numbers, strings, lists)

## Returns

- `{:ok, result_json}` on success
- `{:error, reason}` on failure
- `:not_supported` on non-iOS platforms

# `predict_with_loaded_model`

```elixir
@spec predict_with_loaded_model(String.t(), map()) ::
  {:ok, String.t()} | {:error, term()} | :not_supported
```

Run prediction on an already-loaded model.

Unlike `load_model/2` + `predict/2`, this does NOT load the model.
The model must be loaded first via `load_model/2`.

# `unload_model`

```elixir
@spec unload_model(String.t()) :: :ok | :not_supported
```

Unloads a previously loaded model.

---

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