bugGNU Octave - Bugs: bug #49601, strmatch, incompatible result on...

 
 

bug #49601: strmatch, incompatible result on 'empty' input, (and still around in 2016b)

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Mon 14 Nov 2016 03:16:06 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 24 Nov 2016 12:42:25 PM UTC, comment #7: 

I came across a similar compatibility issue with Matlab:

Octave:


>> strmatch('a',[])
error: strmatch: A must be a string or cell array of strings
error: called from
    strmatch at line 66 column 5


Matlab:


>> strmatch('a',[])
ans =
     []


Guillaume <gyom>
Sun 20 Nov 2016 06:57:24 PM UTC, comment #6: 

I went ahead and pushed the changeset to the development branch of Octave.  Closing report.

Rik <rik5>
Group administrator
Tue 15 Nov 2016 04:48:14 AM UTC, comment #5: 

Try the attached cset.  It matches the behavior that you documented in comment #4 for empty whitespace input.

(file #38969)

Rik <rik5>
Group administrator
Mon 14 Nov 2016 04:53:39 PM UTC, comment #4: 

oops, bad tag:

looking at the original case:


>> strmatch(' ', ' ')
ans =
1

>> strmatch(' ', '  ')
ans =
1

>> strmatch(' ', '        ')
ans =
1

>> strmatch('  ', ' ')
ans =
[]

>> strmatch('  ', '  ')
ans =
1

>> strmatch('   ', '  ')
ans =
[]


Nicholas Jankowski <nrjank>
Group Member
Mon 14 Nov 2016 04:52:42 PM UTC, comment #3: 

looking at the original case:

>> strmatch(' ', ' ')

ans =
     1

>> strmatch(' ', '  ')

ans =
     1

>> strmatch(' ', '        ')

ans =
     1

>> strmatch('  ', ' ')

ans =
     []

>> strmatch('  ', '  ')

ans =
     1

>> strmatch('   ', '  ')

ans =
     []

Nicholas Jankowski <nrjank>
Group Member
Mon 14 Nov 2016 04:46:24 PM UTC, comment #2: 

methinks this is going to me another case of teasing out a sensible ruleset... I'm still at a loss

more matlab output:

>> strmatch(ones(1,1),ones(0,0))
ans =
     []
>> strmatch(ones(0,0),ones(1,1))
ans =
     1
>> strmatch(ones(0,1,0,0),ones(1,1))
ans =
     1


Nicholas Jankowski <nrjank>
Group Member
Mon 14 Nov 2016 03:24:02 PM UTC, comment #1: 

Matlab:

>> strmatch([],[])
ans =
     1
>> strmatch(ones(0,1),ones(0,1))
ans =
  0×1 empty double column vector
>> strmatch(ones(0,1,0,0),ones(0,1))
ans =
  0×1 empty double column vector
>> strmatch(ones(0,1,0,0),ones(0,1,0,1))
ans =
     1


Octave:


>> strmatch([],[])
error: strmatch: S must be a string
error: called from
    strmatch at line 64 column 5


(same results for the other empty input versions)


Also, matlab does still recommend not using strmatch, and recommends validatestring (which Octave has) or startsWith (apparently new in 2016b, so Octave doesn't have a compatible implementation yet)

Nicholas Jankowski <nrjank>
Group Member
Mon 14 Nov 2016 03:16:06 PM UTC, original submission:  

This was just brought up over at stackoverflow:
http://stackoverflow.com/questions/40565761/octave-issue-runnig-matlab-file-at-if-x-0-strmatchxx

in Matlab 2016b:


strmatch(' ', ' ')
ans =
     1


Octave 4.0.3:


>> strmatch(' ', ' ')
ans = [](0x1)


since the function is supposed to trim trailing whitespace, it appears Octave deals with it as comparing empty inputs, producing empty outputs, while Matlab does not.

Compatibility on handling empty inputs seems to have popped up a few places.  I realize this function has been on the 'will be deprecated list' for quite a few years now, but it seems Matlab has been keeping it around so compatibility fixes still make sense. especially if a fix isn't overly complicated

Are there any other similar functions we should check for similar behavior?

Nicholas Jankowski <nrjank>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #38969:  bug49601.cset added by rik5 (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by gyom (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by nrjank (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-20 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
        Release4.0.3 dev
        Operating SystemMicrosoft Windows Any
    2016-11-15 rik5 Attached File- Added bug49601.cset, #38969
        Severity3 - Normal 2 - Minor
        StatusNone Patch Submitted

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code