GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-struct.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "errwarn.h"
31 #include "ovl.h"
32 #include "ov.h"
33 #include "ov-re-mat.h"
34 #include "ov-struct.h"
35 #include "ov-typeinfo.h"
36 #include "ops.h"
37 
38 // struct ops.
39 
40 DEFUNOP (transpose, struct)
41 {
42  const octave_struct& v = dynamic_cast<const octave_struct&> (a);
43 
44  if (v.ndims () > 2)
45  error ("transpose not defined for N-D objects");
46 
47  return octave_value (v.map_value ().transpose ());
48 }
49 
50 DEFUNOP (scalar_transpose, scalar_struct)
51 {
52  const octave_scalar_struct& v = dynamic_cast<const octave_scalar_struct&> (a);
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  const octave_struct& v1 = dynamic_cast<const octave_struct&> (a1);
67  const octave_matrix& v2 = dynamic_cast<const octave_matrix&> (a2);
68 
69  NDArray tmp = v2.array_value ();
70  dim_vector dv = tmp.dims ();
71 
72  if (! dv.all_zero ())
73  error ("invalid concatenation of structure with matrix");
74 
75  return octave_value (v1.map_value ());
76 }
77 
78 static octave_value
81 {
82  const octave_matrix& v1 = dynamic_cast<const octave_matrix&> (a1);
83  const octave_struct& v2 = dynamic_cast<const octave_struct&> (a2);
84 
85  NDArray tmp = v1.array_value ();
86  dim_vector dv = tmp.dims ();
87 
88  if (! dv.all_zero ())
89  error ("invalid concatenation of structure with matrix");
90 
91  return octave_value (v2.map_value ());
92 }
93 
94 void
96 {
99 
100  INSTALL_UNOP_TI (ti, op_transpose, octave_scalar_struct, scalar_transpose);
101  INSTALL_UNOP_TI (ti, op_hermitian, octave_scalar_struct, scalar_transpose);
102 
103  INSTALL_CATOP_TI (ti, octave_struct, octave_struct, s_s_concat);
107 
108  INSTALL_CATOP_TI (ti, octave_struct, octave_matrix, struct_matrix);
109  INSTALL_CATOP_TI (ti, octave_matrix, octave_struct, matrix_struct);
110 }
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:128
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:453
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
bool all_zero(void) const
Definition: dim-vector.h:366
virtual octave_map map_value(void) const
Definition: ov-base.cc:821
virtual int ndims(void) const
Definition: ov-base.h:332
NDArray array_value(bool=false) const
Definition: ov-ch-mat.h:120
octave_map transpose(void) const
Definition: oct-map.cc:499
NDArray array_value(bool=false) const
Definition: ov-re-mat.h:172
octave_scalar_map scalar_map_value(void) const
Definition: ov-struct.h:251
octave_map map_value(void) const
Definition: ov-struct.h:127
void error(const char *fmt,...)
Definition: error.cc:968
const octave_base_value & a2
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
const octave_char_matrix & v2
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:79
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
void install_struct_ops(octave::type_info &ti)
Definition: op-struct.cc:95
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:348
#define DEFUNOP(name, t)
Definition: ops.h:179
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:60
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:47
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1540
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1541
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:389