[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
changes in cellfun
From: |
Jaroslav Hajek |
Subject: |
changes in cellfun |
Date: |
Tue, 15 Dec 2009 21:45:54 +0100 |
hi all,
the following patch
http://hg.savannah.gnu.org/hgweb/octave/rev/76cf4aec34e9
improves (or modifies at least) the behavior of cellfun w.r.t. nargout
of the passed-in function handles.
Previously, a call with nargout = 0 was simply treated as nargout = 1.
As a result, things like
octave:1> cellfun (@(x) disp(x), {1, 2, 3})
error: cellfun: expecting all values to be scalars for UniformOutput = true
were not possible. Now the behavior is more complex. The function
passed to cellfun is always called with nargout equal to nargout of
the call to cellfun.
If each call nevertheless results in at least one result, then cellfun
returns a single result. This ensures that entering simply
octave:1> cellfun (@isscalar, {1, 2, 3})
ans =
1 1 1
still returns the expected output, even though the isscalar function
is actually called with nargout = 0.
Note that this behavior may lead to certain artificial inconsistencies:
octave:2> cellfun (@(x) x + i*nargout, {1, 2, 3})
ans =
1 2 3
octave:3> a = cellfun (@(x) x + i*nargout, {1, 2, 3})
a =
1 + 1i 2 + 1i 3 + 1i
I checked with Matlab 2007 and it does the same. I would be glad if
someone could check a more recent version.
I'm not sure if this should be regarded as a bug.
Yes, it is inconsistent, but I think it's better than the previous
behavior, and I don't see anything better.
comments?
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- changes in cellfun,
Jaroslav Hajek <=