From 36183bf80184673bd8e7b8a9eef4fb915d4755bd Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Thu, 11 Apr 2024 17:07:52 +0200 Subject: [PATCH] Vectorize the multiplication --- math/cmath/include/algebra/math/impl/cmath_operators.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/math/cmath/include/algebra/math/impl/cmath_operators.hpp b/math/cmath/include/algebra/math/impl/cmath_operators.hpp index ef624da7..a6bbcdbe 100644 --- a/math/cmath/include/algebra/math/impl/cmath_operators.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_operators.hpp @@ -205,16 +205,17 @@ ALGEBRA_HOST_DEVICE inline array_t, O> operator*( array_t, O> C; - for (size_type i = 0; i < M; ++i) { + for (size_type i = 0; i < N; ++i) { for (size_type j = 0; j < O; ++j) { scalar_t val = 0; + const scalar_t B_ij = B[j][i]; - for (size_type k = 0; k < N; ++k) { - val += A[k][i] * B[j][k]; + for (size_type k = 0; k < M; ++k) { + val += A[i][k] * B_ij; } - C[j][i] = val; + C[j][k] = val; } }