comparison liboctave/array/CMatrix.cc @ 19510:d0c73e23a505

Change inheritance tree so that <T>Matrix inherit from <T>NDArray. * liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h, liboctave/array/CNDArray.cc, liboctave/array/CNDArray.h, liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h, liboctave/array/dNDArray.cc, liboctave/array/dNDArray.h, liboctave/array/fCMatrix.cc, liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.cc, liboctave/array/fCNDArray.h, liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h, liboctave/array/fNDArray.cc, liboctave/array/fNDArray.h: change base class of Matrix, FloatMatrix, ComplexMatrix, and FloatComplexMatrix to NDArray, FloatNDArray, ComplexNDArray, and FloatComplexNDArray respectively. This will allow to reduce duplicated code since the Matrix classes will be able to inherit many of their methods from their NDArray counterparts. Also remove the matrix_value () method since a constructor now suffices. * liboctave/array/CSparse.h: include CMatrix * libinterp/corefcn/pr-output.cc, libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-flt-cx-mat.cc, libinterp/octave-value/ov-flt-re-mat.cc, libinterp/octave-value/ov-re-mat.cc: replace calls to matrix_value () with constructor with respective Matrix subclass.
author Carnë Draug <carandraug@octave.org>
date Fri, 07 Nov 2014 08:15:55 +0000
parents 65554f5847ac
children 3746b92739f7
comparison
equal deleted inserted replaced
19509:8b4a24081e47 19510:d0c73e23a505
38 #include "Array-util.h" 38 #include "Array-util.h"
39 #include "boolMatrix.h" 39 #include "boolMatrix.h"
40 #include "chMatrix.h" 40 #include "chMatrix.h"
41 #include "dMatrix.h" 41 #include "dMatrix.h"
42 #include "CMatrix.h" 42 #include "CMatrix.h"
43 #include "CNDArray.h"
43 #include "CRowVector.h" 44 #include "CRowVector.h"
44 #include "dRowVector.h" 45 #include "dRowVector.h"
45 #include "CDiagMatrix.h" 46 #include "CDiagMatrix.h"
46 #include "dDiagMatrix.h" 47 #include "dDiagMatrix.h"
47 #include "CmplxCHOL.h" 48 #include "CmplxCHOL.h"
265 static const Complex Complex_NaN_result (octave_NaN, octave_NaN); 266 static const Complex Complex_NaN_result (octave_NaN, octave_NaN);
266 267
267 // Complex Matrix class 268 // Complex Matrix class
268 269
269 ComplexMatrix::ComplexMatrix (const Matrix& a) 270 ComplexMatrix::ComplexMatrix (const Matrix& a)
270 : MArray<Complex> (a) 271 : ComplexNDArray (a)
271 { 272 {
272 } 273 }
273 274
274 ComplexMatrix::ComplexMatrix (const RowVector& rv) 275 ComplexMatrix::ComplexMatrix (const RowVector& rv)
275 : MArray<Complex> (rv) 276 : ComplexNDArray (rv)
276 { 277 {
277 } 278 }
278 279
279 ComplexMatrix::ComplexMatrix (const ColumnVector& cv) 280 ComplexMatrix::ComplexMatrix (const ColumnVector& cv)
280 : MArray<Complex> (cv) 281 : ComplexNDArray (cv)
281 { 282 {
282 } 283 }
283 284
284 ComplexMatrix::ComplexMatrix (const DiagMatrix& a) 285 ComplexMatrix::ComplexMatrix (const DiagMatrix& a)
285 : MArray<Complex> (a.dims (), 0.0) 286 : ComplexNDArray (a.dims (), 0.0)
286 { 287 {
287 for (octave_idx_type i = 0; i < a.length (); i++) 288 for (octave_idx_type i = 0; i < a.length (); i++)
288 elem (i, i) = a.elem (i, i); 289 elem (i, i) = a.elem (i, i);
289 } 290 }
290 291
291 ComplexMatrix::ComplexMatrix (const ComplexRowVector& rv) 292 ComplexMatrix::ComplexMatrix (const ComplexRowVector& rv)
292 : MArray<Complex> (rv) 293 : ComplexNDArray (rv)
293 { 294 {
294 } 295 }
295 296
296 ComplexMatrix::ComplexMatrix (const ComplexColumnVector& cv) 297 ComplexMatrix::ComplexMatrix (const ComplexColumnVector& cv)
297 : MArray<Complex> (cv) 298 : ComplexNDArray (cv)
298 { 299 {
299 } 300 }
300 301
301 ComplexMatrix::ComplexMatrix (const ComplexDiagMatrix& a) 302 ComplexMatrix::ComplexMatrix (const ComplexDiagMatrix& a)
302 : MArray<Complex> (a.dims (), 0.0) 303 : ComplexNDArray (a.dims (), 0.0)
303 { 304 {
304 for (octave_idx_type i = 0; i < a.length (); i++) 305 for (octave_idx_type i = 0; i < a.length (); i++)
305 elem (i, i) = a.elem (i, i); 306 elem (i, i) = a.elem (i, i);
306 } 307 }
307 308
308 // FIXME: could we use a templated mixed-type copy function here? 309 // FIXME: could we use a templated mixed-type copy function here?
309 310
310 ComplexMatrix::ComplexMatrix (const boolMatrix& a) 311 ComplexMatrix::ComplexMatrix (const boolMatrix& a)
311 : MArray<Complex> (a) 312 : ComplexNDArray (a)
312 { 313 {
313 } 314 }
314 315
315 ComplexMatrix::ComplexMatrix (const charMatrix& a) 316 ComplexMatrix::ComplexMatrix (const charMatrix& a)
316 : MArray<Complex> (a.dims (), 0.0) 317 : ComplexNDArray (a.dims (), 0.0)
317 { 318 {
318 for (octave_idx_type i = 0; i < a.rows (); i++) 319 for (octave_idx_type i = 0; i < a.rows (); i++)
319 for (octave_idx_type j = 0; j < a.cols (); j++) 320 for (octave_idx_type j = 0; j < a.cols (); j++)
320 elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); 321 elem (i, j) = static_cast<unsigned char> (a.elem (i, j));
321 } 322 }
322 323
323 ComplexMatrix::ComplexMatrix (const Matrix& re, const Matrix& im) 324 ComplexMatrix::ComplexMatrix (const Matrix& re, const Matrix& im)
324 : MArray<Complex> (re.dims ()) 325 : ComplexNDArray (re.dims ())
325 { 326 {
326 if (im.rows () != rows () || im.cols () != cols ()) 327 if (im.rows () != rows () || im.cols () != cols ())
327 (*current_liboctave_error_handler) ("complex: internal error"); 328 (*current_liboctave_error_handler) ("complex: internal error");
328 329
329 octave_idx_type nel = numel (); 330 octave_idx_type nel = numel ();
466 467
467 ComplexMatrix& 468 ComplexMatrix&
468 ComplexMatrix::insert (const ComplexMatrix& a, 469 ComplexMatrix::insert (const ComplexMatrix& a,
469 octave_idx_type r, octave_idx_type c) 470 octave_idx_type r, octave_idx_type c)
470 { 471 {
471 Array<Complex>::insert (a, r, c); 472 ComplexNDArray::insert (a, r, c);
472 return *this; 473 return *this;
473 } 474 }
474 475
475 ComplexMatrix& 476 ComplexMatrix&
476 ComplexMatrix::insert (const ComplexRowVector& a, 477 ComplexMatrix::insert (const ComplexRowVector& a,
3246 } 3247 }
3247 3248
3248 ComplexMatrix 3249 ComplexMatrix
3249 ComplexMatrix::diag (octave_idx_type k) const 3250 ComplexMatrix::diag (octave_idx_type k) const
3250 { 3251 {
3251 return MArray<Complex>::diag (k); 3252 return ComplexNDArray::diag (k);
3252 } 3253 }
3253 3254
3254 ComplexDiagMatrix 3255 ComplexDiagMatrix
3255 ComplexMatrix::diag (octave_idx_type m, octave_idx_type n) const 3256 ComplexMatrix::diag (octave_idx_type m, octave_idx_type n) const
3256 { 3257 {