bugGNU Octave - Bugs: bug #36555, strfind() should work with numeric...

 
 

bug #36555: strfind() should work with numeric arrays

Submitter:  Júlio Hoffimann Mendes <juliohm>
Submitted:  Mon 28 May 2012 08:03:19 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  2 Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  juliohm 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

Sat 20 Nov 2021 01:54:12 AM UTC, comment #8: 

I don't see any reason to keep this open.  Easy workaround is just to use char() to cast numeric array to a character vector if one really, really wants to use strfind on numeric data.

Rik <rik5>
Group administrator
Wed 17 Nov 2021 12:43:12 AM UTC, comment #7: 

just noting this is still present in Octave 6.4.0., suggesting it be closed as a 'won't fix' until someone really wants to make it happen. it lives in c++ space vs m-space, so that limits number of people who might mess with it to people with generally more important things to work on.

Also, this is clearly undocumented behavior. Matlab docs are usually fairly clear with accepted input types. for strfind it states:


str — Input text
string array | character vector | cell array of character vectors

https://www.mathworks.com/help/matlab/ref/strfind.html

As Rik said the simple input validation hack wasn't enough to make this work. Now, if the quick fix works for all but floats/complex, maybe an input_check could be added to the hack to throw an error specifically for those while allowing integer inputs to pass and therefore provide partial undocumented compatibility. Maybe a 'partial undocumented compatibility' note could be added to the docstring.

But simply closing as a won't fix seems quite appropriate as well.

Nicholas Jankowski <nrjank>
Group Member
Sat 19 Dec 2020 04:52:02 PM UTC, comment #6: 

In the old days, a character array was just a normal 2-dimensional numeric array with a flag that said "display as characters instead of numbers".  So I'd bet that strfind in Matlab is just operating on numeric values, always.

John W. Eaton <jwe>
Group administrator
Fri 18 Dec 2020 11:25:40 PM UTC, comment #5: 

Yeah, this is somewhat bogus.  Matlab clearly documents, and the function name presumes, that the input should be a character array.  Yet, it seems that it really only cares if the input is numeric.

I took a quick stab at fixing this, but it fails for floating point and complex numbers.  If we want to fix this it probably means major surgery on strfind.cc which doesn't seem worth the effort.

My crude stab bypassing the input validation is attached.

(file #50518)

Rik <rik5>
Group administrator
Fri 18 Dec 2020 09:05:09 PM UTC, comment #4: 

behavior still present in Octave 6.1.0

Matlab 2020b:

>> strfind([1 2 3], [2 3])
ans =
     2
>> strfind([1.1 2 3], [2 3])
ans =
     2
>> strfind([1 2.1 3], [2 3])
ans =
     []
>> strfind([1 2.1 3], [2.1 3])
ans =
     2
>> strfind([1 2+2i 3], [2+2i 3])
ans =
     2
>> strfind([1 2 3], [2+2i 3])
ans =
     []


Octave 6.1.0:

octave:1> strfind([1 2 3],[2 3])
error: strfind: PATTERN must be a string or cell array of strings
(same for all other combinations above)


since matlab doc says input can be a char vector, was wondering if it was just operating on any integer array, but appears it doesn't even error on non-integers. it's just doing a numerical pattern match of whatever you feed it.

Nicholas Jankowski <nrjank>
Group Member
Sun 20 Nov 2016 03:20:53 PM UTC, comment #3: 

Changing the Severity to Wish.

Rik <rik5>
Group administrator
Sat 19 Nov 2016 09:42:55 PM UTC, comment #2: 

This behaves still the same with Octave 4.2.0.

Hartmut <hardy>
Mon 28 May 2012 08:18:50 PM UTC, comment #1: 

There are some similarities with bug 33537

https://savannah.gnu.org/bugs/index.php?33537

Ben Abbott <bpabbott>
Group Member
Mon 28 May 2012 08:03:19 PM UTC, original submission:  

In MATLAB, the following works:

strfind([1 2 3],[2 3])

It's not the expected behavior for *str*find(), but is useful.

Júlio Hoffimann Mendes <juliohm>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #50518:  strfind.diff added by rik5 (1KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-20 rik5 StatusConfirmed Wont Fix
        Open/ClosedOpen Closed
    2020-12-18 rik5 Attached File- Added strfind.diff, #50518
    2016-11-20 rik5 Severity3 - Normal 1 - Wish
        Priority3 - Low 2
    2015-05-22 rik5 Priority5 - Normal 3 - Low
    2014-01-19 mtmiller CategoryNone Octave Function
        StatusNone Confirmed
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code