commit 50a60a5: [Minor] Fix tensor projections multiplication

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Aug 19 17:14:05 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-08-19 18:11:35 +0100
URL: https://github.com/rspamd/rspamd/commit/50a60a54fd4dd9cab1a520b4bf1b54c1dd206f56 (HEAD -> master)

[Minor] Fix tensor projections multiplication

---
 src/lua/lua_tensor.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/lua/lua_tensor.c b/src/lua/lua_tensor.c
index 252c9ab92..6e5bec7d8 100644
--- a/src/lua/lua_tensor.c
+++ b/src/lua/lua_tensor.c
@@ -60,6 +60,7 @@ lua_newtensor (lua_State *L, int ndims, const int *dim, bool zero_fill, bool own
 	struct rspamd_lua_tensor *res;
 
 	res = lua_newuserdata (L, sizeof (struct rspamd_lua_tensor));
+	memset (res, 0, sizeof (*res));
 
 	res->ndims = ndims;
 	res->size = 1;
@@ -453,10 +454,10 @@ lua_tensor_mul (lua_State *L)
 
 	if (t1 && t2) {
 		gint dims[2], shadow_dims[2];
-		dims[0] = transA ? t1->dim[1] : t1->dim[0];
-		shadow_dims[0] = transB ? t2->dim[1] : t2->dim[0];
-		dims[1] = transB ? t2->dim[0] : t2->dim[1];
-		shadow_dims[1] = transA ? t1->dim[0] : t1->dim[1];
+		dims[0] = abs (transA ? t1->dim[1] : t1->dim[0]);
+		shadow_dims[0] = abs (transB ? t2->dim[1] : t2->dim[0]);
+		dims[1] = abs (transB ? t2->dim[0] : t2->dim[1]);
+		shadow_dims[1] = abs (transA ? t1->dim[0] : t1->dim[1]);
 
 		if (shadow_dims[0] != shadow_dims[1]) {
 			return luaL_error (L, "incompatible dimensions %d x %d * %d x %d",


More information about the Commits mailing list