diff options
| author | y-jan137 <yousefjan24000@gmail.com> | 2026-03-12 15:01:35 +0300 |
|---|---|---|
| committer | y-jan137 <yousefjan24000@gmail.com> | 2026-03-12 15:01:35 +0300 |
| commit | 8ac4d298a209a2b381f203c2b63e59ace9736846 (patch) | |
| tree | fb1fbda3739afb60f76dd4bb48241957a5a3baa0 /include/matrix.hpp | |
| parent | bfd7f0d6a9f81e093a390be968058732cc7562c6 (diff) | |
Add matrix, vector classes and tests
Diffstat (limited to 'include/matrix.hpp')
| -rw-r--r-- | include/matrix.hpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/matrix.hpp b/include/matrix.hpp new file mode 100644 index 0000000..ba3e4ae --- /dev/null +++ b/include/matrix.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include <cstddef> +#include <initializer_list> +#include <vector> + +namespace linalg { + +class Matrix { +public: + Matrix() = default; + Matrix(std::size_t rows, std::size_t cols); + Matrix(std::size_t rows, std::size_t cols, double value); + Matrix(std::initializer_list<std::initializer_list<double>> values); + + [[nodiscard]] std::size_t rows() const noexcept; + [[nodiscard]] std::size_t cols() const noexcept; + [[nodiscard]] bool empty() const noexcept; + + double& operator()(std::size_t i, std::size_t j); + const double& operator()(std::size_t i, std::size_t j) const; + + void fill(double value); + + double* data() noexcept; + const double* data() const noexcept; + + static Matrix identity(std::size_t n); + static Matrix zeros(std::size_t rows, std::size_t cols); + +private: + [[nodiscard]] std::size_t index(std::size_t i, std::size_t j) const; + void check_bounds(std::size_t i, std::size_t j) const; + + std::size_t rows_ = 0; + std::size_t cols_ = 0; + std::vector<double> data_; +}; + +} // namespace linalg + |