From bug-request at octave dot org Mon Dec 12 08:18:21 2005 Subject: transpose of struct array From: David Bateman To: bug at octave dot org Date: Mon, 12 Dec 2005 15:14:01 +0100 This is a multi-part message in MIME format. --------------060003010601070902050705 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit The competition can do a transpose of a struct array, so should we. Here is the patch D. 2005-12-12 David Bateman * OPERATORS/op-struct.cc (transpose): New function (install_struct_ops): Use it * oct-map.cc (transpose): New function *oct-map.h (transpose): Declare it. -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary --------------060003010601070902050705 Content-Type: text/plain; name="patch.struct-20051212" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.struct-20051212" *** ./src/OPERATORS/op-struct.cc.orig4 2005-04-26 21:24:35.000000000 +0200 --- ./src/OPERATORS/op-struct.cc 2005-12-12 14:02:09.000000000 +0100 *************** *** 34,44 **** --- 34,60 ---- // 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); } *** ./src/oct-map.h.orig4 2005-12-12 14:03:25.000000000 +0100 --- ./src/oct-map.h 2005-12-12 14:03:10.000000000 +0100 *************** *** 123,128 **** --- 123,130 ---- 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; *** ./src/oct-map.cc.orig4 2005-12-12 14:07:54.000000000 +0100 --- ./src/oct-map.cc 2005-12-12 14:15:07.000000000 +0100 *************** *** 87,92 **** --- 87,106 ---- } 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; --------------060003010601070902050705-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------