Thread Subject: conv2 in R2008b very slow

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 18 Dec, 2008 18:14:03

Message: 1 of 23

I just realized that conv2 is very slow in 2008b. I created a 2D filter by

GaussWidth = [23, 180];
F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWidth(1), 0, 0, 1, [0 0]);
% custumgauss -> see FileExchange

% Array of zeros
G1 = zeros(600, 1000);

% Set one single point
G1(300, 400) = 1.5;

% in R2008a:
tic; G2 = conv2(G1, F, 'same'); toc
>> Elapsed time is 0.014846 seconds.

% in R2008b:
tic; G2 = conv2(G1, F, 'same'); toc
>> Elapsed time is 17.831022 seconds.

Same machine, no background activity, reproducable. Why?

Andreas

Subject: conv2 in R2008b very slow

From: Matt

Date: 18 Dec, 2008 18:21:03

Message: 2 of 23

"Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <gie3tb$qen$1@fred.mathworks.com>...
> I just realized that conv2 is very slow in 2008b. I created a 2D filter by
>
> GaussWidth = [23, 180];
> F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWidth(1), 0, 0, 1, [0 0]);
> % custumgauss -> see FileExchange
>
> % Array of zeros
> G1 = zeros(600, 1000);
>
> % Set one single point
> G1(300, 400) = 1.5;
>
> % in R2008a:
> tic; G2 = conv2(G1, F, 'same'); toc
> >> Elapsed time is 0.014846 seconds.
>
> % in R2008b:
> tic; G2 = conv2(G1, F, 'same'); toc
> >> Elapsed time is 17.831022 seconds.
>
> Same machine, no background activity, reproducable. Why?
>
> Andreas



Can you give the dimensions of F? I don't want to have to download customgauss off the FEX to make this test.

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 19 Dec, 2008 07:15:10

Message: 3 of 23

"Matt" <mjacobson.removethis@xorantech.com> wrote in message <gie4af$nh6$1@fred.mathworks.com>...
> "Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <gie3tb$qen$1@fred.mathworks.com>...
> > I just realized that conv2 is very slow in 2008b. I created a 2D filter by
> >
> > GaussWidth = [23, 180];
> > F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWidth(1), 0, 0, 1, [0 0]);
> > % custumgauss -> see FileExchange
...
>
> Can you give the dimensions of F? I don't want to have to download customgauss off the FEX to make this test.

size(F) is 180 x 180

Andreas

Subject: conv2 in R2008b very slow

From: Matt

Date: 19 Dec, 2008 17:03:03

Message: 4 of 23

"Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <gie3tb$qen$1@fred.mathworks.com>...
> I just realized that conv2 is very slow in 2008b. I created a 2D filter by
>
> GaussWidth = [23, 180];
> F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWidth(1), 0, 0, 1, [0 0]);
> % custumgauss -> see FileExchange
>
> % Array of zeros
> G1 = zeros(600, 1000);
>
> % Set one single point
> G1(300, 400) = 1.5;
>
> % in R2008a:
> tic; G2 = conv2(G1, F, 'same'); toc
> >> Elapsed time is 0.014846 seconds.
>
> % in R2008b:
> tic; G2 = conv2(G1, F, 'same'); toc
> >> Elapsed time is 17.831022 seconds.
>
> Same machine, no background activity, reproducable. Why?
>
> Andreas


I can't explain the discrepancy, but I would be more suspicious of the R2008a version.

Given the sizes of your arrays, 17 sec. is not an unreasonable computation time. It is even 3 times faster than on my machine!

You would also never use conv2 with such large arrays. You would implement the convolution through FFTs, unless you knew one of them was very sparse. In the latter case, you would have to get more creative, or wait until conv2 supports sparse data inputs.

Subject: conv2 in R2008b very slow

From: Matt

Date: 19 Dec, 2008 17:10:21

Message: 5 of 23

