4508
|
1 // Template array classes with like-type math ops |
|
2 /* |
|
3 |
|
4 Copyright (C) 1996, 1997 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
21 02110-1301, USA. |
4508
|
22 |
|
23 */ |
|
24 |
|
25 #if !defined (octave_MArrayN_h) |
|
26 #define octave_MArrayN_h 1 |
|
27 |
|
28 #include "ArrayN.h" |
4513
|
29 #include "MArray2.h" |
|
30 #include "dim-vector.h" |
|
31 |
|
32 // N-dimensional array with math ops. |
4508
|
33 |
|
34 // But first, some preprocessor abuse... |
|
35 |
|
36 #include "MArray-defs.h" |
|
37 |
|
38 MARRAY_OPS_FORWARD_DECLS (MArrayN) |
|
39 |
|
40 template <class T> |
|
41 class |
|
42 MArrayN : public ArrayN<T> |
|
43 { |
4513
|
44 protected: |
4508
|
45 |
4587
|
46 MArrayN (T *d, const dim_vector& dv) : ArrayN<T> (d, dv) { } |
4508
|
47 |
4513
|
48 public: |
4508
|
49 |
|
50 MArrayN (void) : ArrayN<T> () {} |
|
51 |
4587
|
52 MArrayN (const dim_vector& dv) : ArrayN<T> (dv) { } |
4508
|
53 |
4587
|
54 MArrayN (const dim_vector& dv, const T& val) : ArrayN<T> (dv, val) { } |
4513
|
55 |
4902
|
56 template <class U> |
|
57 explicit MArrayN (const Array2<U>& a) : ArrayN<T> (a) { } |
4508
|
58 |
4902
|
59 template <class U> |
|
60 MArrayN (const ArrayN<U>& a) : ArrayN<T> (a) { } |
4508
|
61 |
4902
|
62 template <class U> |
|
63 MArrayN (const MArrayN<U>& a) : ArrayN<T> (a) { } |
4508
|
64 |
|
65 ~MArrayN (void) { } |
|
66 |
|
67 MArrayN<T>& operator = (const MArrayN<T>& a) |
|
68 { |
|
69 ArrayN<T>::operator = (a); |
|
70 return *this; |
|
71 } |
4902
|
72 |
5602
|
73 octave_idx_type nnz (void) const |
|
74 { |
|
75 octave_idx_type retval = 0; |
|
76 |
|
77 const T *d = this->data (); |
|
78 |
|
79 octave_idx_type nel = this->numel (); |
|
80 |
|
81 for (octave_idx_type i = 0; i < nel; i++) |
|
82 { |
|
83 if (d[i] != T ()) |
|
84 retval++; |
|
85 } |
|
86 |
|
87 return retval; |
|
88 } |
|
89 |
4902
|
90 MArrayN<T> reshape (const dim_vector& new_dims) const |
|
91 { return ArrayN<T>::reshape (new_dims); } |
|
92 |
|
93 MArrayN<T> permute (const Array<int>& vec, bool inv = false) const |
|
94 { return ArrayN<T>::permute (vec, inv); } |
|
95 |
|
96 MArrayN<T> ipermute (const Array<int>& vec) const |
|
97 { return ArrayN<T>::ipermute (vec); } |
|
98 |
|
99 MArrayN squeeze (void) const { return ArrayN<T>::squeeze (); } |
4508
|
100 }; |
|
101 |
|
102 #endif |
4513
|
103 |
|
104 /* |
|
105 ;;; Local Variables: *** |
|
106 ;;; mode: C++ *** |
|
107 ;;; End: *** |
|
108 */ |