octave-maintainers
[Top][All Lists]
Advanced

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

Re: logical vectors and statistics functions


From: John W. Eaton
Subject: Re: logical vectors and statistics functions
Date: Wed, 9 Feb 2011 15:51:06 -0500

On  9-Feb-2011, Rik wrote:

| > On Wed, Feb 9, 2011 at 9:46 AM, John W. Eaton <address@hidden> wrote:
| >> On  9-Feb-2011, Michael Creel wrote:
| >>
| >> | One change between 3.2.x and 3.4.0 that I have noticed is that mean(a)
| >> | no longer works if a is a vector of booleans. sum(a) continues to
| >> | work, however. Might be worth a mention unless the change is not
| >> | intentional.
| >>
| >> Not intentional.
| 
| It actually was intentional.  I tightened up the input validation routines
| for all the base statistics functions.  Previously there wasn't a lot of
| checking and the routines would error out with strange messages when, in
| fact, they had only been called in an incorrect manner.
| 
| The error message is pretty clear that mean is looking for a numeric
| argument rather than a logical one:
| 
| mean (logical (1))
| error: mean: X must be a numeric vector or matrix
| 
| One way to get around this is to cast the logical to a numeric class before
| the call to mean() like so:
| 
| mean (double (x))
| 
| Of course, if we choose, we could also accept logical arguments and convert
| them to double within the routines.  If this happens it should probably
| also go along with an overhaul of the routines to make sure that they
| return an output of the same class as the input (single, double, etc.)
| This won't work for logical inputs where we would always need to return a
| numeric class.  See this bug about not returning the same class
| (http://savannah.gnu.org/bugs/?32168).

OK.  I think it would be convenient if functions like mean just worked
automatically for logical inputs.  If Matlab allows it, there is
another reason to do it, so we don't see complaints from people who
are porting code to Octave and expect the Matlab behavior.  So could
someone please check to see what Matlab does for

  x = rand (10,1) > 0.5;
  class (x)
  m = mean (x)
  class (m)

?

Thanks,

jwe


reply via email to

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