[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ismember bugs
From: |
Søren Hauberg |
Subject: |
Re: ismember bugs |
Date: |
Sat, 11 Aug 2007 01:53:40 +0200 |
User-agent: |
Thunderbird 1.5.0.12 (X11/20070604) |
Søren Hauberg skrev:
Hi,
I just had a look at the 'ismember' bugs (to see the bugs, run 'test
ismember'). I find the 'ismember' code fairly hard to read, so I rewrote
the function from scratch. I've attached the result. Assuming the
'cellstr' bug that I just reported to the bugs-list is fixed this
implementation fixes the bugs. The downside is that my new
implementation is quite a bit more slow (too slow). It depends on the
'cellfun' function, which then is the slow part. I don't consider this
an alternative to the current implementation, but I'm posting the
implementation here in case somebody wants to see the code.
Sorry about replying to my own post, but I used part of my just-posted
code to patch the current implementation of ismember. I still don't
understand that implementation, but I can fix the bugs (patch attached).
This assumes that the cellstr bug is fixed.
Søren
--- /home/sh/Programmer/share/octave/2.9.13/m/set/ismember.m 2007-08-10
22:48:08.000000000 +0200
+++ ismember.m 2007-08-11 01:49:25.000000000 +0200
@@ -33,6 +33,20 @@
print_usage ();
endif
+
+ ## Convert char matrices to cell arrays
+ if (ischar(a))
+ a = cellstr(a);
+ endif
+ if (ischar(S))
+ S = cellstr(S);
+ endif
+
+ ## Input checking (this check is for matlab compatibility)
+ if ( !isa(a, class(S)) )
+ error("ismember: both input arguments must be the same type");
+ endif
+
if (isempty (a) || isempty (S))
c = zeros (size (a), "logical");
else
@@ -121,7 +135,7 @@
%!assert (ismember ('abc', {'abc', 'def'}), true);
%!assert (isempty (ismember ([], [1, 2])), true);
%!xtest assert (ismember ('', {'abc', 'def'}), false);
-%!xtest fail ('ismember ([], {1, 2})', 'error:.*');
+%!fail ('ismember ([], {1, 2})', 'error:.*');
%!fail ('ismember ({[]}, {1, 2})', 'error:.*');
%!assert (ismember ({'foo', 'bar'}, {'foobar'}), logical ([0, 0]))
%!assert (ismember ({'foo'}, {'foobar'}), false)
- ismember bugs, Søren Hauberg, 2007/08/10
- Re: ismember bugs,
Søren Hauberg <=