changeset 12640:de98e4cb9248 octave-forge

check for sparse matrices and and convert to full if needed
author schloegl
date Thu, 18 Jun 2015 15:09:49 +0000
parents 061284acaabd
children e3998369a32e
files extra/NaN/NEWS extra/NaN/inst/covm.m extra/NaN/inst/sumskipnan.m extra/NaN/src/covm_mex.cpp extra/NaN/src/sumskipnan_mex.cpp
diffstat 5 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/NEWS	Thu Jun 18 08:23:13 2015 +0000
+++ b/extra/NaN/NEWS	Thu Jun 18 15:09:49 2015 +0000
@@ -1,3 +1,7 @@
+
+- check for sparse input matrices and
+  convert to full if needed
+
 2015-06-01: Release of NaN v.2.7.6
 
 - improve accuracy of normcdf (bug #38170) 
--- a/extra/NaN/inst/covm.m	Thu Jun 18 08:23:13 2015 +0000
+++ b/extra/NaN/inst/covm.m	Thu Jun 18 15:09:49 2015 +0000
@@ -143,6 +143,12 @@
                 end;
 	end;
 
+	if issparse(X) || issparse(Y), 
+		fprintf(2,'sumskipnan: sparse matrix converted to full matrix\n');
+		X=full(X); 
+		Y=full(Y); 
+	end;
+
 	[CC,NN] = covm_mex(real(X), real(Y), FLAG_NANS_OCCURED, W);
 	%% complex matrices 
 	if ~isreal(X) && ~isreal(Y)
--- a/extra/NaN/inst/sumskipnan.m	Thu Jun 18 08:23:13 2015 +0000
+++ b/extra/NaN/inst/sumskipnan.m	Thu Jun 18 15:09:49 2015 +0000
@@ -119,6 +119,10 @@
 try
 	
 	%% using sumskipnan_mex.mex
+	if issparse(x), 
+		fprintf(2,'sumskipnan: sparse matrix converted to full matrix\n');
+		x = full(x); 
+	end;
 
 	%% !!! hack: FLAG_NANS_OCCURED is an output argument, reserve memory !!!
 	if isempty(FLAG_NANS_OCCURED),
--- a/extra/NaN/src/covm_mex.cpp	Thu Jun 18 08:23:13 2015 +0000
+++ b/extra/NaN/src/covm_mex.cpp	Thu Jun 18 15:09:49 2015 +0000
@@ -83,10 +83,10 @@
 
 
 	// get 1st argument
-	if(mxIsDouble(PInputs[0]) && !mxIsComplex(PInputs[0]))
+	if(mxIsDouble(PInputs[0]) && !mxIsComplex(PInputs[0]) && !mxIsSparse(PInputs[0]) )
 		X0  = mxGetPr(PInputs[0]);
 	else 	
-		mexErrMsgTxt("First argument must be REAL/DOUBLE.");
+		mexErrMsgTxt("First argument must be non-sparse REAL/DOUBLE.");
 	rX = mxGetM(PInputs[0]);		
 	cX = mxGetN(PInputs[0]);		
 		
--- a/extra/NaN/src/sumskipnan_mex.cpp	Thu Jun 18 08:23:13 2015 +0000
+++ b/extra/NaN/src/sumskipnan_mex.cpp	Thu Jun 18 15:09:49 2015 +0000
@@ -98,10 +98,10 @@
 	        mexErrMsgTxt("SUMSKIPNAN.MEX has 1 to 3 output arguments.");
 
 	// get 1st argument
-	if(mxIsDouble(PInputs[0]) && !mxIsComplex(PInputs[0]))
+	if(mxIsDouble(PInputs[0]) && !mxIsComplex(PInputs[0]) && !mxIsSparse(PInputs[0]) )
 		LInput  = mxGetPr(PInputs[0]);
 	else 	
-		mexErrMsgTxt("First argument must be REAL/DOUBLE.");
+		mexErrMsgTxt("First argument must be and not sparse REAL/DOUBLE.");
 
     	// get 2nd argument
     	if  (PInputCount > 1) {