Mercurial > hg > octave-nkf
diff liboctave/DiagArray2.h @ 8375:e3c9102431a9
fix design problems of diag & perm matrix classes
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Dec 2008 10:20:18 +0100 |
parents | 8b1a2555c4e2 |
children | 937921654627 |
line wrap: on
line diff
--- a/liboctave/DiagArray2.h +++ b/liboctave/DiagArray2.h @@ -3,6 +3,7 @@ Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton +Copyright (C) 2008 Jaroslav Hajek This file is part of Octave. @@ -31,8 +32,6 @@ #include "Array.h" #include "lo-error.h" -class idx_vector; - // A two-dimensional array with diagonal elements only. // // Idea and example code for Proxy class and functions from: @@ -46,9 +45,13 @@ // James Kanze email: kanze@us-es.sel.de // GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France +// Array<T> is inherited privately because we abuse the dimensions variable +// for true dimensions. Therefore, the inherited Array<T> object is not a valid +// Array<T> object, and should not be publicly accessible. + template <class T> class -DiagArray2 : public Array<T> +DiagArray2 : private Array<T> { private: @@ -112,6 +115,8 @@ public: + typedef T element_type; + DiagArray2 (void) : Array<T> (dim_vector (0, 0)) { } DiagArray2 (octave_idx_type r, octave_idx_type c) : Array<T> (r < c ? r : c) @@ -131,7 +136,7 @@ { this->dimensions = a.dims (); } template <class U> - DiagArray2 (const DiagArray2<U>& a) : Array<T> (a) + DiagArray2 (const DiagArray2<U>& a) : Array<T> (a.diag ()) { this->dimensions = a.dims (); } ~DiagArray2 (void) { } @@ -144,6 +149,24 @@ return *this; } + + octave_idx_type dim1 (void) const { return Array<T>::dimensions(0); } + octave_idx_type dim2 (void) const { return Array<T>::dimensions(1); } + + octave_idx_type rows (void) const { return dim1 (); } + octave_idx_type cols (void) const { return dim2 (); } + octave_idx_type columns (void) const { return dim2 (); } + + octave_idx_type length (void) const { return Array<T>::length (); } + octave_idx_type nelem (void) const { return dim1 () * dim2 (); } + octave_idx_type numel (void) const { return nelem (); } + + size_t byte_size (void) const { return length () * sizeof (T); } + + dim_vector dims (void) const { return Array<T>::dimensions; } + + Array<T> diag (octave_idx_type k = 0) const; + Proxy elem (octave_idx_type r, octave_idx_type c) { return Proxy (this, r, c); @@ -151,7 +174,7 @@ Proxy checkelem (octave_idx_type r, octave_idx_type c) { - if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) + if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) { (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); @@ -162,7 +185,7 @@ Proxy operator () (octave_idx_type r, octave_idx_type c) { - if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) + if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) { (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); @@ -204,6 +227,15 @@ DiagArray2<T> transpose (void) const; DiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const; + + const T *data (void) const { return Array<T>::data (); } + + const T *fortran_vec (void) const { return Array<T>::fortran_vec (); } + + T *fortran_vec (void) { return Array<T>::fortran_vec (); } + + void print_info (std::ostream& os, const std::string& prefix) const + { Array<T>::print_info (os, prefix); } }; #endif