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/vector.hpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 include/vector.hpp (limited to 'include/vector.hpp') diff --git a/include/vector.hpp b/include/vector.hpp new file mode 100644 index 0000000..e6bc0ce --- /dev/null +++ b/include/vector.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include + +namespace linalg { + +class Vector { +public: + Vector() = default; + explicit Vector(std::size_t n); + Vector(std::size_t n, double value); + Vector(std::initializer_list values); + + [[nodiscard]] std::size_t size() const noexcept; + [[nodiscard]] bool empty() const noexcept; + + double& operator[](std::size_t i); + const double& operator[](std::size_t i) const; + + void fill(double value); + + double* data() noexcept; + const double* data() const noexcept; + + auto begin() noexcept { return data_.begin(); } + auto end() noexcept { return data_.end(); } + auto begin() const noexcept { return data_.begin(); } + auto end() const noexcept { return data_.end(); } + auto cbegin() const noexcept { return data_.cbegin(); } + auto cend() const noexcept { return data_.cend(); } + +private: + void check_index(std::size_t i) const; + + std::vector data_; +}; + +Vector operator+(const Vector& lhs, const Vector& rhs); +Vector operator-(const Vector& lhs, const Vector& rhs); +Vector operator*(const Vector& v, double scalar); +Vector operator*(double scalar, const Vector& v); +double dot(const Vector& lhs, const Vector& rhs); + +} // namespace linalg -- cgit v1.2.3