{"id":18552452,"url":"https://github.com/andrejewski/matt","last_synced_at":"2025-10-16T21:11:04.561Z","repository":{"id":24948265,"uuid":"28365933","full_name":"andrejewski/matt","owner":"andrejewski","description":"JavaScript DSL for Matrices","archived":false,"fork":false,"pushed_at":"2015-11-20T16:05:17.000Z","size":14,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T00:02:38.804Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrejewski.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}},"created_at":"2014-12-22T23:46:24.000Z","updated_at":"2022-01-06T16:02:13.000Z","dependencies_parsed_at":"2022-08-27T12:20:57.541Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/matt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fmatt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fmatt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fmatt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fmatt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/matt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755554,"owners_count":20990626,"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":[],"created_at":"2024-11-06T21:14:15.634Z","updated_at":"2025-10-16T21:11:04.486Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Matt\n====\n\nMatt is a JavaScript DSL for Matrices. Determinate, transpose, and invert immutable, ES6-ready matrices with ease.\n\nMatt is available on [NPM](https://www.npmjs.org/package/matt).\n\n```sh\nnpm install matt\n```\n\nMatt is pretty intuitive to use if already familiar with common matrix operations and transforms. It looks like this, required in Node.js:\n\n```js\nvar Matt = require('matt');\nvar Matrix = Matt.Matrix;\nvar assert = require('assert');\n\n// list-style (1D Array)\nvar A = new Matrix(3, 3, [\n\t1, 2, 3,\n\t4, 5, 6,\n\t7, 8, 9\n]);\n\n// table-style (2D Array)\nvar B = new Matrix([\n\t[1, 2, 3],\n\t[4, 5, 6],\n\t[7, 8, 9]\n]);\n\nassert(A.equals(B));\nassert(A.transpose().transpose().equals(A));\nassert.equal(A.trace(), B.trace());\n```\n\nAlso see **[Seth](https://github.com/andrejewski/seth)**, my other mathematical DSL for Set Theory.\n\n## Features\n\nMatt exposes one core `Matrix` ES6 written and ready class with tons of matrix methods. Methods include `get`, `set`, `getRow`, `setRow`, `getColumn`, `setColumn`, `getDiagonal`, `getRightDiagonal`, `trace`, `rightTrace`, `add`, `subtract`, `multiply`, `joinHorizontal`, `joinVertical`, `clone`, `map`, `fmap`, `forEach`, `reduce`, `scale`, `transpose`, `identity`, `submatrix`, `minor`, `cofactor`, `cofactorMatrix`, `invert`, `determinant`, `isSquare`, `equals`, `toArray`, `toTable`, and `toString`.\n\nAll methods are tested and throw appropriate errors when the operation is impossible. For example, `determinant` will throw when called on a non-square matrix.\n\nMatrices are immutable. All methods that mutate a matrix will return a new matrix. This means variables will not be overwritten with new data and operations can be chained and composed more functionally.\n\n## Documentation\n\nThe method signatures of the Matrix class are listed.\n\n```\nconstructor(rows Number, cols Number, elements [Any]) Matrix\nget(row Number, col Number) Any\nset(row Number, col Number, value Any) Matrix\ngetRow(row Number) [Any]\nsetRow(row Number, elements [Any]) Matrix\ngetColumn(col Number) [Any]\nsetColumn(col Number, elements [Any]) Matrix\ngetDiagonal(\u003coffset Number = 0\u003e) [Any]\ngetRightDiagonal(\u003coffset Number = 0\u003e) [Any]\ntrace() Number\nrightTrace() Number\nadd(matrix Matrix, \u003creduce Function(elementA Any, elementB Any) Any\u003e) Matrix\nsubtract(matrix Matrix, \u003creduce Function(elementA Any, elementB Any) Any\u003e) Matrix\nmultiply(matrix Matrix, \u003creduce Function(elementA Any, elementB Any) Any\u003e) Matrix\njoinHorizontal(matrix Matrix) Matrix\njoinVertical(matrix Matrix) Matrix\nclone() Matrix\nmap(fn Function(element Any, row Number, col Number, matrix Matrix)) Matrix\nfmap(fn Function(element Any, row Number, col Number, matrix Matrix)) Matrix\nforEach(fn Function(element Any, row Number, col Number, matrix Matrix)) void\nreduce(fn Function(acc Any, value Any, row Number, col Number, matrix Matrix), \u003cmemo Any = M(0,0)\u003e) Matrix\nscale(num Number) Matrix\ntranspose() Matrix\nidentity() Matrix\nsubmatrix(topLeftRow Number, topLeftCol Number, bottomRightRow Number, bottomRightCol Number) Matrix\nminor(row Number, col Number) Matrix\ncofactor(row Number, col Number) Number\ncofactorMatrix() Matrix\ninvert() Matrix\ndeterminant() Number\nisSquare() boolean\nequals(matrix Matrix) boolean\ntoArray() [Any]\ntoTable() [[Any]]\ntoString() String\n```\n\nFor complete documentation, please refer to the tests as they double as documentation quite well. In the `matt` directory run:\n\n```sh\nnpm install \u0026\u0026 npm run build \u0026\u0026 npm test\n```\n\n## Performance\n\nEvery effort has been and will be made to keep Matt performant. As JavaScript is a higher-level language, Matt's performance will not rival the C family's any time soon. However with V8 optimizations, new primitive [data types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays), and projects such as [asm.js](http://asmjs.org/), performance will get better over time.\n\nMatt was designed to be ready to embrace these changes. Unlike most matrix implementations, Matt deals with one-dimensional instead of two-dimensional arrays. This decision was made for multiple reasons.\n\n- JavaScript arrays are not really arrays, just objects with some array-like methods. Thus, there is really not much reason to deal with arrays in arrays for the sake of performance.\n\n- Since V8 and others optimize for array methods, Matt uses built-in functions, initializes arrays where possible, and runs for loops wherever possible to gain those speed boosts. Arrays also enjoy faster lookup than tables (2D arrays) while being less messy.\n\n- Typing. It is faster and easier to write `2, 2, [1, 2, 3, 4]` than `[[1,2],[3,4]]`; more with larger and nested matrices. It is also better for the new ES6 destructuring syntax we all will be using soon enough.\n\nThese decisions and details are really only important to contributors. The bottom-line is: expect Matt to be just as fast as any other JavaScript matrix library (I know, not setting the bar very high) and to continue seeing more improvements as they become possible in the language.\n\nThe places where performance is worst is the same as all other implementations: determinants and inversions when `N` (i.e. `N * N` matrices) is large and anything when `N` is very, very, very large.\n\n## Contributing\n\nI have never taken a class on advanced linear algebra or matrices (heck I'm still in high school). I did read the [Wikipedia page](http://en.wikipedia.org/wiki/Matrix_(mathematics)) a few dozen times. This is just an interest of mine that I saw was lacking in implementation in the open-source JavaScript community at large, so I wanted to attempt to fill the gap.\n\nIf you are a professional linear algebraist or even an amateur like me, if there is a bug please open an issue. If there is a feature this DSL should have, more common operations or methods, please point me to them or be hardcore and send me the pull request.\n\nContributions are incredibly welcome as long as they are standardly applicable and pass the tests (or break bad ones). Tests are written in Mocha and assertions are done with the Node.js core `assert` module.\n\n```bash\n# generating source\nnpm run build\n# running tests\nnpm test\n```\n\nFollow me on [Twitter](https://twitter.com/compooter) for updates or just for the lolz and please check out my other [repositories](https://github.com/andrejewski) if I have earned it. I thank you for reading.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fmatt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Fmatt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fmatt/lists"}