bugGNU Octave - Bugs: bug #55245, exist accepts empty matrix as...

 
 

bug #55245: exist accepts empty matrix as first argument in Matlab but is error in Octave

Submitter:  Richard <crobar>
Submitted:  Wed 19 Dec 2018 04:16:56 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  Richard Crozier Open/Closed:  * Closed
Release:  * 4.4.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 21 Dec 2018 09:35:28 PM UTC, comment #9: 

In general, Octave validates its inputs more strictly than Matlab to prevent Garbage In / Garbage Out.  In this case, I think it is useful for the programmer to be made aware that the input was not a character string as was likely expected.  But it was good to point out the discrepancy so that others may happen on this issue report.

Rik <rik5>
Group administrator
Thu 20 Dec 2018 09:26:26 PM UTC, comment #8: 

You are right John.  Matlab does not explicitly document the behavior with empty input.  I was happy to find an easy solution for it and I really don't mind to just drop this item ;-)

Maybe we should mark this as won't fix and close it?

Kai Torben Ohlhus <siko1056>
Group Member
Thu 20 Dec 2018 04:40:40 PM UTC, comment #7: 

Just to be clear, I'm not really arguing for or against, just reporting the difference, since incompatibilities are deemed to be bugs.

I know about the issue, so I can avoid it in future when writing code for both platforms, most users will not though.

Richard <crobar>
Thu 20 Dec 2018 04:30:09 PM UTC, comment #6: 

The docs also clearly state that the input type is supposed to be a character array or string.

John W. Eaton <jwe>
Group administrator
Thu 20 Dec 2018 01:30:02 PM UTC, comment #5: 

Actually, the docs do state the following of the return value for exist:

  1. - name does not exist or cannot be found for other reasons



Richard <crobar>
Thu 20 Dec 2018 01:23:57 PM UTC, comment #4: 

It's not documented and probably accidental.

In my case I discovered it because class properties initially default to [], and a class property was a file name. I didn't check for empty before exist as it had worked so far in Matlab.

There are easy workarounds, but it will cause potentially cause code developed for Matlab which behaves correctly to throw an error in Octave. Up to you if you think this is important.

Richard <crobar>
Thu 20 Dec 2018 05:04:49 AM UTC, comment #3: 

This is somewhat bizarre behavior.  How is it useful?  Is it documented and intentional, or is it more likely that it is just somehow an accident of the implementation?  For example checking that the arguments are empty before checking the type, even though the variable name is documented to be a character string.

John W. Eaton <jwe>
Group administrator
Thu 20 Dec 2018 12:29:12 AM UTC, comment #2: 

As a general rule: if any of the one or two permitted arguments is empty, return "0".


>> exist ({}, 'bla')

ans =

     0

>> exist ({}, [])

ans =

     0

>> exist ('a', [])

ans =

     0


Kai Torben Ohlhus <siko1056>
Group Member
Thu 20 Dec 2018 12:22:40 AM UTC, comment #1: 

A small addition regarding the output of Matlab R2018b:


>> exist ([])

ans =

     0

>> exist ({})

ans =

     0


"ans" is in both cases really the double value "0" as described by the docstring.

Kai Torben Ohlhus <siko1056>
Group Member
Wed 19 Dec 2018 04:16:56 PM UTC, original submission:  

exist accepts empty matrix as first argument in Matlab but this is an error in Octave

In Matlab R2018b


>> exist ([])

ans =

     0.0000e+000


In Octave 4.4.1


octave:2> exist ([])
error: wrong type argument 'null_matrix'
error: exist: NAME must be a string



Richard <crobar>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by crobar (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-21 rik5 StatusConfirmed Wont Fix
        Open/ClosedOpen Closed
    2018-12-20 siko1056 Assigned tosiko1056 None
    2018-12-20 siko1056 StatusNone Confirmed
        Assigned toNone siko1056

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code