# HG changeset patch # User jwe # Date 1134420317 0 # Node ID 9fc532d861d4933b8b1ebbcf0b8ce813e697f71d # Parent 3074a549d64455f28783591c40c9007f42ecf8bf [project @ 2005-12-12 20:45:16 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2005-12-12 David Bateman + + * 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 * Cell.cc (Cell::column): New function. diff --git a/src/OPERATORS/op-struct.cc b/src/OPERATORS/op-struct.cc --- 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); } diff --git a/src/oct-map.cc b/src/oct-map.cc --- 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; diff --git a/src/oct-map.h b/src/oct-map.h --- a/src/oct-map.h +++ b/src/oct-map.h @@ -123,6 +123,8 @@ int ndims (void) const { return dimensions.length (); } + Octave_map transpose (void) const; + Octave_map reshape (const dim_vector& new_dims) const; Octave_map resize (const dim_vector& dv) const;