Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR] Performance improvement of the builtin dist function #1959

Closed
wants to merge 2 commits into from

Conversation

ramesesz
Copy link
Contributor

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.

The following experiment was run with varying rows and cols size:

X = rand(rows=4000, cols=800, min=-1, max=1, seed=42)

for (i in 1:100){
    Y = new_distance_matrix(X)
}

print( sum(Y) )


new_distance_matrix = function(matrix[double] X)
  return (matrix[double] out)
{
  n = nrow(X)
  s = rowSums(X * X)
  out = - 2*X %*% t(X) + s + t(s)
  out = replace(target = out, pattern=NaN, replacement = 0);
}

Terminal outputs from the experiments using the time prefix and -stats argument of the systemds CLI can be seen here.

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.
@j143 j143 added this to the systemds-3.2.0 milestone Dec 17, 2023
@Baunsgaard
Copy link
Contributor

thanks for the PR it is now merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants