op-struct.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-re-mat.h"
00031 #include "ov-struct.h"
00032 #include "ov-typeinfo.h"
00033 #include "ops.h"
00034 
00035 // struct ops.
00036 
00037 DEFUNOP (transpose, struct)
00038 {
00039   CAST_UNOP_ARG (const octave_struct&);
00040 
00041   if (v.ndims () > 2)
00042     {
00043       error ("transpose not defined for N-d objects");
00044       return octave_value ();
00045     }
00046   else
00047     return octave_value (v.map_value().transpose ());
00048 }
00049 
00050 DEFUNOP (scalar_transpose, scalar_struct)
00051 {
00052   CAST_UNOP_ARG (const octave_scalar_struct&);
00053 
00054   return octave_value (v.scalar_map_value ());
00055 }
00056 
00057 DEFNDCATOP_FN (s_s_concat, struct, struct, map, map, concat)
00058 DEFNDCATOP_FN (s_ss_concat, struct, scalar_struct, map, map, concat)
00059 DEFNDCATOP_FN (ss_s_concat, scalar_struct, struct, map, map, concat)
00060 DEFNDCATOP_FN (ss_ss_concat, scalar_struct, scalar_struct, map, map, concat)
00061 
00062 static octave_value
00063 oct_catop_struct_matrix (octave_base_value& a1, const octave_base_value& a2,
00064                          const Array<octave_idx_type>&)
00065 {
00066   octave_value retval;
00067   CAST_BINOP_ARGS (const octave_struct&, const octave_matrix&);
00068   NDArray tmp = v2.array_value ();
00069   dim_vector dv = tmp.dims ();
00070   if (dv.all_zero ())
00071     retval = octave_value (v1.map_value ());
00072   else
00073     error ("invalid concatenation of structure with matrix");
00074   return retval;
00075 }
00076 
00077 static octave_value
00078 oct_catop_matrix_struct (octave_base_value& a1, const octave_base_value& a2,
00079                          const Array<octave_idx_type>&)
00080 {
00081   octave_value retval;
00082   CAST_BINOP_ARGS (const octave_matrix&, const octave_struct&);
00083   NDArray tmp = v1.array_value ();
00084   dim_vector dv = tmp.dims ();
00085   if (dv.all_zero ())
00086     retval = octave_value (v2.map_value ());
00087   else
00088     error ("invalid concatenation of structure with matrix");
00089   return retval;
00090 }
00091 
00092 void
00093 install_struct_ops (void)
00094 {
00095   INSTALL_UNOP (op_transpose, octave_struct, transpose);
00096   INSTALL_UNOP (op_hermitian, octave_struct, transpose);
00097 
00098   INSTALL_UNOP (op_transpose, octave_scalar_struct, scalar_transpose);
00099   INSTALL_UNOP (op_hermitian, octave_scalar_struct, scalar_transpose);
00100 
00101   INSTALL_CATOP (octave_struct, octave_struct, s_s_concat);
00102   INSTALL_CATOP (octave_struct, octave_scalar_struct, s_ss_concat)
00103   INSTALL_CATOP (octave_scalar_struct, octave_struct, ss_s_concat)
00104   INSTALL_CATOP (octave_scalar_struct, octave_scalar_struct, ss_ss_concat)
00105 
00106   INSTALL_CATOP (octave_struct, octave_matrix, struct_matrix);
00107   INSTALL_CATOP (octave_matrix, octave_struct, matrix_struct);
00108 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines