[Top][All Lists]

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

[Octave-bug-tracker] [bug #63713] NaN should be able to take class input

From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #63713] NaN should be able to take class input options like ones and zeros
Date: Thu, 26 Jan 2023 15:01:09 -0500 (EST)


                 Summary: NaN should be able to take class input options like
ones and zeros
                 Project: GNU Octave
               Submitter: nrjank
               Submitted: Thu 26 Jan 2023 03:01:07 PM EST
                Category: Octave Function
                Severity: 1 - Wish
                Priority: 5 - Normal
              Item Group: Feature Request
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: dev
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: None


Follow-up Comments:

Date: Thu 26 Jan 2023 03:01:07 PM EST By: Nicholas Jankowski <nrjank>
NaN can take an optional input to specify whether the output type should be
double or single.  Ones and zeros take a similar optional input, but they can
take any class with a valid type conversion. This report is to request the
classes that can be input to NaN be expanded to the same set as for ones and
zeros.  As built-in functions, it should have much less overhead than calls to
'cast' (which seems to come up a lot as we update functions to match Matlab's
outputs for empty inputs if they aren't limited to single and double).


>> class(ones(2,'single'))
ans = single
>> class(ones(2,'uint8'))
ans = uint8
>> class(ones(2,'logical'))
ans = logical

>> class(NaN(2,'single'))
ans = single

>> class(NaN(2,'uint8'))
error: NaN: invalid class name

>> cast(NaN(2),'uint8')
ans =

  0  0
  0  0

>> class(NaN(2,'logical'))
error: NaN: invalid class name

>> cast(NaN(2),'logical')
error: invalid conversion from NaN to logical
error: called from
    cast at line 118 column 5

noting above that cast(NaN, 'logical') fails in both Octave and Matlab. I see
that many functions in Matlab that would output a NaN for supported numeric
types, output a 0 for non-supported types like int8, uint8, etc., and that
includes logical:

Matlab 2022b:

>> median(single([]))
ans =

>> median(int8([]))
ans =

>> median(logical([]))
ans =

I would propose also (perhaps should be a separate feature request) that cast
(NaN, 'logical') should output zero just as the int class does.


Reply to this item at:


Message sent via Savannah

reply via email to

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