"Matt" <mjacobson.removethis@xorantech.com> wrote in message <gigk47$hri$1@fred.mathworks.com>...
> "Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <gie3tb$qen$1@fred.mathworks.com>...
> > I just realized that conv2 is very slow in 2008b. I created a 2D filter by
> >
> > GaussWidth = [23, 180];
> > F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWidth(1), 0, 0, 1, [0 0]);
> > % custumgauss -> see FileExchange
> >
> > % Array of zeros
> > G1 = zeros(600, 1000);
> >
> > % Set one single point
> > G1(300, 400) = 1.5;
> >
> > % in R2008a:
> > tic; G2 = conv2(G1, F, 'same'); toc
> > >> Elapsed time is 0.014846 seconds.
> >
> > % in R2008b:
> > tic; G2 = conv2(G1, F, 'same'); toc
> > >> Elapsed time is 17.831022 seconds.
> >
> > Same machine, no background activity, reproducable. Why?
> >
> > Andreas
>
>
> I can't explain the discrepancy, but I would be more suspicious of the R2008a version.
>
> Given the sizes of your arrays, 17 sec. is not an unreasonable computation time. It is even 3 times faster than on my machine!
>
> You would also never use conv2 with such large arrays. You would implement the convolution through FFTs, unless you knew one of them was very sparse. In the latter case, you would have to get more creative, or wait until conv2 supports sparse data inputs.
>



I just had my coworker (running R2008a) run the test on the same data sizes. He gets nowhere near your .01 sec. compute time.

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 23 Dec, 2008 20:23:02

Message: 6 of 23


> I just had my coworker (running R2008a) run the test on the same data sizes. He gets nowhere near your .01 sec. compute time.

So, what's the reason for this prolonged computation time. If you turn the task manager on, you will see that matlab is computing a lot, but what?

Andreas

Subject: conv2 in R2008b very slow

From: Matt

Date: 26 Dec, 2008 00:25:03

Message: 7 of 23

"Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <girhb6$n50$1@fred.mathworks.com>...
>
> > I just had my coworker (running R2008a) run the test on the same data sizes. He gets nowhere near your .01 sec. compute time.
>
> So, what's the reason for this prolonged computation time. If you turn the task manager on, you will see that matlab is computing a lot, but what?


Why do you consider the computation time unduly high? The arrays you are convolving are large. It's a difficult computation requiring a lot of flops. That's the reason why MATLAB is working so hard.

Subject: conv2 in R2008b very slow

From: ImageAnalyst

Date: 26 Dec, 2008 04:59:07

Message: 8 of 23

On Dec 18, 1:14=A0pm, "Andreas Sprenger" <sprenge...@yahoo.de> wrote:
> I just realized that conv2 is very slow in 2008b. I created a 2D filter b=
y
>
> GaussWidth =3D [23, 180];
> F =3D customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWid=
th(1), 0, 0, 1, [0 0]);
> % custumgauss -> see FileExchange
>
> % Array of zeros
> G1 =3D zeros(600, 1000);
>
> % Set one single point
> G1(300, 400) =3D 1.5;
>
> % in R2008a:
> tic; G2 =3D conv2(G1, F, 'same'); toc
>
> >> Elapsed time is 0.014846 seconds.
>
> % in R2008b:
> tic; G2 =3D conv2(G1, F, 'same'); toc
>
> >> Elapsed time is 17.831022 seconds.
>
> Same machine, no background activity, reproducable. Why?
>
> Andreas

-------------------------------------------------------------------------
Andreas:
Interesting question. here are my times:
% in R2008b: 21.170 seconds.
% in R2008a: 0.018 seconds.
URL for customgauss:
http://www.mathworks.com/matlabcentral/fx_files/9556/1/customgauss.m
Maybe Steve Eddins can give an answer.
Regards,
ImageAnalyst

Subject: conv2 in R2008b very slow

From: Matt

Date: 26 Dec, 2008 14:04:02

Message: 9 of 23

> Andreas:
> Interesting question. here are my times:
> % in R2008b: 21.170 seconds.
> % in R2008a: 0.018 seconds.

Did you check quantitative agreement between the results of each?
I just can't believe it's possible to do a convolution that size in 0.018 sec.

But if so, what kind of machine are you using?

Subject: conv2 in R2008b very slow

From: ImageAnalyst

Date: 26 Dec, 2008 14:19:08

Message: 10 of 23

On Dec 26, 9:04=A0am, "Matt" <mjacobson.removet...@xorantech.com> wrote:
> > Andreas:
> > Interesting question. =A0here are my times:
> > % in R2008b: 21.170 seconds.
> > % in R2008a: =A0 0.018 seconds.
>
> Did you check quantitative agreement between the results of each?
> I just can't believe it's possible to do a convolution that size in 0.018=
 sec.
