0

Is there a way to pass additional numeric arguments to the function (or handle) inside parcellfun()?

For example, if I have a cell array Images and I want to apply medfilt2() to them, I'll write something like:

Images = parcellfun( nproc, @medfilt2, Images, 'UniformOutput', false );

What is, if at all, a way to pass additional arguments to medfilt2, in this case, let's say [7 7]?


Octave's help has this to say:

[O1, O2, ...] = parcellfun (NPROC, FUN, A1, A2, ...)

.. A1, A2 etc. should be cell arrays of equal size.

GNU Octave 3.8.1, in case it helps.

Community
  • 1
  • 1
a-Jays
  • 1,182
  • 9
  • 20

1 Answers1

1

You want the same parameter for all inputs, create a anonmyous function:

medfilt2wparam=@(A)medfilt2(A, [7 7])

Now use the code you already have with the function medfilt2wparam

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thanks, that was smart! I'm not familiar with how Octave treats such functions, so could you say what overhead would this involve? – a-Jays Apr 23 '15 at 11:25
  • 1
    I don't find any numbers for octave, but you could run this code to compare the values: http://stackoverflow.com/questions/1673193 If I remember correct octave is slower than matlab and it does not really matter which way you use to call a function (anonymous, handle, etc..) because the overhead is about the same. – Daniel Apr 23 '15 at 11:37
  • It looks like anonymous functions take significantly more time. I cannot make a general statement for Octave's speed compared to Matlab's, but I _have_ seen and executed codes that run faster on Octave (Linux) than on Matlab (Windows) on similar machines. There might be differences that I'm overlooking, though. – a-Jays Apr 23 '15 at 12:12
  • @a-Jays As recalled in [comment #11 of a patch](https://savannah.gnu.org/patch/?func=detailitem&item_id=8303#comment11), anonymous functions are the standard way. Besides, `parcellfun` itself has a larger overhead than the anonymous function call. – ederag Apr 23 '15 at 14:16
  • @ederag `parcellfun`'s overhead is easily compensated for by its utility as a parallel processor, I think. But I was only wondering if there'll be any benefits of being able to write something like `parcellfun( nproc, @func, cell_array, arg1, arg2 .. )` instead of making an anonymous function like above. – a-Jays Apr 23 '15 at 14:40
  • @a-Jays So my comment did answer your question: if you are happy with `parcellfun`, then your function execution time is much larger than the overhead of `parcellfun` (and _a fortiori_ of anonymous function call). Hence avoiding the anonymous function call would not give you any timing benefit. – ederag Apr 23 '15 at 18:28
  • @a-Jays: using the `[7,7]` as an input argument for each call would require it to be repeated `numel(A)` times, don't think this is efficient. – Daniel Apr 23 '15 at 19:16
  • 1
    @ederag Agreed, although not perhaps with your last statement, looking at the link to another question mentioned earlier in this thread. – a-Jays Apr 23 '15 at 20:11
  • @Daniel but that would be anyway unavoidable, is it not? The function _has_ to be called that many times. – a-Jays Apr 23 '15 at 20:13
  • @a-Jays They are summing the duration of 1e6 calls and get less than 2s. This makes only 2 us per call. Test the efficiency of `parcellfun` with a function that fast (and even in the ms execution time range). You'll see what I mean. – ederag Apr 27 '15 at 17:12