Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mfschubert/jeig
Faster eigendecompositions for jax
https://github.com/mfschubert/jeig
Last synced: about 1 month ago
JSON representation
Faster eigendecompositions for jax
- Host: GitHub
- URL: https://github.com/mfschubert/jeig
- Owner: mfschubert
- License: bsd-3-clause
- Created: 2024-06-11T15:47:40.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-11T03:14:15.000Z (about 1 month ago)
- Last Synced: 2024-10-11T03:15:36.256Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 93.8 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jeig - Eigendecompositions wrapped for jax
`v0.1.3`## Overview
This package wraps eigendecompositions as provided by jax, numpy, scipy, and torch for use with jax. Depending upon your system and your versions of these packages, you may observe significant speed differences.
![Speed comparison](https://github.com/mfschubert/jeig/blob/main/docs/speed.png?raw=true)
## Install
jeig can be installed via pip,
```
pip install jeig
```
This will also install torch. If you only need torch for use with jeig, then the CPU-only version could be sufficient and you may wish to install manually as described in the [pytorch docs](https://pytorch.org/get-started/locally/).## Example usage
```python
import jax
import jeigmatrix = jax.random.normal(jax.random.PRNGKey(0), (8, 320, 320))
jeig.set_backend("jax")
%timeit jeig.eig(matrix)jeig.set_backend("numpy")
%timeit jeig.eig(matrix)jeig.set_backend("scipy")
%timeit jeig.eig(matrix)jeig.set_backend("torch")
%timeit jeig.eig(matrix)
```
```
916 ms ± 101 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
1.47 s ± 165 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
782 ms ± 75.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
150 ms ± 10.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
```## Credit
The torch implementation of eigendecomposition is due to a [comment](https://github.com/google/jax/issues/10180#issuecomment-1092098074) by @YouJiacheng.