Filter löschen
Filter löschen

Anyone know where I can find the source code for conv2.m?

19 Ansichten (letzte 30 Tage)
I have been debugging a ginormous program for the past 6 hours, and have finally isolated the issue down a single function: conv2.m
The bug I ran into was that the output of this program was varying between machines (obviously not ideal given that I prefer my computers to behave in a deterministic manner). All other variables have seriously already been looked into, so don't bother offering other suggestions. The issue is that conv2.m is performing different on different machines. I would like to include this source code into my program so that that does not happen. Anyone know where I can access it?
  3 Kommentare
Image Analyst
Image Analyst am 29 Apr. 2016
Do you have a very very large filter kernel and single precision variables? (Known problem due to precision limitations). Or is one computer 32 bits and another 64 bits?
Chris Endemann
Chris Endemann am 29 Apr. 2016
Bearbeitet: Chris Endemann am 30 Apr. 2016
The inputs to the conv2.m are both identical (called isequal on them). These inputs are computed within my program and made up of thousands of doubles, so wouldn't that likely rule out this possibility? I would think that if any rounding error is to blame, it would show up in more than just the conv2.m function (this program calls many, many functions including conv2).
Follow-up: I just rounded my input using round(x,4) and still encounter discrepancies--albeit fewer.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Renato Agurto
Renato Agurto am 29 Apr. 2016
Bearbeitet: Renato Agurto am 29 Apr. 2016
According to
type conv2
this is a built-in function (like mean, max, sum, etc), not a funtion programmed as a .m file. What you see when you type.
edit conv2
is just there to display the help text
If it's giving you problems, you could try to write the funtion yourself (my_conv2.m). See the documentation for conv2; section Algorithms

Weitere Antworten (2)

J. Webster
J. Webster am 29 Apr. 2016
I found this. Though I couldn't tell you if its the one that works for you or not.
I post with the caveat that I don't really know what mathwork's position on this would be. I suspect the reason that the source can't be found in a .m file is because it was converted to C or assembly or something to improve the speed. Since they make the source to most all of their library available, then it would seem odd to me that they would want to protect this code for some reason.

Steven Lord
Steven Lord am 29 Apr. 2016
The conv2 function is built into MATLAB, and we do not distribute the source code for this function.
It sounds like you've isolated the differences to a single call to conv2 with the same data. If that is the case can you send information to reproduce this behavior to Technical Support for investigation (to determine if it is a bug) using the Contact Us link in the upper-right corner of this page? Some of the information you should include:
  • Which releases of MATLAB are you using on the two machines? [If you're using different releases, try using the same release on both machines to eliminate the possibility that conv2 changed between the two releases.]
  • What OS are you using on the two machines?
  • Is the data you're passing as input to conv2 identical, down to the last bit (the isequal function returns true) on the two machines?
  • Include a MAT-file containing the data you pass into conv2 and the exact command you use to call conv2.
  3 Kommentare
Walter Roberson
Walter Roberson am 1 Mai 2016
Rounding issues between OS are possible. The high performance libraries are compiled for each OS and chip. The Intel MKL (Math Kernel Library) is available for Linux but would not typically be installed on systems because it is not FOSS (Free Open Source Software), just Royalty Free. AMD machines need a different high performance library.
So to be really sure, you should save() the data just before the conv2 call and compare it.
Håkon Hoel
Håkon Hoel am 4 Dez. 2023
For the purpose of using conv2 in scientific works, it would be beneficial to know whether it is based on direct convolution or fft, or a bit of both? From computing the cputime of runs, it seems the function has O(n^2) complexity, which is consistent with direct convolution, but it would be nice to hear it from you.

Melden Sie sich an, um zu kommentieren.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by