2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_matrix_h) |
|
24 #define octave_matrix_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
|
32 #include <string> |
|
33 |
|
34 class ostream; |
|
35 |
|
36 #include "mx-base.h" |
2477
|
37 #include "oct-alloc.h" |
2376
|
38 #include "str-vec.h" |
|
39 |
|
40 #include "error.h" |
|
41 #include "ov-base.h" |
|
42 #include "ov-typeinfo.h" |
|
43 |
|
44 class Octave_map; |
|
45 class octave_value_list; |
|
46 |
|
47 class tree_walker; |
|
48 |
|
49 // Real matrix values. |
|
50 |
|
51 class |
|
52 octave_matrix : public octave_base_value |
|
53 { |
|
54 public: |
|
55 |
|
56 octave_matrix (void) |
|
57 : octave_base_value () { } |
|
58 |
|
59 octave_matrix (const Matrix& m) |
|
60 : octave_base_value (), matrix (m) { } |
|
61 |
|
62 octave_matrix (const DiagMatrix& d) |
|
63 : octave_base_value (), matrix (d) { } |
|
64 |
|
65 octave_matrix (const RowVector& v, int pcv = -1); |
|
66 |
|
67 octave_matrix (const ColumnVector& v, int pcv = -1); |
|
68 |
|
69 octave_matrix (const octave_matrix& m) |
|
70 : octave_base_value (), matrix (m.matrix) { } |
|
71 |
|
72 ~octave_matrix (void) { } |
|
73 |
|
74 octave_value *clone (void) { return new octave_matrix (*this); } |
|
75 |
2477
|
76 void *operator new (size_t size) |
|
77 { return allocator.alloc (size); } |
|
78 |
|
79 void operator delete (void *p, size_t size) |
|
80 { allocator.free (p, size); } |
2376
|
81 |
2410
|
82 octave_value *try_narrowing_conversion (void); |
|
83 |
2962
|
84 octave_value do_index_op (const octave_value_list& idx) const; |
2376
|
85 |
|
86 void assign (const octave_value_list& idx, const Matrix& rhs); |
|
87 |
2948
|
88 void assign_struct_elt (assign_op, const string& elt_nm, |
|
89 const octave_value& rhs); |
|
90 |
|
91 void assign_struct_elt (assign_op, const string& elt_nm, |
|
92 const octave_value_list& idx, |
|
93 const octave_value& rhs); |
|
94 |
2376
|
95 idx_vector index_vector (void) const { return idx_vector (matrix); } |
|
96 |
2962
|
97 octave_value |
|
98 do_struct_elt_index_op (const string& nm, const octave_value_list& idx, |
|
99 bool silent); |
|
100 |
|
101 octave_value do_struct_elt_index_op (const string& nm, bool silent); |
2948
|
102 |
|
103 octave_variable_reference |
|
104 struct_elt_ref (octave_value *parent, const string& nm); |
|
105 |
2376
|
106 int rows (void) const { return matrix.rows (); } |
|
107 int columns (void) const { return matrix.columns (); } |
|
108 |
|
109 bool is_defined (void) const { return true; } |
|
110 |
|
111 bool is_real_matrix (void) const { return true; } |
|
112 |
|
113 octave_value all (void) const { return matrix.all (); } |
|
114 octave_value any (void) const { return matrix.any (); } |
|
115 |
|
116 bool is_real_type (void) const { return true; } |
|
117 |
|
118 bool is_matrix_type (void) const { return true; } |
|
119 |
|
120 bool is_numeric_type (void) const { return true; } |
|
121 |
|
122 bool valid_as_scalar_index (void) const; |
|
123 |
|
124 bool valid_as_zero_index (void) const { return is_zero_by_zero (); } |
|
125 |
|
126 bool is_true (void) const; |
|
127 |
|
128 double double_value (bool = false) const; |
|
129 |
2916
|
130 double scalar_value (bool = false) const { return double_value (); } |
|
131 |
2376
|
132 Matrix matrix_value (bool = false) const { return matrix; } |
|
133 |
|
134 Complex complex_value (bool = false) const; |
|
135 |
|
136 ComplexMatrix complex_matrix_value (bool = false) const { return matrix; } |
|
137 |
|
138 octave_value not (void) const { return octave_value (! matrix); } |
|
139 |
|
140 octave_value uminus (void) const { return octave_value (- matrix); } |
|
141 |
|
142 octave_value transpose (void) const |
|
143 { return octave_value (matrix.transpose ()); } |
|
144 |
|
145 octave_value hermitian (void) const |
|
146 { return octave_value (matrix.transpose ()); } |
|
147 |
|
148 void increment (void) { matrix += 1.0; } |
|
149 |
|
150 void decrement (void) { matrix -= 1.0; } |
|
151 |
|
152 octave_value convert_to_str (void) const; |
|
153 |
2901
|
154 void print (ostream& os, bool pr_as_read_syntax = false) const; |
|
155 |
|
156 void print_raw (ostream& os, bool pr_as_read_syntax = false) const; |
|
157 |
|
158 bool print_name_tag (ostream& os, const string& name) const; |
2376
|
159 |
|
160 int type_id (void) const { return t_id; } |
|
161 |
|
162 string type_name (void) const { return t_name; } |
|
163 |
|
164 static int static_type_id (void) { return t_id; } |
|
165 |
|
166 static void register_type (void) |
|
167 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
168 |
|
169 private: |
|
170 |
|
171 Matrix matrix; |
|
172 |
2477
|
173 static octave_allocator allocator; |
|
174 |
|
175 // Type id of matrix objects, set by register_type (). |
2376
|
176 static int t_id; |
|
177 |
2477
|
178 // Type name of matrix objects, defined in ov-re-mat.cc. |
2376
|
179 static const string t_name; |
|
180 }; |
|
181 |
|
182 #endif |
|
183 |
|
184 /* |
|
185 ;;; Local Variables: *** |
|
186 ;;; mode: C++ *** |
|
187 ;;; End: *** |
|
188 */ |