Mercurial > octave
annotate src/OPERATORS/op-struct.cc @ 12646:eaba9d671fb7 stable
Allow transpose to work for scalar structs (bug #33218)
* op-struct.cc (oct_op_scalar_transpose): New function.
(install_struct_ops): Install transpose and hermitian operators for
scalar structs.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 04 May 2011 21:44:05 -0400 |
parents | fd0a3ac60b0e |
children | e8fe03bfc051 |
rev | line source |
---|---|
4939 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 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 | |
47 return octave_value (v.map_value().transpose ()); | |
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 |
4939 | 57 DEFNDCATOP_FN (struct_struct, struct, struct, map, map, concat) |
58 | |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
59 static octave_value |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
60 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
|
61 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
|
62 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
63 octave_value retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
64 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
|
65 NDArray tmp = v2.array_value (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
66 dim_vector dv = tmp.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
67 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
68 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
|
69 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
70 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
|
71 return retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
72 } |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
73 |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
74 static octave_value |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 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
|
76 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
|
77 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
78 octave_value retval; |
8318
cc29ef9a2d84
Correct cast of matrix by cell or struct concatenation
David Bateman <dbateman@free.fr>
parents:
7959
diff
changeset
|
79 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
|
80 NDArray tmp = v1.array_value (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
81 dim_vector dv = tmp.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
82 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
83 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
|
84 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
85 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
|
86 return retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
87 } |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
88 |
4939 | 89 void |
90 install_struct_ops (void) | |
91 { | |
5571 | 92 INSTALL_UNOP (op_transpose, octave_struct, transpose); |
93 INSTALL_UNOP (op_hermitian, octave_struct, transpose); | |
94 | |
12646
eaba9d671fb7
Allow transpose to work for scalar structs (bug #33218)
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 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
|
96 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
|
97 |
4939 | 98 INSTALL_CATOP (octave_struct, octave_struct, struct_struct); |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 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
|
100 INSTALL_CATOP (octave_matrix, octave_struct, matrix_struct); |
4939 | 101 } |