This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new d01c61d7d5 [MINOR] Performance improvement of dist
d01c61d7d5 is described below
commit d01c61d7d56f250223f60fff6e773ba0870a7bee
Author: ramesesz <[email protected]>
AuthorDate: Mon Dec 11 16:43:13 2023 +0100
[MINOR] Performance improvement of dist
This patch improves the builtin dist function
by removing the outer product operator. For 100
function calls on an arbitrary matrix with 4000
rows and 800 cols, the new dist function shortens
the runtime from 66.541s to 60.268s.
Closes #1959
---
scripts/builtin/dist.dml | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/builtin/dist.dml b/scripts/builtin/dist.dml
index 26ded9a197..f296fd717b 100644
--- a/scripts/builtin/dist.dml
+++ b/scripts/builtin/dist.dml
@@ -32,7 +32,8 @@
#
-----------------------------------------------------------------------------------------------
m_dist = function(Matrix[Double] X) return (Matrix[Double] Y) {
- G = X %*% t(X);
- Y = sqrt(-2 * G + outer(diag(G), t(diag(G)), "+"));
+ n = nrow(X)
+ s = rowSums(X^2)
+ Y = sqrt(-2 * X %*% t(X) + s + t(s))
Y = replace(target = Y, pattern=NaN, replacement = 0);
}