Mercurial > hg > octave-nkf
annotate liboctave/MArray.h @ 8589:0131fa223dbc
make length invariant in range-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 26 Jan 2009 07:49:04 +0100 |
parents | 82be108cc558 |
children | b756ce0002db |
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 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
66 MArray<T> transpose (void) const { return Array<T>::transpose (); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
67 MArray<T> hermitian (T (*fcn) (const T&) = 0) const { return Array<T>::hermitian (fcn); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
68 |
5602 | 69 octave_idx_type nnz (void) const |
70 { | |
71 octave_idx_type retval = 0; | |
72 | |
73 const T *d = this->data (); | |
74 | |
75 octave_idx_type nel = this->numel (); | |
76 | |
77 for (octave_idx_type i = 0; i < nel; i++) | |
78 { | |
79 if (d[i] != T ()) | |
80 retval++; | |
81 } | |
82 | |
83 return retval; | |
84 } | |
85 | |
6508 | 86 double norm (double p) const; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
87 float norm (float p) const; |
5602 | 88 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
89 template <class U, class F> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
90 MArray<U> map (F fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
91 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
92 return Array<T>::template map<U> (fcn); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
93 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
94 |
3573 | 95 // Currently, the OPS functions don't need to be friends, but that |
96 // may change. | |
97 | |
3610 | 98 // MARRAY_OPS_FRIEND_DECLS (MArray) |
237 | 99 }; |
100 | |
101 #endif | |
102 | |
103 /* | |
104 ;;; Local Variables: *** | |
105 ;;; mode: C++ *** | |
106 ;;; End: *** | |
107 */ |