{"id":25059956,"url":"https://github.com/stla/eigenr","last_synced_at":"2025-10-30T02:15:26.464Z","repository":{"id":56934186,"uuid":"313610201","full_name":"stla/EigenR","owner":"stla","description":"Complex matrix algebra with Eigen","archived":false,"fork":false,"pushed_at":"2024-04-28T15:07:16.000Z","size":126,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T20:50:50.481Z","etag":null,"topics":["eigen","r","rcpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stla.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-11-17T12:19:32.000Z","updated_at":"2024-08-24T18:47:00.000Z","dependencies_parsed_at":"2024-04-23T12:08:00.945Z","dependency_job_id":null,"html_url":"https://github.com/stla/EigenR","commit_stats":{"total_commits":81,"total_committers":2,"mean_commits":40.5,"dds":"0.012345679012345734","last_synced_commit":"1ffb3091d4bfa6fb0cd5fbfdaa1cc06f7bb6ea69"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FEigenR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FEigenR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FEigenR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FEigenR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stla","download_url":"https://codeload.github.com/stla/EigenR/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248895605,"owners_count":21179264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["eigen","r","rcpp"],"created_at":"2025-02-06T15:56:01.475Z","updated_at":"2025-10-30T02:15:21.419Z","avatar_url":"https://github.com/stla.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\r\ntitle: \"EigenR\"\r\noutput: github_document\r\neditor_options: \r\n  chunk_output_type: console\r\n---\r\n\r\n\u003c!-- badges: start --\u003e\r\n[![R-CMD-check](https://github.com/stla/EigenR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/stla/EigenR/actions/workflows/R-CMD-check.yaml)\r\n\u003c!-- badges: end --\u003e\r\n\r\n```{r setup, include=FALSE}\r\nknitr::opts_chunk$set(\r\n  echo = TRUE, collapse = TRUE, warning = FALSE, message = FALSE\r\n)\r\n```\r\n\r\nOriginally, I entitled this package *Fast Matrix Algebra with 'Eigen'*, because \r\nI expected it to be faster than R base. But this is not the case. So I entitled \r\nit *Complex Matrix Algebra with 'Eigen'*, because it supports some operations \r\non complex matrices which are not supported by R base: determinant, Cholesky \r\ndecomposition, and linear least-squares problems.\r\n\r\n```{r packages}\r\nlibrary(EigenR)\r\nlibrary(microbenchmark)\r\n```\r\n\r\n## Determinant\r\n\r\n```{r det_benchmark}\r\nset.seed(666L)\r\nM \u003c- matrix(rnorm(300L*300L, mean = 1), 300L, 300L)\r\nM[sample.int(300L*300L, 300L*270L)] \u003c- 0 # 90% of zeros\r\nMs \u003c- asSparseMatrix(M)\r\nmicrobenchmark(\r\n  base          = det(M),\r\n  EigenR        = Eigen_det(M),\r\n  EigenR_sparse = Eigen_det(Ms), # :-(\r\n  times = 200L\r\n)\r\n```\r\n\r\nDeterminants of complex matrices are supported:\r\n\r\n```{r det_cplx_benchmark}\r\nset.seed(666L)\r\nMr \u003c- matrix(rnorm(100L*100L, mean = 1), 100L, 100L)\r\nMi \u003c- matrix(rnorm(100L*100L, mean = 1), 100L, 100L)\r\nM \u003c- Mr + 1i * Mi\r\nlibrary(complexplus)\r\nmicrobenchmark(\r\n  EigenR      = Eigen_det(M), # :-)\r\n  complexplus = Det(M), \r\n  times = 30L\r\n)\r\n```\r\n\r\n## Inverse matrix\r\n\r\n```{r inverse_benchmark}\r\nset.seed(666L)\r\nM \u003c- matrix(rnorm(100L*100L), 100L, 100L)\r\nmicrobenchmark(\r\n  base   = solve(M),\r\n  EigenR = Eigen_inverse(M), # :-)\r\n  times = 500L\r\n)\r\n```\r\n\r\n## Pseudo-inverse matrix\r\n\r\n```{r pseudoinverse_benchmark}\r\nset.seed(666L)\r\nM \u003c- matrix(rnorm(100L*70L), 100L, 70L)\r\nlibrary(MASS)\r\nlibrary(pracma)\r\nmicrobenchmark(\r\n  MASS   = ginv(M),\r\n  pracma = pinv(M),\r\n  EigenR = Eigen_pinverse(M), # :-)\r\n  times = 500L\r\n)\r\n```\r\n\r\n## Cholesky decomposition\r\n\r\n```{r chol_benchmark}\r\nset.seed(666L)\r\nM \u003c- matrix(rpois(10000L, 25), 100L, 100L)\r\nA \u003c- crossprod(M)\r\nmicrobenchmark(\r\n  base   = chol(A),\r\n  EigenR = Eigen_chol(A), \r\n  times = 1000L\r\n)\r\n```\r\n\r\nCholesky decomposition of complex matrices is supported.\r\n\r\n## Pivoted Cholesky decomposition\r\n\r\n```{r UtDU_benchmark, warning=FALSE}\r\nset.seed(666L)\r\nM \u003c- matrix(rgamma(202L*199L, 10), 202L, 199L)\r\nM \u003c- cbind(M, M[, 1L] + 3*M[, 2L])\r\nA \u003c- crossprod(M)\r\nmicrobenchmark(\r\n  base   = chol(A, pivot = TRUE),\r\n  EigenR = Eigen_UtDU(A), # :-)\r\n  times = 1000L\r\n)\r\n```\r\n\r\nPivoted Cholesky decomposition of complex matrices is supported.\r\n\r\n## Kernel\r\n\r\n```{r kernel_benchmark}\r\nset.seed(666L)\r\nM \u003c- matrix(rpois(10000L, 25), 100L, 100L)\r\nA \u003c- cbind(M, M)\r\nAt \u003c- t(A)\r\nlibrary(MASS)\r\nmicrobenchmark(\r\n  MASS       = Null(At),\r\n  EigenR_LU  = Eigen_kernel(A, method = \"LU\"),  # :-)\r\n  EigenR_COD = Eigen_kernel(A, method = \"COD\"), \r\n  times = 100L\r\n)\r\n```\r\n\r\n## Linear least-squares problems\r\n\r\n```{r lsSolve_benchmark}\r\nset.seed(666L)\r\nn \u003c- 700L; p \u003c- 200L\r\nA \u003c- matrix(rnorm(n * p), n, p)\r\nb \u003c- rnorm(n)\r\nmicrobenchmark(\r\n  stats       = lm.fit(A, b),\r\n  EigenR_svd  = Eigen_lsSolve(A, b, method = \"svd\"), #  :-(\r\n  EigenR_cod  = Eigen_lsSolve(A, b, method = \"cod\"), #  :-)\r\n  times = 100L\r\n)\r\n```\r\n\r\nComplex matrices `A` and `b` are supported.\r\n\r\n## Exponential\r\n\r\n```{r exp_benchmark}\r\nset.seed(666L)\r\nM \u003c- matrix(rnorm(40L*40L, mean = 1), 40L, 40L)\r\nmicrobenchmark(\r\n  expm   = expm::expm(M),\r\n  EigenR = Eigen_exp(M), # :-)\r\n  times = 500L\r\n)\r\n```\r\n\r\nExponential of complex matrices is supported:\r\n\r\n```{r exp_cplx_benchmark}\r\nset.seed(666L)\r\nMr \u003c- matrix(rnorm(40L*40L, mean = 1), 40L, 40L)\r\nMi \u003c- matrix(rnorm(40L*40L, mean = 1), 40L, 40L)\r\nM \u003c- Mr + 1i * Mi\r\nlibrary(complexplus)\r\nmicrobenchmark(\r\n  complexplus = matexp(M), \r\n  EigenR      = Eigen_exp(M), # :-)\r\n  times = 500L\r\n)\r\n```\r\n\r\n## Schur decomposition\r\n\r\n```{r schur_real}\r\nset.seed(666L)\r\nM \u003c- matrix(rnorm(200L*200L, mean = 1), 200L, 200L)\r\nlibrary(Matrix)\r\nmicrobenchmark(\r\n  Matrix = Schur(M), \r\n  EigenR = Eigen_realSchur(M), # :-)\r\n  times = 50L\r\n)\r\n```\r\n\r\nUse `Eigen_complexSchur` for the complex Schur decomposition.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Feigenr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstla%2Feigenr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Feigenr/lists"}