From fe2eeee7a80e4d3cc201ed65b0d22aa788ffdff1 Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Thu, 17 Sep 2026 23:13:40 +0200 Subject: [PATCH] feat: add matrix division by scalar --- include/mat.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/mat.hpp b/include/mat.hpp index 9f73046..7fe081a 100644 --- a/include/mat.hpp +++ b/include/mat.hpp @@ -242,4 +242,28 @@ mat operator*(const mat& lhs, const mat_col& rhs) { return res; } +template +mat operator/(const mat& lhs, T rhs) { + mat res; + for (std::size_t i = 0; i < M; ++i) { + for (std::size_t j = 0; j < N; ++j) { + res[i][j] = lhs[i][j] / rhs; + } + } + + return res; +} + +template +mat operator/(T lhs, const mat& rhs) { + mat res; + for (std::size_t i = 0; i < M; ++i) { + for (std::size_t j = 0; j < N; ++j) { + res[i][j] = lhs / rhs[i][j]; + } + } + + return res; +} + #endif // MAT_HPP