Mercurial > hg > octave-avbm
changeset 4936:e63617efbd3f
[project @ 2004-08-06 16:18:17 by jwe]
author | jwe |
---|---|
date | Fri, 06 Aug 2004 16:18:18 +0000 |
parents | 4fc993a4e072 |
children | 4cf211c83158 |
files | src/ChangeLog src/Makefile.in src/oct-map.cc src/oct-map.h src/ov-struct.h |
diffstat | 5 files changed, 63 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2004-08-06 David Bateman <dbateman@free.fr> + + * OPERATORS/op-struct.cc: New file. + * ov-struct.h (octave_struct::resize (const dim_vector&)): + New function. + * oct-map.h (Octave_map::resize (const dim_vector&)): New function. + * ov-map.cc (Octave_map::reshape): + Correct return for same sized reshape. + (Octave_map::resize (const dim_vector&)): New function. + (concat (const Octave_map&, const Octave_map&, const Array<int>&)): + Complete concatenation function. + * Makefile.in (OP_XSRC): Include op-struct.cc in the list. + 2004-08-05 John W. Eaton <jwe@octave.org> * pt-stmt.h (tree_statement::set_command,
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -112,7 +112,7 @@ op-fil-rec.cc op-fil-str.cc op-list.cc op-m-cm.cc \ op-m-cs.cc op-m-m.cc op-m-s.cc op-range.cc op-s-cm.cc \ op-s-cs.cc op-s-m.cc op-s-s.cc op-str-m.cc \ - op-str-s.cc op-str-str.cc op-streamoff.cc \ + op-str-s.cc op-str-str.cc op-streamoff.cc op-struct.cc \ $(INTTYPE_OP_XSRC) OP_SRC := $(addprefix OPERATORS/, $(OP_XSRC))
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -66,8 +66,10 @@ for (const_iterator p = begin (); p != end (); p++) retval.assign (key(p), contents(p).reshape (new_dims)); - dimensions = new_dims; + retval.dimensions = new_dims; } + else + retval = *this; return retval; } @@ -88,13 +90,51 @@ return retval; } +Octave_map +Octave_map::resize (const dim_vector& dv) const +{ + Octave_map retval; + + if (dv != dims ()) + { + for (const_iterator p = begin (); p != end (); p++) + { + Cell tmp = contents(p); + tmp.resize(dv); + retval.assign (key(p), tmp); + } + + retval.dimensions = dv; + } + else + retval = *this; + + + return retval; +} + Octave_map concat (const Octave_map& ra, const Octave_map& rb, const Array<int>& ra_idx) { - // XXX FIXME XXX + if (ra.length() != rb.length()) + { + error ("field name mismatch in structure concatenation"); + return Octave_map (); + } + Octave_map retval; - //Octave_map retval (ra); - //::concat_ra (retval, rb, dim) + for (Octave_map::const_iterator pa = ra.begin (); pa != ra.end (); pa++) + { + Octave_map::const_iterator pb = rb.seek (ra.key(pa)); + if (pa == rb.end()) + { + error ("field name mismatch in structure concatenation"); + return Octave_map (); + } + + retval.assign (ra.key(pa), ra.contents(pa).insert(rb.contents(pb), + ra_idx)); + } return retval; }
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -116,6 +116,8 @@ Octave_map reshape (const dim_vector& new_dims) const; + Octave_map resize (const dim_vector& dv) const; + int numel (void) const; friend Octave_map concat (const Octave_map& ra, const Octave_map& rb,
--- a/src/ov-struct.h +++ b/src/ov-struct.h @@ -93,6 +93,9 @@ octave_value reshape (const dim_vector& new_dims) const { return map.reshape (new_dims); } + octave_value resize (const dim_vector& dv) const + { return map.resize (dv); } + bool is_defined (void) const { return true; } bool is_constant (void) const { return true; }