-
Notifications
You must be signed in to change notification settings - Fork 2
/
juliaCall.R
50 lines (36 loc) · 1.08 KB
/
juliaCall.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# libraries ---------------------------------------------------------------
library(tidyverse)
# setup julia -------------------------------------------------------------
Sys.setenv(JULIA_NUM_THREADS = "7")
library(JuliaCall)
julia <- julia_setup()
# functions -----------------------------------------------------------------
generate_toy_data <- function(n) {
map(1:n, function(x) {
result <- rnorm(n = 89)
names(result) <- str_c("DIM_", formatC(1:89, width = 4, flag = 0))
result
}
) %>% bind_rows
}
measure_sim_mat_julia <- function(tibble_1, tibble_2) {
julia$library("Distances")
julia$assign("X", tibble_1 %>%
select(-1) %>%
as.matrix %>%
t)
julia$assign("Y", tibble_2 %>%
select(-1) %>%
as.matrix %>%
t)
1 - julia$eval("pairwise(cosine_dist, X, Y, dims=2)")
}
# test --------------------------------------------------------------------
{
tic()
results <- measure_sim_mat_julia(
generate_toy_data(100),
generate_toy_data(55000)
)
toc()
}