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

Unified ML API for Dala apps on iOS and Android.

Single entry point for machine learning in Dala, integrating:

- **Nx** - Core tensor library (pure Elixir, works everywhere)
- **Scholar** - Traditional ML (regression, clustering, SVM, etc.)
- **NxSignal** - Digital signal processing (audio, time series)
- **Axon** - Neural networks (deep learning)
- **EMLX** - Apple Silicon GPU acceleration (iOS only, auto-configured)
- **CoreML** - iOS-native ML framework (Neural Engine, iOS only)
- **ONNX Runtime** - Cross-platform inference engine (iOS/Android)

## Quick Start

    # Zero-config setup (call once at app startup)
    Dala.ML.setup()

    # Now use any of the integrated libraries
    tensor = Nx.tensor([1.0, 2.0, 3.0])
    Nx.sum(tensor)

## Platform Support

| Library | iOS Device | iOS Sim | Android |
|---------|-----------|--------|---------|
| Nx | ✅ | ✅ | ✅ |
| Scholar | ✅ | ✅ | ✅ |
| NxSignal | ✅ | ✅ | ✅ |
| Axon | ✅ | ✅ | ✅ |
| EMLX (GPU) | ✅ | ✅ | ❌ |
| CoreML | ✅ | ✅ | ❌ |
| ONNX Runtime | ✅ | ✅ | ✅ |

# `android?`

```elixir
@spec android?() :: boolean()
```

Returns `true` if running on Android.

# `available_backends`

```elixir
@spec available_backends() :: [atom()]
```

Returns a list of available ML backends for the current platform.

# `benchmark`

```elixir
@spec benchmark(keyword()) :: map()
```

Benchmarks a simple ML operation on the current backend.

Returns `%{time_ms: float, backend: term, gflops: float}`.

# `ios?`

```elixir
@spec ios?() :: boolean()
```

Returns `true` if running on any iOS platform (device or simulator).

# `ios_device?`

```elixir
@spec ios_device?() :: boolean()
```

Returns `true` if running on a real iOS device (not simulator).

# `ios_simulator?`

```elixir
@spec ios_simulator?() :: boolean()
```

Returns `true` if running in iOS Simulator.

# `predict`

```elixir
@spec predict(term(), term()) :: {:ok, term()} | {:error, term()}
```

Runs inference using the best available backend.

Dispatches based on model type:
- Binary (string) on iOS → CoreML
- Integer → ONNX session
- Tuple → Axon model

# `setup`

```elixir
@spec setup() :: :ok
```

Sets up the ML stack for the current platform.

Call once at app startup. Detects platform and configures the best
available backend automatically.

# `status`

```elixir
@spec status() :: map()
```

Gets the current ML stack status.

# `verify`

```elixir
@spec verify() :: map()
```

Quick verification that the ML stack is working.

---

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