Mercurial > forge
changeset 11650:782ff6bb04a9 octave-forge
moving implementation of spmv from operator to method.
author | michelemartone |
---|---|
date | Fri, 26 Apr 2013 23:06:58 +0000 |
parents | 0240a1a0928d |
children | 879b7c96162b |
files | main/sparsersb/src/sparsersb.cc |
diffstat | 1 files changed, 37 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/main/sparsersb/src/sparsersb.cc Fri Apr 26 21:48:19 2013 +0000 +++ b/main/sparsersb/src/sparsersb.cc Fri Apr 26 23:06:58 2013 +0000 @@ -1040,6 +1040,41 @@ } } +octave_value spmv(const octave_matrix&v2)const +{ + rsb_err_t errval=RSB_ERR_NO_ERROR; + RSBOI_DEBUG_NOTICE(RSBOI_D_EMPTY_MSG); + + if(this->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=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(); } + 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; + } + 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=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(); } + 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; + } +} + private: DECLARE_OCTAVE_ALLOCATOR @@ -1544,34 +1579,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); - 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.rows(); - octave_idx_type nrhs=b_nc; - Matrix retval(ldc,nrhs,RSBOI_ZERO); - if(v1.columns()!=b_nr) { error("matrices dimensions do not match!\n"); return Matrix(); } - errval=rsb_spmm(RSB_TRANSPOSITION_N,&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.rows(); - octave_idx_type nrhs=b_nc; - ComplexMatrix retval(ldc,nrhs,RSBOI_ZERO); - if(v1.columns()!=b_nr) { error("matrices dimensions do not match!\n"); return ComplexMatrix(); } - errval=rsb_spmm(RSB_TRANSPOSITION_N,&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.spmv(v2); } DEFBINOP(op_trans_mul, sparse_rsb_mtx, matrix) @@ -1580,6 +1588,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 (); @@ -1592,7 +1601,6 @@ 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_spmv(RSB_TRANSPOSITION_T,&rsboi_pone,v1.mtxAp,(RSBOI_T*)b.data(),RSBOI_OV_STRIDE,&rsboi_pone,(RSBOI_T*)retval.data(),RSBOI_OV_STRIDE); 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; @@ -1609,7 +1617,6 @@ 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_spmv(RSB_TRANSPOSITION_T,&rsboi_pone,v1.mtxAp,(RSBOI_T*)b.data(),RSBOI_OV_STRIDE,&rsboi_pone,(RSBOI_T*)retval.data(),RSBOI_OV_STRIDE); 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;