comparison src/ov-re-mat.cc @ 2948:56be458e237f

[project @ 1997-05-09 13:37:35 by jwe]
author jwe
date Fri, 09 May 1997 13:51:06 +0000
parents 4e7bea116f24
children ac3368dba5d3
comparison
equal deleted inserted replaced
2947:cf676ff8b702 2948:56be458e237f
38 #include "oct-obj.h" 38 #include "oct-obj.h"
39 #include "ops.h" 39 #include "ops.h"
40 #include "ov-scalar.h" 40 #include "ov-scalar.h"
41 #include "ov-re-mat.h" 41 #include "ov-re-mat.h"
42 #include "pr-output.h" 42 #include "pr-output.h"
43 #include "variables.h"
43 44
44 octave_allocator 45 octave_allocator
45 octave_matrix::allocator (sizeof (octave_matrix)); 46 octave_matrix::allocator (sizeof (octave_matrix));
46 47
47 int 48 int
142 default: 143 default:
143 error ("invalid number of indices (%d) for indexed matrix assignment", 144 error ("invalid number of indices (%d) for indexed matrix assignment",
144 len); 145 len);
145 break; 146 break;
146 } 147 }
148 }
149
150 void
151 octave_matrix::assign_struct_elt (assign_op, const string& nm,
152 const octave_value& rhs)
153 {
154 octave_value retval;
155
156 Matrix m = rhs.matrix_value ();
157
158 if (! error_state)
159 {
160 int nr = -1;
161 int nc = -1;
162
163 int dim = -1;
164
165 if (m.rows () == 1 && m.cols () == 2)
166 {
167 nr = NINT (m (0, 0));
168 nc = NINT (m (0, 1));
169 }
170 else if (m.rows () == 2 && m.cols () == 1)
171 {
172 nr = NINT (m (0, 0));
173 nc = NINT (m (1, 0));
174 }
175 else if (m.rows () == 1 && m.cols () == 1)
176 {
177 dim = NINT (m (0, 0));
178
179 nr = matrix.rows ();
180 nc = matrix.cols ();
181 }
182
183 if (nm == "size")
184 {
185 if (nr >= 0 && nc >= 0)
186 matrix.resize (nr, nc, 0.0);
187 else
188 error ("invalid size specification = [%d, %d] specified",
189 nr, nc);
190 }
191 else if (nm == "rows")
192 {
193 if (dim >= 0)
194 matrix.resize (dim, nc, 0.0);
195 else
196 error ("invalid row dimension = %d specified", dim);
197 }
198 else if (nm == "cols" || nm == "columns")
199 {
200 if (dim >= 0)
201 matrix.resize (nr, dim, 0.0);
202 else
203 error ("invalid column dimension = %d specified", dim);
204 }
205 }
206 }
207
208 void
209 octave_matrix::assign_struct_elt (assign_op, const string&,
210 const octave_value_list&,
211 const octave_value&)
212 {
213 error ("indexed assignment for matrix properties is not implemented");
214 }
215
216 octave_value
217 octave_matrix::struct_elt_val (const string& nm, bool silent) const
218 {
219 octave_value retval;
220
221 double nr = static_cast<double> (matrix.rows ());
222 double nc = static_cast<double> (matrix.cols ());
223
224 if (nm == "rows")
225 retval = nr;
226 else if (nm == "cols" || nm == "columns")
227 retval = nc;
228 else if (nm == "size")
229 {
230 Matrix tmp (1, 2);
231
232 tmp.elem (0, 0) = nr;
233 tmp.elem (0, 1) = nc;
234
235 retval = tmp;
236 }
237 else if (! silent)
238 error ("structure has no member `%s'", nm.c_str ());
239
240 return retval;
241 }
242
243 octave_variable_reference
244 octave_matrix::struct_elt_ref (octave_value *parent, const string& nm)
245 {
246 return octave_variable_reference (parent, nm);
147 } 247 }
148 248
149 bool 249 bool
150 octave_matrix::valid_as_scalar_index (void) const 250 octave_matrix::valid_as_scalar_index (void) const
151 { 251 {