Mercurial > hg > octave-lyh
changeset 6006:588dfb92e19e
[project @ 2006-09-27 14:54:04 by jwe]
author | jwe |
---|---|
date | Wed, 27 Sep 2006 14:54:05 +0000 |
parents | b4351cfb5659 |
children | 52b520087c50 |
files | src/ChangeLog src/DLD-FUNCTIONS/sparse.cc src/Makefile.in |
diffstat | 3 files changed, 9 insertions(+), 189 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,11 @@ -2006-05-17 Bill Denney <bill@givebillmoney.com> +2006-09-27 David Bateman <dbateman@free.fr> + + * DLD-FUNCTIONS/sparse.cc (spfind, sparse_find): Delete. + * DLD-FUNCTIONS/spfind.cc: New file implementating compatible + sparse find function. + * Makefile.in (DLD_XSRC): Add spfind.cc. + +2006-09-26 Bill Denney <bill@givebillmoney.com> * DLD-FUNCTIONS/find.cc (find_nonzero_elem_idx, Ffind): Handle direction and limit on number of elements to find.
--- a/src/DLD-FUNCTIONS/sparse.cc +++ b/src/DLD-FUNCTIONS/sparse.cc @@ -399,193 +399,6 @@ return retval; } -static octave_value_list -sparse_find (const SparseMatrix& v) -{ - octave_value_list retval; - octave_idx_type nnz = v.nnz (); - dim_vector dv = v.dims (); - octave_idx_type nr = dv(0); - octave_idx_type nc = dv (1); - - ColumnVector I (nnz), J (nnz); - ColumnVector S (nnz); - - for (octave_idx_type i = 0, cx = 0; i < nc; i++) - { - OCTAVE_QUIT; - for (octave_idx_type j = v.cidx(i); j < v.cidx(i+1); j++ ) - { - I (cx) = static_cast<double> (v.ridx(j) + 1); - J (cx) = static_cast<double> (i + 1); - S (cx) = v.data(j); - cx++; - } - } - - if (dv(0) == 1) - { - retval(0) = I.transpose (); - retval(1) = J.transpose (); - retval(2) = S.transpose (); - } - else - { - retval(0) = I; - retval(1) = J; - retval(2) = S; - } - retval(3) = static_cast<double> (nr); - retval(4) = static_cast<double> (nc); - - return retval; -} - -static octave_value_list -sparse_find (const SparseComplexMatrix& v) -{ - octave_value_list retval; - octave_idx_type nnz = v.nnz (); - dim_vector dv = v.dims (); - octave_idx_type nr = dv(0); - octave_idx_type nc = dv (1); - - ColumnVector I (nnz), J (nnz); - ComplexColumnVector S (nnz); - - for (octave_idx_type i = 0, cx = 0; i < nc; i++) - { - OCTAVE_QUIT; - for (octave_idx_type j = v.cidx(i); j < v.cidx(i+1); j++ ) - { - I (cx) = static_cast<double> (v.ridx(j) + 1); - J (cx) = static_cast<double> (i + 1); - S (cx) = v.data(j); - cx++; - } - } - - if (dv(0) == 1) - { - retval(0) = I.transpose (); - retval(1) = J.transpose (); - retval(2) = S.transpose (); - } - else - { - retval(0) = I; - retval(1) = J; - retval(2) = S; - } - retval(3) = static_cast<double> (nr); - retval(4) = static_cast<double> (nc); - - return retval; -} - -static octave_value_list -sparse_find (const SparseBoolMatrix& v) -{ - octave_value_list retval; - octave_idx_type nnz = v.nnz (); - dim_vector dv = v.dims (); - octave_idx_type nr = dv(0); - octave_idx_type nc = dv (1); - - ColumnVector I (nnz), J (nnz); - ColumnVector S (nnz); - - for (octave_idx_type i = 0, cx = 0; i < nc; i++) - { - OCTAVE_QUIT; - for (octave_idx_type j = v.cidx(i); j < v.cidx(i+1); j++ ) - { - I (cx) = static_cast<double> (v.ridx(j) + 1); - J (cx) = static_cast<double> (i + 1); - S (cx) = static_cast<double> (v.data(j)); - cx++; - } - } - - if (dv(0) == 1) - { - retval(0) = I.transpose (); - retval(1) = J.transpose (); - retval(2) = S.transpose (); - } - else - { - retval(0) = I; - retval(1) = J; - retval(2) = S; - } - retval(3) = static_cast<double> (nr); - retval(4) = static_cast<double> (nc); - - return retval; -} - -// PKG_ADD: dispatch ("find", "spfind", "sparse matrix"); -// PKG_ADD: dispatch ("find", "spfind", "sparse complex matrix"); -// PKG_ADD: dispatch ("find", "spfind", "sparse bool matrix"); -DEFUN_DLD (spfind, args, nargout , - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[...] =} spfind (...)\n\ -SPFIND: a sparse version of the find operator\n\ -@enumerate\n\ - @item\n\ -@var{x }= spfind( @var{a })\n\ - @itemize @w\n\ -is analagous to @var{x}= find(@var{A}(:))@*\n\ -where @var{A}= full(@var{a})\n\ - @end itemize\n\ - @item\n\ -[@var{i},@var{j},@var{v},@var{nr},@var{nc}] = spfind( @var{a} )\n\ - @itemize @w\n\ -returns column vectors @var{i},@var{j},@var{v} such that@*\n\ -@var{a}= sparse(@var{i},@var{j},@var{v},@var{nr},@var{nc})\n\ - @end itemize\n\ -@end enumerate\n\ -@seealso{sparse}\n\ -@end deftypefn") -{ - octave_value_list retval; - int nargin = args.length (); - - if (nargin != 1) - { - print_usage (); - return retval; - } - - - octave_value arg = args(0); - - if (arg.is_sparse_type ()) - { - if (arg.type_name () == "sparse matrix") - retval = sparse_find (args(0).sparse_matrix_value ()); - else if (arg.type_name () == "sparse complex matrix" ) - retval = sparse_find (args(0).sparse_complex_matrix_value ()); - else if (arg.type_name () == "sparse bool matrix" ) - retval = sparse_find (args(0).sparse_bool_matrix_value ()); - else - gripe_wrong_type_arg ("spfind", arg); - } - else - gripe_wrong_type_arg ("spfind", arg); - - if (nargout == 1 || nargout ==0 ) - { - // only find location as fortran index - octave_value_list tmp; - tmp(0) = retval(0) + (retval(1)-1)*retval(3); - retval = tmp; - } - - return retval; -} - #define SPARSE_DIM_ARG_BODY(NAME, FUNC) \ int nargin = args.length(); \ octave_value retval; \
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -51,7 +51,7 @@ givens.cc hess.cc inv.cc kron.cc lpsolve.cc lsode.cc \ lu.cc luinc.cc matrix_type.cc minmax.cc pinv.cc qr.cc \ quad.cc qz.cc rand.cc regexp.cc schur.cc sort.cc sparse.cc \ - spchol.cc spdet.cc spkron.cc splu.cc spparms.cc spqr.cc \ + spchol.cc spdet.cc spfind.cc spkron.cc splu.cc spparms.cc spqr.cc \ sqrtm.cc svd.cc syl.cc time.cc \ __gnuplot_raw__.l __glpk__.cc __pchip_deriv__.cc __qp__.cc