Mercurial > hg > octave-terminal
changeset 5571:9fc532d861d4
[project @ 2005-12-12 20:45:16 by jwe]
author | jwe |
---|---|
date | Mon, 12 Dec 2005 20:45:17 +0000 |
parents | 3074a549d644 |
children | c45cf76df06f |
files | src/ChangeLog src/OPERATORS/op-struct.cc src/oct-map.cc src/oct-map.h |
diffstat | 4 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2005-12-12 David Bateman <dbateman@free.fr> + + * OPERATORS/op-struct.cc (transpose): New function. + (install_struct_ops): Install it. + + * oct-map.cc (Octave_map::transpose): New function. + * oct-map.h: Provide decl. + 2005-12-08 John W. Eaton <jwe@octave.org> * Cell.cc (Cell::column): New function.
--- a/src/OPERATORS/op-struct.cc +++ b/src/OPERATORS/op-struct.cc @@ -34,11 +34,27 @@ // struct ops. +DEFUNOP (transpose, cell) +{ + CAST_UNOP_ARG (const octave_struct&); + + if (v.ndims () > 2) + { + error ("transpose not defined for N-d objects"); + return octave_value (); + } + else + return octave_value (v.map_value().transpose ()); +} + DEFNDCATOP_FN (struct_struct, struct, struct, map, map, concat) void install_struct_ops (void) { + INSTALL_UNOP (op_transpose, octave_struct, transpose); + INSTALL_UNOP (op_hermitian, octave_struct, transpose); + INSTALL_CATOP (octave_struct, octave_struct, struct_struct); }
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -87,6 +87,20 @@ } Octave_map +Octave_map::transpose (void) const +{ + assert (ndims () == 2); + dim_vector dv = dims (); + + Octave_map retval (dim_vector (dv(1), dv(0))); + + for (const_iterator p = begin (); p != end (); p++) + retval.assign (key(p), Cell (contents(p).transpose ())); + + return retval; +} + +Octave_map Octave_map::reshape (const dim_vector& new_dims) const { Octave_map retval;