Mercurial > hg > octave-terminal
changeset 10753:bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 25 Jun 2010 09:50:55 +0200 |
parents | d1b09c44d797 |
children | 92eb5fb58ebc |
files | src/ChangeLog src/oct-map.cc src/oct-map.h src/ov-struct.cc src/ov.cc |
diffstat | 5 files changed, 52 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2010-06-25 Jaroslav Hajek <highegg@gmail.com> + + * oct-map.h (octave_map::octave_map (const dim_vector&, const + octave_fields&)): New internal ctor. + + * oct-map.cc (octave_map::assign): Handle no fields case. + 2010-06-25 Jaroslav Hajek <highegg@gmail.com> * ov-struct.cc (Fcell2struct): Rewrite.
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -833,6 +833,12 @@ optimize_dimensions (); } + else if (nfields () == 0) + { + octave_map tmp (dimensions, rhs.xkeys); + tmp.assign (i, rhs); + *this = tmp; + } else { Array<octave_idx_type> perm; @@ -870,6 +876,12 @@ optimize_dimensions (); } + else if (nfields () == 0) + { + octave_map tmp (dimensions, rhs.xkeys); + tmp.assign (i, j, rhs); + *this = tmp; + } else { Array<octave_idx_type> perm; @@ -907,6 +919,12 @@ optimize_dimensions (); } + else if (nfields () == 0) + { + octave_map tmp (dimensions, rhs.xkeys); + tmp.assign (ia, rhs); + *this = tmp; + } else { Array<octave_idx_type> perm;
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -247,6 +247,9 @@ octave_map (const octave_fields& k) : xkeys (k), xvals (k.nfields ()), dimensions () { } + octave_map (const dim_vector& dv, const octave_fields& k) + : xkeys (k), xvals (k.nfields (), Cell (dv)), dimensions (dv) { } + public: octave_map (void) : xkeys (), xvals (), dimensions () { } @@ -257,7 +260,7 @@ : xkeys (k), xvals (k.length ()), dimensions (1, 1) { } octave_map (const dim_vector& dv, const string_vector& k) - : xkeys (k), xvals (k.length ()), dimensions (dv) { } + : xkeys (k), xvals (k.length (), Cell (dv)), dimensions (dv) { } octave_map (const octave_map& m) : xkeys (m.xkeys), xvals (m.xvals), dimensions (m.dimensions) { }
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -1418,7 +1418,7 @@ bool success = true; octave_idx_type len = 0; - if (extract_keyword (is, "length", len, true) && len >= 0) + if (extract_keyword (is, "length", len) && len >= 0) { if (len > 0) { @@ -2043,14 +2043,31 @@ if (! error_state) { - octave_map map; - Array<idx_vector> ia (std::max (dim+1, vals.ndims ()), 1, - idx_vector::colon); + int nd = std::max (dim+1, vals.ndims ()); + // result dimensions. + dim_vector rdv = vals.dims ().redim (nd); + + assert (ext == rdv(dim)); + if (nd == 2) + { + rdv(0) = rdv(1-dim); + rdv(1) = 1; + } + else + { + for (int i = dim + 1; i < nd; i++) + rdv(i-1) = rdv(i); + + rdv.resize (nd-1); + } + + octave_map map (rdv); + Array<idx_vector> ia (nd, 1, idx_vector::colon); for (octave_idx_type i = 0; i < ext; i++) { ia(dim) = i; - map.setfield (fields(i), vals.index (ia)); + map.setfield (fields(i), vals.index (ia).reshape (rdv)); } retval = map;
--- a/src/ov.cc +++ b/src/ov.cc @@ -2653,6 +2653,7 @@ octave_sparse_matrix::register_type (); octave_sparse_complex_matrix::register_type (); octave_struct::register_type (); + octave_scalar_struct::register_type (); octave_class::register_type (); octave_cs_list::register_type (); octave_magic_colon::register_type ();