jeig


Namejeig JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryVarious eigendecomposition implementations wrapped for jax.
upload_time2024-06-11 18:35:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseBSD 3-Clause License Copyright (c) 2024, Martin Schubert Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords jax eigendecomposition eig torch scipy numpy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jeig - Eigendecompositions wrapped for jax
`v0.0.2`

## 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.

The wrapped `eig` function also includes a custom vjp rule so that gradients with respect to eigenvalues and eigenvectors can be computed.

![Speed comparison](/docs/speed.png)

## 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 is 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 jeig.eig as jeig

matrix = jax.random.normal(jax.random.PRNGKey(0), (8, 320, 320))

jeig.BACKEND_EIG = jeig.JAX
%timeit jeig.eig(matrix)

jeig.BACKEND_EIG = jeig.NUMPY
%timeit jeig.eig(matrix)

jeig.BACKEND_EIG = jeig.SCIPY
%timeit jeig.eig(matrix)

jeig.BACKEND_EIG = jeig.TORCH
%timeit jeig.eig(matrix)
```
```
376 ms ± 11.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
689 ms ± 11.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
414 ms ± 19 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
136 ms ± 4 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
```

## Credit
The high-level `eig` function and the tests are adapted from [fmmax](https://github.com/facebookresearch/fmmax/tree/main/src/fmmax). The torch implementation of eigendecomposition is due to a [comment](https://github.com/google/jax/issues/10180#issuecomment-1092098074) by @YouJiacheng.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jeig",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "Martin Schubert <mfschubert@gmail.com>",
    "keywords": "jax, eigendecomposition, eig, torch, scipy, numpy",
    "author": null,
    "author_email": "Martin Schubert <mfschubert@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3b/a9/0ff13ee0261541917b9b8fe0edb8502c66410543567184118d515fb95152/jeig-0.0.2.tar.gz",
    "platform": null,
    "description": "# jeig - Eigendecompositions wrapped for jax\n`v0.0.2`\n\n## Overview\n\nThis 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.\n\nThe wrapped `eig` function also includes a custom vjp rule so that gradients with respect to eigenvalues and eigenvectors can be computed.\n\n![Speed comparison](/docs/speed.png)\n\n## Install\njeig can be installed via pip,\n```\npip install jeig\n```\nThis will also install torch. If you only need torch for use with jeig, then the CPU-only version is sufficient and you may wish to install manually as described in the [pytorch docs](https://pytorch.org/get-started/locally/).\n\n## Example usage\n\n```python\nimport jax\nimport jeig.eig as jeig\n\nmatrix = jax.random.normal(jax.random.PRNGKey(0), (8, 320, 320))\n\njeig.BACKEND_EIG = jeig.JAX\n%timeit jeig.eig(matrix)\n\njeig.BACKEND_EIG = jeig.NUMPY\n%timeit jeig.eig(matrix)\n\njeig.BACKEND_EIG = jeig.SCIPY\n%timeit jeig.eig(matrix)\n\njeig.BACKEND_EIG = jeig.TORCH\n%timeit jeig.eig(matrix)\n```\n```\n376 ms \u00b1 11.4 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\n689 ms \u00b1 11.2 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\n414 ms \u00b1 19 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\n136 ms \u00b1 4 ms per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\n```\n\n## Credit\nThe high-level `eig` function and the tests are adapted from [fmmax](https://github.com/facebookresearch/fmmax/tree/main/src/fmmax). The torch implementation of eigendecomposition is due to a [comment](https://github.com/google/jax/issues/10180#issuecomment-1092098074) by @YouJiacheng.\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2024, Martin Schubert  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "Various eigendecomposition implementations wrapped for jax.",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [
        "jax",
        " eigendecomposition",
        " eig",
        " torch",
        " scipy",
        " numpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96e4e7e6b5d20003e0788d27e1b1b3972f849dc4294c704efc58513103538dfa",
                "md5": "d21307991c25e1dcd374894ec1e6fb69",
                "sha256": "4515c27ac5fe680b63509360dcb9b8f23b4411cd97949262b915685c067c2c72"
            },
            "downloads": -1,
            "filename": "jeig-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d21307991c25e1dcd374894ec1e6fb69",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6703,
            "upload_time": "2024-06-11T18:35:52",
            "upload_time_iso_8601": "2024-06-11T18:35:52.152294Z",
            "url": "https://files.pythonhosted.org/packages/96/e4/e7e6b5d20003e0788d27e1b1b3972f849dc4294c704efc58513103538dfa/jeig-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ba90ff13ee0261541917b9b8fe0edb8502c66410543567184118d515fb95152",
                "md5": "cf164b17d962d9920f2fb12097fb2c24",
                "sha256": "44c204e908a44579716a36f92cb0f3def1c386b10aab98eccc2994996b3dfa29"
            },
            "downloads": -1,
            "filename": "jeig-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cf164b17d962d9920f2fb12097fb2c24",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8727,
            "upload_time": "2024-06-11T18:35:53",
            "upload_time_iso_8601": "2024-06-11T18:35:53.435713Z",
            "url": "https://files.pythonhosted.org/packages/3b/a9/0ff13ee0261541917b9b8fe0edb8502c66410543567184118d515fb95152/jeig-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-11 18:35:53",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "jeig"
}
        
Elapsed time: 0.28139s