ismember with empty arguments

View: New views
2 Messages — Rating Filter:   Alert me  

ismember with empty arguments

by Marco Caliari-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear maintainers,

I discovered a different behaviour between Octave and Matlab for the
function ismember when the option 'rows' is given and one of the two
arguments is empty.
In Matlab:

>> ismember(ones(2),[],'rows')
ans =

      0
      0
>> ismember([],ones(2),'rows')
ans =

    Empty matrix: 0-by-1
>> ismember([],[],'rows')
ans =

    Empty matrix: 0-by-1

Although I don't completely understand this behaviour, I enclosed a patch
(against 3.2.3) which reproduces it.

Changelog

2009-10-16  Marco Caliari  <marco.caliari@...>

  * ismember.m: Fix behaviour for empty arguments.

Marco
[ismember.m.patch]

--- ismember.m.orig 2009-10-16 10:33:32.000000000 +0200
+++ ismember.m 2009-10-16 10:27:54.000000000 +0200
@@ -95,6 +95,12 @@
             endif
           endfor
           tf = logical (a_idx);
+ elseif (strcmpi (rows_opt, "rows") && isempty(s))
+  tf = false(size(a,1),1);
+  a_idx = false(size(a,1),1);
+ elseif (strcmpi (rows_opt, "rows") && isempty(a))
+  tf = zeros(0,1);
+  a_idx = zeros(0,1);
         elseif (strcmpi (rows_opt, "rows"))
           error ("ismember: with 'rows' both sets must be matrices with an equal number of columns");
         else


Re: ismember with empty arguments

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 16, 2009 at 11:33 AM, Marco Caliari <marco.caliari@...> wrote:

> Dear maintainers,
>
> I discovered a different behaviour between Octave and Matlab for the
> function ismember when the option 'rows' is given and one of the two
> arguments is empty.
> In Matlab:
>
>>> ismember(ones(2),[],'rows')
>
> ans =
>
>     0
>     0
>>>
>>> ismember([],ones(2),'rows')
>
> ans =
>
>   Empty matrix: 0-by-1
>>>
>>> ismember([],[],'rows')
>
> ans =
>
>   Empty matrix: 0-by-1
>
> Although I don't completely understand this behaviour, I enclosed a patch
> (against 3.2.3) which reproduces it.
>
> Changelog
>
> 2009-10-16  Marco Caliari  <marco.caliari@...>
>
>        * ismember.m: Fix behaviour for empty arguments.
>
> Marco

Since you patch doesn't apply to development sources, I created another:
http://hg.savannah.gnu.org/hgweb/octave/rev/aab4f2aa9ed9

thanks

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz