{"id":30290752,"url":"https://github.com/usercrixus/42matrix","last_synced_at":"2025-08-16T23:54:45.735Z","repository":{"id":307764739,"uuid":"1028038558","full_name":"usercrixus/42matrix","owner":"usercrixus","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-10T19:53:27.000Z","size":7553,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-10T21:20:04.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/usercrixus.png","metadata":{"files":{"readme":"README.md","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-28T23:59:30.000Z","updated_at":"2025-08-10T19:53:30.000Z","dependencies_parsed_at":"2025-08-02T05:13:14.130Z","dependency_job_id":null,"html_url":"https://github.com/usercrixus/42matrix","commit_stats":null,"previous_names":["usercrixus/42matrix"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/usercrixus/42matrix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercrixus%2F42matrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercrixus%2F42matrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercrixus%2F42matrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercrixus%2F42matrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usercrixus","download_url":"https://codeload.github.com/usercrixus/42matrix/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercrixus%2F42matrix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270786443,"owners_count":24644563,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"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":[],"created_at":"2025-08-16T23:54:44.708Z","updated_at":"2025-08-16T23:54:45.692Z","avatar_url":"https://github.com/usercrixus.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Matrix \u0026 VectorAlgebra — Modern C++ Linear Algebra (Header-only)\n\nA small, header-only linear algebra toolkit featuring:\n\n- **`VectorAlgebra\u003cT\u003e`** — a `std::vector\u003cT\u003e` with element-wise ops, dot/cross products, norms, interpolation, and linear combinations.\n- **`Matrix\u003cT\u003e`** — a matrix built on `std::vector\u003cVectorAlgebra\u003cT\u003e\u003e` with transpose, row-echelon, rank, determinant, inverse, multiplication, trace, interpolation, and a perspective projection helper.\n\nWorks with real types (`int`, `float`, `double`) and complex (`std::complex\u003cfloat\u003e`, `std::complex\u003cdouble\u003e`). Complex support follows standard linear algebra conventions (Hermitian dot, real-valued norms).\n\n---\n\n## Table of contents\n- [Install \u0026 Build](#install--build)\n- [Hello world](#hello-world)\n- [Design notes](#design-notes)\n- [VectorAlgebra API](#vectoralgebra-api)\n- [Matrix API](#matrix-api)\n- [Complex numbers](#complex-numbers)\n- [Errors \u0026 exceptions](#errors--exceptions)\n- [FAQ \u0026 tips](#faq--tips)\n- [License](#license)\n\n---\n\n## Install \u0026 Build\n\nThis library is **header-only**. Just add the two headers to your project:\n\n```\nMatrix/\n ├─ VectorAlgebra.hpp\n └─ Matrix.hpp\n```\n\nInclude them:\n\n```cpp\n#include \"Matrix/VectorAlgebra.hpp\"\n#include \"Matrix/Matrix.hpp\"\n```\n\n### Build example (g++)\n```bash\ng++ -std=c++20 -Wall -Wextra -Werror main.cpp -o demo\n./demo\n```\n\n---\n\n## Hello world\n\n```cpp\n#include \"Matrix/VectorAlgebra.hpp\"\n#include \"Matrix/Matrix.hpp\"\n#include \u003ciostream\u003e\n\nint main() {\n    VectorAlgebra\u003cfloat\u003e a = {1, 2, 3};\n    VectorAlgebra\u003cfloat\u003e b = {4, 5, 6};\n\n    std::cout \u003c\u003c \"a + b = \" \u003c\u003c (a + b) \u003c\u003c \"\\n\";\n    std::cout \u003c\u003c \"a · b = \" \u003c\u003c a.dotProduct(b) \u003c\u003c \"\\n\";\n    std::cout \u003c\u003c \"||a||2 = \" \u003c\u003c a.normEuclidean() \u003c\u003c \"\\n\";\n\n    Matrix\u003cfloat\u003e M = Matrix\u003cfloat\u003e::from({{1, 2}, {3, 4}});\n    VectorAlgebra\u003cfloat\u003e x = {1, 1};\n    std::cout \u003c\u003c \"M * x = \" \u003c\u003c (M * x) \u003c\u003c \"\\n\";\n}\n```\n\nExample output:\n```\na + b = [5, 7, 9]\na · b = 32\n||a||2 = 3.74166\nM * x = [3, 7]\n```\n\n---\n\n## Design notes\n\n- `VectorAlgebra\u003cT\u003e` **inherits publicly** from `std::vector\u003cT\u003e` to keep standard vector behaviors (iterators, indexing, etc.) and add math methods/operators.\n- `Matrix\u003cT\u003e` **inherits privately** from `std::vector\u003cVectorAlgebra\u003cT\u003e\u003e` to control the public surface (exposes `operator[]`, `begin`, `end`).\n- All operations do **dimension checks** and throw exceptions on mismatch.\n\n---\n\n## VectorAlgebra API\n\n### Type \u0026 construction\n```cpp\ntemplate \u003ctypename T\u003e\nclass VectorAlgebra : public std::vector\u003cT\u003e {\npublic:\n    using std::vector\u003cT\u003e::vector; // inherit constructors\n    using ScalarType = decltype(std::abs(T{})); // real scalar type for norms\n};\n```\n\nCreate like a normal vector:\n```cpp\nVectorAlgebra\u003cfloat\u003e v = {1, 2, 3};\nVectorAlgebra\u003cint\u003e   u(5, 0);   // [0,0,0,0,0]\n```\n\n### Static utilities\n```cpp\nstatic VectorAlgebra\u003cT\u003e linearCombinaison(const std::vector\u003cVectorAlgebra\u003cT\u003e\u003e\u0026 vects, const VectorAlgebra\u003cT\u003e\u0026 coef);\nstatic VectorAlgebra\u003cT\u003e linearInterpolation(const VectorAlgebra\u003cT\u003e\u0026 a, const VectorAlgebra\u003cT\u003e\u0026 b, float ratio);\nstatic float angleCos(const VectorAlgebra\u003cT\u003e\u0026 a, const VectorAlgebra\u003cT\u003e\u0026 b);\n```\n\n### Vector metrics\n```cpp\nScalarType normManhattan() const; // ∑ |x_i|\nScalarType normEuclidean() const; // sqrt(∑ |x_i|^2)\nScalarType normSupremum() const;  // max_i |x_i|\n```\n\n### Reductions \u0026 products\n```cpp\nT sum();\nT dotProduct(const VectorAlgebra\u003cT\u003e\u0026 v) const;\n```\n\n### Element-wise operators\n```cpp\nVectorAlgebra\u003cT\u003e operator+(const VectorAlgebra\u003cT\u003e\u0026) const;\nVectorAlgebra\u003cT\u003e operator-(const VectorAlgebra\u003cT\u003e\u0026) const;\nVectorAlgebra\u003cT\u003e operator*(const VectorAlgebra\u003cT\u003e\u0026) const;\nVectorAlgebra\u003cT\u003e operator/(const VectorAlgebra\u003cT\u003e\u0026) const;\ntemplate \u003ctypename Scalar\u003e\nVectorAlgebra\u003cT\u003e operator*(Scalar s) const;\ntemplate \u003ctypename Scalar\u003e\nVectorAlgebra\u003cT\u003e operator/(Scalar s) const;\ntemplate \u003ctypename Scalar, typename U\u003e\nVectorAlgebra\u003cU\u003e operator*(Scalar s, const VectorAlgebra\u003cU\u003e\u0026 v);\ntemplate \u003ctypename Scalar, typename U\u003e\nVectorAlgebra\u003cU\u003e operator/(Scalar s, const VectorAlgebra\u003cU\u003e\u0026 v);\n```\n\n### Cross product (3D only)\n```cpp\nstatic VectorAlgebra\u003cT\u003e crossProduct(const VectorAlgebra\u003cT\u003e\u0026 a, const VectorAlgebra\u003cT\u003e\u0026 b);\n```\n\n---\n\n## Matrix API\n\n### Construction\n```cpp\nstatic Matrix\u003cT\u003e from(const std::vector\u003cVectorAlgebra\u003cT\u003e\u003e\u0026 rows);\nbool isSquare() const;\n```\n\n### Basic ops\n```cpp\nMatrix\u003cT\u003e transpose() const;\nVectorAlgebra\u003cT\u003e operator*(const VectorAlgebra\u003cT\u003e\u0026 x) const;\nMatrix\u003cT\u003e operator*(const Matrix\u003cT\u003e\u0026 B) const;\n```\n\n### Row-echelon \u0026 rank\n```cpp\nMatrix\u003cT\u003e rowEchelon() const;\nunsigned int rank() const;\nMatrix\u003cT\u003e rowEchelonNormalize(int\u0026 swapCount) const;\n```\n\n### Determinant, trace, inverse\n```cpp\nT determinant() const;\nT trace();\nMatrix\u003cT\u003e invert() const;\n```\n\n### Interpolation\n```cpp\nstatic Matrix\u003cT\u003e linearInterpolation(const Matrix\u003cT\u003e\u0026 A, const Matrix\u003cT\u003e\u0026 B, float ratio);\n```\n\n### Perspective projection helper\n```cpp\nstatic Matrix\u003cT\u003e projection(float fov_deg, float aspect_ratio, float near_plane, float far_plane);\n```\n\n---\n\n## Complex numbers\n\n- **Dot product:** `a.dotProduct(b)` computes `∑ conj(a_i) * b_i`.\n- **Norms:** return real scalar types (`ScalarType`) via `std::abs`/`std::norm`.\n- **Angle cosine:** intentionally **throws** for complex vectors.\n- All matrix routines work with `std::complex`.\n\n---\n\n## Errors \u0026 exceptions\n\nMost precondition failures throw `std::invalid_argument`.\n\n`std::logic_error` is thrown for conceptual errors.\n\n---\n\n## FAQ \u0026 tips\n\n- **Why inherit from `std::vector`?** Convenience \u0026 zero-overhead reuse.\n- **Performance:** Not optimized for heavy workloads; prefer Eigen/Blaze for that.\n- **Numerical stability:** Only basic pivoting implemented.\n- **Printing:** `operator\u003c\u003c` defined for both vectors and matrices.\n\n---\n\n## License\n\nMIT License","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusercrixus%2F42matrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusercrixus%2F42matrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusercrixus%2F42matrix/lists"}