changeset 11596:493ef9d1c25d octave-forge

implemented a way to specify the type of a matrix, when loading from file.
author michelemartone
date Wed, 03 Apr 2013 17:41:37 +0000
parents 344a62cf0446
children b3a2cfb1a0c1
files main/sparsersb/doc/sparsersb.txt main/sparsersb/src/sparsersb.cc
diffstat 2 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/main/sparsersb/doc/sparsersb.txt	Wed Apr 03 16:37:41 2013 +0000
+++ b/main/sparsersb/doc/sparsersb.txt	Wed Apr 03 17:41:37 2013 +0000
@@ -3,11 +3,12 @@
      Create a sparse RSB matrix from the full matrix A.
 
  -- Loadable Function: [S, NROWS, NCOLS, NNZ, REPINFO, FIELD, SYMMETRY]
-= sparsersb (FILENAME)
+= sparsersb (MFN, MTS)
      Create a sparse RSB matrix by loading the Matrix Market matrix
-     file named FILENAME.  In the case FILENAME is "?", a string
-     listing the available numerical types with BLAS-style characters
-     will be returned.
+     file named MFN. The optional argument MTS can specify either real
+     ("D") or complex ("Z") type. Default is real.  In the case MFN is
+     "?", a string listing the available numerical types with
+     BLAS-style characters will be returned.
 
  -- Loadable Function: S = sparsersb (I, J, SV, M, N, NZMAX)
      Create a sparse RSB matrix given integer index vectors I and J, a
--- a/main/sparsersb/src/sparsersb.cc	Wed Apr 03 16:37:41 2013 +0000
+++ b/main/sparsersb/src/sparsersb.cc	Wed Apr 03 17:41:37 2013 +0000
@@ -246,11 +246,11 @@
 			RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
 		}
 
-		octave_sparse_rsb_mtx (const std::string &fn, rsb_type_t typecode=RSBOI_TYPECODE) : octave_sparse_matrix (RSBIO_DEFAULT_CORE_MATRIX)
+		octave_sparse_rsb_mtx (const std::string &mfn, rsb_type_t typecode=RSBOI_TYPECODE) : octave_sparse_matrix (RSBIO_DEFAULT_CORE_MATRIX)
 		{
 			rsb_err_t errval=RSB_ERR_NO_ERROR;
 			RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
-			if(!(this->A = rsb_file_mtx_load(fn.c_str(),RSBOI_RF,typecode,&errval)))
+			if(!(this->A = rsb_file_mtx_load(mfn.c_str(),RSBOI_RF,typecode,&errval)))
 				RSBOI_ERROR(RSBOI_0_ALERRMSG);
 			RSBOI_PERROR(errval);
 			if(!this->A)
@@ -1639,9 +1639,9 @@
 Create a sparse RSB matrix from the full matrix @var{a}.\n"\
 /*is forced back to a full matrix if resulting matrix is sparse\n*/\
 "\n\
-@deftypefnx {Loadable Function} {[@var{s}, @var{nrows}, @var{ncols}, @var{nnz}, @var{repinfo}, @var{field}, @var{symmetry}] =} "RSBOI_FNS" (@var{filename})\n\
-Create a sparse RSB matrix by loading the Matrix Market matrix file named @var{filename}.\n"\
-"In the case @var{filename} is \""RSBOI_LIS"\", a string listing the available numerical types with BLAS-style characters will be returned.\n"\
+@deftypefnx {Loadable Function} {[@var{s}, @var{nrows}, @var{ncols}, @var{nnz}, @var{repinfo}, @var{field}, @var{symmetry}] =} "RSBOI_FNS" (@var{mfn}, @var{mts})\n\
+Create a sparse RSB matrix by loading the Matrix Market matrix file named @var{mfn}. The optional argument {@var{mts}} can specify either real (\"D\") or complex (\"Z\") type. Default is real.\n"\
+"In the case @var{mfn} is \""RSBOI_LIS"\", a string listing the available numerical types with BLAS-style characters will be returned.\n"\
 "\n\
 @deftypefnx {Loadable Function} {@var{s} =} "RSBOI_FNS" (@var{i}, @var{j}, @var{sv}, @var{m}, @var{n}, @var{nzmax})\n\
 Create a sparse RSB matrix given integer index vectors @var{i} and @var{j},\n\
@@ -1835,14 +1835,32 @@
 			if (error_state) goto err;
 			if(mfn==RSBOI_LIS)
 			{
-				retval.append(RSB_NUMERICAL_TYPE_PREPROCESSOR_SYMBOLS);
+				//retval.append(RSB_NUMERICAL_TYPE_PREPROCESSOR_SYMBOLS);
+#if RSBOI_WANT_DOUBLE_COMPLEX
+				retval.append("D Z");
+#else
+				retval.append("D");
+#endif
 				goto ret;
 			}
 			else
 			{
+				rsb_type_t typecode=RSBOI_TYPECODE;
 				RSBOI_WARN(RSBOI_0_UNFFEMSG);
 				RSBOI_WARN("shall set the type, here");
-				retval.append(matrix=new octave_sparse_rsb_mtx(mfn));
+				if(nargin>1 && args(1).is_string())
+				{
+					const std::string mts = args(1).string_value();
+					if(mts=="complex" || mts=="Z")
+#if RSBOI_WANT_DOUBLE_COMPLEX
+						typecode=RSB_NUMERICAL_TYPE_DOUBLE_COMPLEX;
+#else
+						error("complex type is not supported !");
+#endif
+					if(mts=="real" || mts=="D")
+						typecode=RSB_NUMERICAL_TYPE_DOUBLE;
+				}
+				retval.append(matrix=new octave_sparse_rsb_mtx(mfn,typecode));
 				if(nargout) nargout--;
 				if(nargout) retval.append(matrix->rows()),--nargout;
 				if(nargout) retval.append(matrix->cols()),--nargout;