annotate libinterp/operators/op-struct.cc @ 31706:597f3ee61a48 stable

update Octave Project Developers copyright for the new year
author John W. Eaton <jwe@octave.org>
date Fri, 06 Jan 2023 13:11:27 -0500
parents e88a07dec498
children 3722c5b1a8c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31605
diff changeset
3 // Copyright (C) 1996-2023 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
28 #endif
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
29
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21014
diff changeset
30 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20833
diff changeset
31 #include "ovl.h"
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
32 #include "ov.h"
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
33 #include "ov-re-mat.h"
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
34 #include "ov-struct.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
35 #include "ov-typeinfo.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
36 #include "ops.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
37
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
38 OCTAVE_BEGIN_NAMESPACE(octave)
29989
b260322f6730 move xdiv, xnorm, and xpow inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
39
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
40 // struct ops.
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
41
12646
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
42 DEFUNOP (transpose, struct)
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
43 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
44 const octave_struct& v = dynamic_cast<const octave_struct&> (a);
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
45
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
46 if (v.ndims () > 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20940
diff changeset
47 error ("transpose not defined for N-D objects");
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
48
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
49 return octave_value (v.map_value ().transpose ());
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
50 }
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
51
12646
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
52 DEFUNOP (scalar_transpose, scalar_struct)
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
53 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
54 const octave_scalar_struct& v = dynamic_cast<const octave_scalar_struct&> (a);
12646
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
55
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
56 return octave_value (v.scalar_map_value ());
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
57 }
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
58
12760
e8fe03bfc051 allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents: 12646
diff changeset
59 DEFNDCATOP_FN (s_s_concat, struct, struct, map, map, concat)
e8fe03bfc051 allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents: 12646
diff changeset
60 DEFNDCATOP_FN (s_ss_concat, struct, scalar_struct, map, map, concat)
e8fe03bfc051 allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents: 12646
diff changeset
61 DEFNDCATOP_FN (ss_s_concat, scalar_struct, struct, map, map, concat)
e8fe03bfc051 allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents: 12646
diff changeset
62 DEFNDCATOP_FN (ss_ss_concat, scalar_struct, scalar_struct, map, map, concat)
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
63
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
64 static octave_value
28630
35f974bab4c8 fix constness of cat op args
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
65 oct_catop_struct_matrix (const octave_base_value& a1,
35f974bab4c8 fix constness of cat op args
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
66 const octave_base_value& a2,
9931
fb6b6fcafa62 untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
67 const Array<octave_idx_type>&)
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
68 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
69 const octave_struct& v1 = dynamic_cast<const octave_struct&> (a1);
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
70 const octave_matrix& v2 = dynamic_cast<const octave_matrix&> (a2);
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
71
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
72 NDArray tmp = v2.array_value ();
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
73 dim_vector dv = tmp.dims ();
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
74
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
75 if (! dv.all_zero ())
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
76 error ("invalid concatenation of structure with matrix");
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
77
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
78 return octave_value (v1.map_value ());
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
79 }
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
80
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
81 static octave_value
28630
35f974bab4c8 fix constness of cat op args
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
82 oct_catop_matrix_struct (const octave_base_value& a1,
35f974bab4c8 fix constness of cat op args
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
83 const octave_base_value& a2,
9931
fb6b6fcafa62 untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
84 const Array<octave_idx_type>&)
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
85 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
86 const octave_matrix& v1 = dynamic_cast<const octave_matrix&> (a1);
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
87 const octave_struct& v2 = dynamic_cast<const octave_struct&> (a2);
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
88
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
89 NDArray tmp = v1.array_value ();
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
90 dim_vector dv = tmp.dims ();
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
91
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
92 if (! dv.all_zero ())
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
93 error ("invalid concatenation of structure with matrix");
20833
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
94
9c4c87679985 restructure calls to error
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
95 return octave_value (v2.map_value ());
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
96 }
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
97
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
98 void
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
99 install_struct_ops (octave::type_info& ti)
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
100 {
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
101 INSTALL_UNOP_TI (ti, op_transpose, octave_struct, transpose);
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
102 INSTALL_UNOP_TI (ti, op_hermitian, octave_struct, transpose);
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
103
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
104 INSTALL_UNOP_TI (ti, op_transpose, octave_scalar_struct, scalar_transpose);
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
105 INSTALL_UNOP_TI (ti, op_hermitian, octave_scalar_struct, scalar_transpose);
12646
eaba9d671fb7 Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
106
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
107 INSTALL_CATOP_TI (ti, octave_struct, octave_struct, s_s_concat);
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
108 INSTALL_CATOP_TI (ti, octave_struct, octave_scalar_struct, s_ss_concat)
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
109 INSTALL_CATOP_TI (ti, octave_scalar_struct, octave_struct, ss_s_concat)
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
110 INSTALL_CATOP_TI (ti, octave_scalar_struct, octave_scalar_struct, ss_ss_concat)
12760
e8fe03bfc051 allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents: 12646
diff changeset
111
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
112 INSTALL_CATOP_TI (ti, octave_struct, octave_matrix, struct_matrix);
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
113 INSTALL_CATOP_TI (ti, octave_matrix, octave_struct, matrix_struct);
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
114 }
29989
b260322f6730 move xdiv, xnorm, and xpow inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
115
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
116 OCTAVE_END_NAMESPACE(octave)