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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1993
1b57120c997b [project @ 1996-03-03 01:16:15 by jwe]
jwe
parents: 1992
diff changeset
1 // Template array classes with like-type math ops
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
2 /*
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
3
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2003, 2004,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8774
diff changeset
5 2005, 2006, 2007, 2008, 2009 John W. Eaton
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
6
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
8
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
12 option) any later version.
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
13
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
17 for more details.
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
18
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
21 <http://www.gnu.org/licenses/>.
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
22
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
23 */
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
24
382
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 237
diff changeset
25 #if !defined (octave_MArray_h)
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 237
diff changeset
26 #define octave_MArray_h 1
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 237
diff changeset
27
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
28 #include "Array.h"
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
29
3573
6ae6f1180e62 [project @ 2000-02-04 09:01:59 by jwe]
jwe
parents: 3504
diff changeset
30 // One dimensional array with math ops.
3107
a8dcfbf87ea3 [project @ 1997-11-19 22:34:59 by jwe]
jwe
parents: 2847
diff changeset
31
3573
6ae6f1180e62 [project @ 2000-02-04 09:01:59 by jwe]
jwe
parents: 3504
diff changeset
32 // But first, some preprocessor abuse...
3107
a8dcfbf87ea3 [project @ 1997-11-19 22:34:59 by jwe]
jwe
parents: 2847
diff changeset
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
a8dcfbf87ea3 [project @ 1997-11-19 22:34:59 by jwe]
jwe
parents: 2847
diff changeset
35
6708
0ce71beb1cf3 [project @ 2007-06-13 06:40:48 by jwe]
jwe
parents: 6508
diff changeset
36 MARRAY_OPS_FORWARD_DECLS (MArray, )
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
37
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
38 template <class T>
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
39 class
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
40 MArray : public Array<T>
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
41 {
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
42 protected:
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
43
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
44 MArray (T *d, octave_idx_type l) : Array<T> (d, l) { }
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
45
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
46 public:
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
47
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
48 MArray (void) : Array<T> () { }
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
49
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
50 explicit MArray (octave_idx_type n) : Array<T> (n) { }
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
51
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
52 MArray (octave_idx_type n, const T& val) : Array<T> (n, val) { }
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
53
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
54 MArray (const MArray<T>& a) : Array<T> (a) { }
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3573
diff changeset
55
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3107
diff changeset
56 MArray (const Array<T>& a) : Array<T> (a) { }
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
57
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1213
diff changeset
58 ~MArray (void) { }
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1213
diff changeset
59
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
60 MArray<T>& operator = (const MArray<T>& a)
1213
9689615b34f2 [project @ 1995-04-06 02:25:15 by jwe]
jwe
parents: 1011
diff changeset
61 {
9689615b34f2 [project @ 1995-04-06 02:25:15 by jwe]
jwe
parents: 1011
diff changeset
62 Array<T>::operator = (a);
9689615b34f2 [project @ 1995-04-06 02:25:15 by jwe]
jwe
parents: 1011
diff changeset
63 return *this;
9689615b34f2 [project @ 1995-04-06 02:25:15 by jwe]
jwe
parents: 1011
diff changeset
64 }
3573
6ae6f1180e62 [project @ 2000-02-04 09:01:59 by jwe]
jwe
parents: 3504
diff changeset
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
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
69 octave_idx_type nnz (void) const
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
70 {
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
71 octave_idx_type retval = 0;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
72
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
73 const T *d = this->data ();
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
74
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
75 octave_idx_type nel = this->numel ();
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
76
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
77 for (octave_idx_type i = 0; i < nel; i++)
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
78 {
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
79 if (d[i] != T ())
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
80 retval++;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
81 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
82
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
83 return retval;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
84 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
85
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 5602
diff changeset
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
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5307
diff changeset
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
6ae6f1180e62 [project @ 2000-02-04 09:01:59 by jwe]
jwe
parents: 3504
diff changeset
101 // Currently, the OPS functions don't need to be friends, but that
6ae6f1180e62 [project @ 2000-02-04 09:01:59 by jwe]
jwe
parents: 3504
diff changeset
102 // may change.
6ae6f1180e62 [project @ 2000-02-04 09:01:59 by jwe]
jwe
parents: 3504
diff changeset
103
3610
1222153daafb [project @ 2000-03-17 02:31:58 by jwe]
jwe
parents: 3585
diff changeset
104 // MARRAY_OPS_FRIEND_DECLS (MArray)
237
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
105 };
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
106
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
107 #endif
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
108
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
109 /*
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
110 ;;; Local Variables: ***
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
111 ;;; mode: C++ ***
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
112 ;;; End: ***
5a9e23307fb0 [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents:
diff changeset
113 */