Mercurial > hg > octave-nkf
annotate libinterp/operators/op-struct.cc @ 17296:3a9efb68272d ss-3-7-6
snapshot 3.7.6
* configure.ac (OCTAVE_VERSION): Bump to 3.7.6.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Aug 2013 15:17:54 -0400 |
parents | 2fc554ffbc28 |
children | d63878346099 |
rev | line source |
---|---|
4939 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12760
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
4939 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4939 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4939 | 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" | |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
30 #include "ov-re-mat.h" |
4939 | 31 #include "ov-struct.h" |
32 #include "ov-typeinfo.h" | |
33 #include "ops.h" | |
34 | |
35 // struct ops. | |
36 | |
12646
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
37 DEFUNOP (transpose, struct) |
5571 | 38 { |
39 CAST_UNOP_ARG (const octave_struct&); | |
40 | |
41 if (v.ndims () > 2) | |
42 { | |
43 error ("transpose not defined for N-d objects"); | |
44 return octave_value (); | |
45 } | |
46 else | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
47 return octave_value (v.map_value ().transpose ()); |
5571 | 48 } |
49 | |
12646
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
50 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
|
51 { |
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
52 CAST_UNOP_ARG (const octave_scalar_struct&); |
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
53 |
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
54 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
|
55 } |
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
56 |
12760
e8fe03bfc051
allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents:
12646
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 DEFNDCATOP_FN (ss_ss_concat, scalar_struct, scalar_struct, map, map, concat) |
4939 | 61 |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
62 static octave_value |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
63 oct_catop_struct_matrix (octave_base_value& a1, const octave_base_value& a2, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
64 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
|
65 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
66 octave_value retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
67 CAST_BINOP_ARGS (const octave_struct&, const octave_matrix&); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
68 NDArray tmp = v2.array_value (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
69 dim_vector dv = tmp.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
70 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
71 retval = octave_value (v1.map_value ()); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
72 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
73 error ("invalid concatenation of structure with matrix"); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
74 return retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 } |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
76 |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
77 static octave_value |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
78 oct_catop_matrix_struct (octave_base_value& a1, const octave_base_value& a2, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
79 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
|
80 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
81 octave_value retval; |
8318
cc29ef9a2d84
Correct cast of matrix by cell or struct concatenation
David Bateman <dbateman@free.fr>
parents:
7959
diff
changeset
|
82 CAST_BINOP_ARGS (const octave_matrix&, const octave_struct&); |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
83 NDArray tmp = v1.array_value (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
84 dim_vector dv = tmp.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
85 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
86 retval = octave_value (v2.map_value ()); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
87 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
88 error ("invalid concatenation of structure with matrix"); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
89 return retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
90 } |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 |
4939 | 92 void |
93 install_struct_ops (void) | |
94 { | |
5571 | 95 INSTALL_UNOP (op_transpose, octave_struct, transpose); |
96 INSTALL_UNOP (op_hermitian, octave_struct, transpose); | |
97 | |
12646
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 INSTALL_UNOP (op_transpose, octave_scalar_struct, scalar_transpose); |
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
99 INSTALL_UNOP (op_hermitian, octave_scalar_struct, scalar_transpose); |
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
100 |
12760
e8fe03bfc051
allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents:
12646
diff
changeset
|
101 INSTALL_CATOP (octave_struct, octave_struct, s_s_concat); |
e8fe03bfc051
allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents:
12646
diff
changeset
|
102 INSTALL_CATOP (octave_struct, octave_scalar_struct, s_ss_concat) |
e8fe03bfc051
allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents:
12646
diff
changeset
|
103 INSTALL_CATOP (octave_scalar_struct, octave_struct, ss_s_concat) |
e8fe03bfc051
allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents:
12646
diff
changeset
|
104 INSTALL_CATOP (octave_scalar_struct, octave_scalar_struct, ss_ss_concat) |
e8fe03bfc051
allow concatenation of scalar structures with []
John W. Eaton <jwe@octave.org>
parents:
12646
diff
changeset
|
105 |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 INSTALL_CATOP (octave_struct, octave_matrix, struct_matrix); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
107 INSTALL_CATOP (octave_matrix, octave_struct, matrix_struct); |
4939 | 108 } |