在Julia中使用巨大数组的有效方法

时间:2019-06-05 20:13:14

标签: arrays python-3.x memory multidimensional-array julia

我有大量的实验数据,这些数据是用Python编写的UI收集的。数组的大小约为数十GB,存储为无符号整数,并通过已知因子转换为浮点数。此数组的典型大小为64 x 64 x 10 ^ 5条目。 在pythonic用户界面中,一切运行非常顺利。我们具有最实时的可视化效果,可以绘制每个一维子数组的许多行为(沿长方向),加载和关闭它们。然后将它们另存为hdf5文件。

当我尝试使用更好的计算机在Julia中对它们进行数字处理时,一切都会变得迟钝。超级慢。无反应。因此,我显然必须做错了什么。

Actuall代码示例包括以下功能:


function centerandreshapedata(xxs::Array, factor::Number)
    irrrelevant,largo=size(xxs)
    aux=Array{Int16}(undef, 64,64, largo);
    result=Array{Float16}(undef, 64,64, largo);
    for j=1:64,k=1:64
        aux[k,j,:]=xxs[j+(k-1)*64,:]
    end
    result=((aux.-2048).*factor);
    # factor is converting the floats to Float64
    result=convert.(Float16, result)
    return result
end


function DiscreteLaplacian(data)
    temp=copy(Datos)
    (mu,lu)=size(Datos)    
    izq=reshape(temp[1,:],(1,lu))
    der=reshape(temp[end,:],(1,lu))
    #Padding the data
    temp=vcat(izq, temp, der)
    temp=hcat(temp[:,1], temp, temp[:,end])
    largo,ancho=size(temp)
    aux=Array{Float32}(undef, 3,3)
    result=zeros(size(temp))

 for j=2:largo-1, k=2:ancho-1
        aux=temp[j-1:j+1,k-1:k+1]
        result[j,k]=sum(LaplacianKernel.*aux)
    end
    #DO  Crop the borders
    result=result[2:end-1,2:end-1]
    return result
end

我需要处理这些数据的典型事情是重塑形状,应用有限差分算子和其他线性变换,逐片搜索某些值,诸如此类。 python UI似乎比我的Julia rutines响应更快。我对此感到非常困惑。

也用PyPlot.jl绘制它们需要花费很多时间,但这可能是另一个问题。

0 个答案:

没有答案