Octave-Forge - Extra packages for GNU Octave | |
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code |
00001 // Template array classes with like-type math ops 00002 /* 00003 00004 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007, 2008, 00005 2009 John W. Eaton 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_MArrayN_h) 00026 #define octave_MArrayN_h 1 00027 00028 #include "Array.h" 00029 #include "MArray2.h" 00030 #include "dim-vector.h" 00031 00032 // N-dimensional array with math ops. 00033 00034 // But first, some preprocessor abuse... 00035 00036 #include "MArray-decl.h" 00037 00038 MARRAY_OPS_FORWARD_DECLS (MArrayN, ) 00039 00040 template <class T> 00041 class 00042 MArrayN : public Array<T> 00043 { 00044 protected: 00045 00046 MArrayN (T *d, const dim_vector& dv) : Array<T> (d, dv) { } 00047 00048 public: 00049 00050 MArrayN (void) : Array<T> () {} 00051 00052 MArrayN (const dim_vector& dv) : Array<T> (dv) { } 00053 00054 MArrayN (const dim_vector& dv, const T& val) : Array<T> (dv, val) { } 00055 00056 template <class U> 00057 explicit MArrayN (const Array2<U>& a) : Array<T> (a) { } 00058 00059 template <class U> 00060 MArrayN (const Array<U>& a) : Array<T> (a) { } 00061 00062 template <class U> 00063 MArrayN (const MArrayN<U>& a) : Array<T> (a) { } 00064 00065 ~MArrayN (void) { } 00066 00067 MArrayN<T>& operator = (const MArrayN<T>& a) 00068 { 00069 Array<T>::operator = (a); 00070 return *this; 00071 } 00072 00073 octave_idx_type nnz (void) const 00074 { 00075 octave_idx_type retval = 0; 00076 00077 const T *d = this->data (); 00078 00079 octave_idx_type nel = this->numel (); 00080 00081 for (octave_idx_type i = 0; i < nel; i++) 00082 { 00083 if (d[i] != T ()) 00084 retval++; 00085 } 00086 00087 return retval; 00088 } 00089 00090 MArrayN<T> reshape (const dim_vector& new_dims) const 00091 { return Array<T>::reshape (new_dims); } 00092 00093 MArrayN<T> permute (const Array<octave_idx_type>& vec, 00094 bool inv = false) const 00095 { return Array<T>::permute (vec, inv); } 00096 00097 MArrayN<T> ipermute (const Array<octave_idx_type>& vec) const 00098 { return Array<T>::ipermute (vec); } 00099 00100 MArrayN squeeze (void) const { return Array<T>::squeeze (); } 00101 00102 MArrayN<T> diag (octave_idx_type k) const 00103 { 00104 return Array<T>::diag (k); 00105 } 00106 00107 template <class U, class F> 00108 MArrayN<U> map (F fcn) const 00109 { 00110 return Array<T>::template map<U> (fcn); 00111 } 00112 00113 void changesign (void); 00114 }; 00115 00116 #endif 00117 00118 /* 00119 ;;; Local Variables: *** 00120 ;;; mode: C++ *** 00121 ;;; End: *** 00122 */