00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #if !defined (octave_Array2_h)
00026 #define octave_Array2_h 1
00027
00028 #include <cassert>
00029 #include <climits>
00030 #include <cstdlib>
00031
00032 #include "Array.h"
00033 #include "lo-error.h"
00034 #include "lo-math.h"
00035
00036 class idx_vector;
00037
00038
00039
00040 template <class T>
00041 class
00042 Array2 : public Array<T>
00043 {
00044 protected:
00045
00046 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c) { return Array<T>::get_size (r, c); }
00047
00048 Array2 (T *d, octave_idx_type r, octave_idx_type c) : Array<T> (d, dim_vector (r, c)) { }
00049
00050 public:
00051
00052 Array2 (void) : Array<T> (dim_vector (0, 0)) { }
00053
00054 Array2 (octave_idx_type r, octave_idx_type c) : Array<T> (dim_vector (r, c)) { }
00055
00056 Array2 (octave_idx_type r, octave_idx_type c, const T& val)
00057 : Array<T> (dim_vector (r, c), val) { }
00058
00059 Array2 (const dim_vector& dv) : Array<T> (dv)
00060 {
00061 if (dv.length () != 2)
00062 (*current_liboctave_error_handler) ("too many dimensions");
00063 }
00064
00065 Array2 (const dim_vector& dv, const T& val) : Array<T> (dv)
00066 {
00067 if (dv.length () != 2)
00068 (*current_liboctave_error_handler) ("too many dimensions");
00069 else
00070 Array<T>::fill (val);
00071 }
00072
00073 Array2 (const Array2<T>& a) : Array<T> (a, a.dims ()) { }
00074
00075 Array2 (const Array<T>& a, octave_idx_type r, octave_idx_type c)
00076 : Array<T> (a, dim_vector (r, c)) { }
00077
00078 template <class U>
00079 Array2 (const Array<U>& a) : Array<T> (a) { }
00080
00081 template <class U>
00082 Array2 (const Array<U>& a, const dim_vector& dv)
00083 : Array<T> (a, dv) { }
00084
00085 ~Array2 (void) { }
00086
00087 Array2<T>& operator = (const Array2<T>& a)
00088 {
00089 if (this != &a)
00090 Array<T>::operator = (a);
00091
00092 return *this;
00093 }
00094
00095 void resize (octave_idx_type r, octave_idx_type c)
00096 { Array<T>::resize_fill (r, c, Array<T>::resize_fill_value ()); }
00097
00098 void resize (octave_idx_type r, octave_idx_type c, const T& val)
00099 { Array<T>::resize_fill (r, c, val); }
00100
00101 Array2<T>& insert (const Array2<T>& a, octave_idx_type r, octave_idx_type c)
00102 {
00103 Array<T>::insert (a, r, c);
00104 return *this;
00105 }
00106
00107 Array2<T> transpose (void) const
00108 {
00109 Array<T> tmp = Array<T>::transpose ();
00110 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00111 }
00112
00113 Array2<T> hermitian (T (*fcn) (const T&) = 0) const
00114 {
00115 Array<T> tmp = Array<T>::hermitian (fcn);
00116 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00117 }
00118
00119 Array2<T> index (const idx_vector& i, bool resize_ok = false,
00120 const T& rfv = Array<T>::resize_fill_value ()) const
00121 {
00122 Array<T> tmp = Array<T>::index (i, resize_ok, rfv);
00123 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00124 }
00125
00126 Array2<T> index (const idx_vector& i, const idx_vector& j, bool resize_ok = false,
00127 const T& rfv = Array<T>::resize_fill_value ()) const
00128 {
00129 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv);
00130 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00131 }
00132
00133 Array2<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
00134 {
00135 Array<T> tmp = Array<T>::sort (dim, mode);
00136 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00137 }
00138
00139 Array2<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00140 sortmode mode = ASCENDING) const
00141 {
00142 Array<T> tmp = Array<T>::sort (sidx, dim, mode);
00143 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00144 }
00145
00146 Array2<T> diag (octave_idx_type k) const
00147 {
00148 return Array<T>::diag (k);
00149 }
00150
00151 template <class U, class F>
00152 Array2<U> map (F fcn) const
00153 {
00154 return Array<T>::template map<U> (fcn);
00155 }
00156 };
00157
00158 #endif
00159
00160
00161
00162
00163
00164