{"id":25240810,"url":"https://github.com/sanaeproject/matrix","last_synced_at":"2026-02-06T22:31:48.925Z","repository":{"id":268318462,"uuid":"903962954","full_name":"SanaeProject/matrix","owner":"SanaeProject","description":"This project aims to develop a library that enables simple implementation and lightweight matrix operations.","archived":false,"fork":false,"pushed_at":"2025-01-08T00:56:36.000Z","size":19693,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop/cpp","last_synced_at":"2025-01-08T01:35:27.244Z","etag":null,"topics":["cpp","matrix-libraries","matrix-library-cpp","oneapi","simplythebest","sycl"],"latest_commit_sha":null,"homepage":"","language":"C++","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/SanaeProject.png","metadata":{"files":{"readme":"README-EN.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-12-16T01:35:16.000Z","updated_at":"2024-12-31T08:42:12.000Z","dependencies_parsed_at":"2025-01-08T01:34:00.441Z","dependency_job_id":"8279b00c-4cba-42fd-a763-2e0818659061","html_url":"https://github.com/SanaeProject/matrix","commit_stats":null,"previous_names":["sanaeprj/matrix","sanaeproject/matrix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SanaeProject%2Fmatrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SanaeProject%2Fmatrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SanaeProject%2Fmatrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SanaeProject%2Fmatrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SanaeProject","download_url":"https://codeload.github.com/SanaeProject/matrix/tar.gz/refs/heads/develop/cpp","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238369498,"owners_count":19460673,"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":["cpp","matrix-libraries","matrix-library-cpp","oneapi","simplythebest","sycl"],"created_at":"2025-02-11T20:48:13.895Z","updated_at":"2026-02-06T22:31:48.900Z","avatar_url":"https://github.com/SanaeProject.png","language":"C++","readme":"# matrixCpp\n## Overview\nThis project aims to develop a library for **simple** and **lightweight** matrix operations.\n\n\u003e [!NOTE]\n\u003e The compiler used is MSVC2022 Cpp14 or Cpp17.\n\n## Contribution Guidelines\nIf you would like to contribute, please follow these steps:\n\n### Steps to Contribute\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/userName`).\n3. Commit your changes (`git commit -m 'comment'`).\n4. Push to the branch (`git push origin feature/userName`).\n5. Create a pull request.\n\n## Classes\n### **matrix** Type\nGenerate matrices of `int` or `double` types using `template`.\n```cpp\ntemplate\u003ctypename Type\u003e\nclass Matrix{\n\t// member\n};\n\nMatrix\u003cint\u003e mint;\nMatrix\u003cdouble\u003e mdouble;\n```\n\n## Implementation Details\n- **Data Storage**\n  Data is stored and processed in `std::vector\u003cstd::vector\u003cType\u003e\u003e`.\n  To enable GPU processing (e.g., with `CUDA`) in the future, a method to expand data into a one-dimensional array will be defined.\n\n- **Type Aliases**\n  Since `std::vector\u003cstd::vector\u003cType\u003e\u003e` can be lengthy during implementation, the following type aliases are defined for convenience: `RowType`, `RowInitType`, `MatrixType`, and `MatrixInitType`. These aliases will also be made `public` for external use.\n  ```cpp\n  template\u003ctypename Type\u003e\n  class matrix{\n  public:\n      template\u003ctypename rowType    \u003e using RowType     = std::vector\u003crowType\u003e;\n      template\u003ctypename rowInitType\u003e using RowInitType = std::initializer_list\u003crowInitType\u003e;\n\n      template\u003ctypename matrixType = Type\u003e using MatrixType     = std::vector          \u003cRowType\u003cmatrixType\u003e\u003e;\n      template\u003ctypename matrixType = Type\u003e using MatrixInitType = std::initializer_list\u003cRowInitType\u003cmatrixType\u003e\u003e;\n  };\n  ```\n\n### Header Files\nThe library will separate `definition files` and `implementation files` to enhance maintainability.\n- **Definition Files**\n  - Class declarations\n  - Function prototype declarations\n  - Macro definitions\n\n- **Implementation Files**\n  - Function implementations\n  - Member function implementations\n\n#### Include Guards\nThe naming convention for include guards is `MATRIXCPP_FILENAME_EXTENSION`.\n```cpp\n// For test.hpp\n#ifndef MATRIXCPP_TEST_HPP\n#define MATRIXCPP_TEST_HPP\n\n// proc...\n\n#endif\n```\n\n#### File Structure\nFiles are divided into `.h` for definition and `.hpp` for implementation.\n- **matrix**\n  Includes all related files such as matrix.h and matrixCalc.hpp.\n- **matrix.h**\n  Contains matrix class definitions, member declarations, and prototypes.\n- **matrixCtor.hpp**\n  Defines constructors.\n- **matrixCalc.hpp**\n  Handles operations such as addition, subtraction, and Hadamard product.\n- **matrixOp.hpp**\n  Implements operator functions.\n- **matrixDec.hpp**\n  Performs matrix decompositions such as LU decomposition, including inverse matrix computation.\n- **matrixUtils.hpp**\n  Manages matrix manipulations such as row swapping.\n\n```\nmatrix ---- matrix.h\n        |-- matrixCtor.hpp\n        |-- matrixCalc.hpp\n        |-- matrixOp.hpp\n        |-- matrixDec.hpp\n        |__ matrixUtils.hpp\n```\n\n## Naming Conventions\n- Use [`camelCase`](https://en.wikipedia.org/wiki/Camel_case) for member names.\n- Use `PascalCase` for class names.\n- **Private Members:** Append `_` to private member names (e.g., `camelCase_`).\n- **Prototype Declarations:** Use the format `ReturnType MemberName(ArgType1, ArgType2, ...);`.\n\n## Code Style\n### Definition Files\n```cpp\ntemplate\u003ctypename Type\u003e\nclass Matrix{\nprivate:\n    // Private Members\n\n    // Variable Members\n    Type testValuePrivate_ = 0; // Comment\n\n    // Function Members (Prototypes)\n    Type testFuncPrivate_(const Matrix\u0026, const Matrix\u0026); // Comment\n\npublic:\n    // Public Members\n\n    // Variable Members\n    Type testValuePublic = 0; // Comment\n\n    // Function Members (Prototypes)\n    Type testFuncPublic(const Matrix\u0026, const Matrix\u0026); // Comment\n};\n```\n\n### Implementation Files\n```cpp\n// Comment\ntemplate\u003ctypename Type\u003e\nType Matrix\u003cType\u003e::testFuncPrivate_(const Matrix\u0026 a, const Matrix\u0026 b){\n    return Type();\n}\n\n// Comment\ntemplate\u003ctypename Type\u003e\nType Matrix\u003cType\u003e::testFuncPublic(const Matrix\u0026 a, const Matrix\u0026 b){\n    return Type();\n}\n```\n\n## Feature List\n### Constructors\n- `Matrix() = default;`  \n  Default constructor.\n\n- `Matrix(const MatrixInitType\u003c\u003e\u0026);`  \n  Constructor with initialization parameters.\n\n- `Matrix(const MatrixType\u003c\u003e\u0026);`  \n  Copy constructor.\n\n- `Matrix(const std::pair\u003csize_t, size_t\u003e\u0026);`  \n  Constructor with size specification.\n\n- `Matrix(const Matrix\u003cType, DcmpType\u003e\u0026);`  \n  Copy constructor.\n\n- `Matrix(Matrix\u003cType\u003e\u0026\u0026) noexcept;`  \n  Move constructor.\n\n### Operator Overloading\n- `Matrix\u003cType\u003e\u0026 operator=(const MatrixInitType\u003cType\u003e\u0026);`  \n  Assignment operator.\n\n- `Matrix\u003cType\u003e\u0026 operator=(const Matrix\u003cType\u003e\u0026);`  \n  Assignment operator.\n\n- `Matrix\u003cType\u003e\u0026 operator\u003c\u003c(const MatrixInitType\u003cType\u003e\u0026);`  \n  Stream insertion operator.\n\n- `Matrix\u003cType\u003e\u0026 operator\u003c\u003c(const Matrix\u003cType\u003e\u0026);`  \n  Stream insertion operator.\n\n- `Matrix\u003cType\u003e\u0026 operator=(Matrix\u003cType\u003e\u0026\u0026);`  \n  Move assignment operator.\n\n- `Matrix\u003cType\u003e\u0026 operator\u003c\u003c(Matrix\u003cType\u003e\u0026\u0026);`  \n  Move stream insertion operator.\n\n- `RowType\u003cType\u003e\u0026 operator[](const size_t\u0026);`  \n  Row access.\n\n- `Matrix\u003cType\u003e\u0026 operator+=(const Matrix\u003cType\u003e\u0026);`  \n  Addition.\n\n- `Matrix\u003cType\u003e\u0026 operator-=(const Matrix\u003cType\u003e\u0026);`  \n  Subtraction.\n\n- `Matrix\u003cType\u003e\u0026 operator*=(const Matrix\u003cType\u003e\u0026);`  \n  Multiplication.\n\n- `Matrix\u003cType\u003e\u0026 operator^=(const Matrix\u003cType\u003e\u0026);`  \n  Hadamard product.\n\n- `Matrix\u003cType\u003e\u0026 operator/=(const Matrix\u003cType\u003e\u0026);`  \n  Hadamard division.\n\n- `Matrix\u003cType\u003e\u0026 operator*=(const Type\u0026);`  \n  Scalar multiplication.\n\n- `Matrix\u003cType\u003e operator+(const Matrix\u003cType\u003e\u0026);`  \n  Addition.\n\n- `Matrix\u003cType\u003e operator-(const Matrix\u003cType\u003e\u0026);`  \n  Subtraction.\n\n- `Matrix\u003cType\u003e operator*(const Matrix\u003cType\u003e\u0026);`  \n  Multiplication.\n\n- `Matrix\u003cType\u003e operator^(const Matrix\u003cType\u003e\u0026);`  \n  Hadamard product.\n\n- `Matrix\u003cType\u003e operator/(const Matrix\u003cType\u003e\u0026);`  \n  Hadamard division.\n\n- `Matrix\u003cType\u003e operator*(const Type\u0026);`  \n  Scalar multiplication.\n\n- `template\u003ctypename Type_\u003e`  \n  `explicit operator Matrix\u003cType_\u003e();`  \n  Type conversion.\n\n### Member Functions\n- `Matrix\u003cType\u003e\u0026 add(const Matrix\u003cType\u003e\u0026);`  \n  Addition.\n\n- `Matrix\u003cType\u003e\u0026 sub(const Matrix\u003cType\u003e\u0026);`  \n  Subtraction.\n\n- `Matrix\u003cType\u003e\u0026 mul(const Matrix\u003cType\u003e\u0026);`  \n  Multiplication.\n\n- `Matrix\u003cType\u003e\u0026 scalarMul(const Type\u0026);`  \n  Scalar multiplication.\n\n- `Matrix\u003cType\u003e\u0026 hadamardMul(const Matrix\u003cType\u003e\u0026);`  \n  Hadamard product.\n\n- `Matrix\u003cType\u003e\u0026 hadamardDiv(const Matrix\u003cType\u003e\u0026);`  \n  Hadamard division.\n\n- `template\u003ctypename calcType\u003e`  \n  `Matrix\u003cType\u003e\u0026 scalarCalc(const Matrix\u003cType\u003e\u0026);`  \n  Scalar calculation.\n\n- `std::vector\u003cMatrix\u003cDcmpType\u003e\u003e luDec(DcmpType epsilon = 1e-9);`  \n  LU decomposition.\n\n- `Matrix\u003cDcmpType\u003e inverse(DcmpType epsilon = 1e-9);`  \n  Inverse matrix.\n\n- `DcmpType det(DcmpType epsilon = 1e-9);`  \n  Determinant.\n\n- `Matrix\u003cType\u003e transpose();`  \n  Transpose.\n\n- `Matrix\u003cType\u003e\u0026 swapRow(const size_t\u0026, const size_t\u0026);`  \n  Row swapping.\n\n- `Matrix\u003cType\u003e\u0026 swapCol(const size_t\u0026, const size_t\u0026);`  \n  Column swapping.\n\n- `Matrix\u003cType\u003e\u0026 resize(const size_t\u0026, const size_t\u0026);`  \n  Resize.\n\n- `const size_t rows() const;`  \n  Get the number of rows.\n\n- `const size_t cols() const;`  \n  Get the number of columns.\n\n- `std::vector\u003cstd::reference_wrapper\u003cType\u003e\u003e rowRef(const size_t\u0026);`  \n  Row reference.\n\n- `std::vector\u003cstd::reference_wrapper\u003cType\u003e\u003e colRef(const size_t\u0026);`  \n  Column reference.\n\n- `Matrix\u003cType\u003e\u0026 forEach(std::function\u003cType()\u003e);`  \n  Apply operations to each element.\n\n- `Matrix\u003cType\u003e\u0026 forEach(std::function\u003cType(size_t, size_t, Type\u0026)\u003e);`  \n  Apply operations to each element (row, column, and value).\n\n- `template\u003ctypename Type_ = Type\u003e`  \n  `static Matrix\u003cType_\u003e identity(const size_t\u0026);`  \n  Generate an identity matrix.\n\n### Stream Output Overloading\n- `template\u003ctypename CharT, typename Traits, typename MatrixType = double\u003e`  \n  `std::basic_ostream\u003cCharT, Traits\u003e\u0026 operator\u003c\u003c(std::basic_ostream\u003cCharT, Traits\u003e\u0026, Matrix\u003cMatrixType\u003e);`  \n  Output matrix.\n\n- `template\u003ctypename CharT, typename Traits, typename MatrixType = double\u003e`  \n  `std::basic_ostream\u003cCharT, Traits\u003e\u0026 operator\u003c\u003c(std::basic_ostream\u003cCharT, Traits\u003e\u0026, std::vector\u003cstd::vector\u003cMatrixType\u003e\u003e);`  \n  Output 2D vectors.\n\n\u003e [!NOTE]\n\u003e Additional decomposition methods such as [`QR decomposition`, `Cholesky decomposition`, `Eigenvalue decomposition`, `SVD decomposition`, and `Jordan normal form`](https://en.wikipedia.org/wiki/Matrix_decomposition) are planned.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanaeproject%2Fmatrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanaeproject%2Fmatrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanaeproject%2Fmatrix/lists"}