{"id":25854784,"url":"https://github.com/jchristopherson/linalg","last_synced_at":"2026-02-28T08:09:02.348Z","repository":{"id":64937516,"uuid":"92610689","full_name":"jchristopherson/linalg","owner":"jchristopherson","description":"A linear algebra library that provides a user-friendly interface to several BLAS and LAPACK routines.","archived":false,"fork":false,"pushed_at":"2025-11-14T19:45:58.000Z","size":12751,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-14T21:25:34.583Z","etag":null,"topics":["blas","cholesky-decomposition","compressed-row-storage","compressed-sparse-row","eigenvalues","eigenvectors","fortran","lapack","linear-algebra","lu-decomposition","qr-decomposition","singular-value-decomposition","sparse-matrix"],"latest_commit_sha":null,"homepage":"","language":"Fortran","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/jchristopherson.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":"2017-05-27T16:30:10.000Z","updated_at":"2025-11-14T19:44:03.000Z","dependencies_parsed_at":"2023-11-18T04:37:12.085Z","dependency_job_id":"d0ef3b26-b9c0-4b4c-a652-ce3222ac7460","html_url":"https://github.com/jchristopherson/linalg","commit_stats":{"total_commits":534,"total_committers":3,"mean_commits":178.0,"dds":0.02059925093632964,"last_synced_commit":"72c60fcc0b525ed3c54bd773b6595f92df3c81f5"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/jchristopherson/linalg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Flinalg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Flinalg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Flinalg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Flinalg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchristopherson","download_url":"https://codeload.github.com/jchristopherson/linalg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristopherson%2Flinalg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29928192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"online","status_checked_at":"2026-02-28T02:00:07.010Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["blas","cholesky-decomposition","compressed-row-storage","compressed-sparse-row","eigenvalues","eigenvectors","fortran","lapack","linear-algebra","lu-decomposition","qr-decomposition","singular-value-decomposition","sparse-matrix"],"created_at":"2025-03-01T16:18:09.206Z","updated_at":"2026-02-28T08:09:02.330Z","avatar_url":"https://github.com/jchristopherson.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# linalg\nA linear algebra library that provides a user-friendly interface to several BLAS and LAPACK routines.  The examples below provide an illustration of just how simple it is to perform a few common linear algebra operations.  There is also an optional C API that is available as part of this library.\n\n## Status\n![Build Status](https://github.com/jchristopherson/linalg/actions/workflows/cmake.yml/badge.svg)\n[![Actions Status](https://github.com/jchristopherson/linalg/workflows/fpm/badge.svg)](https://github.com/jchristopherson/linalg/actions)\n\n## Documentation\nThe documentation can be found [here](https://jchristopherson.github.io/linalg/).\n\n## Building LINALG\n[CMake](https://cmake.org/)This library can be built using CMake.  For instructions see [Running CMake](https://cmake.org/runningcmake/).\n\n[FPM](https://github.com/fortran-lang/fpm) can also be used to build this library using the provided fpm.toml.\n```txt\nfpm build\n```\nThe LINALG library can be used within your FPM project by adding the following to your fpm.toml file.\n```toml\n[dependencies]\nlinalg = { git = \"https://github.com/jchristopherson/linalg\" }\n```\n\n## Standard Solution Example\nThis example solves a normally defined system of 3 equations of 3 unknowns.\n\n```fortran\nprogram example\n    use iso_fortran_env\n    use linalg\n    implicit none\n\n    ! Local Variables\n    real(dp) :: a(3,3), b(3)\n    integer(i32) :: i, pvt(3)\n\n    ! Build the 3-by-3 matrix A.\n    !     | 1   2   3 |\n    ! A = | 4   5   6 |\n    !     | 7   8   0 |\n    a = reshape( \u0026\n        [1.0d0, 4.0d0, 7.0d0, 2.0d0, 5.0d0, 8.0d0, 3.0d0, 6.0d0, 0.0d0], \u0026\n        [3, 3])\n\n    ! Build the right-hand-side vector B.\n    !     | -1 |\n    ! b = | -2 |\n    !     | -3 |\n    b = [-1.0d0, -2.0d0, -3.0d0]\n\n    ! The solution is:\n    !     |  1/3 |\n    ! x = | -2/3 |\n    !     |   0  |\n\n    ! Compute the LU factorization\n    call lu_factor(a, pvt)\n\n    ! Compute the solution.  The results overwrite b.\n    call solve_lu(a, pvt, b)\n\n    ! Display the results.\n    print '(A)', \"LU Solution: X = \"\n    print '(F8.4)', (b(i), i = 1, size(b))\nend program\n```\nThe above program produces the following output.\n```text\nLU Solution: X =\n  0.3333\n -0.6667\n  0.0000\n```\n\n## Overdetermined System Example\nThis example solves an overdetermined system of 3 equations of 2 uknowns.\n\n```fortran\nprogram example\n    use iso_fortran_env\n    use linalg\n    implicit none\n\n    ! Local Variables\n    real(dp) :: a(3,2), b(3)\n    integer(i32) :: i\n\n    ! Build the 3-by-2 matrix A\n    !     | 2   1 |\n    ! A = |-3   1 |\n    !     |-1   1 |\n    a = reshape([2.0d0, -3.0d0, -1.0d0, 1.0d0, 1.0d0, 1.0d0], [3, 2])\n\n    ! Build the right-hand-side vector B.\n    !     |-1 |\n    ! b = |-2 |\n    !     | 1 |\n    b = [-1.0d0, -2.0d0, 1.0d0]\n\n    ! The solution is:\n    ! x = [0.13158, -0.57895]**T\n\n    ! Compute the solution via a least-squares approach.  The results overwrite\n    ! the first 2 elements in b.\n    call solve_least_squares(a, b)\n\n    ! Display the results\n    print '(A)', \"Least Squares Solution: X = \"\n    print '(F9.5)', (b(i), i = 1, size(a, 2))\nend program\n```\nThe above program produces the following output.\n```text\nLeast Squares Solution: X =\n  0.13158\n -0.57895\n```\n\n## Eigen Analysis Example\nThis example computes the eigenvalues and eigenvectors of a mechanical system consisting of several masses connected by springs.\n\n```fortran\n! This is an example illustrating the use of the eigenvalue and eigenvector\n! routines to solve a free vibration problem of 3 masses connected by springs.\n!\n!     k1           k2           k3           k4\n! |-\\/\\/\\-| m1 |-\\/\\/\\-| m2 |-\\/\\/\\-| m3 |-\\/\\/\\-|\n!\n! As illustrated above, the system consists of 3 masses connected by springs.\n! Spring k1 and spring k4 connect the end masses to ground.  The equations of\n! motion for this system are as follows.\n!\n! | m1  0   0 | |x1\"|   | k1+k2  -k2      0  | |x1|   |0|\n! | 0   m2  0 | |x2\"| + |  -k2  k2+k3    -k3 | |x2| = |0|\n! | 0   0   m3| |x3\"|   |   0    -k3    k3+k4| |x3|   |0|\n!\n! Notice: x1\" = the second time derivative of x1.\nprogram example\n    use iso_fortran_env\n    use linalg\n    implicit none\n\n    ! Define the model parameters\n    real(dp), parameter :: pi = 3.14159265359d0\n    real(dp), parameter :: m1 = 0.5d0\n    real(dp), parameter :: m2 = 2.5d0\n    real(dp), parameter :: m3 = 0.75d0\n    real(dp), parameter :: k1 = 5.0d6\n    real(dp), parameter :: k2 = 10.0d6\n    real(dp), parameter :: k3 = 10.0d6\n    real(dp), parameter :: k4 = 5.0d6\n\n    ! Local Variables\n    integer(i32) :: i, j\n    real(dp) :: m(3,3), k(3,3), natFreq(3)\n    complex(dp) :: vals(3), modeShapes(3,3)\n\n    ! Define the mass matrix\n    m = reshape([m1, 0.0d0, 0.0d0, 0.0d0, m2, 0.0d0, 0.0d0, 0.0d0, m3], [3, 3])\n\n    ! Define the stiffness matrix\n    k = reshape([k1 + k2, -k2, 0.0d0, -k2, k2 + k3, -k3, 0.0d0, -k3, k3 + k4], \u0026\n        [3, 3])\n\n    ! Compute the eigenvalues and eigenvectors.\n    call eigen(k, m, vals, vecs = modeShapes)\n\n    ! Sort the eigenvalues and eigenvectors\n    call sort(vals, modeShapes)\n\n    ! Compute the natural frequency values, and return them with units of Hz.  \n    ! Notice, all eigenvalues and eigenvectors are real for this example.\n    natFreq = sqrt(real(vals)) / (2.0d0 * pi)\n\n    ! Display the natural frequency and mode shape values.\n    print '(A)', \"Modal Information:\"\n    do i = 1, size(natFreq)\n        print '(AI0AF8.4A)', \"Mode \", i, \": (\", natFreq(i), \" Hz)\"\n        print '(F10.3)', (real(modeShapes(j,i)), j = 1, size(natFreq))\n    end do\nend program\n```\nThe above program produces the following output.\n```text\nModal Information:\nMode 1: (232.9225 Hz)\n    -0.718\n    -1.000\n    -0.747\nMode 2: (749.6189 Hz)\n    -0.419\n    -0.164\n     1.000\nMode 3: (923.5669 Hz)\n     1.000\n    -0.184\n     0.179\n```\n\n## Sparse Matrix Example\nThe following example solves a sparse system of equations using a direct solver.  The solution is compared to the solution of the same system of equations but in dense format for comparison.\n```fortran\nprogram example\n    use iso_fortran_env\n    use linalg\n    implicit none\n\n    ! Local Variables\n    integer(int32) :: ipiv(4)\n    real(real64) :: dense(4, 4), b(4), x(4), bc(4)\n    type(csr_matrix) :: sparse\n\n    ! Build the matrices as dense matrices\n    dense = reshape([ \u0026\n        5.0d0, 0.0d0, 0.0d0, 0.0d0, \u0026\n        0.0d0, 8.0d0, 0.0d0, 6.0d0, \u0026\n        0.0d0, 0.0d0, 3.0d0, 0.0d0, \u0026\n        0.0d0, 0.0d0, 0.0d0, 5.0d0], [4, 4])\n    b = [2.0d0, -1.5d0, 8.0d0, 1.0d0]\n\n    ! Convert to sparse (CSR format)\n    ! Note, the assignment operator is overloaded to allow conversion.\n    sparse = dense\n\n    ! Compute the solution to the sparse equations\n    call sparse_direct_solve(sparse, b, x)  ! Results stored in x\n\n    ! Print the solution\n    print \"(A)\", \"Sparse Solution:\"\n    print *, x\n\n    ! Perform a sanity check on the solution\n    ! Note, matmul is overloaded to allow multiplication with sparse matrices\n    bc = matmul(sparse, x)\n    print \"(A)\", \"Computed RHS:\"\n    print *, bc\n    print \"(A)\", \"Original RHS:\"\n    print *, b\n\n    ! For comparison, solve the dense system via LU decomposition\n    call lu_factor(dense, ipiv)\n    call solve_lu(dense, ipiv, b)   ! Results stored in b\n    print \"(A)\", \"Dense Solution:\"\n    print *, b\nend program\n```\nThe above program produces the following output.\n```text\nSparse Solution:\n  0.40000000000000002      -0.18750000000000000        2.6666666666666665       0.42500000000000004     \nComputed RHS:\n   2.0000000000000000       -1.5000000000000000        8.0000000000000000        1.0000000000000000\nOriginal RHS:\n   2.0000000000000000       -1.5000000000000000        8.0000000000000000        1.0000000000000000\nDense Solution:\n  0.40000000000000002      -0.18750000000000000        2.6666666666666665       0.42499999999999999\n```\n\n## External Libraries\nHere is a list of external code libraries utilized by this library.\n- [BLAS](http://www.netlib.org/blas/)\n- [LAPACK](http://www.netlib.org/lapack/)\n- [QRUpdate](https://sourceforge.net/projects/qrupdate/)\n- [FERROR](https://github.com/jchristopherson/ferror)\n- [SPARSKIT](https://www-users.cse.umn.edu/~saad/software/SPARSKIT/)\n\nThe dependencies do not necessarily have to be installed to be used.  The build will initially look for installed items, but if not found, will then download and build the latest version as part of the build process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristopherson%2Flinalg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchristopherson%2Flinalg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristopherson%2Flinalg/lists"}