GNU Octave  4.4.1
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-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "errwarn.h"
28 #include "ovl.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 {
39  const octave_struct& v = dynamic_cast<const octave_struct&> (a);
40 
41  if (v.ndims () > 2)
42  error ("transpose not defined for N-D objects");
43 
44  return octave_value (v.map_value ().transpose ());
45 }
46 
47 DEFUNOP (scalar_transpose, scalar_struct)
48 {
49  const octave_scalar_struct& v = dynamic_cast<const octave_scalar_struct&> (a);
50 
51  return octave_value (v.scalar_map_value ());
52 }
53 
54 DEFNDCATOP_FN (s_s_concat, struct, struct, map, map, concat)
55 DEFNDCATOP_FN (s_ss_concat, struct, scalar_struct, map, map, concat)
56 DEFNDCATOP_FN (ss_s_concat, scalar_struct, struct, map, map, concat)
57 DEFNDCATOP_FN (ss_ss_concat, scalar_struct, scalar_struct, map, map, concat)
58 
59 static octave_value
61  const Array<octave_idx_type>&)
62 {
63  const octave_struct& v1 = dynamic_cast<const octave_struct&> (a1);
64  const octave_matrix& v2 = dynamic_cast<const octave_matrix&> (a2);
65 
67  dim_vector dv = tmp.dims ();
68 
69  if (! dv.all_zero ())
70  error ("invalid concatenation of structure with matrix");
71 
72  return octave_value (v1.map_value ());
73 }
74 
75 static octave_value
78 {
79  const octave_matrix& v1 = dynamic_cast<const octave_matrix&> (a1);
80  const octave_struct& v2 = dynamic_cast<const octave_struct&> (a2);
81 
82  NDArray tmp = v1.array_value ();
83  dim_vector dv = tmp.dims ();
84 
85  if (! dv.all_zero ())
86  error ("invalid concatenation of structure with matrix");
87 
88  return octave_value (v2.map_value ());
89 }
90 
91 void
93 {
96 
97  INSTALL_UNOP_TI (ti, op_transpose, octave_scalar_struct, scalar_transpose);
98  INSTALL_UNOP_TI (ti, op_hermitian, octave_scalar_struct, scalar_transpose);
99 
100  INSTALL_CATOP_TI (ti, octave_struct, octave_struct, s_s_concat);
104 
105  INSTALL_CATOP_TI (ti, octave_struct, octave_matrix, struct_matrix);
106  INSTALL_CATOP_TI (ti, octave_matrix, octave_struct, matrix_struct);
107 }
#define DEFUNOP(name, t)
Definition: ops.h:213
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are create an empty structure array with the specified field names If the argument is an return the underlying struct Observe that the syntax is optimized for struct trong struct("foo", 1) esult
Definition: ov-struct.cc:1736
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:386
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
void error(const char *fmt,...)
Definition: error.cc:578
NDArray array_value(bool=false) const
Definition: ov-re-mat.h:170
const octave_base_value & a2
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
virtual octave_map map_value(void) const
Definition: ov-base.cc:819
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:45
void install_struct_ops(octave::type_info &ti)
Definition: op-struct.cc:92
virtual int ndims(void) const
Definition: ov-base.h:330
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:58
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1577
double tmp
Definition: data.cc:6252
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:76
bool all_zero(void) const
Definition: dim-vector.h:327
octave_map map_value(void) const
Definition: ov-struct.h:124
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
const octave_char_matrix & v2
NDArray array_value(bool=false) const
Definition: ov-ch-mat.h:118
octave_map transpose(void) const
Definition: oct-map.cc:500
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:60
octave_map map(dims)
octave_scalar_map scalar_map_value(void) const
Definition: ov-struct.h:248
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1578
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:382
dim_vector dv
Definition: sub2ind.cc:263