{"id":23858791,"url":"https://github.com/tthebc01/eigen-wasm","last_synced_at":"2026-04-22T05:32:04.364Z","repository":{"id":234634420,"uuid":"789284844","full_name":"TtheBC01/Eigen-wasm","owner":"TtheBC01","description":"Matrix computation with Eigen3 in the browser. ","archived":false,"fork":false,"pushed_at":"2024-04-21T21:06:00.000Z","size":470,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-07T10:56:53.640Z","etag":null,"topics":["eigen3","wasm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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":"2024-04-20T06:01:59.000Z","updated_at":"2024-04-21T21:06:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"c1185e8f-2fd2-4eb3-b102-bb9435a53526","html_url":"https://github.com/TtheBC01/Eigen-wasm","commit_stats":null,"previous_names":["tthebc01/eigen-wasm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TtheBC01/Eigen-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FEigen-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FEigen-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FEigen-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FEigen-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TtheBC01","download_url":"https://codeload.github.com/TtheBC01/Eigen-wasm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TtheBC01%2FEigen-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32122713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T00:31:26.853Z","status":"online","status_checked_at":"2026-04-22T02:00:05.693Z","response_time":58,"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","wasm"],"created_at":"2025-01-03T03:19:23.612Z","updated_at":"2026-04-22T05:32:04.336Z","avatar_url":"https://github.com/TtheBC01.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using Eigen in the Browser\n\nA simple [WASM](https://webassembly.org/) interface for the [Eigen Tux](https://eigen.tuxfamily.org/) matrix library. Perform fast matrix-matrix multiplies, norm calculations, and system solves (Ax=b) in a mobile or desktop browser. \n\nCurrently, this demo focuses on dense matrix operations, but could easily be extended to include sparse matrix methods as well. \n\n## Setup\n\n```shell\ngit clone https://github.com/TtheBC01/Eigen-wasm.git\ngit submodule update --init --recursive\ndocker build -t emcc .\ndocker run -it --rm --entrypoint bash -v /path/to/Eigen-wasm:/root/ew -p 8000:8000 emcc\ncd /root/ew\nemcc -v\n```\n\n## Compiling\n\nThe source code is compiled using [emscripten](https://emscripten.org/);\n\n```shell\nemcc src/eigen.cpp -o build/eigen.html -I ./Eigen -sEXPORTED_FUNCTIONS=_float_norm,_float_random_matrix,_float_matrix_matrix_mult,_float_system_solve,_float_matrix_matrix_add,_free -sEXPORTED_RUNTIME_METHODS=cwrap\n```\n\n## Test in Browser\n\nServe the test app from the build folder. After starting the http server, in your browser go to http://localhost:8000/eigen.html. \n\n```shell\ncd build\npython3 -m http.server\n```\n\nOnce the page loads, open the developer console and try the following examples (you should just be able to copy paste the javascript from below). \n\nIn all examples, we use [column-major](https://en.wikipedia.org/wiki/Row-_and_column-major_order) storage. Numerical data is passed as an array which is mapped to \na matrix of the size specified by the number of rows and columns passed to the function. \n\n### Matrix L2 Norm: ||A||_2\n\nCalculate the L2 norm of a matrix with [`float_norm`](/src/eigen.cpp#L8).\n\n```javascript\nconst float_norm = Module.cwrap('float_norm', 'number', ['number', 'number', 'array']);\nrows = 2\ncols = 3\ndata = new Uint8Array(new Float32Array([1.0,2.0,3.0,4.0,5.0,6.0]).buffer);\nfloat_norm(rows, cols, data);\n// should print 9.539392471313477\n```\n\n### Get a Random Matrix: A ~ uniform random\n\nInitalize a matrix to be randome values with [`float_random_matrix`](/src/eigen.cpp#L15).\n\n```javascript\nconst float_random_matrix = Module.cwrap('float_random_matrix', 'null', ['number', 'number'])\nconst rowsA = 4;\nconst colsA = 3;\n\n// create pointer and set data on the heap\nvar nABytes = rowsA * colsA * Float32Array.BYTES_PER_ELEMENT; // total bytes is number of matrix elements times bytes per element\nvar APtr = Module._malloc(nABytes); // allocate a pointer\nvar AHeap = new Uint8Array(Module.HEAPU8.buffer, APtr, nABytes); // put it on the heap\n\nfloat_random_matrix(rowsA, colsA, AHeap.byteOffset);\n\nvar A = new Float32Array(AHeap.buffer, AHeap.byteOffset, rowsA * colsA);\n\nModule._free(AHeap.byteOffset);\n// A should be random values\n```\n\n### Matrix-Matrix Multiply: C = A\\*B\n\nPerform fast matrix-matrix multiplies with [`float_matrix_matrix_mult`](/src/eigen.cpp#L21).\n\n```javascript\nconst float_matrix_matrix_mult = Module.cwrap('float_matrix_matrix_mult', 'null', ['number', 'number', 'array', 'number', 'number', 'array'])\nconst rowsA = 2;\nconst colsA = 3;\nconst rowsB = 3;\nconst colsB = 2;\nconst A = new Uint8Array(new Float32Array([1, 2, 3, 4, 5, 6]).buffer);\nconst B = new Uint8Array(new Float32Array([1, 0, 0, 1, 1, 0]).buffer);\n\n// create pointer and set data on the heap\nvar nCBytes = rowsA * colsB * Float32Array.BYTES_PER_ELEMENT; // total bytes is number of matrix elements times bytes per element\nvar CPtr = Module._malloc(nCBytes); // allocate a pointer\nvar CHeap = new Uint8Array(Module.HEAPU8.buffer, CPtr, nCBytes); // put it on the heap\n\nfloat_matrix_matrix_mult(rowsA, colsA, A, rowsB, colsB, B, CHeap.byteOffset);\n\nvar result = new Float32Array(CHeap.buffer, CHeap.byteOffset, rowsA * colsB );\n\nModule._free(CHeap.byteOffset);\n// result should be [1, 2, 4, 6]\n```\n\n### Solve a System of Equations with Singular Value Decomposition: Ax=(USV^T)x=b\n\nYou can solve a square system or get a least squares solution for a rectagular system using [`float_system_solve`](/src/eigen.cpp#L31).\n\n```javascript\nconst float_system_solve = Module.cwrap('float_system_solve', 'null', ['number', 'number', 'array', 'array'])\nconst rowsA = 4;\nconst colsA = 3;\nconst A = new Uint8Array(new Float32Array([1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 11, 12]).buffer);\nconst b = new Uint8Array(new Float32Array([1, 0, 0, 1]).buffer);\n\n// create pointer and set data on the heap\nvar nXBytes = rowsA * Float32Array.BYTES_PER_ELEMENT; // total bytes is number of matrix elements times bytes per element\nvar XPtr = Module._malloc(nXBytes); // allocate a pointer\nvar XHeap = new Uint8Array(Module.HEAPU8.buffer, XPtr, nXBytes); // put it on the heap\n\nfloat_system_solve(rowsA, colsA, A, b, XHeap.byteOffset);\n\nvar x = new Float32Array(XHeap.buffer, XHeap.byteOffset, colsA);\n\nModule._free(XHeap.byteOffset);\n// x should be [-1.5000003576278687, 1.666666030883789, -0.6666661500930786]\n```\n\n### Add Two Matrices with Scalar Multiplication: C = alpha\\*A + beta\\*B\n\nAdd two congruent matrices and optionally include scalar multiplication in the same call with\n[`float_matrix_matrix_add`](/src/eigen.cpp#L39);\n\n```javascript\nconst float_matrix_matrix_add = Module.cwrap('float_matrix_matrix_add', 'null', ['number', 'number', 'number', 'number', 'array', 'array'])\nconst rows = 4;\nconst cols = 3;\nconst alpha = 0.5; // scalar to multiply A by\nconst beta = 3.14; // scalar to multiply B by\nconst A = new Uint8Array(new Float32Array([1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 11, 12]).buffer);\nconst B = new Uint8Array(new Float32Array([1, 0, 0, 1, 2.15, 9.4, 10, 123, 0.33, 44, 0.1, 12]).buffer);\n\n// create pointer and set data on the heap\nvar nCBytes = rows * cols * Float32Array.BYTES_PER_ELEMENT; // total bytes is number of matrix elements times bytes per element\nvar CPtr = Module._malloc(nCBytes); // allocate a pointer\nvar CHeap = new Uint8Array(Module.HEAPU8.buffer, CPtr, nCBytes); // put it on the heap\n\nfloat_matrix_matrix_add(alpha, beta, rows, cols, A, B, CHeap.byteOffset);\n\nvar C = new Float32Array(CHeap.buffer, CHeap.byteOffset, rows * cols);\n\nModule._free(CHeap.byteOffset);\n// C should be [3.640000104904175, 1, 1.5, 5.140000343322754, 9.25100040435791, 32.51599884033203, 34.900001525878906, 390.7200012207031, 5.536200046539307, 143.16000366210938, 5.814000129699707, 43.68000030517578]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftthebc01%2Feigen-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftthebc01%2Feigen-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftthebc01%2Feigen-wasm/lists"}