4508
|
1 // Template array classes with like-type math ops |
|
2 /* |
|
3 |
7017
|
4 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4508
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
4508
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
4508
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_MArrayN_h) |
|
25 #define octave_MArrayN_h 1 |
|
26 |
|
27 #include "ArrayN.h" |
4513
|
28 #include "MArray2.h" |
|
29 #include "dim-vector.h" |
|
30 |
|
31 // N-dimensional array with math ops. |
4508
|
32 |
|
33 // But first, some preprocessor abuse... |
|
34 |
|
35 #include "MArray-defs.h" |
|
36 |
6708
|
37 MARRAY_OPS_FORWARD_DECLS (MArrayN, ) |
4508
|
38 |
|
39 template <class T> |
|
40 class |
|
41 MArrayN : public ArrayN<T> |
|
42 { |
4513
|
43 protected: |
4508
|
44 |
4587
|
45 MArrayN (T *d, const dim_vector& dv) : ArrayN<T> (d, dv) { } |
4508
|
46 |
4513
|
47 public: |
4508
|
48 |
|
49 MArrayN (void) : ArrayN<T> () {} |
|
50 |
4587
|
51 MArrayN (const dim_vector& dv) : ArrayN<T> (dv) { } |
4508
|
52 |
4587
|
53 MArrayN (const dim_vector& dv, const T& val) : ArrayN<T> (dv, val) { } |
4513
|
54 |
4902
|
55 template <class U> |
|
56 explicit MArrayN (const Array2<U>& a) : ArrayN<T> (a) { } |
4508
|
57 |
4902
|
58 template <class U> |
|
59 MArrayN (const ArrayN<U>& a) : ArrayN<T> (a) { } |
4508
|
60 |
4902
|
61 template <class U> |
|
62 MArrayN (const MArrayN<U>& a) : ArrayN<T> (a) { } |
4508
|
63 |
|
64 ~MArrayN (void) { } |
|
65 |
|
66 MArrayN<T>& operator = (const MArrayN<T>& a) |
|
67 { |
|
68 ArrayN<T>::operator = (a); |
|
69 return *this; |
|
70 } |
4902
|
71 |
5602
|
72 octave_idx_type nnz (void) const |
|
73 { |
|
74 octave_idx_type retval = 0; |
|
75 |
|
76 const T *d = this->data (); |
|
77 |
|
78 octave_idx_type nel = this->numel (); |
|
79 |
|
80 for (octave_idx_type i = 0; i < nel; i++) |
|
81 { |
|
82 if (d[i] != T ()) |
|
83 retval++; |
|
84 } |
|
85 |
|
86 return retval; |
|
87 } |
|
88 |
4902
|
89 MArrayN<T> reshape (const dim_vector& new_dims) const |
|
90 { return ArrayN<T>::reshape (new_dims); } |
|
91 |
6867
|
92 MArrayN<T> permute (const Array<octave_idx_type>& vec, |
|
93 bool inv = false) const |
4902
|
94 { return ArrayN<T>::permute (vec, inv); } |
|
95 |
6867
|
96 MArrayN<T> ipermute (const Array<octave_idx_type>& vec) const |
4902
|
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 */ |