>
> But if so, what kind of machine are you using?

---------------------------------------------------------------------------=
------------
Matt:
I didn't. I simply copied and pasted and didn't do much analysis or
interpretation of results, other than simply noting the elapsed time
in the command window. I ran it on a Dell M90 notebook computer with
a Intel Centrino Duo CPU and 4 GB of RAM. Checking agreement would be
the next step. I could write the array out to a mat file and then read
it back in and subtract. I haven't done this. If you want, you can
simply copy and paste this code into test.m (the customgauss from the
fileexchange is included):

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function test

clc;
GaussWidth =3D [23, 180];
F =3D customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1),
GaussWidth(1), 0, 0, 1, [0 0]);
% customgauss -> see below

% Array of zeros
G1 =3D zeros(600, 1000);

% Set one single point
G1(300, 400) =3D 1.5;

% in R2008b: 21.17 seconds.
% in R2008a: .018 seconds.
tic; G2 =3D conv2(G1, F, 'same'); toc
return; % from test()


% CUSTOMGAUSS Generate a custom 2D gaussian
%
% gauss =3D customgauss(gsize, sigmax, sigmay, theta, offset, factor,
center)
%
% gsize Size of the output 'gauss', should be a 1x2
vector
% sigmax Std. dev. in the X direction
% sigmay Std. dev. in the Y direction
% theta Rotation in degrees
% offset Minimum value in output
% factor Related to maximum value of output, should be
% different from zero
% center The center position of the gaussian, should be a
% 1x2 vector
function ret =3D customgauss(gsize, sigmax, sigmay, theta, offset,
factor, center)
ret =3D zeros(gsize);
rbegin =3D -round(gsize(1) / 2);
cbegin =3D -round(gsize(2) / 2);
for r=3D1:gsize(1)
    for c=3D1:gsize(2)
        ret(r,c) =3D rotgauss(rbegin+r,cbegin+c, theta, sigmax, sigmay,
offset, factor, center);
    end
end


