Mercurial > hg > octave-max
changeset 6813:75d99621f850
[project @ 2007-08-14 17:14:18 by jwe]
author | jwe |
---|---|
date | Tue, 14 Aug 2007 17:14:19 +0000 |
parents | da3d4bb32f35 |
children | 8c89a644df8a |
files | liboctave/ChangeLog liboctave/Sparse.cc scripts/ChangeLog scripts/plot/meshgrid.m |
diffstat | 4 files changed, 35 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2007-08-14 John W. Eaton <jwe@octave.org> + + * Sparse.cc (Sparse<T>::permute): permutation vector is zero based. + Simplify. + 2007-08-10 Michael Goffioul <michael.goffioul@gmail.com> * file-stat.cc (file_stat::update_internal) [__WIN32__]:
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -780,46 +780,28 @@ Sparse<T> Sparse<T>::permute (const Array<octave_idx_type>& perm_vec, bool) const { - dim_vector dv = dims (); - dim_vector dv_new; - - octave_idx_type nd = dv.length (); - - dv_new.resize (nd); - - // Need this array to check for identical elements in permutation array. - Array<bool> checked (nd, false); - - // Find dimension vector of permuted array. - for (octave_idx_type i = 0; i < nd; i++) + // The only valid permutations of a sparse array are [1, 2] and [2, 1]. + + bool fail = false; + bool transpose = false; + + if (perm_vec.length () == 2) { - octave_idx_type perm_el = perm_vec.elem (i); - - if (perm_el > dv.length () || perm_el < 1) - { - (*current_liboctave_error_handler) - ("permutation vector contains an invalid element"); - - return Sparse<T> (); - } - - if (checked.elem(perm_el - 1)) - { - (*current_liboctave_error_handler) - ("PERM cannot contain identical elements"); - - return Sparse<T> (); - } + if (perm_vec(0) == 0 && perm_vec(1) == 1) + /* do nothing */; + else if (perm_vec(0) == 1 && perm_vec(1) == 0) + transpose = true; else - checked.elem(perm_el - 1) = true; - - dv_new (i) = dv (perm_el - 1); + fail = true; } - - if (dv_new == dv) - return *this; else - return transpose (); + fail = true; + + if (fail) + (*current_liboctave_error_handler) + ("permutation vector contains an invalid element"); + + return transpose ? this->transpose () : *this; } template <class T>
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2007-08-13 John W. Eaton <jwe@octave.org> + + * plot/meshgrid.m: Use repmat instead of multiplication. + 2007-08-10 Peter A. Gustafson <petegus@umich.edu> * plot/__go_draw_axes__.m: Add axes position to the usingclause,
--- a/scripts/plot/meshgrid.m +++ b/scripts/plot/meshgrid.m @@ -44,10 +44,13 @@ y = x; endif + ## Use repmat to ensure that the result values have the same type as + ## the arguments. + if (nargout < 3) if (isvector (x) && isvector (y)) - xx = ones (length (y), 1) * x(:).'; - yy = y(:) * ones (1, length (x)); + xx = repmat (x(:).', length (y), 1); + yy = repmat (y(:), 1, length (x)); else error ("meshgrid: arguments must be vectors"); endif @@ -59,11 +62,11 @@ lenx = length (x); leny = length (y); lenz = length (z); - xx = repmat (ones (leny, 1) * x(:).', [1, 1, lenz]); - yy = repmat (y(:) * ones (1, lenx), [1, 1, lenz]); + xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]); + yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]); zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz); else - error ("meshgrid: arguments must be vectors"); + error ("meshgrid: arguments must be vectors"); endif endif