An open API service indexing awesome lists of open source software.

https://github.com/galacticdynamics/xmmutablemap

Immutable Map, compatible with Jax
https://github.com/galacticdynamics/xmmutablemap

immutable-collections jax python

Last synced: about 1 year ago
JSON representation

Immutable Map, compatible with Jax

Awesome Lists containing this project

README

          

xmmutablemap



JAX-compatible Immutable Mapping

JAX prefers immutable objects but neither Python nor JAX provide an immutable
dictionary. 😢 This repository defines a light-weight immutable map
(lower-level than a dict) that JAX understands as a PyTree. 🎉 🕶️

## Installation

[![PyPI platforms][pypi-platforms]][pypi-link]
[![PyPI version][pypi-version]][pypi-link]

```bash
pip install xmmutablemap
```

## Documentation

`xmutablemap` provides the class `ImmutableMap`, which is a full implementation
of
[Python's `Mapping` ABC](https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes).
If you've used a `dict` then you already know how to use `ImmutableMap`! The
things `ImmutableMap` adds is 1) immutability (and related benefits like
hashability) and 2) compatibility with `JAX`.

```python
from xmmutablemap import ImmutableMap

print(ImmutableMap(a=1, b=2, c=3))
# ImmutableMap({'a': 1, 'b': 2, 'c': 3})

print(ImmutableMap({"a": 1, "b": 2.0, "c": "3"}))
# ImmutableMap({'a': 1, 'b': 2.0, 'c': '3'})
```

## Development

[![Actions Status][actions-badge]][actions-link]

We welcome contributions!

[actions-badge]: https://github.com/GalacticDynamics/xmmutablemap/workflows/CI/badge.svg
[actions-link]: https://github.com/GalacticDynamics/xmmutablemap/actions
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/xmmutablemap
[conda-link]: https://github.com/conda-forge/xmmutablemap-feedstock

[pypi-link]: https://pypi.org/project/xmmutablemap/
[pypi-platforms]: https://img.shields.io/pypi/pyversions/xmmutablemap
[pypi-version]: https://img.shields.io/pypi/v/xmmutablemap
[zenodo-badge]: https://zenodo.org/badge/755708966.svg
[zenodo-link]: https://zenodo.org/doi/10.5281/zenodo.10850557