changeset 5748:bca1e9c6b544 octave-forge

performance improvements suggested by profiling
author schloegl
date Wed, 10 Jun 2009 20:37:00 +0000
parents 41f052550e3e
children edead6bb0668
files extra/NaN/inst/covm.m extra/NaN/inst/flag_implicit_skip_nan.m
diffstat 2 files changed, 29 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/inst/covm.m	Wed Jun 10 18:18:07 2009 +0000
+++ b/extra/NaN/inst/covm.m	Wed Jun 10 20:37:00 2009 +0000
@@ -58,11 +58,11 @@
 if nargin<3,
         if nargin==2,
 		if isnumeric(Y),
-                        Mode='M';
-                else
-		        Mode=Y;
-                        Y=[];
-                end;
+			Mode='M';
+		else
+			Mode=Y;
+			Y=[];
+		end;
         elseif nargin==1,
                 Mode = 'M';
                 Y = [];
@@ -124,7 +124,7 @@
 end; 
 	
 
-if mexFLAG2 && mexFLAG && ~isempty(W),	
+if mexFLAG2 && mexFLAG && ~isempty(W),
 	%% the mex-functions here are much slower than the m-scripts below 
 	%% however, the mex-functions support weighting of samples. 
 	if isempty(FLAG_NANS_OCCURED),
@@ -133,8 +133,8 @@
 		FLAG_NANS_OCCURED = logical(0);  % default value 
 	end;
 
-        if (~any(Mode=='D') && ~any(Mode=='E')), % if Mode == M
-       		[CC,NN] = covm_mex(real(X),real(Y),FLAG_NANS_OCCURED,W);
+	if (~any(Mode=='D') && ~any(Mode=='E')), % if Mode == M
+		[CC,NN] = covm_mex(real(X),real(Y),FLAG_NANS_OCCURED,W);
 		%% complex matrices 
 		if ~isreal(X) && ~isreal(Y)
 			[iCC,inn] = covm_mex(imag(X),imag(Y),FLAG_NANS_OCCURED,W);
@@ -151,9 +151,9 @@
 		end; 	
 
        	else  % if any(Mode=='D') || any(Mode=='E'), 
-	        [S1,N1] = sumskipnan(X,1,W);
-	        if ~isempty(Y)
-	               	[S2,N2] = sumskipnan(Y,1,W);
+		[S1,N1] = sumskipnan_mex(X,1,W);
+		if ~isempty(Y)
+	               	[S2,N2] = sumskipnan_mex(Y,1,W);
 	        else 
 	        	S2 = S1; N2 = N1;        	
 		end; 
@@ -208,29 +208,29 @@
         	[S1,N1] = sumskipnan(X,1);
                	[S2,N2] = sumskipnan(Y,1);
                	NN = real(X==X)'*real(Y==Y);
-                
-	        if any(Mode=='D'), % detrending mode
-       			X  = X - ones(r1,1)*(S1./N1);
-               	        Y  = Y - ones(r1,1)*(S2./N2);
-                       	if any(Mode=='1'),  %  'D1'
-                               	NN = NN;
-                       	else   %  'D0'       
-                               	NN = max(NN-1,0);
-                        end;
-                end;         
-                X(X~=X) = 0; % skip NaN's
-       		Y(Y~=Y) = 0; % skip NaN's
+
+		if any(Mode=='D'), % detrending mode
+			X  = X - ones(r1,1)*(S1./N1);
+			Y  = Y - ones(r1,1)*(S2./N2);
+			if any(Mode=='1'),  %  'D1'
+				NN = NN;
+			else	%  'D0'       
+				NN = max(NN-1,0);
+			end;
+                end;
+		X(X~=X) = 0; % skip NaN's
+		Y(Y~=Y) = 0; % skip NaN's
                	CC = X'*Y;
-                
+
                 if any(Mode=='E'), % extended mode
                         NN = [nn, N2; N1', NN];
                         CC = [nn, S2; S1', CC];
                 end;
 	end;
-        
-else        
-        if (~any(Mode=='D') & ~any(Mode=='E')), % if Mode == M
-        	tmp = real(X==X);
+
+else
+	if (~any(Mode=='D') & ~any(Mode=='E')), % if Mode == M
+		tmp = real(X==X);
 		NN  = tmp'*tmp;
 		X(X~=X) = 0; % skip NaN's
 	        CC = X'*X;
--- a/extra/NaN/inst/flag_implicit_skip_nan.m	Wed Jun 10 18:18:07 2009 +0000
+++ b/extra/NaN/inst/flag_implicit_skip_nan.m	Wed Jun 10 20:37:00 2009 +0000
@@ -48,7 +48,7 @@
 
 persistent FLAG_implicit_skip_nan;
 
-if strcmp(version,'3.6'), FLAG_implicit_skip_nan=(1==1); end;	%% hack for the use with Freemat3.6
+%% if strcmp(version,'3.6'), FLAG_implicit_skip_nan=(1==1); end;	%% hack for the use with Freemat3.6
 
 %%% set DEFAULT value of FLAG
 if isempty(FLAG_implicit_skip_nan),