{"id":18339297,"url":"https://github.com/mfschubert/sparsejac","last_synced_at":"2026-03-11T07:33:01.207Z","repository":{"id":177694341,"uuid":"462422590","full_name":"mfschubert/sparsejac","owner":"mfschubert","description":"Efficient forward- and reverse-mode sparse Jacobians using Jax","archived":false,"fork":false,"pushed_at":"2025-09-02T15:31:01.000Z","size":63,"stargazers_count":64,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-02T17:29:30.739Z","etag":null,"topics":["jacobian","jax","sparse"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfschubert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-02-22T18:21:57.000Z","updated_at":"2025-09-02T15:30:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"edfac823-a8bd-4bd0-aa86-c0ee904af11d","html_url":"https://github.com/mfschubert/sparsejac","commit_stats":null,"previous_names":["mfschubert/sparsejac"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mfschubert/sparsejac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfschubert%2Fsparsejac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfschubert%2Fsparsejac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfschubert%2Fsparsejac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfschubert%2Fsparsejac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfschubert","download_url":"https://codeload.github.com/mfschubert/sparsejac/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfschubert%2Fsparsejac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30374311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jacobian","jax","sparse"],"created_at":"2024-11-05T20:17:10.026Z","updated_at":"2026-03-11T07:33:01.198Z","avatar_url":"https://github.com/mfschubert.png","language":"Python","readme":"# sparsejac: Efficient sparse Jacobians using Jax\n`v0.2.0`\n\nSparse Jacobians are frequently encountered in the simulation of physical systems. Jax tranformations `jacfwd` and `jacrev` make it easy to compute dense Jacobians, but these are wasteful when the Jacobian is sparse. `sparsejac` provides a function to more efficiently compute the Jacobian if its sparsity is known. It makes use of the recently-introduced `jax.experimental.sparse` module.\n\nThe graph encoding and coloring algorithms used in this package are relatively basic. As an alternative using more advanced schemes, consider [sparsediffax](https://github.com/gdalle/sparsediffax)--an in-development package that leverages Julia packages such as [SparseMatrixColorings.jl](https://github.com/gdalle/SparseMatrixColorings.jl).\n\n## Install\n```\npip install sparsejac\n```\n\n## Example\nA trivial example with a diagonal Jacobian follows:\n\n```python\nfn = lambda x: x**2\nx = jax.random.uniform(jax.random.PRNGKey(0), shape=(10000,))\n\n@jax.jit\ndef sparse_jacrev_fn(x):\n  with jax.ensure_compile_time_eval():\n    sparsity = jax.experimental.sparse.BCOO.fromdense(jnp.eye(10000))\n    jacrev_fn = sparsejac.jacrev(fn, sparsity=sparsity)\n  return jacrev_fn(x)\n\ndense_jacrev_fn = jax.jit(jax.jacrev(fn))\n\nassert jnp.all(sparse_jacrev_fn(x).todense() == dense_jacrev_fn(x))\n\n%timeit sparse_jacrev_fn(x).block_until_ready()\n%timeit dense_jacrev_fn(x).block_until_ready()\n```\n\nAnd, the performance improvement can easily be seen:\n\n```\n93.1 µs ± 17.2 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n182 ms ± 26.9 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n```\n\n## Performance\n\n- In general, it is preferable to directly provide the sparsity, rather than obtaining it from a dense matrix.\n- GPU may show minimal or no performance advantage over CPU.\n- Users are encouraged to test `jacrev` and `jacfwd` on their specific problem to select the most performant option.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfschubert%2Fsparsejac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfschubert%2Fsparsejac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfschubert%2Fsparsejac/lists"}