{"id":18099963,"url":"https://github.com/rossmacarthur/vectrix","last_synced_at":"2025-04-13T16:09:26.728Z","repository":{"id":54745375,"uuid":"322365255","full_name":"rossmacarthur/vectrix","owner":"rossmacarthur","description":"🏹 Stack-allocated, constant-size, matrix type implemented with const generics","archived":false,"fork":false,"pushed_at":"2024-12-08T11:05:08.000Z","size":262,"stargazers_count":18,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"trunk","last_synced_at":"2025-04-13T16:09:16.831Z","etag":null,"topics":["const-generics","crate","matrix","rust","vector"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rossmacarthur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-17T17:25:16.000Z","updated_at":"2024-12-08T11:05:12.000Z","dependencies_parsed_at":"2023-01-30T03:46:03.362Z","dependency_job_id":null,"html_url":"https://github.com/rossmacarthur/vectrix","commit_stats":null,"previous_names":["rossmacarthur/vectrs"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fvectrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fvectrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fvectrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossmacarthur%2Fvectrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rossmacarthur","download_url":"https://codeload.github.com/rossmacarthur/vectrix/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741204,"owners_count":21154255,"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":["const-generics","crate","matrix","rust","vector"],"created_at":"2024-10-31T21:11:58.178Z","updated_at":"2025-04-13T16:09:26.707Z","avatar_url":"https://github.com/rossmacarthur.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- Generated by cargo-onedoc. DO NOT EDIT. --\u003e\n\n# vectrix\n\n[![Crates.io Version](https://badgers.space/crates/version/vectrix)](https://crates.io/crates/vectrix)\n[![Docs.rs Latest](https://badgers.space/badge/docs.rs/latest/blue)](https://docs.rs/vectrix)\n[![Build Status](https://badgers.space/github/checks/rossmacarthur/vectrix?label=build)](https://github.com/rossmacarthur/vectrix/actions/workflows/build.yaml)\n\nThis crate provides a stack-allocated, constant-size [`Matrix\u003cT, M, N\u003e`][matrix]\ntype implemented using const generics.\n\n## 🚀 Getting started\n\nAdd this crate to your Cargo manifest.\n\n```sh\ncargo add vectrix\n```\n\n`no_std` is also supported by disabling the default std feature.\n\n```sh\ncargo add vectrix --no-default-features --features=macro\n```\n\n## 🤸 Usage\n\n### Types\n\nThe base [`Matrix\u003cT, M, N\u003e`][matrix] type represents a matrix with `M` rows and `N`\ncolumns. This type is a backed by an array of arrays. The data is stored in\ncolumn-major order. Some convenient aliases are provided for common\nmatrices, like vectors.\n\n- [`Matrix\u003cT, M, N\u003e`][matrix] → a generic matrix type with `M` rows and `N` columns.\n- [`Vector\u003cT, M\u003e`][vector] → a column vector with `M` rows.\n- [`RowVector\u003cT, N\u003e`][rowvector] → a row vector with `N` columns.\n\n### Macros\n\nMacros are provided for easy construction of the provided types. These\nmacros will also work in `const` contexts.\n\n- The [`matrix!`][matrix-1] macro can be used to construct a new [`Matrix`][matrix] of any\n  size.\n  \n  ```rust\n  let m = matrix![\n      1, 3, 5;\n      2, 4, 6;\n  ];\n  ```\n  \n  In the above example `matrix` is a `Matrix\u003c_, 2, 3\u003e` type, having 2 rows and\n  3 columns.\n\n- The [`vector!`][vector-1] and [`row_vector!`][row_vector] macros can be used to to construct\n  column and row vectors respectively.\n  \n  ```rust\n  let v = vector![1, 3, 3, 7];\n  //  ^ type `Vector\u003c_, 4\u003e`\n  assert_eq!(v, matrix![1; 3; 3; 7]);\n  \n  let v = row_vector![1, 3, 3, 7];\n  //  ^^^^^^ type `RowVector\u003c_, 4\u003e`\n  assert_eq!(v, matrix![1, 3, 3, 7]);\n  ```\n\n### Constructors\n\nCommonly used constructors are listed below.\n\n- [`::zero()`][zero] → constructs a new matrix filled with\n  [`T::zero()`][tzero].\n- [`::identity()`][identity] → constructs a new identity matrix.\n- [`::repeat(..)`][repeat] → constructs a new matrix filled with\n  the provided value.\n- [`::repeat_with(..)`][repeat_with] → constructs a new matrix\n  filled with values computed by the provided closure.\n- [`::from_iter(..)`][from_iter] → constructs a\n  new matrix from an iterator.\n- [`::new(..)`][new] → constructs a new vector using the\n  provided components.\n\n### Accessing elements\n\nThree types of element access are available.\n\n- `usize` indexing selects the nth element in the matrix as viewed in\n  column-major order.\n  \n  ```rust\n  let m = matrix![\n      1, 2, 3;\n      4, 5, 6;\n  ];\n  assert_eq!(m[1], 4);\n  ```\n\n- `(usize, usize)` indexing selects the element at a particular row and\n  column position.\n  \n  ```rust\n  let m = matrix![\n      1, 2, 3;\n      4, 5, 6;\n  ];\n  assert_eq!(m[(1, 0)], 4);\n  ```\n\n- Component accessors are available for small vectors using traditional\n  names.\n  \n  ```rust\n  let mut v = vector![1, 2, 3, 4, 0, 0];\n  v.y = 3;\n  v.w = 7;\n  assert_eq!(v.x, 1);\n  assert_eq!(v.y, 3);\n  assert_eq!(v.z, 3);\n  assert_eq!(v.w, 7);\n  assert_eq!(v.a, 0);\n  assert_eq!(v.b, 0);\n  ```\n\n### Accessing a row or column\n\nYou can get a reference to particular row or column using the\n[`.row()`][row] or [`.column()`][column] methods. You\ncan get a mutable reference using the `_mut` variants.\n\n```rust\nlet mut m = matrix![\n    1, 2, 3;\n    4, 7, 6;\n];\nlet row = m.row_mut(1);\nrow[1] = 5;\nassert_eq!(m.column(1), \u0026[2, 5]);\n```\n\n### Iteration\n\nElement-wise, column-major order iteration is provided using the following\nmethods.\n\n- [`.into_iter()`][into_iter] → consumes the matrix and returns\n  an owned iterator over each element.\n- [`.iter()`][iter] → returns an iterator over a reference to\n  each element.\n- [`.iter_mut()`][iter_mut] → returns an iterator over a mutable\n  reference to each element.\n\nIteration over rows and columns is provide using the following methods.\n\n- [`.iter_rows()`][iter_rows] → returns an iterator over a\n  reference to each row.\n- [`.iter_rows_mut()`][iter_rows_mut] → returns an iterator over\n  mutable reference to each row.\n- [`.iter_columns()`][iter_columns] → returns an iterator over a\n  reference to each column.\n- [`.iter_columns_mut()`][iter_columns_mut] → returns an\n  iterator over a mutable reference to each column.\n\n#### Slice representation\n\nA slice view of the underlying data is provided using\n[`.as_slice()`][as_slice] and\n[`.as_mut_slice()`][as_mut_slice].\n\n```rust\nlet mut m = matrix![\n    1, 3, 5;\n    2, 3, 6;\n];\nm.as_mut_slice()[3] = 4;\nassert_eq!(m.as_slice(), \u0026[1, 2, 3, 4, 5, 6]);\n```\n\n### Debug\n\nThe [`Debug`][debug] implementation will print out vectors as\nlists and matrices as a list of lists in column-major order.\n\n```rust\nlet v = vector![1.1, 2.0];\nlet m = matrix![1, 2; 3, 4];\nprintln!(\"vector: {:.2?}\", v);\nprintln!(\"matrix: {:?}\", m);\n```\n\nThis will output:\n\n```text\nvector: [1.10, 2.00]\nmatrix: [[1, 3], [2, 4]]\n```\n\n### Display\n\nThe [`Display`][display] implementation will print out the\nmatrix in the traditional box bracket format. Precision is supported as well\nas most of the other formatting traits like\n[`LowerHex`][lowerhex].\n\n```rust\nlet cv = vector![1.1, 2.0];\nlet rv = row_vector![1.1, 2.0];\nlet m = matrix![1, 2; 3, 4];\nprintln!(\"column vector: {:.2}\", cv);\nprintln!(\"row vector: {:.1}\", rv);\nprintln!(\"matrix: {:b}\", m);\n```\n\nThis will output:\n\n```text\ncolumn vector:\n ┌      ┐\n │ 1.10 │\n │ 2.00 │\n └      ┘\n\nrow vector:\n ┌          ┐\n │ 1.1  2.0 │\n └          ┘\n\nmatrix:\n ┌         ┐\n │  1   10 │\n │ 11  100 │\n └         ┘\n```\n\n### Operations\n\n[`Matrix`][matrix] implements many built-in operators. With scalar operands almost\nall operators are implemented and they simply apply the operation to each\nelement in the matrix. Unary operators will do the equivalent. In the\nfollowing example each element in the matrix is multiplied by 2.\n\n```rust\nlet m = matrix![\n    1, -3;\n    3, -7;\n];\nlet exp = matrix![\n    2, -6;\n    6, -14;\n];\nassert_eq!(m * 2, exp);\n```\n\n[`Matrix`][matrix] supports addition and subtraction with same size matrices for\nelement-wise addition and subtraction. In the following example a matrix\nis added to itself.\n\n```rust\nlet m = matrix![\n    1, -3;\n    3, -7;\n];\nlet exp = matrix![\n    2, -6;\n    6, -14;\n];\nassert_eq!(m + m, exp);\n```\n\n## License\n\nThis project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).\n\nSee [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.\n\n\n[as_mut_slice]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.as_mut_slice\n[as_slice]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.as_slice\n[column]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.column\n[debug]: https://doc.rust-lang.org/stable/std/fmt/trait.Debug.html\n[display]: https://doc.rust-lang.org/stable/std/fmt/trait.Display.html\n[from_iter]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.from_iter\n[identity]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.identity\n[into_iter]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.into_iter\n[iter]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.iter\n[iter_columns]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.iter_columns\n[iter_columns_mut]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.iter_columns_mut\n[iter_mut]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.iter_mut\n[iter_rows]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.iter_rows\n[iter_rows_mut]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.iter_rows_mut\n[lowerhex]: https://doc.rust-lang.org/stable/std/fmt/trait.LowerHex.html\n[matrix]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html\n[matrix-1]: https://docs.rs/vectrix/latest/vectrix/macro.matrix.html\n[new]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.new\n[repeat]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.repeat\n[repeat_with]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.repeat_with\n[row]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.row\n[row_vector]: https://docs.rs/vectrix/latest/vectrix/macro.row_vector.html\n[rowvector]: https://docs.rs/vectrix/latest/vectrix/type.RowVector.html\n[tzero]: https://docs.rs/vectrix/latest/vectrix/trait.Zero.html#tymethod.zero\n[vector]: https://docs.rs/vectrix/latest/vectrix/type.Vector.html\n[vector-1]: https://docs.rs/vectrix/latest/vectrix/macro.vector.html\n[zero]: https://docs.rs/vectrix/latest/vectrix/struct.Matrix.html#method.zero\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossmacarthur%2Fvectrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frossmacarthur%2Fvectrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossmacarthur%2Fvectrix/lists"}