[Top][All Lists]

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

[Octave-bug-tracker] [bug #51403] isequal is slow

From: Guillaume
Subject: [Octave-bug-tracker] [bug #51403] isequal is slow
Date: Mon, 10 Jul 2017 05:41:17 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0

Follow-up Comment #5, bug #51403 (project octave):

First, sorry, the summary of the bug should have been that "isequal is not as
fast than Matlab's version" (and indeed, it's a builtin in Matlab;
exist('isequal','builtin') is 5).

I can indeed see that extra care was taken to optimize the function (thanks to
both of you) and couldn't think of any change to make it faster myself. I
would guess that most of the time, this function is called with two arguments:
do you think it would be possible to modify the function to run iteratively
over arguments such that it might be faster with two arguments but a bit
slower with more than two?

I added a special handling for cellstr which makes things a bit faster for me
- at a cost of an extra call to cellfun() if the inputs are not cellstr. It
also assumes that the content of the cellstr can be tested with strcmp().

--- a/scripts/general/private/__isequal__.m     Fri Jul 07 08:17:32 2017
+++ b/scripts/general/private/__isequal__.m     Mon Jul 10 10:27:33 2017
@@ -117,14 +117,22 @@
         t = __isequal__ (args{:});
+    elseif (iscellstr (x) && all (cellfun (@iscellstr, varargin)))
+      idx = 0;
+      while (t && idx < numel (x))
+        idx += 1;
+        t = all (strcmp (x{idx}, [cellindexmat(varargin, idx){:}]));
+      endwhile
     elseif (iscell (x))
       ## Check that each element of a cell is equal.
       l_x = numel (x);
       idx = 0;
+      args = cell (1, 2+l_v);
+      args{1} = nans_compare_equal;
       while (t && idx < l_x)
         idx += 1;
-        args = cell (1, 2+l_v);
-        args(1:2) = {nans_compare_equal, x{idx}};
+        args{2} = x{idx};
         args(3:end) = [cellindexmat(varargin, idx){:}];
         t = __isequal__ (args{:});


Reply to this item at:


  Message sent via/by Savannah

reply via email to

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