bugGNU Octave - Bugs: bug #51412, strcmp with multidimensional char...


bug #51412: strcmp with multidimensional char arrays

Submitted by:  Guillaume <gyom>
Submitted on:  Fri 07 Jul 2017 09:48:27 AM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Tue 11 Jul 2017 04:25:48 PM UTC, comment #9:

This does need to be tackled, but it is not going to be easy. Matlab's documentation refers to cellstr as

Octave has assumed, quite reasonably, that a character vector is a 1xN char array. But the code examples clearly show that Matlab doesn't require a vector---It only requires a char array object for each cell.

Also, Matlab has recently introduced string arrays which are yet another fundamental object type to join char arrays and cellstrs. Eventually Octave will probably support these so it makes sense that at the same time that is_string, string_value, and cellstr_value are overhauled to make them Matlab compatible, that we also address string arrays. In fact, we might want to reserve is_string to test for the new string array class and use another function name (maybe ischar?) to test if something is just a char array.

Some more slightly bad news. I did work up a cset that fixes the issue with strcmp, but by avoiding cellstr it is 10X slower.

Rik <rik5>
Project Administrator
Tue 11 Jul 2017 09:04:07 AM UTC, comment #8:

MATLAB 2016a

Ceral Paquet <octavebugs>
Mon 10 Jul 2017 08:53:14 PM UTC, comment #7:

Another test for someone with Matlab

If I read the documentation correctly, Matlab should return false for both cases.

Rik <rik5>
Project Administrator
Mon 10 Jul 2017 06:39:05 PM UTC, comment #6:

Could someone with matlab test this?

Rik <rik5>
Project Administrator
Mon 10 Jul 2017 05:16:57 PM UTC, comment #5:

In addition I think we need to be wary about the definitions of "string" and "cell string" in this function, and places where string_value and cellstr_value are used to compare two operands.

The is_string and iscellstr tests return true for values that cannot be exactly represented by our normal definition of what a "string" is.

Simple example of a two-dimensional character matrix:

The string_value method truncates a multi-dimensional character vector to return just the first row (this has been discussed in other bug reports). The cellstr_value method calls string_value.

Mike Miller <mtmiller>
Project Administrator
Mon 10 Jul 2017 04:59:17 PM UTC, comment #4:

Documentation for Matlab's behavior is at http://www.mathworks.com/help/matlab/ref/strcmp.html.

Mixed char matrix / cellstr comparisons are tricky. In bug #51187 I had to change the ismember functionality specifically for Matlab compatibility

The do_strcmp_fun function is in libinterp/corefcn/strfns.cc. I see that there are several cases to handle broadcasting correctly. For example, when doing

I have to rebuild Octave with debugging features in order to test what is going on, but it may be an obvious extra case in the if/else tree needs to be added to handle this.

Rik <rik5>
Project Administrator
Mon 10 Jul 2017 04:53:47 PM UTC, comment #3:

Ok, so our definition of "iscellstr" is correct, but something for which "iscellstr" returns true cannot necessarily be turned into a one-dimensional array of strings.

Mike Miller <mtmiller>
Project Administrator
Mon 10 Jul 2017 09:25:39 AM UTC, comment #2:

Here is the Matlab output for the same calls:

Guillaume <gyom>
Fri 07 Jul 2017 08:04:53 PM UTC, comment #1:

So to me the immediately interesting cases are

The 3-dimensional cases probably fail because

but elsewhere in Octave's baseline, code expects that if something is a cellstr, it can be converted into a vector of strings.

What does Matlab iscellstr return in this case?

Mike Miller <mtmiller>
Project Administrator
Fri 07 Jul 2017 09:48:27 AM UTC, original submission:

strcmp seems to differ from Matlab when the input is not a row vector, see with the following code:

In Octave:

while in Matlab:

Guillaume <gyom>


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

Attach Files:

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 octavebugs (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by gyom (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-07-11 rik5 StatusNone => Confirmed

    Back to the top

    Powered by Savane 3.4