1993
|
1 // Template array classes with like-type math ops |
237
|
2 /* |
|
3 |
2847
|
4 Copyright (C) 1996, 1997 John W. Eaton |
237
|
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. |
237
|
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/>. |
237
|
21 |
|
22 */ |
|
23 |
382
|
24 #if !defined (octave_MArray_h) |
|
25 #define octave_MArray_h 1 |
|
26 |
237
|
27 #include "Array.h" |
|
28 |
3573
|
29 // One dimensional array with math ops. |
3107
|
30 |
3573
|
31 // But first, some preprocessor abuse... |
3107
|
32 |
3573
|
33 #include "MArray-defs.h" |
3107
|
34 |
6708
|
35 MARRAY_OPS_FORWARD_DECLS (MArray, ) |
237
|
36 |
|
37 template <class T> |
3585
|
38 class |
|
39 MArray : public Array<T> |
237
|
40 { |
|
41 protected: |
|
42 |
5275
|
43 MArray (T *d, octave_idx_type l) : Array<T> (d, l) { } |
237
|
44 |
|
45 public: |
|
46 |
|
47 MArray (void) : Array<T> () { } |
3585
|
48 |
5275
|
49 explicit MArray (octave_idx_type n) : Array<T> (n) { } |
3585
|
50 |
5275
|
51 MArray (octave_idx_type n, const T& val) : Array<T> (n, val) { } |
3585
|
52 |
|
53 MArray (const MArray<T>& a) : Array<T> (a) { } |
|
54 |
3419
|
55 MArray (const Array<T>& a) : Array<T> (a) { } |
237
|
56 |
1230
|
57 ~MArray (void) { } |
|
58 |
237
|
59 MArray<T>& operator = (const MArray<T>& a) |
1213
|
60 { |
|
61 Array<T>::operator = (a); |
|
62 return *this; |
|
63 } |
3573
|
64 |
5602
|
65 octave_idx_type nnz (void) const |
|
66 { |
|
67 octave_idx_type retval = 0; |
|
68 |
|
69 const T *d = this->data (); |
|
70 |
|
71 octave_idx_type nel = this->numel (); |
|
72 |
|
73 for (octave_idx_type i = 0; i < nel; i++) |
|
74 { |
|
75 if (d[i] != T ()) |
|
76 retval++; |
|
77 } |
|
78 |
|
79 return retval; |
|
80 } |
|
81 |
6508
|
82 double norm (double p) const; |
5602
|
83 |
3573
|
84 // Currently, the OPS functions don't need to be friends, but that |
|
85 // may change. |
|
86 |
3610
|
87 // MARRAY_OPS_FRIEND_DECLS (MArray) |
237
|
88 }; |
|
89 |
|
90 #endif |
|
91 |
|
92 /* |
|
93 ;;; Local Variables: *** |
|
94 ;;; mode: C++ *** |
|
95 ;;; End: *** |
|
96 */ |