changeset 11649:0240a1a0928d octave-forge

the tester will handle the case with no UMFPACK installed. implemented ./= and .*= (op_el_ldiv_eq, op_el_mul_eq) with vectors for row wise scaling (this is in contrast to octave's defaults). placeholders for op_el_div_eq, op_el_mul_eq.
author michelemartone
date Fri, 26 Apr 2013 21:48:19 +0000
parents 567933605445
children 782ff6bb04a9
files main/sparsersb/src/sparsersb.cc main/sparsersb/src/sparsersbtester.m
diffstat 2 files changed, 108 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/main/sparsersb/src/sparsersb.cc	Wed Apr 24 20:16:15 2013 +0000
+++ b/main/sparsersb/src/sparsersb.cc	Fri Apr 26 21:48:19 2013 +0000
@@ -525,6 +525,10 @@
 		}
 #endif
 
+		//octave_value::assign_op, int, int, octave_value (&)(const octave_base_value&, const octave_base_value&)
+		//octave_value::assign_op, int, int, octave_value (&)
+		//octave_value  assign_op (const octave_base_value&, const octave_base_value&) {}
+		// octave_value::assign_op octave_value::binary_op_to_assign_op (binary_op op) { assign_op retval; return retval; }
 #if RSBOI_WANT_SUBSREF
 		octave_value subsref (const std::string &type, const std::list<octave_value_list>& idx)
 		{
@@ -678,6 +682,8 @@
 		octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx, const octave_value& rhs)
 		{
 			octave_value retval;
+			rsb_err_t errval=RSB_ERR_NO_ERROR;
+
 			RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
 			switch (type[0])
 			{
@@ -707,12 +713,30 @@
 							if (n_idx == 2 )
 							{
 								idx_vector i = idx.front() (0).index_vector ();
+								idx_vector j = idx.front() (1).index_vector ();
+#if 0
+								// for op_el_div_eq and op_el_mul_eq
+								std :: cout << "ic2 " << i.is_colon() << "\n" ;
+								if( i.is_colon() && !j.is_colon() )
+								{
+									ComplexMatrix cm=rhs.complex_matrix_value();
+									std :: cout << " : , .\n";
+									errval=rsb_mtx_upd_values(this->mtxAp,RSB_ELOPF_SCALE_ROWS,cm.data());
+								}
+								if(!i.is_colon() &&  j.is_colon() )
+								{
+									std :: cout << " . , :\n";
+								}
+								if( i.is_colon() && j.is_colon() )
+								{
+									std :: cout << " : , :\n";
+								}
+#endif
 								if (! error_state)
 								{
 									if(is_real_type())
 									{
 										rsb_err_t errval=RSB_ERR_NO_ERROR;
-										idx_vector j = idx.front() (1).index_vector ();
 										octave_idx_type ii=-1,jj=-1;
 										RSBOI_T rv=rhs.double_value();
 										ii=i(0); jj=j(0);
@@ -732,7 +756,6 @@
 									else
 									{
 										rsb_err_t errval=RSB_ERR_NO_ERROR;
-										idx_vector j = idx.front() (1).index_vector ();
 										octave_idx_type ii=-1,jj=-1;
 										Complex rv=rhs.complex_value();
 										ii=i(0); jj=j(0);
@@ -983,6 +1006,40 @@
 	}
 #endif
 
+octave_value scale_rows(const octave_matrix&v2, bool want_div=false)
+{
+	rsb_err_t errval=RSB_ERR_NO_ERROR;
+	RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
+	if(this->is_real_type())
+	{
+		const Matrix rm = want_div?1.0/v2.matrix_value ():v2.matrix_value ();
+		octave_idx_type b_nc = rm.cols ();
+		octave_idx_type b_nr = rm.rows ();
+		octave_idx_type ldb=b_nr;
+		octave_idx_type ldc=this->columns();
+		octave_idx_type nrhs=b_nc;
+		Matrix retval(ldc,nrhs,RSBOI_ZERO);
+		if(this->rows()!=b_nr) { error("matrices dimensions do not match!\n"); return Matrix(); }
+		errval=rsb_mtx_upd_values(this->mtxAp,RSB_ELOPF_SCALE_ROWS,rm.data());
+		RSBOI_PERROR(errval);
+		return retval;
+	}
+	else
+	{
+		const ComplexMatrix cm = want_div?1.0/v2.complex_matrix_value ():v2.complex_matrix_value ();
+		octave_idx_type b_nc = cm.cols ();
+		octave_idx_type b_nr = cm.rows ();
+		octave_idx_type ldb=b_nr;
+		octave_idx_type ldc=this->columns();
+		octave_idx_type nrhs=b_nc;
+		ComplexMatrix retval(ldc,nrhs,RSBOI_ZERO);
+		if(this->rows()!=b_nr) { error("matrices dimensions do not match!\n"); return ComplexMatrix(); }
+		errval=rsb_mtx_upd_values(this->mtxAp,RSB_ELOPF_SCALE_ROWS,cm.data());
+		RSBOI_PERROR(errval);
+		return retval;
+	}
+}
+
 	private:
 
 		DECLARE_OCTAVE_ALLOCATOR
@@ -1379,6 +1436,32 @@
 }
 #endif
 
+#if RSBOI_WANT_DOUBLE_COMPLEX
+#if 0
+DEFASSIGNOP(rsb_op_el_div_eq, sparse_rsb_mtx, scalar)
+{
+	CAST_BINOP_ARGS (const octave_sparsersb_mtx &, const octave_scalar&);
+	std::cout << "rsb_op_el_div_eq!\n";
+	RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG);
+	return v1.rsboi_get_scaled_copy_inv(v2.complex_value());
+}
+#endif
+
+DEFASSIGNOP(rsb_op_el_mul_eq_sc, sparse_rsb_mtx, matrix)
+{
+	rsb_err_t errval=RSB_ERR_NO_ERROR;
+	CAST_BINOP_ARGS (octave_sparsersb_mtx &, const octave_matrix&);
+	return v1.scale_rows(v2,false);
+}
+
+DEFASSIGNOP(rsb_op_el_div_eq_sc, sparse_rsb_mtx, matrix)
+{
+	rsb_err_t errval=RSB_ERR_NO_ERROR;
+	CAST_BINOP_ARGS (octave_sparsersb_mtx &, const octave_matrix&);
+	return v1.scale_rows(v2,true);
+}
+#endif
+
 DEFBINOP(el_pow, sparse_rsb_mtx, scalar)
 {
 	CAST_BINOP_ARGS (const octave_sparsersb_mtx &, const octave_scalar&);
@@ -1553,12 +1636,16 @@
 	/* pure elemental; scalar and sparse arguments ?! */
 								 // ?
 	INSTALL_BINOP (op_el_ldiv, octave_sparsersb_mtx, , );
+	INSTALL_BINOP (op_el_ldiv_eq, octave_sparsersb_mtx, , ); // errval=rsb_mtx_upd_values(this->mtxAp,RSB_ELOPF_SCALE_ROWS,cm.data());
+	INSTALL_BINOP (op_el_mul_eq, octave_sparsersb_mtx, , ); // diagonal subst ??
 	INSTALL_BINOP (op_el_and, octave_sparsersb_mtx, , );
 	INSTALL_BINOP (op_el_or, octave_sparsersb_mtx, , );
 	/* shift operations: they may be left out from the implementation */
 	INSTALL_BINOP (op_lshift, octave_sparsersb_mtx, , );
 	INSTALL_BINOP (op_rshift, octave_sparsersb_mtx, , );
 	#endif
+	// INSTALL_ASSIGNOP (op_el_div_eq, octave_sparsersb_mtx, octave_matrix, rsb_op_el_div_eq_sc); // errval=rsb_mtx_upd_values(this->mtxAp,RSB_ELOPF_SCALE_ROWS,cm.data());
+	// INSTALL_ASSIGNOP (op_el_mul_eq, octave_sparsersb_mtx, octave_matrix, rsb_op_el_mul_eq_sc);
 	//INSTALL_WIDENOP (octave_sparsersb_mtx, octave_sparse_matrix,octave_sparse_rsb_to_octave_sparse_conv);/* a DEFCONV .. */
 	//INSTALL_ASSIGNCONV (octave_sparsersb_mtx, octave_sparse_matrix,octave_sparse_matrix);/* .. */
 	// no need for the following: need a good conversion function, though
--- a/main/sparsersb/src/sparsersbtester.m	Wed Apr 24 20:16:15 2013 +0000
+++ b/main/sparsersb/src/sparsersbtester.m	Fri Apr 26 21:48:19 2013 +0000
@@ -46,10 +46,12 @@
 end
 
 function testmsg(match,tname,erreason)
-	if(match)
+	if(match>0)
 		printf(" [*] %s test passed",tname)
+	elseif(match==0)
+		printf(" [!] %s test failed",tname)
 	else
-		printf(" [!] %s test failed",tname)
+		printf(" [~] %s ",tname)
 	end
 	if(nargin<3)
 		printf(".\n")
@@ -200,6 +202,15 @@
 	testmsg(match,"pcg");
 end
 
+function hwl=have_working_luinc()
+	try
+	a=luinc (sparse([1,1;1,1]),1);
+	hwl=1;
+	catch 
+	hwl=0;
+	end_try_catch
+end
+
 function match=testpcrm(OM,XM)
 	# FIXME! This test ignores OM and XM !
 	match=1;
@@ -363,8 +374,12 @@
 	match&=testelms(OM,XM);
 	match&=testasgn(OM,XM);
 	if nnz(OM)>1
-		match&=testpcgm(OM,XM);
-		match&=testpcrm(OM,XM);
+		if have_working_luinc()
+			match&=testpcgm(OM,XM);
+			match&=testpcrm(OM,XM);
+		else
+			testmsg(-1,"luinc does not work; probably UMFPACK is not installed: skipping some tests.")
+		endif
 		match&=testmult(OM,XM);
 		match&=testspsv(OM,XM);
 		match&=testnorm(OM,XM);