相关疑难解决方法(0)

加速朱莉娅写得不好的R例子

朱莉娅将性能与R进行比较的例子似乎特别令人费解. https://github.com/JuliaLang/julia/blob/master/test/perf/perf.R

你可以从下面的两种算法中获得最快的性能(最好解释你改变了什么以使它更像R)?

## mandel

mandel = function(z) {
    c = z
    maxiter = 80
    for (n in 1:maxiter) {
        if (Mod(z) > 2) return(n-1)
        z = z^2+c
    }
    return(maxiter)
}

mandelperf = function() {
    re = seq(-2,0.5,.1)
    im = seq(-1,1,.1)
    M = matrix(0.0,nrow=length(re),ncol=length(im))
    count = 1
    for (r in re) {
        for (i in im) {
            M[count] = mandel(complex(real=r,imag=i))
            count = count + 1
        }
    }
    return(M)
}

assert(sum(mandelperf()) == 14791)

## quicksort ##

qsort_kernel = function(a, …
Run Code Online (Sandbox Code Playgroud)

optimization r julia

72
推荐指数
2
解决办法
7972
查看次数

标签 统计

julia ×1

optimization ×1

r ×1