https://github.com/sanaeproject/matrix
This project aims to develop a library that enables simple implementation and lightweight matrix operations.
https://github.com/sanaeproject/matrix
cpp matrix-libraries matrix-library-cpp oneapi simplythebest sycl
Last synced: 5 days ago
JSON representation
This project aims to develop a library that enables simple implementation and lightweight matrix operations.
- Host: GitHub
- URL: https://github.com/sanaeproject/matrix
- Owner: SanaeProject
- License: mit
- Created: 2024-12-16T01:35:16.000Z (about 1 year ago)
- Default Branch: develop/cpp
- Last Pushed: 2025-01-08T00:56:36.000Z (about 1 year ago)
- Last Synced: 2025-01-08T01:35:27.244Z (about 1 year ago)
- Topics: cpp, matrix-libraries, matrix-library-cpp, oneapi, simplythebest, sycl
- Language: C++
- Homepage:
- Size: 18.8 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README-EN.md
- License: LICENSE
Awesome Lists containing this project
README
# matrixCpp
## Overview
This project aims to develop a library for **simple** and **lightweight** matrix operations.
> [!NOTE]
> The compiler used is MSVC2022 Cpp14 or Cpp17.
## Contribution Guidelines
If you would like to contribute, please follow these steps:
### Steps to Contribute
1. Fork the repository.
2. Create a new branch (`git checkout -b feature/userName`).
3. Commit your changes (`git commit -m 'comment'`).
4. Push to the branch (`git push origin feature/userName`).
5. Create a pull request.
## Classes
### **matrix** Type
Generate matrices of `int` or `double` types using `template`.
```cpp
template
class Matrix{
// member
};
Matrix mint;
Matrix mdouble;
```
## Implementation Details
- **Data Storage**
Data is stored and processed in `std::vector>`.
To enable GPU processing (e.g., with `CUDA`) in the future, a method to expand data into a one-dimensional array will be defined.
- **Type Aliases**
Since `std::vector>` 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.
```cpp
template
class matrix{
public:
template using RowType = std::vector;
template using RowInitType = std::initializer_list;
template using MatrixType = std::vector >;
template using MatrixInitType = std::initializer_list>;
};
```
### Header Files
The library will separate `definition files` and `implementation files` to enhance maintainability.
- **Definition Files**
- Class declarations
- Function prototype declarations
- Macro definitions
- **Implementation Files**
- Function implementations
- Member function implementations
#### Include Guards
The naming convention for include guards is `MATRIXCPP_FILENAME_EXTENSION`.
```cpp
// For test.hpp
#ifndef MATRIXCPP_TEST_HPP
#define MATRIXCPP_TEST_HPP
// proc...
#endif
```
#### File Structure
Files are divided into `.h` for definition and `.hpp` for implementation.
- **matrix**
Includes all related files such as matrix.h and matrixCalc.hpp.
- **matrix.h**
Contains matrix class definitions, member declarations, and prototypes.
- **matrixCtor.hpp**
Defines constructors.
- **matrixCalc.hpp**
Handles operations such as addition, subtraction, and Hadamard product.
- **matrixOp.hpp**
Implements operator functions.
- **matrixDec.hpp**
Performs matrix decompositions such as LU decomposition, including inverse matrix computation.
- **matrixUtils.hpp**
Manages matrix manipulations such as row swapping.
```
matrix ---- matrix.h
|-- matrixCtor.hpp
|-- matrixCalc.hpp
|-- matrixOp.hpp
|-- matrixDec.hpp
|__ matrixUtils.hpp
```
## Naming Conventions
- Use [`camelCase`](https://en.wikipedia.org/wiki/Camel_case) for member names.
- Use `PascalCase` for class names.
- **Private Members:** Append `_` to private member names (e.g., `camelCase_`).
- **Prototype Declarations:** Use the format `ReturnType MemberName(ArgType1, ArgType2, ...);`.
## Code Style
### Definition Files
```cpp
template
class Matrix{
private:
// Private Members
// Variable Members
Type testValuePrivate_ = 0; // Comment
// Function Members (Prototypes)
Type testFuncPrivate_(const Matrix&, const Matrix&); // Comment
public:
// Public Members
// Variable Members
Type testValuePublic = 0; // Comment
// Function Members (Prototypes)
Type testFuncPublic(const Matrix&, const Matrix&); // Comment
};
```
### Implementation Files
```cpp
// Comment
template
Type Matrix::testFuncPrivate_(const Matrix& a, const Matrix& b){
return Type();
}
// Comment
template
Type Matrix::testFuncPublic(const Matrix& a, const Matrix& b){
return Type();
}
```
## Feature List
### Constructors
- `Matrix() = default;`
Default constructor.
- `Matrix(const MatrixInitType<>&);`
Constructor with initialization parameters.
- `Matrix(const MatrixType<>&);`
Copy constructor.
- `Matrix(const std::pair&);`
Constructor with size specification.
- `Matrix(const Matrix&);`
Copy constructor.
- `Matrix(Matrix&&) noexcept;`
Move constructor.
### Operator Overloading
- `Matrix& operator=(const MatrixInitType&);`
Assignment operator.
- `Matrix& operator=(const Matrix&);`
Assignment operator.
- `Matrix& operator<<(const MatrixInitType&);`
Stream insertion operator.
- `Matrix& operator<<(const Matrix&);`
Stream insertion operator.
- `Matrix& operator=(Matrix&&);`
Move assignment operator.
- `Matrix& operator<<(Matrix&&);`
Move stream insertion operator.
- `RowType& operator[](const size_t&);`
Row access.
- `Matrix& operator+=(const Matrix&);`
Addition.
- `Matrix& operator-=(const Matrix&);`
Subtraction.
- `Matrix& operator*=(const Matrix&);`
Multiplication.
- `Matrix& operator^=(const Matrix&);`
Hadamard product.
- `Matrix& operator/=(const Matrix&);`
Hadamard division.
- `Matrix& operator*=(const Type&);`
Scalar multiplication.
- `Matrix operator+(const Matrix&);`
Addition.
- `Matrix operator-(const Matrix&);`
Subtraction.
- `Matrix operator*(const Matrix&);`
Multiplication.
- `Matrix operator^(const Matrix&);`
Hadamard product.
- `Matrix operator/(const Matrix&);`
Hadamard division.
- `Matrix operator*(const Type&);`
Scalar multiplication.
- `template`
`explicit operator Matrix();`
Type conversion.
### Member Functions
- `Matrix& add(const Matrix&);`
Addition.
- `Matrix& sub(const Matrix&);`
Subtraction.
- `Matrix& mul(const Matrix&);`
Multiplication.
- `Matrix& scalarMul(const Type&);`
Scalar multiplication.
- `Matrix& hadamardMul(const Matrix&);`
Hadamard product.
- `Matrix& hadamardDiv(const Matrix&);`
Hadamard division.
- `template`
`Matrix& scalarCalc(const Matrix&);`
Scalar calculation.
- `std::vector> luDec(DcmpType epsilon = 1e-9);`
LU decomposition.
- `Matrix inverse(DcmpType epsilon = 1e-9);`
Inverse matrix.
- `DcmpType det(DcmpType epsilon = 1e-9);`
Determinant.
- `Matrix transpose();`
Transpose.
- `Matrix& swapRow(const size_t&, const size_t&);`
Row swapping.
- `Matrix& swapCol(const size_t&, const size_t&);`
Column swapping.
- `Matrix& resize(const size_t&, const size_t&);`
Resize.
- `const size_t rows() const;`
Get the number of rows.
- `const size_t cols() const;`
Get the number of columns.
- `std::vector> rowRef(const size_t&);`
Row reference.
- `std::vector> colRef(const size_t&);`
Column reference.
- `Matrix& forEach(std::function);`
Apply operations to each element.
- `Matrix& forEach(std::function);`
Apply operations to each element (row, column, and value).
- `template`
`static Matrix identity(const size_t&);`
Generate an identity matrix.
### Stream Output Overloading
- `template`
`std::basic_ostream& operator<<(std::basic_ostream&, Matrix);`
Output matrix.
- `template`
`std::basic_ostream& operator<<(std::basic_ostream&, std::vector>);`
Output 2D vectors.
> [!NOTE]
> 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.