MDiagArray2.h

Go to the documentation of this file.
00001 // Template array classes with like-type math ops
00002 /*
00003 
00004 Copyright (C) 1996-2012 John W. Eaton
00005 Copyright (C) 2010 VZLU Prague
00006 
00007 This file is part of Octave.
00008 
00009 Octave is free software; you can redistribute it and/or modify it
00010 under the terms of the GNU General Public License as published by the
00011 Free Software Foundation; either version 3 of the License, or (at your
00012 option) any later version.
00013 
00014 Octave is distributed in the hope that it will be useful, but WITHOUT
00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00017 for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with Octave; see the file COPYING.  If not, see
00021 <http://www.gnu.org/licenses/>.
00022 
00023 */
00024 
00025 #if !defined (octave_MDiagArray2_h)
00026 #define octave_MDiagArray2_h 1
00027 
00028 #include "DiagArray2.h"
00029 #include "MArray.h"
00030 
00031 // Two dimensional diagonal array with math ops.
00032 
00033 // But first, some preprocessor abuse...
00034 
00035 #include "MArray-decl.h"
00036 
00037 MDIAGARRAY2_OPS_FORWARD_DECLS (MDiagArray2, )
00038 
00039 template <class T>
00040 class
00041 MDiagArray2 : public DiagArray2<T>
00042 {
00043 public:
00044 
00045   MDiagArray2 (void) : DiagArray2<T> () { }
00046 
00047   MDiagArray2 (octave_idx_type r, octave_idx_type c) : DiagArray2<T> (r, c) { }
00048 
00049   MDiagArray2 (octave_idx_type r, octave_idx_type c, const T& val) : DiagArray2<T> (r, c, val) { }
00050 
00051   MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { }
00052 
00053   MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { }
00054 
00055   template <class U>
00056   MDiagArray2 (const DiagArray2<U>& a) : DiagArray2<T> (a) { }
00057 
00058   explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { }
00059 
00060   MDiagArray2 (const Array<T>& a, octave_idx_type r, octave_idx_type c)
00061     : DiagArray2<T> (a, r, c) { }
00062 
00063   ~MDiagArray2 (void) { }
00064 
00065   MDiagArray2<T>& operator = (const MDiagArray2<T>& a)
00066     {
00067       DiagArray2<T>::operator = (a);
00068       return *this;
00069     }
00070 
00071   MArray<T> array_value () const
00072     {
00073       return DiagArray2<T>::array_value ();
00074     }
00075 
00076   octave_idx_type nnz (void) const
00077     {
00078       octave_idx_type retval = 0;
00079 
00080       const T *d = this->data ();
00081 
00082       octave_idx_type nel = this->length ();
00083 
00084       for (octave_idx_type i = 0; i < nel; i++)
00085         {
00086           if (d[i] != T ())
00087             retval++;
00088         }
00089 
00090       return retval;
00091     }
00092 
00093   MArray<T> diag (octave_idx_type k = 0) const
00094     { return DiagArray2<T>::diag (k); }
00095 
00096   MDiagArray2<T> transpose (void) const { return DiagArray2<T>::transpose (); }
00097   MDiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const { return DiagArray2<T>::hermitian (fcn); }
00098 
00099   bool is_multiple_of_identity (T val) const;
00100 
00101   // Currently, the OPS functions don't need to be friends, but that
00102   // may change.
00103 
00104   MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2, )
00105 
00106 };
00107 
00108 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines