aboutsummaryrefslogtreecommitdiff
path: root/include/vector.hpp
diff options
context:
space:
mode:
authory-jan137 <yousefjan24000@gmail.com>2026-03-12 15:01:35 +0300
committery-jan137 <yousefjan24000@gmail.com>2026-03-12 15:01:35 +0300
commit8ac4d298a209a2b381f203c2b63e59ace9736846 (patch)
treefb1fbda3739afb60f76dd4bb48241957a5a3baa0 /include/vector.hpp
parentbfd7f0d6a9f81e093a390be968058732cc7562c6 (diff)
Add matrix, vector classes and tests
Diffstat (limited to 'include/vector.hpp')
-rw-r--r--include/vector.hpp46
1 files changed, 46 insertions, 0 deletions
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 <cstddef>
+#include <initializer_list>
+#include <vector>
+
+namespace linalg {
+
+class Vector {
+public:
+ Vector() = default;
+ explicit Vector(std::size_t n);
+ Vector(std::size_t n, double value);
+ Vector(std::initializer_list<double> 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<double> 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