Mercurial > hg > octave-lojdl
changeset 4561:e84592dc70b9
[project @ 2003-10-28 21:07:59 by jwe]
author | jwe |
---|---|
date | Tue, 28 Oct 2003 21:07:59 +0000 |
parents | 661246155bbc |
children | 4699bdb4c362 |
files | libcruft/ChangeLog src/ChangeLog src/load-save.cc src/oct-map.cc src/oct-map.h src/ov-struct.cc src/pt-loop.cc |
diffstat | 7 files changed, 93 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/libcruft/ChangeLog +++ b/libcruft/ChangeLog @@ -1,3 +1,8 @@ +2003-10-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * misc/quit.h (octave_interrupt_hook, octave_bad_alloc_hook): + Move declarations outside of extern "C" block. + 2003-10-27 John W. Eaton <jwe@bevo.che.wisc.edu> * misc/f77-fcn.h: Only use inline if this is C++.
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,19 @@ 2003-10-28 John W. Eaton <jwe@bevo.che.wisc.edu> + * load-save.cc (save_mat5_binary_element): Use numel instead of + array_length. + * ov-struct.cc (octave_struct::print_raw): Likewise. + * pt-loop.cc (tree_complex_for_command::eval): Likewise. + * oct-map.cc (Octave_map::numel): New function. + * oct-map.h: Provide decl. + + * oct-map.cc, oct-map.h (Octave_map::array_length): Delete. + (common_size): New static function. + (Octave_map::assign): Make resizing work for N-d cell objects. + + * oct-map.cc (Octave_map::dims): New function. + * oct-map.h: Provide decl. + * pr-output.cc (print_empty_nd_array): New static function. (PRINT_ND_ARRAY): Use it.
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -4422,7 +4422,7 @@ os.write (buf, 32); } - int len = m.array_length (); + int len = m.numel (); for (Octave_map::iterator i = m.begin (); i != m.end (); i++) {
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -57,15 +57,19 @@ } int -Octave_map::array_length (void) const +Octave_map::numel (void) const { - if (array_len == 0 && length () != 0) + int retval; + + if (empty ()) + retval = 0; + else { - const_iterator p = begin (); - array_len = contents(p).length (); + Cell tmp = contents (begin ()); + retval = tmp.numel (); } - return array_len; + return retval; } static string_vector @@ -120,6 +124,40 @@ return *this; } +static dim_vector +common_size (const dim_vector& a, const dim_vector& b) +{ + dim_vector retval; + + int a_len = a.length (); + int b_len = b.length (); + + int new_len = std::max (a_len, b_len); + int min_len = std::min (a_len, b_len); + + retval.resize (new_len); + + for (int i = 0; i < min_len; i++) + retval(i) = std::max (a(i), b(i)); + + if (a_len < b_len) + { + for (int i = min_len; i < b_len; i++) + retval(i) = b(i); + } + else if (a_len > b_len) + { + for (int i = min_len; i < a_len; i++) + retval(i) = a(i); + } + + std::cerr << a.str () << std::endl; + std::cerr << b.str () << std::endl; + std::cerr << retval.str () << std::endl; + + return retval; +} + Octave_map& Octave_map::assign (const octave_value_list& idx, const std::string& key, const Cell& rhs) @@ -132,21 +170,23 @@ if (! error_state) { - int rhs_len = tmp.length (); + dim_vector rhs_dims = tmp.dims (); - int len = array_length (); + dim_vector curr_dims = dims (); + + dim_vector new_dims = common_size (rhs_dims, curr_dims); - if (rhs_len < len) + if (new_dims != rhs_dims) { - tmp.resize_and_fill (len, fill_value); + tmp.resize_and_fill (new_dims, fill_value); } - else if (rhs_len > len) + else if (new_dims != curr_dims) { for (iterator p = begin (); p != end (); p++) - contents(p).resize_and_fill (rhs_len, fill_value); + contents(p).resize_and_fill (rhs_dims, fill_value); + } - array_len = rhs_len; - } + dimensions = new_dims; map[key] = tmp; } @@ -161,9 +201,7 @@ map[key] = rhs; else { - Cell tmp = contents (begin ()); - - if (tmp.length () == rhs.length ()) + if (dimensions () == rhs.dims ()) map[key] = rhs; else error ("invalid structure assignment");
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -42,36 +42,30 @@ typedef std::map<std::string, Cell>::iterator iterator; typedef std::map<std::string, Cell>::const_iterator const_iterator; - Octave_map (void) : map (), array_len (0) { } + Octave_map (void) : map (), dimensions (0, 0) { } Octave_map (const std::string& key, const octave_value& value) - : map (), array_len (1) - { - map[key] = Cell (value); - } + : map (), dimensions (1, 1) + { map[key] = Cell (value); } Octave_map (const std::string& key, const Cell& vals) - : map (), array_len (vals.length ()) - { - map[key] = vals; - } + : map (), dimensions (vals.dims ()) + { map[key] = vals; } Octave_map (const std::string& key, const octave_value_list& val_list) - : map (), array_len (val_list.length ()) - { - map[key] = val_list; - } + : map (), dimensions (1, val_list.length ()) + { map[key] = val_list; } - Octave_map (const Octave_map& m) - : map (m.map), array_len (m.array_len) { } + Octave_map (const Octave_map& m) : map (m.map), dimensions (m.dimensions) { } Octave_map& operator = (const Octave_map& m) { if (this != &m) { map = m.map; - array_len = m.array_len; + dimensions = m.dimensions; } + return *this; } @@ -116,11 +110,13 @@ string_vector keys (void) const; - int rows (void) const { return 1; } + int rows (void) const { return dimensions(0); } + + int columns (void) const { return dimensions(1); } - int columns (void) const { return array_length (); } + dim_vector dims (void) const { return dimensions; } - int array_length (void) const; + int numel (void) const; Octave_map& assign (const octave_value_list& idx, const Octave_map& rhs); @@ -136,8 +132,8 @@ // The map of names to values. std::map<std::string, Cell> map; - // The current size of this struct array; - mutable int array_len; + // The current size. + mutable dim_vector dimensions; }; #endif