Mercurial > hg > octave-terminal
changeset 7046:fbf8576cf399
[project @ 2007-10-22 12:12:20 by dbateman]
author | dbateman |
---|---|
date | Mon, 22 Oct 2007 12:12:20 +0000 |
parents | 271fa61d8fae |
children | d00f05fb8105 |
files | src/ChangeLog src/oct-map.cc src/oct-map.h src/ov-struct.cc src/ov-struct.h |
diffstat | 5 files changed, 193 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -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 + <idx_vector>&, ...)): New forms of the index function. + * oct-map.h (squeeze, permute, indx (const octave_value_list&, bool), + index (idx_vector&, ...), index (Array <idx_vector>&, ...)): 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<int>&, bool): New methods. 2007-10-19 Kai Habel <kai.habel@gmx.de>
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -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<int>& 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<idx_vector>& 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++ ***
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -87,6 +87,10 @@ ~Octave_map (void) { } + Octave_map squeeze (void) const; + + Octave_map permute (const Array<int>& 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<idx_vector>& ra_idx, int resize_ok = 0, + const octave_value& rfv = Cell::resize_fill_value ()) const; private:
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -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_vector> 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 {
--- a/src/ov-struct.h +++ b/src/ov-struct.h @@ -83,6 +83,14 @@ const std::list<octave_value_list>& idx, const octave_value& rhs); + octave_value squeeze (void) const { return map.squeeze (); } + + octave_value permute (const Array<int>& 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;