I found julia’s repeat function run very slowly than matlab’s repmat and python too,here is my code of julia and matlab for a test of two functions,
anyone if want test a python script can write it yourself or ask me to update one.
the test contains smaller arrays and bigger,script and function,if any illogicality please point it out and i’ll try to write a correctly ones.
using Random
using BenchmarkTools
a1=bitrand(25,2500);
a2=bitrand(2500,2500);
(clen,alen)=size(a1);
ta=BitArray(zeros(1,alen));
@btime for i=1:20
ta[1,:]=a1[i,:];
A=repeat(ta,outer = [clen-i+1,1]);
end
(clen,alen)=size(a2);
ta=BitArray(zeros(1,alen));
@btime for i=1:20
ta[1,:]=a2[i,:];
A=repeat(ta,outer = [clen-i+1,1]);
end
function reptime(a)
(clen,alen)=size(a);
ta=BitArray(zeros(1,alen));
A=similar(ta)
for i=1:20
ta[1,:]=a[i,:];
A=repeat(ta,outer = [clen-i+1,1]);
end
return A
end
@btime reptime(a1);
@btime reptime(a2);
MATLAB code
a1=logical(randi(2,25,2500)-1);
a2=logical(randi(2,2500,2500)-1);
tic
[clen,~]=size(a1);
for i=1:20
A=repmat(a1(i,:),[clen-i+1,1]);
end
toc
tic
[clen,~]=size(a2);
for i=1:20
A=repmat(a2(i,:),[clen-i+1,1]);
end
toc
tic
reptime(a1);
toc
tic
reptime(a2);
toc
function A=reptime(a)
[clen,~]=size(a);
for i=1:20
A=repmat(a(i,:),[clen-i+1,1]);
end
end
also you can download those script on github
https://github.com/outyang/repeatandrepmat