Julia 对于大字符串,replace()失败
我有以下代码:Julia 对于大字符串,replace()失败,julia,Julia,我有以下代码: cd(joinpath(homedir(),"Desktop")) using HDF5 using JLD # read contents of a file t = readall("sourceFile") # remove unnecessary characters t = replace(t, r"( 1:1\.0+)|(( 1:1\.0+)|(([1-6]:)|((\|user )|(\|))))", "") # convert string into Fl
cd(joinpath(homedir(),"Desktop"))
using HDF5
using JLD
# read contents of a file
t = readall("sourceFile")
# remove unnecessary characters
t = replace(t, r"( 1:1\.0+)|(( 1:1\.0+)|(([1-6]:)|((\|user )|(\|))))", "")
# convert string into Float64 array (approximately ~140 columns)
data = readdlm(IOBuffer(t), ' ', char(10))
# save array on the hard drive
save("data.jld", "data", data)
当我使用行数为10^4或更少的sourceFile测试它时,它工作得很好。但是,当源文件有大约5*10^6行时,它会在t=replace(t,r)(1:1\.0+)((1:1\.0+))(([1-6]:))|((\\| user)|(\\|)(\|)用户)(\|)(\|))),“”)
处失败,并显示以下消息
这个问题很老了,是根据朱莉娅的旧版本提出的。但是,检查这是否适用于最新版本会很有用。我最近在Julia的最新
0.5
版本中对此进行了测试,上面的代码似乎可以正常工作,每行有600个字符,共5*10^6行。整个操作在我的笔记本电脑上占用了大约5G的峰值内存
julia> t=[randstring(600) for i=1:5*10^6];
julia> writecsv("/Users/aviks/tmp/long.csv", t)
julia> t=readstring("/Users/aviks/tmp/long.csv");
julia> length(t)
3005000000
julia> @time t = replace(t, r"( 1:1\.0+)|(( 1:1\.0+)|(([1-6]:)|((\|user )|(\|))))", "");
43.599660 seconds (137 allocations: 3.358 GB, 0.85% gc time)
(注:请注意,
readall
现在被弃用,取而代之的是readstring
)。您可以随时编辑您的问题。您是否可以提交一份错误报告?您是否可以尝试使用刚刚标记的Julia 0.4-rc1版本,看看错误是否仍然存在?我知道regex替换库是一个版本,它周围的一些代码被重构了。你使用的是哪个版本的libpcre?这可能是错误的根源