GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
op-struct.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "gripes.h"
28 #include "oct-obj.h"
29 #include "ov.h"
30 #include "ov-re-mat.h"
31 #include "ov-struct.h"
32 #include "ov-typeinfo.h"
33 #include "ops.h"
34 
35 // struct ops.
36 
37 DEFUNOP (transpose, struct)
38 {
40 
41  if (v.ndims () > 2)
42  {
43  error ("transpose not defined for N-d objects");
44  return octave_value ();
45  }
46  else
47  return octave_value (v.map_value ().transpose ());
48 }
49 
50 DEFUNOP (scalar_transpose, scalar_struct)
51 {
53 
54  return octave_value (v.scalar_map_value ());
55 }
56 
57 DEFNDCATOP_FN (s_s_concat, struct, struct, map, map, concat)
58 DEFNDCATOP_FN (s_ss_concat, struct, scalar_struct, map, map, concat)
59 DEFNDCATOP_FN (ss_s_concat, scalar_struct, struct, map, map, concat)
60 DEFNDCATOP_FN (ss_ss_concat, scalar_struct, scalar_struct, map, map, concat)
61 
62 static octave_value
64  const Array<octave_idx_type>&)
65 {
66  octave_value retval;
68  NDArray tmp = v2.array_value ();
69  dim_vector dv = tmp.dims ();
70  if (dv.all_zero ())
71  retval = octave_value (v1.map_value ());
72  else
73  error ("invalid concatenation of structure with matrix");
74  return retval;
75 }
76 
77 static octave_value
80 {
81  octave_value retval;
83  NDArray tmp = v1.array_value ();
84  dim_vector dv = tmp.dims ();
85  if (dv.all_zero ())
86  retval = octave_value (v2.map_value ());
87  else
88  error ("invalid concatenation of structure with matrix");
89  return retval;
90 }
91 
92 void
94 {
97 
98  INSTALL_UNOP (op_transpose, octave_scalar_struct, scalar_transpose);
99  INSTALL_UNOP (op_hermitian, octave_scalar_struct, scalar_transpose);
100 
105 
106  INSTALL_CATOP (octave_struct, octave_matrix, struct_matrix);
107  INSTALL_CATOP (octave_matrix, octave_struct, matrix_struct);
108 }
#define DEFUNOP(name, t)
Definition: ops.h:231
virtual octave_map map_value(void) const
Definition: ov-base.cc:934
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:382
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:664
void error(const char *fmt,...)
Definition: error.cc:476
const octave_base_value const Array< octave_idx_type > &ra_idx octave_int16_scalar & v1
void install_struct_ops(void)
Definition: op-struct.cc:93
#define CAST_BINOP_ARGS(t1, t2)
Definition: ops.h:79
const octave_base_value & a2
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:337
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1297
static octave_value oct_catop_matrix_struct(octave_base_value &a1, const octave_base_value &a2, const Array< octave_idx_type > &)
Definition: op-struct.cc:78
bool all_zero(void) const
Definition: dim-vector.h:304
#define INSTALL_CATOP(t1, t2, f)
Definition: ops.h:51
Handles the reference counting for all the derived classes.
Definition: Array.h:45
const octave_char_matrix & v2
static octave_value oct_catop_struct_matrix(octave_base_value &a1, const octave_base_value &a2, const Array< octave_idx_type > &)
Definition: op-struct.cc:63
NDArray array_value(bool=false) const
Definition: ov-ch-mat.h:114
#define INSTALL_UNOP(op, t, f)
Definition: ops.h:38
#define CAST_UNOP_ARG(t)
Definition: ops.h:76
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1298
virtual NDArray array_value(bool=false) const
Definition: ov-base.cc:558
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:364
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))