# HG changeset patch # User dbateman # Date 1193055140 0 # Node ID fbf8576cf399770ce541516f4244df4d852d3bd3 # Parent 271fa61d8faee877b49b8ce36456c80fd333ed1f [project @ 2007-10-22 12:12:20 by dbateman] diff -r 271fa61d8fae -r fbf8576cf399 src/ChangeLog --- a/src/ChangeLog Mon Oct 22 11:52:39 2007 +0000 +++ b/src/ChangeLog Mon Oct 22 12:12:20 2007 +0000 @@ -2,6 +2,19 @@ * data.cc (Ftic, Ftoc, Fcputime): New builtin versions of the benchmarking functions for speed. + * oct-map.cc (Octave_map::squeeze, Octave_map::permute): New methods. + (Octave_map::index (const octave_value_list&, bool)): Add resize_ok + argument, define as const and use const_iterator internally. + (Octave_map::index (idx_vector&, ...), Octave_map::index (Array + &, ...)): New forms of the index function. + * oct-map.h (squeeze, permute, indx (const octave_value_list&, bool), + index (idx_vector&, ...), index (Array &, ...)): Add + or update declaration. + * ov-struct.cc (octave_struct::do_index_op (const octave_value_list&, + bool)): New method. + * ov-struct.h (do_index_op (const octave_value_list&, bool)): Declare + it. + (squeeze (void), permute (const Arra&, bool): New methods. 2007-10-19 Kai Habel diff -r 271fa61d8fae -r fbf8576cf399 src/oct-map.cc --- a/src/oct-map.cc Mon Oct 22 11:52:39 2007 +0000 +++ b/src/oct-map.cc Mon Oct 22 12:12:20 2007 +0000 @@ -49,6 +49,42 @@ error ("Octave_map: expecting keys to be cellstr"); } +Octave_map +Octave_map::squeeze (void) const +{ + Octave_map retval (dims ().squeeze ()); + + for (const_iterator pa = begin (); pa != end (); pa++) + { + Cell tmp = contents (pa).squeeze (); + + if (error_state) + break; + + retval.assign (key (pa), tmp); + } + + return retval; +} + +Octave_map +Octave_map::permute (const Array& vec, bool inv) const +{ + Octave_map retval (dims ()); + + for (const_iterator pa = begin (); pa != end (); pa++) + { + Cell tmp = contents (pa).permute (vec, inv); + + if (error_state) + break; + + retval.assign (key (pa), tmp); + } + + return retval; +} + Cell& Octave_map::contents (const std::string& k) { @@ -422,15 +458,15 @@ } Octave_map -Octave_map::index (const octave_value_list& idx) +Octave_map::index (const octave_value_list& idx, bool resize_ok) const { Octave_map retval; if (idx.length () > 0) { - for (iterator p = begin (); p != end (); p++) + for (const_iterator p = begin (); p != end (); p++) { - Cell tmp = contents(p).index (idx); + Cell tmp = contents(p).index (idx, resize_ok); if (error_state) break; @@ -444,6 +480,62 @@ return retval; } +Octave_map +Octave_map::index (idx_vector& i, int resize_ok, const octave_value& rfv) const +{ + Octave_map retval (dims ()); + + for (const_iterator p = begin (); p != end (); p++) + { + Cell tmp = contents (p).index (i, resize_ok, rfv); + + if (error_state) + break; + + retval.assign (key (p), tmp); + } + + return retval; +} + +Octave_map +Octave_map::index (idx_vector& i, idx_vector& j, int resize_ok, + const octave_value& rfv) const +{ + Octave_map retval (dims ()); + + for (const_iterator p = begin (); p != end (); p++) + { + Cell tmp = contents (p).index (i, j, resize_ok, rfv); + + if (error_state) + break; + + retval.assign (key (p), tmp); + } + + return retval; +} + +Octave_map +Octave_map::index (Array& ra_idx, int resize_ok, + const octave_value& rfv) const +{ + Octave_map retval (dims ()); + + for (const_iterator p = begin (); p != end (); p++) + { + Cell tmp = contents (p).index (ra_idx, resize_ok, rfv); + + if (error_state) + break; + + retval.assign (key (p), tmp); + } + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r 271fa61d8fae -r fbf8576cf399 src/oct-map.h --- a/src/oct-map.h Mon Oct 22 11:52:39 2007 +0000 +++ b/src/oct-map.h Mon Oct 22 12:12:20 2007 +0000 @@ -87,6 +87,10 @@ ~Octave_map (void) { } + Octave_map squeeze (void) const; + + Octave_map permute (const Array& vec, bool inv = false) const; + // This is the number of keys. octave_idx_type nfields (void) const { return map.size (); } @@ -172,7 +176,17 @@ Octave_map& assign (const std::string& k, const Cell& rhs); - Octave_map index (const octave_value_list& idx); + Octave_map index (const octave_value_list& idx, + bool resize_ok = false) const; + + Octave_map index (idx_vector& i, int resize_ok = 0, + const octave_value& rfv = Cell::resize_fill_value ()) const; + + Octave_map index (idx_vector& i, idx_vector& j, int resize_ok = 0, + const octave_value& rfv = Cell::resize_fill_value ()) const; + + Octave_map index (Array& ra_idx, int resize_ok = 0, + const octave_value& rfv = Cell::resize_fill_value ()) const; private: diff -r 271fa61d8fae -r fbf8576cf399 src/ov-struct.cc --- a/src/ov-struct.cc Mon Oct 22 11:52:39 2007 +0000 +++ b/src/ov-struct.cc Mon Oct 22 12:12:20 2007 +0000 @@ -403,6 +403,68 @@ return retval; } +octave_value +octave_struct::do_index_op (const octave_value_list& idx, bool resize_ok) +{ + octave_value retval; + + octave_idx_type n_idx = idx.length (); + + int nd = map.ndims (); + + switch (n_idx) + { + case 0: + retval = map; + break; + + case 1: + { + idx_vector i = idx (0).index_vector (); + + if (! error_state) + retval = map.index (i, resize_ok, Cell::resize_fill_value ()); + } + break; + + default: + { + if (n_idx == 2 && nd == 2) + { + idx_vector i = idx (0).index_vector (); + + if (! error_state) + { + idx_vector j = idx (1).index_vector (); + + if (! error_state) + retval = map.index (i, j, resize_ok, + Cell::resize_fill_value ()); + } + } + else + { + Array idx_vec (n_idx); + + for (octave_idx_type i = 0; i < n_idx; i++) + { + idx_vec(i) = idx(i).index_vector (); + + if (error_state) + break; + } + + if (! error_state) + retval = map.index (idx_vec, resize_ok, + Cell::resize_fill_value ()); + } + } + break; + } + + return retval; +} + size_t octave_struct::byte_size (void) const { diff -r 271fa61d8fae -r fbf8576cf399 src/ov-struct.h --- a/src/ov-struct.h Mon Oct 22 11:52:39 2007 +0000 +++ b/src/ov-struct.h Mon Oct 22 12:12:20 2007 +0000 @@ -83,6 +83,14 @@ const std::list& idx, const octave_value& rhs); + octave_value squeeze (void) const { return map.squeeze (); } + + octave_value permute (const Array& vec, bool inv = false) const + { return map.permute (vec, inv); } + + octave_value do_index_op (const octave_value_list& idx, + bool resize_ok = false); + dim_vector dims (void) const { return map.dims (); } size_t byte_size (void) const;