-
Notifications
You must be signed in to change notification settings - Fork 301
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
Use stats::dist()
to calculate Euclidean distances?
#1874
Comments
For completeness:
|
edzer
added a commit
that referenced
this issue
Jan 5, 2022
OK, this branch gives us library(sf)
# Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE
n = 4000
df = data.frame(x = runif(n, 171000, 861000), y = runif(n, 133000, 775000))
pts_sf = st_as_sf(df, coords = c("x", "y"), crs = "epsg:2180")
results = bench::mark(
iterations = 30, check = FALSE, time_unit = "s",
sf = sf::st_distance(pts_sf, which = "Euclidean"),
stats = as.matrix(stats::dist(st_coordinates(pts_sf), method = "euclidean")),
)
# Warning message:
# Some expressions had a GC in every iteration; so filtering is disabled.
results[, 1:6]
# # A tibble: 2 × 6
# expression min median `itr/sec` mem_alloc `gc/sec`
# <bch:expr> <dbl> <dbl> <dbl> <bch:byt> <dbl>
# 1 sf 0.589 0.595 1.67 581MB 3.45
# 2 stats 0.511 0.534 1.84 580MB 3.75 |
Dan Baston has just implemented patch in GEOS that improve the performance of point-to-point calculations. In the future, it would be interesting to see what is faster: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have ~50,000 points and would like to calculate the Euclidean distance matrix. Currently
st_distance()
seems to be the slowest way to do it (below is the benchmark). Could you consider usingstats::dist()
to speed up this operation? Here is also Rfast::Dist, written in C++, which is super fast. fields::rdist is pretty fast too.The text was updated successfully, but these errors were encountered: