changeset 11651:879b7c96162b octave-forge

absorbed spmm transposed calling with method spmm.
author michelemartone
date Fri, 26 Apr 2013 23:18:55 +0000
parents 782ff6bb04a9
children 7546d8797855
files main/sparsersb/src/sparsersb.cc
diffstat 1 files changed, 10 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/main/sparsersb/src/sparsersb.cc	Fri Apr 26 23:06:58 2013 +0000
+++ b/main/sparsersb/src/sparsersb.cc	Fri Apr 26 23:18:55 2013 +0000
@@ -1040,10 +1040,11 @@
 	}
 }
 
-octave_value spmv(const octave_matrix&v2)const
+octave_value spmm(const octave_matrix&v2, bool do_trans=false)const
 {
 	rsb_err_t errval=RSB_ERR_NO_ERROR;
 	RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
+	rsb_trans_t transa = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
 
 	if(this->is_real_type())
 	{
@@ -1051,10 +1052,12 @@
 		octave_idx_type b_nc = b.cols ();
 		octave_idx_type b_nr = b.rows ();
 		octave_idx_type ldb=b_nr;
-		octave_idx_type ldc=this->rows();
+		octave_idx_type ldc=do_trans?this->columns():this->rows();
 		octave_idx_type nrhs=b_nc;
 		Matrix retval(ldc,nrhs,RSBOI_ZERO);
 		if(this->columns()!=b_nr) { error("matrices dimensions do not match!\n"); return Matrix(); }
+		if(( do_trans) &&(this->rows() !=b_nr)) { error("matrices dimensions do not match!\n"); return Matrix(); }
+		if((!do_trans)&&(this->columns()!=b_nr)) { error("matrices dimensions do not match!\n"); return Matrix(); }
 		errval=rsb_spmm(RSB_TRANSPOSITION_N,&rsboi_pone,this->mtxAp,nrhs,RSB_OI_DMTXORDER,(RSBOI_T*)b.data(),ldb,&rsboi_zero,(RSBOI_T*)retval.data(),ldc);
 		RSBOI_PERROR(errval);
 		return retval;
@@ -1065,10 +1068,11 @@
 		octave_idx_type b_nc = b.cols ();
 		octave_idx_type b_nr = b.rows ();
 		octave_idx_type ldb=b_nr;
-		octave_idx_type ldc=this->rows();
+		octave_idx_type ldc=do_trans?this->columns():this->rows();
 		octave_idx_type nrhs=b_nc;
 		ComplexMatrix retval(ldc,nrhs,RSBOI_ZERO);
-		if(this->columns()!=b_nr) { error("matrices dimensions do not match!\n"); return ComplexMatrix(); }
+		if(( do_trans) &&(this->rows() !=b_nr)) { error("matrices dimensions do not match!\n"); return ComplexMatrix(); }
+		if((!do_trans)&&(this->columns()!=b_nr)) { error("matrices dimensions do not match!\n"); return ComplexMatrix(); }
 		errval=rsb_spmm(RSB_TRANSPOSITION_N,&rsboi_pone,this->mtxAp,nrhs,RSB_OI_DMTXORDER,(RSBOI_T*)b.data(),ldb,&rsboi_zero,(RSBOI_T*)retval.data(),ldc);
 		RSBOI_PERROR(errval);
 		return retval;
@@ -1579,7 +1583,7 @@
 	rsb_err_t errval=RSB_ERR_NO_ERROR;
 	CAST_BINOP_ARGS (const octave_sparsersb_mtx&, const octave_matrix&);
 	RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
-	return v1.spmv(v2);
+	return v1.spmm(v2, false);
 }
 
 DEFBINOP(op_trans_mul, sparse_rsb_mtx, matrix)
@@ -1588,39 +1592,7 @@
 	RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
 	rsb_err_t errval=RSB_ERR_NO_ERROR;
 	CAST_BINOP_ARGS (const octave_sparsersb_mtx&, const octave_matrix&);
-
-	if(v1.is_real_type())
-	{
-		const Matrix b = v2.matrix_value ();
-		octave_idx_type b_nc = b.cols ();
-		octave_idx_type b_nr = b.rows ();
-		octave_idx_type ldb=b_nr;
-		octave_idx_type ldc=v1.columns();
-		octave_idx_type nrhs=b_nc;
-		Matrix retval(ldc,nrhs,RSBOI_ZERO);
-		if(v1.rows()!=b_nr) { error("matrices dimensions do not match!\n"); return Matrix(); }
-		//octave_stdout << "have: ldc=" <<ldc << " bc=" << b_nc<< " nrhs=" << nrhs << " retval="<< retval<< "\n";
-
-		errval=rsb_spmm(RSB_TRANSPOSITION_T,&rsboi_pone,v1.mtxAp,nrhs,RSB_OI_DMTXORDER,(RSBOI_T*)b.data(),ldb,&rsboi_zero,(RSBOI_T*)retval.data(),ldc);
-		RSBOI_PERROR(errval);
-		return retval;
-	}
-	else
-	{
-		const ComplexMatrix b = v2.complex_matrix_value ();
-		octave_idx_type b_nc = b.cols ();
-		octave_idx_type b_nr = b.rows ();
-		octave_idx_type ldb=b_nr;
-		octave_idx_type ldc=v1.columns();
-		octave_idx_type nrhs=b_nc;
-		ComplexMatrix retval(ldc,nrhs,RSBOI_ZERO);
-		if(v1.rows()!=b_nr) { error("matrices dimensions do not match!\n"); return ComplexMatrix(); }
-		//octave_stdout << "have: ldc=" <<ldc << " bc=" << b_nc<< " nrhs=" << nrhs << " retval="<< retval<< "\n";
-
-		errval=rsb_spmm(RSB_TRANSPOSITION_T,&rsboi_pone,v1.mtxAp,nrhs,RSB_OI_DMTXORDER,(RSBOI_T*)b.data(),ldb,&rsboi_zero,(RSBOI_T*)retval.data(),ldc);
-		RSBOI_PERROR(errval);
-		return retval;
-	}
+	return v1.spmm(v2, true);
 }
 
 static void install_sparsersb_ops (void)