octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #55659] s_idx output of ismember uses last occ


From: Rik
Subject: [Octave-bug-tracker] [bug #55659] s_idx output of ismember uses last occurrence when there are duplicates, Matlab uses first
Date: Mon, 29 Jul 2019 17:29:42 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Update of bug #55659 (project octave):

                Priority:                       2 => 1 - Later              

    _______________________________________________________

Follow-up Comment #2:

Here is another piece of sample code along with analysis.

For the following code, Matlab returns [0, 0, 2, 1]


A = [5 3 4 2];
B = [2 4 4 4 6 8];
[~,ib] = ismember(A,B)
ib = [0, 0, 2, 1]


Octave, however, returns [0, 0, 4, 1].

The same result can be had in Matlab if the "legacy" option is used with
ismember (which uses the algorithm from Matlab versions prior to 2012b).

The difference is that when there are repeated, non-unique values in the set
B, Matlab returns the index of the first occurrence while Octave returns the
index of the last occurrence.

Debugging further in the ismember.m file, it is the call to lookup() which
returns the last index rather than the first index.

Changing lookup() is a lot of work, and likely to have other consequences.

The problem could be worked around in the ismember.m file by sorting the input
set in descending order before calling lookup() and then returning


s_idx(tf) = (numel (tf) + 1) - is(s_idx(tf));


But, all of the manipulation seems like a lot of work just to get Matlab
compatibility on indices which still work for indexing. 


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?55659>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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