help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applying a function to selected element type in a mixed-type cell ar


From: Jordi Gutiérrez Hermoso
Subject: Re: Applying a function to selected element type in a mixed-type cell array
Date: Tue, 22 May 2012 09:50:01 -0400

On 22 May 2012 03:05, Juan Pablo Carbajal <address@hidden> wrote:
> On Tue, May 22, 2012 at 12:56 AM, Philip Nienhuis <address@hidden> wrote:
>> Ben Abbott wrote:
>>>
>>>
>>> On May 21, 2012, at 5:43 PM, Philip Nienhuis wrote:
>>>
>>>> Suppose a cell array like:
>>>>
>>>> arr = {10, int32(15), 'Txt'; '', 25, true; NaN, 'String', single(100)}
>>>>
>>>> How can all numeric values efficiently (w/o for loops etc.) be converted
>>>> to double, leaving the other cell array contents untouched?
[snip]
>>> A Two-liner ?
>>>
>>>        n = cellfun (@isnumeric, arr, "UniformOutput", true);
>>>        arr(n) = cellfun (@double, arr(n), "UniformOutput", false);
[snip]
> cool,
> Can anybody explain to me why the two-liner is 3-4 times faster than
> the function version?

Basically, this:

    
http://hg.savannah.gnu.org/hgweb/octave/file/d95e719ef108/src/DLD-FUNCTIONS/cellfun.cc#l441

You'll see that for certain kinds of functions, we can take a better
code path.

Come to think of it, it would be very easy to also optimise isnumeric
in this fashion.

HTH,
- Jordi G. H.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]