From 8ac4d298a209a2b381f203c2b63e59ace9736846 Mon Sep 17 00:00:00 2001 From: y-jan137 Date: Thu, 12 Mar 2026 15:01:35 +0300 Subject: Add matrix, vector classes and tests --- include/matrix.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/matrix.hpp (limited to 'include/matrix.hpp') 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 +#include +#include + +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> 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 data_; +}; + +} // namespace linalg + -- cgit v1.2.3