Mercurial > hg > octave-terminal
changeset 5570:3074a549d644
[project @ 2005-12-08 21:01:50 by jwe]
author | jwe |
---|---|
date | Thu, 08 Dec 2005 21:01:50 +0000 |
parents | f7b4dfd541d1 |
children | 9fc532d861d4 |
files | src/Cell.cc src/Cell.h src/ChangeLog src/lex.l src/pt-loop.cc |
diffstat | 5 files changed, 79 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Cell.cc +++ b/src/Cell.cc @@ -115,6 +115,31 @@ } Cell +Cell::column (octave_idx_type i) const +{ + Cell retval; + + if (ndims () < 3) + { + if (i < 0 || i >= cols ()) + error ("invalid column selection"); + else + { + octave_idx_type nr = rows (); + + retval.resize (dim_vector (nr, 1)); + + for (octave_idx_type j = 0; j < nr; j++) + retval.xelem (j) = elem (j, i); + } + } + else + error ("Cell::column: requires 2-d cell array"); + + return retval; +} + +Cell Cell::concat (const Cell& rb, const Array<octave_idx_type>& ra_idx) { return insert (rb, ra_idx);
--- a/src/Cell.h +++ b/src/Cell.h @@ -90,6 +90,8 @@ Cell reshape (const dim_vector& new_dims) const { return ArrayN<octave_value>::reshape (new_dims); } + Cell column (octave_idx_type i) const; + // XXX FIXME XXX boolMatrix all (int /* dim */ = 0) const { return boolMatrix (); }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ +2005-12-08 John W. Eaton <jwe@octave.org> + + * Cell.cc (Cell::column): New function. + * pt-loop.cc (DO_ND_LOOP): Simplify. + (simple_for_loop_command::eval): Correctly handle N-d numeric and + cell arrays when only the first dimension is 0. + 2005-12-07 John W. Eaton <jwe@octave.org> + * lex.l (NL): Also accept '\r'. + * error.cc (Vbacktrace_on_warning, warning_options, Vlast_warning_id, Vlast_error_id): New file-scope variables. (Vwarning_frequency, Vwarning_option): Delete unused variables.
--- a/src/lex.l +++ b/src/lex.l @@ -275,7 +275,7 @@ D [0-9] S [ \t] -NL ((\n)|(\r\n)) +NL ((\n)|(\r)|(\r\n)) SNL ({S}|{NL}) EL (\.\.\.) BS (\\)
--- a/src/pt-loop.cc +++ b/src/pt-loop.cc @@ -238,20 +238,25 @@ } \ while (0) -#define DO_ND_LOOP(arg) \ +#define DO_ND_LOOP(TYPE, ARG) \ do \ { \ - int ndims = dv.length (); \ - Array<idx_vector> idx; \ - octave_idx_type steps = dv.numel () / dv (0); \ - idx.resize (ndims, idx_vector (static_cast<octave_idx_type> (1))); \ - idx (0) = idx_vector (':'); \ + octave_idx_type steps = dv(1); \ \ for (octave_idx_type i = 0; i < steps; i++) \ { \ MAYBE_DO_BREAKPOINT; \ \ - octave_value val (arg.index(idx)); \ + TYPE tmp; \ + \ + int nr = ARG.rows (); \ + \ + tmp.resize (dim_vector (nr, 1)); \ + \ + for (int j = 0; j < nr; j++) \ + tmp.xelem (j) = ARG.xelem (j, i); \ + \ + octave_value val (tmp); \ \ bool quit = false; \ \ @@ -261,14 +266,6 @@ if (quit) \ break; \ \ - for (int j = 1; j < ndims; j++) \ - { \ - idx(j) = idx_vector (idx(j)(0) + 2); \ - if (idx(j)(0) < dv(j)) \ - break; \ - else \ - idx(j) = idx_vector (static_cast<octave_idx_type> (1)); \ - } \ } \ } \ while (0) @@ -382,12 +379,27 @@ if (error_state) goto cleanup; - if (dv.numel () > 0) + // XXX FIXME XXX -- maybe we need a function for this? + int ndims = dv.length (); + for (int i = 2; i < ndims; i++) + dv(1) *= dv(i); + + if (dv(1) > 0) { if (rhs.is_real_type ()) - DO_ND_LOOP(m_tmp); + { + if (ndims > 2) + m_tmp = m_tmp.reshape (dv); + + DO_ND_LOOP(NDArray, m_tmp); + } else - DO_ND_LOOP(cm_tmp); + { + if (ndims > 2) + cm_tmp = cm_tmp.reshape (dv); + + DO_ND_LOOP(ComplexNDArray, cm_tmp); + } } } else if (rhs.is_map ()) @@ -419,8 +431,18 @@ dim_vector dv = c_tmp.dims (); - if (dv.numel () > 0) - DO_ND_LOOP(c_tmp); + // XXX FIXME XXX -- maybe we need a function for this? + int ndims = dv.length (); + for (int i = 2; i < ndims; i++) + dv(1) *= dv(i); + + if (dv(1) > 0) + { + if (ndims > 2) + c_tmp = c_tmp.reshape (dv); + + DO_ND_LOOP(Cell, c_tmp); + } } else {