{"id":23858770,"url":"https://github.com/tthebc01/peigen","last_synced_at":"2026-04-18T03:32:38.826Z","repository":{"id":107378059,"uuid":"476057981","full_name":"TtheBC01/pEigen","owner":"TtheBC01","description":"Python bindings for Eigen Tux library using Boost Python","archived":false,"fork":false,"pushed_at":"2024-06-22T05:17:32.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T10:38:49.517Z","etag":null,"topics":["eigen3","matrix-factorization","matrix-library","python"],"latest_commit_sha":null,"homepage":"","language":"C++","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/TtheBC01.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}},"created_at":"2022-03-30T21:32:34.000Z","updated_at":"2024-06-22T05:17:35.000Z","dependencies_parsed_at":"2025-01-03T03:19:20.435Z","dependency_job_id":"095714c6-511b-4c77-8b07-e3a83cf73eed","html_url":"https://github.com/TtheBC01/pEigen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TtheBC01/pEigen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FpEigen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FpEigen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FpEigen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FpEigen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TtheBC01","download_url":"https://codeload.github.com/TtheBC01/pEigen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FpEigen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31955712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"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":["eigen3","matrix-factorization","matrix-library","python"],"created_at":"2025-01-03T03:19:11.230Z","updated_at":"2026-04-18T03:32:38.810Z","avatar_url":"https://github.com/TtheBC01.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pEigen: Eigen for Python\n\nThis project is a simple wrapper for the [Eigen Tux](https://eigen.tuxfamily.org/) library using \n[Boost.Python](https://github.com/boostorg/python). It exposes dense and sparse matrix objects as\nwell as matrix decomposition methods. Matrix compuatation (particularly factorization) using Eigen\nare usually *much* faster that other packages like numpy or scipy.\n\nEigen has some of the fastest matrix decomposition implementations available (for CPUs). The pEigen package is\njust a thin wrapper that exposes this capability for python users. Compared to Numpy, pEigen is about \n10 times smaller, and typically much faster for large factorizations like SVD and QR. \n\nFor information about building this project locally for contributing, see the [developer docs](/DEV.md).\n\n## Examples\n\nHere are a few quick examples of how to use pEigen:\n\n### Dense Matrices\n\nYou can create dense matrices by specifying the number of rows and columns. Matrices are stored in column-major order (currently this is the only storage model).\n\n```python\nimport libpeigen as peigen\n\nrows = 2\ncols = 3\n\n# create a dense matrix with all zeros\ndmat = peigen.dense_matrix(rows, cols)\n\n# or initialize it with a list of numbers\ndata = [1,2,3,4,5,6]\ndmat = peigen.dense_matrix(data, rows, cols)\n\n# you can also set individual elements\n# this sets the second row, first column to 2.15\ndmat.set_elem(2.15,1,0)\n\n# you can retrieve a single element as number-type like this\nmyElement = dmat.get_elem(1,0) # should be 4\n\n# initialize the whole matrix with random double precision floats with a seed value\n# if you use the same seed, you will get the same random matrix on the same machine\ndmat.set_random(3)\n\n# the [] operator return a dense matrix object\ndmat[1].show() # this will return the second row as a dense matrix\ndmat[1][0].show() # this will return the element on the second row on the first column as a dense matrix\n\n# you can get the number of elements in the matrix with the len() operator\nlen(dmat) # should be 6\n\nprint(\"Number of Rows: \", dmat.rows())\nprint(\"Number of Cols: \", dmat.cols())\nprint(\"Matrix Norm: \", dmat.norm())\n\n# You can always call .show() on a matrix object to pretty-print the contents\ndmat.transpose().show()\n\n# Alternatively you can use the str() operator\nprint(str(dmat.transpose()))\n\n# scalar multiplication\ndmat *= 3.14\n\n# matrix multiplication\nnew_dmat = peigen.dense_matrix(rows,cols)\nnew_dmat.assign(dmat) # deep copy into new dense matrix object\nresult = dmat * new_dmat.transpose() # result is a new dense matrix object\n\n# matrix addition\nresult = dmat + new_dmat\n# or\ndmat += new_dmat\n\n# matrix subtraction\nresult = dmat - new_dmat\n# or\ndmat -= new_dmat\n```\n\nYou can also access arbitrary blocks of a dense matrix.\n\n```python\nstartingRow = 5\nstartingCol = 6\nnum_rows = 4\nnum_cols = 3\n\n# make a new matrix from a block of an existing matrix\nmy_block = dmat.block(startingRow, startingCol, num_rows, num_cols)\n\n# or grab the (off)diagonals from a matrix\nmy_diagonal = dmat.diagonal(1) # returns the diagonal of a (potentially rectangular) offset by 1 in this case\n```\n\nYou can save a dense matrix to a file to use later.\n\n```python\ndmat.save(\"myMat.mat\")\n\nnew_dmat = peigen.dense_matrix()\nnew_dmat.load(\"myMat.mat\")\n```\n\n### Sparse Matrices\n\nJust like with dense matrices, you can create a sparse matrix by pre-specifying the number of rows and columns. Sparse matrices are stored\nin [compressed sparse column](https://docs.nvidia.com/nvpl/_static/sparse/storage_format/sparse_matrix.html#compressed-sparse-column-csc) (CSC) format. \n\n```python\nimport libpeigen as peigen\n\n# sparse matrices can be very large yet take up very little memory if the number of non-zero elements is small\nrows = 1000\ncols = 2000\n\nsmat = peigen.sparse_matrix(rows,cols)\n\n# get the number of non-zero elements\nsmat.nnz() # will be 0 right after initialization\nlen(smat) # does the same thing\n\n# you can set individual elements like this\nsmat.set_elem(3.14, 499, 299) # now the element on the 500th row and 300th column is 3.14\n\n# get the number of rows, columns, and the matrix norm just like with dense matrices\nprint(\"Number of Rows: \", smat.rows())\nprint(\"Number of Cols: \", smat.cols())\nprint(\"Matrix Norm: \", smat.norm())\n\n# you can multiply two sparse matrices together\nnew_smat = peigen.sparse_matrix()\nnew_smat.assign(smat)\nresult = new_smat.transpose() * smat\n\n# you can also multiply dense and sparse matrices together\ndmat = peigen.dense_matrix(rows, cols)\ndmat.set_random(1)\nresult = dmat.transpose() * smat\nresult = smat.transpose() * dmat\n```\n\nYou can also save a sparse matrix to a file to use later.\n\n```python\nsmat.save(\"myMat.mat\")\n\nnew_smat = peigen.dense_matrix()\nnew_smat.load(\"myMat.mat\")\n```\n\n## Factorizations\n\nThe pEigen package exposes SVD and QR decomposition from Eigen Tux.\n\n### Singular Value Decomposition\n\n```python\nimport libpeigen as peigen\n\nrows = 10\ncols = 20\ndmat = peigen.dense_matrix(rows, cols)\ndmat.set_random(1)\n\n# initialize a factorizer object \nfactorizer = peigen.factorizer(dmat)\n\n# compute the singular value decomposition (USV^T) with the Bidiagonal Divide and Conquer method\nfactorizer.bdcsvd()\n\n# get the singular values as a dense diagonal matrix\nfactorizer.get_singular_values().show()\n\n# get the left singular vector matrix\nfactorizer.get_u().show()\n\n# get the right singular vector matrix\nfactorizer.get_v().show()\n```\n\n### QR Factorization\n\n```python\nrows = 10\ncols = 20\ndmat = peigen.dense_matrix(rows, cols)\ndmat.set_random(1)\n\n# initialize a factorizer object \nfactorizer = peigen.factorizer(dmat)\n\n# compute QR decomposition with the Householder method\nfactorizer.householder_qr()\n\n# get the Q matrix\nfactorizer.get_q().show()\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftthebc01%2Fpeigen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftthebc01%2Fpeigen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftthebc01%2Fpeigen/lists"}