This is an automated email from the ASF dual-hosted git repository.
janardhan pushed a commit to branch SYSTEMDS-2102-vectorize-fm-gradient
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to
refs/heads/SYSTEMDS-2102-vectorize-fm-gradient by this push:
new eda27d01d9 Update fm.dml
eda27d01d9 is described below
commit eda27d01d91f5440d2d4535982aeaf4e587e4178
Author: Janardhan Pulivarthi <[email protected]>
AuthorDate: Fri Apr 7 21:42:29 2023 +0530
Update fm.dml
---
scripts/nn/layers/fm.dml | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/scripts/nn/layers/fm.dml b/scripts/nn/layers/fm.dml
index ccbc31d122..149994dfd7 100644
--- a/scripts/nn/layers/fm.dml
+++ b/scripts/nn/layers/fm.dml
@@ -87,14 +87,19 @@ backward = function(matrix[double] dout, matrix[double] X,
matrix[double] w0, ma
# Second term -> V(i,f) * (X(i))^2
- Xt = t( X^2 ) %*% dout # shape (d,1)
-
- g_V2 = Xt[1,] %*% V[1,]
-
- for (i in 2:d) {
- tmp = Xt[i,] %*% V[i,]
- g_V2 = rbind(g_V2, tmp)
- }
+ # Xt = t( X^2 ) %*% dout # shape (d,1)
+
+ # code with loops
+ # g_V2 = Xt[1,] %*% V[1,]
+ # for (i in 2:d) {
+ # tmp = Xt[i,] %*% V[i,]
+ # g_V2 = rbind(g_V2, tmp)
+ # }
+
+ # vectorized code
+ X_squared = X^2
+ Xt = t(X_squared) %*% dout
+ g_V2 = Xt %*% V
xv = X %*% V