octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #66642] cellfun & arrayfun return zero values


From: Fernando
Subject: [Octave-bug-tracker] [bug #66642] cellfun & arrayfun return zero values if function returns fewer outputs than expected
Date: Sat, 11 Jan 2025 09:03:24 -0500 (EST)

Follow-up Comment #10, bug #66642 (group octave):

Ok, I see what you mean. In the case of UniformOutput==true, current code (in
stable) for cellfun only copies a function output if the ouput is defined. If
it's undefined, it doesn't do the assignment. That's why you don't get the
error.

This is done by the block of code starting on line 581 of cellfun.cc:


                  for (int j = 0; j < num_to_copy; j++)
                    {
                      if (tmp(j).is_defined ())
                        {
                          octave_value val = tmp(j);

                          if (val.numel () != 1)
                            error ("cellfun: all values must be scalars when
UniformOutput = true");

                          retv[j] = val.resize (fdims);
                        }
                    }


and also at a similar block starting at line 596.

In the case of non-uniform output, Octave assigns the outputs in lines
663-664:


              for (int j = 0; j < num_to_copy; j++)
                results[j](count) = tmp(j);


which will assign the value, even if undefined, to a cell element. I guess the
assignment operation does not check if the value being assinged is defined. I
don't know if it should, or if we should take care not to assign undefined
elements.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?66642>

_______________________________________________
Mensaje enviado vía Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature


reply via email to

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