changeset 1090:0580d586285f octave-forge

improve performance (exist-function and FLAG_IMPLICIT_SKIP_NAN are removed because they slow down significantly);
author schloegl
date Fri, 31 Oct 2003 18:15:38 +0000
parents 25c161909166
children f306e0ee69c6
files extra/NaN/INSTALL extra/NaN/sumskipnan.m
diffstat 2 files changed, 45 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/INSTALL	Fri Oct 31 18:13:28 2003 +0000
+++ b/extra/NaN/INSTALL	Fri Oct 31 18:15:38 2003 +0000
@@ -1,15 +1,10 @@
 
 Installing the NaN-tb with Octave:
 ----------------------------------
-a) You need repmat.m;
-    If you have not installed it yet, you should do it now. 
-Download e.g. P. Kienzle's version from  
-http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/octave/octave-forge/main/general/repmat.m?rev=HEAD&content-type=text/plain 
-
-b) extract files from NaNnnn.tar.gz and move them into 
+a) extract files from NaNnnn.tar.gz and move them into 
 .../octave/.../m/statistics/base/ 
 
-c) Alternatively, the files can be moved into any other directory; but you 
+b) Alternatively, the files can be moved into any other directory; but you 
 must remove from .../octave/.../m/statistics/base/ 
 mean.m, meansq.m, median.m, moment.m, skewness.m, kurtosis.m, std.m, var.m
 and from .../source_forge/.../statistics/*
@@ -18,7 +13,7 @@
 (Optional) You can remove nansum, nanmean, nanmedian, etc. because you do not need 
 them anymore. 
 
-d) (Re-)start Octave and run NANINSTTEST. 
+c) (Re-)start Octave and run NANINSTTEST. 
 This checks whether the installation was successful. 
 
 
@@ -33,6 +28,14 @@
 c) (Re-)start Matlab and run NANINSTTEST. 
 This checks whether the installation was successful. 
 
+d) [OPTIONAL]: 
+  To improve speed, you should compile the cmex-function SUMSKIPNAN.CPP
+    mex sumskipnan.cpp
+  Run NANINSTTEST again to check the stability of the compiled SUMSKIPNAN.  
+
+e) HINT: if the MEX-file SUMSKIPNAN crashes, remove it. Then the (slower) M-file is used. 
+     
+
 
 	$Id$
 	$Revision$
--- a/extra/NaN/sumskipnan.m	Fri Oct 31 18:13:28 2003 +0000
+++ b/extra/NaN/sumskipnan.m	Fri Oct 31 18:15:38 2003 +0000
@@ -59,61 +59,38 @@
         DIM = [];
 end;
 
-DONE = 0; 
-if flag_implicit_skip_nan & (exist('sumskipnan2')==3);
-                
-	% an efficient implementation in C of the following lines 
-        % could significantly increase performance 
-        % only one loop and only one check for isnan is needed
-        %
-        % Outline of the algorithm: 
-        % for { k=1,o=0,count=0; k++; k<N} 
-        % 	if ~isnan(i(k)) 
-        % 	{ 	o     += i(k);
-        %               count += 1;
-        %		tmp    = i(k)*i(k)
-        %		o2    += tmp;
-        %		o3    += tmp.*tmp;
-        %       }; 
-        
-
-        % use MEX-file SUMSKIPNAN2 from Patrick Houweling <phouweling@yahoo.com>
-	try,
-	        switch nargout,
-	        case {0,1}
-    			[o] = sumskipnan2(i, DIM);
-	        case 2
-    		        [o, count] = sumskipnan2(i, DIM);
-	        case 3
-    	                [o, count, SSQ] = sumskipnan2(i, DIM);
-	        case 4
-        	        [o, count, SSQ, S4M] = sumskipnan2(i, DIM);
-	        end              
-    		DONE = 1; 
-	catch;
-		DONE = 0;  
-	end
-end;	     
-
-   
-if ~DONE, % else  
-        if isempty(DIM),
-                DIM=min(find(size(i)>1));
-                if isempty(DIM), DIM = 1; end;
-        end;
-        if nargout>1
-                count = sum(~isnan(i),DIM); 
-        end;
-        if flag_implicit_skip_nan, %%% skip always NaN's
-                i(isnan(i)) = 0;
-        end;
-        o = sum(i,DIM);
-        if nargout>2,
-                i = real(i).^2 + imag(i).^2;
-                SSQ = sum(i,DIM);
-                if nargout>3,
-                        S4M = sum(i.^2,DIM);
-                end;
-        end;
+% an efficient implementation in C of the following lines 
+% could significantly increase performance 
+% only one loop and only one check for isnan is needed
+% An MEX-Implementation is available in sumskipnan.cpp
+%
+% Outline of the algorithm: 
+% for { k=1,o=0,count=0; k++; k<N} 
+% 	if ~isnan(i(k)) 
+% 	{ 	o     += i(k);
+%               count += 1;
+%		tmp    = i(k)*i(k)
+%		o2    += tmp;
+%		o3    += tmp.*tmp;
+%       }; 
+
+
+if isempty(DIM),
+        DIM=min(find(size(i)>1));
+        if isempty(DIM), DIM = 1; end;
 end;
-
+if nargout>1,
+        count = sum(~isnan(i),DIM); 
+end;
+
+%if flag_implicit_skip_nan, %%% skip always NaN's
+i(isnan(i)) = 0;
+%end;
+o = sum(i,DIM);
+if nargout>2,
+        i = real(i).^2 + imag(i).^2;
+        SSQ = sum(i,DIM);
+        if nargout>3,
+                S4M = sum(i.^2,DIM);
+        end;
+end;