Mercurial > octave
annotate liboctave/MArray.h @ 7503:8c32f95c2639
convert mapper functions to new format
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 20 Feb 2008 04:22:50 -0500 |
parents | a1dbe9d80eee |
children | 82be108cc558 |
rev | line source |
---|---|
1993 | 1 // Template array classes with like-type math ops |
237 | 2 /* |
3 | |
7017 | 4 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2003, 2004, |
5 2005, 2006, 2007 John W. Eaton | |
237 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
237 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
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 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
85 template <class U, class F> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
86 MArray<U> map (F fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
87 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
88 return Array<T>::template map<U> (fcn); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
89 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
90 |
3573 | 91 // Currently, the OPS functions don't need to be friends, but that |
92 // may change. | |
93 | |
3610 | 94 // MARRAY_OPS_FRIEND_DECLS (MArray) |
237 | 95 }; |
96 | |
97 #endif | |
98 | |
99 /* | |
100 ;;; Local Variables: *** | |
101 ;;; mode: C++ *** | |
102 ;;; End: *** | |
103 */ |