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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
1 /*
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
2
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8318
diff changeset
3 Copyright (C) 1996, 1997, 2004, 2005, 2007, 2008 John W. Eaton
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
4
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
6
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5571
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5571
diff changeset
10 option) any later version.
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
11
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
15 for more details.
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
16
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5571
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5571
diff changeset
19 <http://www.gnu.org/licenses/>.
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
20
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
21 */
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
22
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
25 #endif
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
26
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
27 #include "gripes.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
28 #include "oct-obj.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
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
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
31 #include "ov-struct.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
32 #include "ov-typeinfo.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
33 #include "ops.h"
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
34
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
35 // struct ops.
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
36
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
37 DEFUNOP (transpose, cell)
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
38 {
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
39 CAST_UNOP_ARG (const octave_struct&);
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
40
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
41 if (v.ndims () > 2)
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
42 {
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
43 error ("transpose not defined for N-d objects");
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
44 return octave_value ();
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 else
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
47 return octave_value (v.map_value().transpose ());
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
48 }
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
49
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
50 DEFNDCATOP_FN (struct_struct, struct, struct, map, map, concat)
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
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
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
82 void
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
83 install_struct_ops (void)
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
84 {
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
85 INSTALL_UNOP (op_transpose, octave_struct, transpose);
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
86 INSTALL_UNOP (op_hermitian, octave_struct, transpose);
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5307
diff changeset
87
4939
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
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
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
91 }
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
92
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
93 /*
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
94 ;;; Local Variables: ***
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
95 ;;; mode: C++ ***
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
96 ;;; End: ***
22388c7625a0 [project @ 2004-08-10 04:33:51 by jwe]
jwe
parents:
diff changeset
97 */