# opencr.backends

*module*

The array layer: cunumpy, with explicit execution boundaries.

OpenCR's reference path is NumPy and SciPy (sparse matrices, sparse LU, stiff
integrators), one set of conditions at a time. The batched path
(`opencr.backends.batched`) evaluates the Maxwellian rate coefficients
and does the quasi-static reduction of many conditions at once as dense
arrays on cunumpy's ``xp``, which is NumPy or CuPy for the whole process
(``cunumpy.set_backend("cupy")`` moves it to the GPU when one is available).
The code is written once against ``xp``; nothing in OpenCR chooses between
the two.

The execution boundaries are explicit: inputs cross to ``xp`` with
``xp.asarray`` when a batch is assembled, outputs come back as NumPy arrays
with ``xp.to_numpy``, and a `Function` rate always
runs on the host. `device` says where the arrays live.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/backends/__init__.py#L1-L1)

## opencr.backends.device

*function*

```python
def device() -> str
```

Return where cunumpy's arrays live: ``"gpu"`` on CuPy, else ``"cpu"``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/backends/__init__.py#L25-L27)

**Modules**

- `opencr.backends.batched`
- `opencr.backends.jax_backend`
