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