octave-maintainers
[Top][All Lists]
Advanced

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

Re: Interpreter performance


From: Bill Denney
Subject: Re: Interpreter performance
Date: Sun, 01 Oct 2006 22:24:32 -0400
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

Bill Denney wrote:
In strings, it is used in at least lower, upper, and deblank in ways that I saw easy to fix. It's also used in places like __isequal__ and
it might be possible to speed up datevec.
Here are the patches.

Bill

scripts/Changelog:
2006-10-01  Bill Denney <address@hidden>

* strings/deblank.m, strings/upper.m, strings/lower.m, general/__isequal__.m: minimize looping using cellfun.
Index: __isequal__.m
===================================================================
RCS file: /cvs/octave/scripts/general/__isequal__.m,v
retrieving revision 1.5
diff -u -r1.5 __isequal__.m
--- __isequal__.m       28 Mar 2006 11:25:29 -0000      1.5
+++ __isequal__.m       2 Oct 2006 02:16:43 -0000
@@ -54,11 +54,9 @@
 
     n_x = length (fieldnames (x));
 
-    t = true;
-    for argn = 1:l_v
-      y = varargin{argn};
-      t = t && isstruct (y) && (n_x == length (fieldnames (y)));
-    endfor
+    t = all (cellfun ("isstruct", varargin)) && ...
+      all (n_x == cellfun ("length", ...
+           cellfun ("fieldnames", varargin, "UniformOutput", 0)));
     if (!t)
       return;
     endif
@@ -84,11 +82,8 @@
     x = x(:);
     l_x = length (x);
 
-    t = true;
-    for argn = 1:l_v
-      y = varargin{argn}(:);
-      t = t && (iscell (y) || islist (y)) && (l_x == length (y));
-    endfor
+    t = all ((cellfun ("iscell", varargin) | cellfun ("islist", varargin)) && 
...
+             all (l_x == cellfun ("length", varargin)));
     if (!t)
       return;
     endif
Index: deblank.m
===================================================================
RCS file: /cvs/octave/scripts/strings/deblank.m,v
retrieving revision 1.20
diff -u -r1.20 deblank.m
--- deblank.m   22 Sep 2005 18:36:23 -0000      1.20
+++ deblank.m   2 Oct 2006 02:18:03 -0000
@@ -45,9 +45,7 @@
 
   elseif (iscell(s))
 
-    for i = 1:numel (s)
-      s{i} = deblank (s{i});
-    endfor
+    s = cellfun ("deblank", s, "UniformOutput", 0);
 
   else
     error ("deblank: expecting string argument");
Index: lower.m
===================================================================
RCS file: /cvs/octave/scripts/strings/lower.m,v
retrieving revision 1.8
diff -u -r1.8 lower.m
--- lower.m     16 Mar 2006 04:09:07 -0000      1.8
+++ lower.m     2 Oct 2006 02:18:03 -0000
@@ -35,10 +35,7 @@
   if (ischar (s))
     retval = tolower (s);
   elseif (iscellstr (s))
-    retval = cell (size (s));
-    for i = 1:(numel (s))
-      retval{i} = tolower(s{i});
-    endfor
+    retval = cellfun ("tolower", s, "UniformOutput", 0);
   else
     error ("lower: `s' must be a string or cell array of strings");
   endif
Index: upper.m
===================================================================
RCS file: /cvs/octave/scripts/strings/upper.m,v
retrieving revision 1.8
diff -u -r1.8 upper.m
--- upper.m     16 Mar 2006 04:09:07 -0000      1.8
+++ upper.m     2 Oct 2006 02:18:03 -0000
@@ -35,10 +35,7 @@
   if (ischar (s))
     retval = toupper (s);
   elseif (iscellstr (s))
-    retval = cell (size (s));
-    for i = 1:(numel (s))
-      retval{i} = toupper(s{i});
-    endfor
+    retval = cellfun ("toupper", s, "UniformOutput", 0);
   else
     error ("upper: `s' must be a string or cell array of strings");
   endif

reply via email to

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