Mercurial > hg > octave-lyh
annotate liboctave/MArray.h @ 8934:c2099a4d12ea
partially optimize accumarray
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 09 Mar 2009 10:59:19 +0100 |
parents | eb63fbe60fab |
children | 66970dd627f6 |
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, |
8920 | 5 2005, 2006, 2007, 2008, 2009 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 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
34 #include "MArray-decl.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 |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
95 // Performs indexed accumulative addition. |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
96 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
97 void idx_add (const idx_vector& idx, T val); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
98 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
99 void idx_add (const idx_vector& idx, const MArray<T>& vals); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
100 |
3573 | 101 // Currently, the OPS functions don't need to be friends, but that |
102 // may change. | |
103 | |
3610 | 104 // MARRAY_OPS_FRIEND_DECLS (MArray) |
237 | 105 }; |
106 | |
107 #endif | |
108 | |
109 /* | |
110 ;;; Local Variables: *** | |
111 ;;; mode: C++ *** | |
112 ;;; End: *** | |
113 */ |