function val =3D rotgauss(x, y, theta, sigmax, sigmay, offset, factor,
center)
xc =3D center(1);
yc =3D center(2);
theta =3D (theta/180)*pi;
xm =3D (x-xc)*cos(theta) - (y-yc)*sin(theta);
ym =3D (x-xc)*sin(theta) + (y-yc)*cos(theta);
u =3D (xm/sigmax)^2 + (ym/sigmay)^2;
val =3D offset + factor*exp(-u/2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Regards,
ImageAnalyst

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 26 Dec, 2008 15:55:03

Message: 11 of 23

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <64571b05-b09d-4d55-a8b5-a4921d84398e@s24g2000vbp.googlegroups.com>...
> On Dec 26, 9:04=A0am, "Matt" <mjacobson.removet...@xorantech.com> wrote:
> > > Andreas:
> > > Interesting question. =A0here are my times:
> > > % in R2008b: 21.170 seconds.
> > > % in R2008a: =A0 0.018 seconds.
> >
> > Did you check quantitative agreement between the results of each?
> > I just can't believe it's possible to do a convolution that size in 0.018=
> sec.
> >
> > But if so, what kind of machine are you using?
>
> ---------------------------------------------------------------------------=
> ------------
> Matt:
> I didn't. I simply copied and pasted and didn't do much analysis or
> interpretation of results, other than simply noting the elapsed time
> in the command window. I ran it on a Dell M90 notebook computer with
> a Intel Centrino Duo CPU and 4 GB of RAM. Checking agreement would be
> the next step. I could write the array out to a mat file and then read
> it back in and subtract. I haven't done this. If you want, you can
> simply copy and paste this code into test.m (the customgauss from the
> fileexchange is included):

Ok, I calculated the two matrizes by 2008a and 2008b and subtracted them. The sum is zero, so the calculation is the same - but the computation time in 2008b is about 1000 times longer. Again: why?

Andreas

BTW: the calculation times were 0.019018 s in 2008a and 17.730552 in 2008b on a conventional PC with a Core2Duo Intel Processor, WinXP Prof, 2GB RAM, NVIDIA 7600 GS and Quadro NVS 290 graphic cards.

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 26 Dec, 2008 16:16:44

Message: 12 of 23

"Matt" <mjacobson.removethis@xorantech.com> wrote in message <gj2o8i$pul$1@fred.mathworks.com>...
> > Andreas:
> > Interesting question. here are my times:
> > % in R2008b: 21.170 seconds.
> > % in R2008a: 0.018 seconds.
>
> Did you check quantitative agreement between the results of each?
> I just can't believe it's possible to do a convolution that size in 0.018 sec.
>
> But if so, what kind of machine are you using?

Concerning my computer: Core2Duo E6600 (2x2.4 GHz), 2GB RAM, NVIDIA Geforce 7600 GS and Quadro NVS 290, WinXP Prof.

I did one more test. On my computer I have three versions currently installed and got the following calculation times:

Matlab 7.0.0.19920: 0.016000 s
Matlab 7.6.0.324: 0.019018 s
Matlab 7.7.0.471: 17.730552 s

I subtracted those three results one another: no differences, all are the same (sum(sum(abs(A - B))). I'm really interested in what's the reason for this big difference in calculation speed.

In the lab we have some older PCs with single user licenses running ML 6.0 and 6.5. I could check the calculation times on these machines in a few days...


Andreas

Subject: conv2 in R2008b very slow

From: ImageAnalyst

Date: 26 Dec, 2008 17:23:45

Message: 13 of 23

On Dec 26, 11:16=A0am, "Andreas Sprenger" <sprenge...@yahoo.de> wrote:
> "Matt" <mjacobson.removet...@xorantech.com> wrote in message <gj2o8i$pu..=
.@fred.mathworks.com>...
> > > Andreas:
> > > Interesting question. =A0here are my times:
> > > % in R2008b: 21.170 seconds.
> > > % in R2008a: =A0 0.018 seconds.
>
> > Did you check quantitative agreement between the results of each?
> > I just can't believe it's possible to do a convolution that size in 0.0=
18 sec.
>
> > But if so, what kind of machine are you using?
>
> Concerning my computer: Core2Duo E6600 (2x2.4 GHz), 2GB RAM, NVIDIA Gefor=
ce 7600 GS and Quadro NVS 290, WinXP Prof.
>
> I did one more test. On my computer I have three versions currently insta=
lled and got the following calculation times:
>
> Matlab 7.0.0.19920: 0.016000 s
> Matlab 7.6.0.324: 0.019018 s
> Matlab 7.7.0.471: 17.730552 s
>
> I subtracted those three results one another: no differences, all are the=
 same (sum(sum(abs(A - B))). I'm really interested in what's the reason for=
 this big difference in calculation speed.
>
> In the lab we have some older PCs with single user licenses running ML 6.=
0 and 6.5. I could check the calculation times on these machines in a few d=
ays...
>
> Andreas

--------------------------------------------------------
Andreas:
I tried an interesting experiment, after wondering if it had something
to do with the routine checking to see if the kernel were separable
and then trying to make some kind of optimization. I replaced the
kernel F with just an array of random numbers - the same size 23x180.
Well when I did that:
R2008a: 0.02 seconds
R2008b: 3.46 seconds
Now the latest version is only about 173 times slower. If I use conv2
with the 'full' option, I get the same times as with the 'same'
option.
Regards,
ImageAnalyst

Subject: conv2 in R2008b very slow

From: Matt

Date: 26 Dec, 2008 19:28:02

Message: 14 of 23

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f4977e4c-f1a7-4ef2-b024-0a0f46eac45a@v4g2000vbb.googlegroups.com>...
> Andreas:
> I tried an interesting experiment, after wondering if it had something
> to do with the routine checking to see if the kernel were separable
> and then trying to make some kind of optimization. I replaced the
> kernel F with just an array of random numbers - the same size 23x180.

Andreas told me in an earlier post that size(F)=[180 180] not [23,180].

So now, I'm confused...

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 26 Dec, 2008 19:59:03

Message: 15 of 23


> Andreas told me in an earlier post that size(F)=[180 180] not [23,180].
>
size(F) = [180 180], correct. It is a gaussian kernel with a standard deviation of [23 23].

I checked out the option 'full':
ML 7.0 : 0.016000 s
2008a: 0.006248 s
2008b: 17.435871 s

Andreas

Subject: conv2 in R2008b very slow

From: Matt

Date: 26 Dec, 2008 20:06:02

Message: 16 of 23

"Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <gj3d26$stu$1@fred.mathworks.com>...
>
> > Andreas told me in an earlier post that size(F)=[180 180] not [23,180].
> >
> size(F) = [180 180], correct. It is a gaussian kernel with a standard deviation of [23 23].

Well, whatever the issue is, it's hardware dependent. I haven't seen the convolution crunched in less than 15 sec., on any version of MATLAB.

Subject: conv2 in R2008b very slow

From: Image Analyst

Date: 26 Dec, 2008 20:36:02

Message: 17 of 23

"Matt" <mjacobson.removethis@xorantech.com> wrote in message <gj3dfa$o4q$1@fred.mathworks.com>...
> "Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message <gj3d26$stu$1@fred.mathworks.com>...
> >
> > > Andreas told me in an earlier post that size(F)=[180 180] not [23,180].
> > >
> > size(F) = [180 180], correct. It is a gaussian kernel with a standard deviation of [23 23].
>
> Well, whatever the issue is, it's hardware dependent. I haven't seen the convolution crunched in less than 15 sec., on any version of MATLAB.
-----------------------------------------------------------------------------------------
Well it may be hardware dependent and that's why none of the systems you're trying it on with R2008a finish in like the .02 seconds that Andreas and I are getting. However I'm running the same code on the same hardware and getting vastly different times with the different versions so, even with the same hardware (the kind that seems to be able to do it very fast), there is some software version dependent issue also. I tried it with a variety of sizes, even with the image being an integer multiple of kernel sizes, and with images being multiples of 64 in size, and with images and kernels being random arrays of numbers, and no matter . . . R2008b is always vastly slower than R2008a. I don't know why.
Regards,
ImageAnalyst

Subject: conv2 in R2008b very slow

From: Matt

Date: 27 Dec, 2008 14:42:02

Message: 18 of 23

> -----------------------------------------------------------------------------------------
> Well it may be hardware dependent and that's why none of the systems you're trying it on with R2008a finish in like the .02 seconds that Andreas and I are getting. However I'm running the same code on the same hardware and getting vastly different times with the different versions so, even with the same hardware (the kind that seems to be able to do it very fast), there is some software version dependent issue also. I tried it with a variety of sizes, even with the image being an integer multiple of kernel sizes, and with images being multiples of 64 in size, and with images and kernels being random arrays of numbers, and no matter . . . R2008b is always vastly slower than R2008a. I don't know why.
--------------------------------------------------------------------------------------------


If I had to guess, I'd say it was because the "fast conv2" is being internally implemented using ffts for some reason. When I run this experiment using fft() commands instead of conv2(), I get the kind of speeds you are citing, but only then.

As a test, you could run this test again but enlarge F to be the same size as G1. If you find that the compute time is insensitive to this enlargment, it's a pretty clear indicator that ffts are being used

Subject: conv2 in R2008b very slow

From: Steve Eddins

Date: 29 Dec, 2008 15:32:37

Message: 19 of 23

ImageAnalyst wrote:
> On Dec 18, 1:14 pm, "Andreas Sprenger" <sprenge...@yahoo.de> wrote:
>> I just realized that conv2 is very slow in 2008b. I created a 2D filter by
>>
>> GaussWidth = [23, 180];
>> F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1), GaussWidth(1), 0, 0, 1, [0 0]);
>> % custumgauss -> see FileExchange
>>
>> % Array of zeros
>> G1 = zeros(600, 1000);
>>
>> % Set one single point
>> G1(300, 400) = 1.5;
>>
>> % in R2008a:
>> tic; G2 = conv2(G1, F, 'same'); toc
>>
>>>> Elapsed time is 0.014846 seconds.
>> % in R2008b:
>> tic; G2 = conv2(G1, F, 'same'); toc
>>
>>>> Elapsed time is 17.831022 seconds.
>> Same machine, no background activity, reproducable. Why?
>>
>> Andreas
>
> -------------------------------------------------------------------------
> Andreas:
> Interesting question. here are my times:
> % in R2008b: 21.170 seconds.
> % in R2008a: 0.018 seconds.
> URL for customgauss:
> http://www.mathworks.com/matlabcentral/fx_files/9556/1/customgauss.m
> Maybe Steve Eddins can give an answer.
> Regards,
> ImageAnalyst

FYI: MathWorks makes no "official" attempt to follow up on issues posted
in this user newsgroup. Although several engineers, including me, do
regularly read posts here, it's probably fair to say that the best we
can do is skim them quickly because of the high volume.

I did not notice this thread until today, because I was pretty busy
earlier this month, and I was on vacation most of last week.

If you see something like this that might indicate a bug, I recommend
that you contact MathWorks technical support directly
(www.mathworks.com/support/) in addition to whatever you want to post
here. A case like this would probably have been forwarded immediately
by tech support to a MATLAB Math developer, and an answer might have
been available quickly.

Anyway ... I was able to reproduce the anomaly. My experiments indicate
that the R2008a version of conv2 is exploiting the fact that G1 has only
a single nonzero element. You can see the difference in R2008a if you try:

G1 = rand(600, 1000);

I do not know what changed. I'll pass this report along to the MATLAB
Math team for their investigation.

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: conv2 in R2008b very slow

From: Steve Eddins

Date: 29 Dec, 2008 15:40:54

Message: 20 of 23

Steve Eddins wrote:
> [snip]
> Anyway ... I was able to reproduce the anomaly. My experiments indicate
> that the R2008a version of conv2 is exploiting the fact that G1 has only
> a single nonzero element.

PS. Here are simpler reproduction steps that do not require the
function customgauss from the MATLAB Central File Exchange:

F = rand(180, 180);
G1 = zeros(600, 1000);
G1(300, 400) = 1.5;
tic; G2 = conv2(G1, F, 'same'); toc

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: conv2 in R2008b very slow

From: Bobby Cheng

Date: 6 Jan, 2009 23:00:14

Message: 21 of 23

The zeros in the first matrix is the issue here.

Run

conv2(zeros(2),inf(2))
conv2(inf(2),zeros(2))

In R2008a and before, MATLAB would see the zeros and would do a short cut
without computation. This leads to different results and timing depending on
the size of the inputs and the order of the inputs.

In R2008b, the behaviour is consistent and conv2 is actually faster if
inputs contains mostly nonzeros.

What I would like to know more is that if this is a test input? Or is this a
typical input from an application, and what will this application be?

---Bobby Cheng
Numerical Analyst
The MathWorks, Inc.

"Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message
news:gie3tb$qen$1@fred.mathworks.com...
>I just realized that conv2 is very slow in 2008b. I created a 2D filter by
>
> GaussWidth = [23, 180];
> F = customgauss([GaussWidth(2), GaussWidth(2)], GaussWidth(1),
> GaussWidth(1), 0, 0, 1, [0 0]);
> % custumgauss -> see FileExchange
>
> % Array of zeros
> G1 = zeros(600, 1000);
>
> % Set one single point
> G1(300, 400) = 1.5;
>
> % in R2008a:
> tic; G2 = conv2(G1, F, 'same'); toc
>>> Elapsed time is 0.014846 seconds.
>
> % in R2008b:
> tic; G2 = conv2(G1, F, 'same'); toc
>>> Elapsed time is 17.831022 seconds.
>
> Same machine, no background activity, reproducable. Why?
>
> Andreas
>

Subject: conv2 in R2008b very slow

From: Andreas Sprenger

Date: 25 Jun, 2009 14:03:01

Message: 22 of 23

Ok,

I can reproduce this issue. Running on R2008b or R2009a

% Test with zeros.
>> F = rand(180, 180);
>> G1 = zeros(600, 1000);
>> G1(300, 400) = 1.5;
>> tic; G2 = conv2(G1, F, 'same'); toc

takes the same time as

% Test with non-zeros.
>> F = rand(180, 180);
>> G1 = randn(600, 1000)*0.001;
>> G1(300, 400) = 1.5;
>> tic; G2 = conv2(G1, F, 'same'); toc

in R2008a and before the test with non-zeros takes about 1.5 times longer than in R2008b and newer. Therefore conv2 seems to be faster now - even though the the computation with zeros was 1000x faster in R2008a and before (compared to current versions).

And yes, I have this computation with zeros quite often. Hence I have to re-think and re-write my functions and to change the analysis of my projects. Or using older Matlab versions; waiting 1000x longer is not useful ...

Andreas

"Bobby Cheng" <bcheng@mathworks.com> wrote in message <gk0noi$ja4$1@fred.mathworks.com>...
> The zeros in the first matrix is the issue here.
>
> Run
>
> conv2(zeros(2),inf(2))
> conv2(inf(2),zeros(2))
>
> In R2008a and before, MATLAB would see the zeros and would do a short cut
> without computation. This leads to different results and timing depending on
> the size of the inputs and the order of the inputs.
>
> In R2008b, the behaviour is consistent and conv2 is actually faster if
> inputs contains mostly nonzeros.
>
> What I would like to know more is that if this is a test input? Or is this a
> typical input from an application, and what will this application be?
>
> ---Bobby Cheng
> Numerical Analyst
> The MathWorks, Inc.
>

Subject: conv2 in R2008b very slow

From: Bobby Cheng

Date: 25 Jun, 2009 20:23:14

Message: 23 of 23

Hi Andreas,

I understand your pain. Just to understand your expectation more in order
for me to make the changes. In R2008a,

>> A = zeros(100);
>> B = ones(100);
>> tic; conv2(A,B); toc
Elapsed time is 0.000295 seconds.
>> tic; conv2(B,A); toc
Elapsed time is 0.195365 seconds.
>> A = zeros(100);
>> B = ones(99);
>> tic; conv2(A,B); toc
Elapsed time is 0.000260 seconds.
>> tic; conv2(B,A); toc
Elapsed time is 0.000306 seconds.
>> A = zeros(99);
>> B = ones(100);
>> tic; conv2(A,B); toc
Elapsed time is 0.194260 seconds.
>> tic; conv2(B,A); toc
Elapsed time is 0.195057 seconds.

Does this bother you? It bothers me. I think it would be easy to revert to
R2008a behaviour. But if this performance difference is not acceptable, then
it is a completely different ball game.

---Bob.


"Andreas Sprenger" <sprenger_a@yahoo.de> wrote in message
news:h2002l$400$1@fred.mathworks.com...
> Ok,
>
> I can reproduce this issue. Running on R2008b or R2009a
>
> % Test with zeros.
>>> F = rand(180, 180);
>>> G1 = zeros(600, 1000);
>>> G1(300, 400) = 1.5;
>>> tic; G2 = conv2(G1, F, 'same'); toc
>
> takes the same time as
>
> % Test with non-zeros.
>>> F = rand(180, 180);
>>> G1 = randn(600, 1000)*0.001;
>>> G1(300, 400) = 1.5;
>>> tic; G2 = conv2(G1, F, 'same'); toc
>
> in R2008a and before the test with non-zeros takes about 1.5 times longer
> than in R2008b and newer. Therefore conv2 seems to be faster now - even
> though the the computation with zeros was 1000x faster in R2008a and
> before (compared to current versions).
>
> And yes, I have this computation with zeros quite often. Hence I have to
> re-think and re-write my functions and to change the analysis of my
> projects. Or using older Matlab versions; waiting 1000x longer is not
> useful ...
>
> Andreas
>
> "Bobby Cheng" <bcheng@mathworks.com> wrote in message
> <gk0noi$ja4$1@fred.mathworks.com>...
>> The zeros in the first matrix is the issue here.
>>
>> Run
>>
>> conv2(zeros(2),inf(2))
>> conv2(inf(2),zeros(2))
>>
>> In R2008a and before, MATLAB would see the zeros and would do a short cut
>> without computation. This leads to different results and timing depending
>> on
>> the size of the inputs and the order of the inputs.
>>
>> In R2008b, the behaviour is consistent and conv2 is actually faster if
>> inputs contains mostly nonzeros.
>>
>> What I would like to know more is that if this is a test input? Or is
>> this a
>> typical input from an application, and what will this application be?
>>
>> ---Bobby Cheng
>> Numerical Analyst
>> The MathWorks, Inc.
>>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
conv2 of large ... amcum ammcum 31 Dec, 2008 22:23:40
conv2 Andreas Sprenger 18 Dec, 2008 13:15:06
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com