From af87db21b8c72d16e4f63aba9fcfecd48167e71d Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 12 Oct 2025 12:50:40 +0200 Subject: Added multiplication for matrices and vectors --- modules/codec/c++/math.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'modules/codec/c++/math.hpp') diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp index 095c8ca..a8bbba1 100644 --- a/modules/codec/c++/math.hpp +++ b/modules/codec/c++/math.hpp @@ -53,5 +53,33 @@ data, Encoding> vectorize_data(const data +data, Encoding> multiply(const data, Encoding>& left, const data, Encoding>& right){ + data, Encoding> lr; + + for(uint64_t i = 0u; i < M; ++i){ + for(uint64_t j = 0u; j < N; ++j){ + for(uint64_t k = 0u; k < K; ++k){ + lr.at({{i,j}}) = lr.at({{i,j}}) + left.at({{i,k}}) * right.at({{k,j}}); + } + } + } + + return lr; +} + +template +data, Encoding> multiply(const data, Encoding>& left, const data, Encoding>& right){ + data, Encoding> lr; + + for(uint64_t i = 0u; i < M; ++i){ + for(uint64_t j = 0u; j < N; ++j){ + lr.at({{i}}) = lr.at({{i}}) + left.at({{i,j}}) * right.at({{j}}); + } + } + + return lr; +} } } -- cgit v1.2.3