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
- Host: GitHub
- URL: https://github.com/galacticdynamics/xmmutablemap
- Owner: GalacticDynamics
- License: mit
- Created: 2024-07-10T21:22:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-01T02:14:16.000Z (about 1 year ago)
- Last Synced: 2025-06-04T10:50:42.389Z (about 1 year ago)
- Topics: immutable-collections, jax, python
- Language: Python
- Homepage:
- Size: 54.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
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