Joel Schaerer
2008-06-16 14:47:27 UTC
Hi all,
I've found that the 2D convolution code in scipy is significantly slower than
matlab's. The following code:
--------------------------------------------------------------------
#!/usr/bin/python
import scipy.io as io
import scipy.signal
aa=io.loadmat('input.mat')
seq=aa["seq"]
seq_f=[]
kernel=scipy.randn(21,21)
for k in xrange(seq.shape[2]):
seq_f.append(scipy.signal.convolve2d(seq[:,:,k],kernel,'same'))
--------------------------------------------------------------------
Executes about 8 times slower than the following matlab code (executed with
matlab7 on 32bit linux):
--------------------------------------------------------------------
clear all
close all
clc
load input.mat
g=randn(21,21);
seq_f=zeros(size(seq));
for p=1:size(seq,3),
seq_f(:,:,p)=conv2(seq(:,:,p),g,'same');
end
--------------------------------------------------------------------
I've traced the convolve code in scipy to the pylab_convolve2D function in
firfilter.c. It contains the nice following warning:
/* This could definitely be more optimized... */
...
Anyways, convolution is crucial for some applications,
so I wanted to report this. I also tried to look for
some good open source convolution code so that it
might be incorporated into scipy, but couldn't find any.
Would anyone know of one?
Totally unrelated question to the scipy devs: do you plan
to add a hierarchical data structure such as kd-trees to
scipy? With a nice API, it would be a great feature.
I've found that the 2D convolution code in scipy is significantly slower than
matlab's. The following code:
--------------------------------------------------------------------
#!/usr/bin/python
import scipy.io as io
import scipy.signal
aa=io.loadmat('input.mat')
seq=aa["seq"]
seq_f=[]
kernel=scipy.randn(21,21)
for k in xrange(seq.shape[2]):
seq_f.append(scipy.signal.convolve2d(seq[:,:,k],kernel,'same'))
--------------------------------------------------------------------
Executes about 8 times slower than the following matlab code (executed with
matlab7 on 32bit linux):
--------------------------------------------------------------------
clear all
close all
clc
load input.mat
g=randn(21,21);
seq_f=zeros(size(seq));
for p=1:size(seq,3),
seq_f(:,:,p)=conv2(seq(:,:,p),g,'same');
end
--------------------------------------------------------------------
I've traced the convolve code in scipy to the pylab_convolve2D function in
firfilter.c. It contains the nice following warning:
/* This could definitely be more optimized... */
...
Anyways, convolution is crucial for some applications,
so I wanted to report this. I also tried to look for
some good open source convolution code so that it
might be incorporated into scipy, but couldn't find any.
Would anyone know of one?
Totally unrelated question to the scipy devs: do you plan
to add a hierarchical data structure such as kd-trees to
scipy? With a nice API, it would be a great feature.