{"id":17331907,"url":"https://github.com/ocramz/sparse-linear-algebra","last_synced_at":"2026-03-09T07:36:17.620Z","repository":{"id":56878582,"uuid":"67581067","full_name":"ocramz/sparse-linear-algebra","owner":"ocramz","description":"Numerical computation in native Haskell","archived":false,"fork":false,"pushed_at":"2026-01-16T14:46:46.000Z","size":986,"stargazers_count":90,"open_issues_count":26,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-16T22:51:27.027Z","etag":null,"topics":["eigenvalues","eigenvectors","iterative-linear-solvers","iterative-methods","linear-algebra","linear-systems","lu-factorization","matrix","matrix-computations","matrix-factorization","matrix-product","matrix-transpose","numerical-calculations","numerical-methods","scientific-computations","scientific-computing","sparse-data","sparse-linear-systems","sparse-systems","sparse-vectors"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocramz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.markdown","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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},"funding":{"github":"ocramz"}},"created_at":"2016-09-07T07:03:38.000Z","updated_at":"2026-01-16T14:46:47.000Z","dependencies_parsed_at":"2022-08-20T11:40:33.537Z","dependency_job_id":null,"html_url":"https://github.com/ocramz/sparse-linear-algebra","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ocramz/sparse-linear-algebra","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocramz%2Fsparse-linear-algebra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocramz%2Fsparse-linear-algebra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocramz%2Fsparse-linear-algebra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocramz%2Fsparse-linear-algebra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocramz","download_url":"https://codeload.github.com/ocramz/sparse-linear-algebra/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocramz%2Fsparse-linear-algebra/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30287427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"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":["eigenvalues","eigenvectors","iterative-linear-solvers","iterative-methods","linear-algebra","linear-systems","lu-factorization","matrix","matrix-computations","matrix-factorization","matrix-product","matrix-transpose","numerical-calculations","numerical-methods","scientific-computations","scientific-computing","sparse-data","sparse-linear-systems","sparse-systems","sparse-vectors"],"created_at":"2024-10-15T14:56:01.224Z","updated_at":"2026-03-09T07:36:17.551Z","avatar_url":"https://github.com/ocramz.png","language":"Haskell","readme":"# sparse-linear-algebra\n\nNumerical computation in native Haskell\n\n[![Hackage](https://img.shields.io/hackage/v/sparse-linear-algebra.svg)](https://hackage.haskell.org/package/sparse-linear-algebra)  [![Build Status](https://travis-ci.org/ocramz/sparse-linear-algebra.png)](https://travis-ci.org/ocramz/sparse-linear-algebra)\n[![sparse-linear-algebra](http://stackage.org/package/sparse-linear-algebra/badge/lts)](http://stackage.org/lts/package/sparse-linear-algebra)\n[![sparse-linear-algebra](http://stackage.org/package/sparse-linear-algebra/badge/nightly)](http://stackage.org/nightly/package/sparse-linear-algebra)\n\nThis library provides common numerical analysis functionality, without requiring any external bindings. It aims to serve as an experimental platform for scientific computation in a purely functional setting.\n\n\n## State of the library \n\nMar 14, 2018: Mostly functional, but there are still a few (documented) bugs. Complex number support is still incomplete, so the users are advised to not rely on that for the time being. The issues related to Complex number handling are tracked in #51, #12, #30.\n\n\n## News\n\nOct 7, 2017: The library is evolving in a number of ways, to reflect performance observations and user requests:\n\n* typeclasses and instances for primitive types will become `sparse-linear-algebra-core`, along with a typeclass-oriented reformulation of the numerical algorithms that used to depend on the nested IntMap representation.\nThis will let other developers build on top of this library, in the spirit of `vector-space` and `linear`.\n\n* The `vector`-based backend is being reworked.\n\n* An `accelerate`-based backend is under development [6, 7].\n\n\n## Contents\n\n* Iterative linear solvers (`\u003c\\\u003e`)\n\n    * Generalized Minimal Residual (GMRES) (non-Hermitian systems) \n\n    * BiConjugate Gradient (BCG)\n\n    * Conjugate Gradient Squared (CGS)\n\n    * BiConjugate Gradient Stabilized (BiCGSTAB) (non-Hermitian systems)\n\n    * Moore-Penrose pseudoinverse (`pinv`) (rectangular systems)\n\n* Direct linear solvers\n\n    * LU-based (`luSolve`); forward and backward substitution (`triLowerSolve`, `triUpperSolve`)\n    \n* Matrix factorization algorithms\n\n    * QR (`qr`)\n\n    * LU (`lu`)\n\n    * Cholesky (`chol`)\n\n    * Arnoldi iteration (`arnoldi`)\n\n* Eigenvalue algorithms\n\n    * QR (`eigsQR`)\n\n    * QR-Arnoldi (`eigsArnoldi`) \n\n\n\n* Utilities : Vector and matrix norms, matrix condition number, Givens rotation, Householder reflection\n\n* Predicates : Matrix orthogonality test (A^T A ~= I)\n\n\n\n### Under development\n\n* Eigenvalue algorithms\n\n    * Rayleigh quotient iteration (`eigRayleigh`)\n\n* Matrix factorization algorithms\n\n    * Golub-Kahan-Lanczos bidiagonalization (`gklBidiag`)\n   \n    * Singular value decomposition (SVD)\n\n* Iterative linear solvers\n\n    * Transpose-Free Quasi-Minimal Residual (TFQMR)\n\n---------\n\n## Examples\n\nThe module `Numeric.LinearAlgebra.Sparse` contains the user interface.\n\n### Creation of sparse data\n\nThe `fromListSM` function creates a sparse matrix from a collection of its entries in (row, column, value) format. This is its type signature:\n\n    fromListSM :: Foldable t =\u003e (Int, Int) -\u003e t (IxRow, IxCol, a) -\u003e SpMatrix a\n\nand, in case you have a running GHCi session (the terminal is denoted from now on by `λ\u003e`), you can try something like this:\n\n    λ\u003e amat = fromListSM (3,3) [(0,0,2),(1,0,4),(1,1,3),(1,2,2),(2,2,5)] :: SpMatrix Double\n\nSimilarly, `fromListSV` is used to create sparse vectors: \n\n    fromListSV :: Int -\u003e [(Int, a)] -\u003e SpVector a\n    \n\nAlternatively, the user can copy the contents of a list to a (dense) SpVector using\n\n    fromListDenseSV :: Int -\u003e [a] -\u003e SpVector a\n\n\n\n### Displaying sparse data\n\nBoth sparse vectors and matrices can be pretty-printed using `prd`:\n\n    λ\u003e prd amat\n\n    ( 3 rows, 3 columns ) , 5 NZ ( density 55.556 % )\n\n    2.00   , _      , _      \n    4.00   , 3.00   , 2.00   \n    _      , _      , 5.00       \n\n*Note (sparse storage)*: sparse data should only contain non-zero entries not to waste memory and computation.\n\n*Note (approximate output)*: `prd` rounds the results to two significant digits, and switches to scientific notation for large or small values. Moreover, values which are indistinguishable from 0 (see the `Numeric.Eps` module) are printed as `_`. \n\n\n### Matrix factorizations, matrix product\n\nThere are a few common matrix factorizations available; in the following example we compute the LU factorization of matrix `amat` and verify it with the matrix-matrix product `##` of its factors :\n\n    λ\u003e (l, u) \u003c- lu amat\n    λ\u003e prd $ l ## u\n    \n    ( 3 rows, 3 columns ) , 9 NZ ( density 100.000 % )\n\n    2.00   , _      , _      \n    4.00   , 3.00   , 2.00   \n    _      , _      , 5.00       \n\n\nNotice that the result is _dense_, i.e. certain entries are numerically zero but have been inserted into the result along with all the others (thus taking up memory!).\nTo preserve sparsity, we can use a sparsifying matrix-matrix product `#~#`, which filters out all the elements x for which `|x| \u003c= eps`, where `eps` (defined in `Numeric.Eps`) depends on the numerical type used (e.g. it is 10^-6 for `Float`s and 10^-12 for `Double`s).\n\n    λ\u003e prd $ l #~# u\n    \n    ( 3 rows, 3 columns ) , 5 NZ ( density 55.556 % )\n\n    2.00   , _      , _      \n    4.00   , 3.00   , 2.00   \n    _      , _      , 5.00 \n\n\nA matrix is transposed using the `transpose` function.\n\nSometimes we need to compute matrix-matrix transpose products, which is why the library offers the infix operators `#^#` (i.e. matrix transpose * matrix) and `##^` (matrix * matrix transpose):\n\n    λ\u003e amat' = amat #^# amat\n    λ\u003e prd amat'\n    \n    ( 3 rows, 3 columns ) , 9 NZ ( density 100.000 % )\n\n    20.00  , 12.00  , 8.00   \n    12.00  , 9.00   , 6.00   \n    8.00   , 6.00   , 29.00      \n\n    \n    λ\u003e lc \u003c- chol amat'\n    λ\u003e prd $ lc ##^ lc\n    \n    ( 3 rows, 3 columns ) , 9 NZ ( density 100.000 % )\n\n    20.00  , 12.00  , 8.00   \n    12.00  , 9.00   , 10.80  \n    8.00   , 10.80  , 29.00      \n\n\nIn the last example we have also shown the Cholesky decomposition (M = L L^T where L is a lower-triangular matrix), which is only defined for symmetric positive-definite matrices.\n\n### Linear systems\n\nLarge sparse linear systems are best solved with iterative methods. `sparse-linear-algebra` provides a selection of these via the `\u003c\\\u003e` (inspired by Matlab's \"backslash\" function. Currently this method uses GMRES as default) :\n\n    λ\u003e b = fromListDenseSV 3 [3,2,5] :: SpVector Double\n    λ\u003e x \u003c- amat \u003c\\\u003e b\n    λ\u003e prd x\n\n    ( 3 elements ) ,  3 NZ ( density 100.000 % )\n\n    1.50   , -2.00  , 1.00      \n\n\nThe result can be verified by computing the matrix-vector action `amat #\u003e x`, which should (ideally) be very close to the right-hand side `b` :\n\n    λ\u003e prd $ amat #\u003e x\n\n    ( 3 elements ) ,  3 NZ ( density 100.000 % )\n\n    3.00   , 2.00   , 5.00       \n    \n\nThe library also provides a forward-backward substitution solver (`luSolve`) based on a triangular factorization of the system matrix (usually LU). This should be the preferred for solving smaller, dense systems. Using the LU factors defined previously we can cross-verify the two solution methods:\n\n    λ\u003e x' \u003c- luSolve l u b\n    λ\u003e prd x'\n\n    ( 3 elements ) ,  3 NZ ( density 100.000 % )\n\n    1.50   , -2.00  , 1.00     \n\n\n\n\n\n\n\n\n\n## License\n\nGPL3, see LICENSE\n\n## Credits\n\nInspired by\n\n* `linear` : https://hackage.haskell.org/package/linear\n* `vector-space` : https://hackage.haskell.org/package/vector-space\n* `sparse-lin-alg` : https://github.com/laughedelic/sparse-lin-alg\n\n## References\n\n[1] Y. Saad, Iterative Methods for Sparse Linear Systems, 2nd ed., 2000\n\n[2] G.H. Golub and C.F. Van Loan, Matrix Computations, 3rd ed., 1996\n\n[3] T.A. Davis, Direct Methods for Sparse Linear Systems, 2006\n\n[4] L.N. Trefethen, D. Bau, Numerical Linear Algebra, SIAM, 1997\n\n[5] W.H. Press, S.A. Teukolsky, W.T. Vetterling, B.P. Flannery, Numerical Recipes in Fortran 77, 2nd ed., 1992\n\n[6] M. M. T. Chakravarty, et al., Accelerating Haskell array codes with multicore GPUs - DAMP'11\n\n[7] [`accelerate`](http://hackage.haskell.org/package/accelerate)","funding_links":["https://github.com/sponsors/ocramz"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focramz%2Fsparse-linear-algebra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focramz%2Fsparse-linear-algebra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focramz%2Fsparse-linear-algebra/lists"}