Mercurial > hg > octave-nkf
annotate src/OPERATORS/op-struct.cc @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | cc29ef9a2d84 |
children | fb6b6fcafa62 |
rev | line source |
---|---|
4939 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2004, 2005, 2007, 2008 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 | |
5571 | 37 DEFUNOP (transpose, cell) |
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 | |
4939 | 50 DEFNDCATOP_FN (struct_struct, struct, struct, map, map, concat) |
51 | |
7959
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
52 static octave_value |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
53 oct_catop_struct_matrix (octave_base_value& a1, const octave_base_value& a2, |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
54 const Array<octave_idx_type>&) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
55 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
56 octave_value retval; |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
57 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
|
58 NDArray tmp = v2.array_value (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
59 dim_vector dv = tmp.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
60 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
61 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
|
62 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
63 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
|
64 return retval; |
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 |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
67 static octave_value |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
68 oct_catop_matrix_struct (octave_base_value& a1, const octave_base_value& a2, |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
69 const Array<octave_idx_type>&) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
70 { |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
71 octave_value retval; |
8318
cc29ef9a2d84
Correct cast of matrix by cell or struct concatenation
David Bateman <dbateman@free.fr>
parents:
7959
diff
changeset
|
72 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
|
73 NDArray tmp = v1.array_value (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
74 dim_vector dv = tmp.dims (); |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 if (dv.all_zero ()) |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
76 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
|
77 else |
a73b80cd1f10
allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
78 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
|
79 return retval; |
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 |
4939 | 82 void |
83 install_struct_ops (void) | |
84 { | |
5571 | 85 INSTALL_UNOP (op_transpose, octave_struct, transpose); |
86 INSTALL_UNOP (op_hermitian, octave_struct, transpose); | |
87 | |
4939 | 88 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
|
89 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
|
90 INSTALL_CATOP (octave_matrix, octave_struct, matrix_struct); |
4939 | 91 } |
92 | |
93 /* | |
94 ;;; Local Variables: *** | |
95 ;;; mode: C++ *** | |
96 ;;; End: *** | |
97 */ |