Mercurial > octave
annotate liboctave/MDiagArray2.h @ 8367:445d27d79f4e
support permutation matrix objects
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 04 Dec 2008 08:31:56 +0100 |
parents | 8b1a2555c4e2 |
children | e3c9102431a9 |
rev | line source |
---|---|
1993 | 1 // Template array classes with like-type math ops |
1988 | 2 /* |
3 | |
7017 | 4 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2007 |
5 John W. Eaton | |
1988 | 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. | |
1988 | 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/>. | |
1988 | 22 |
23 */ | |
24 | |
25 #if !defined (octave_MDiagArray2_h) | |
26 #define octave_MDiagArray2_h 1 | |
27 | |
28 #include "DiagArray2.h" | |
29 #include "MArray2.h" | |
30 | |
3580 | 31 // Two dimensional diagonal array with math ops. |
3107 | 32 |
3580 | 33 // But first, some preprocessor abuse... |
3107 | 34 |
3580 | 35 #include "MArray-defs.h" |
3107 | 36 |
6708 | 37 MDIAGARRAY2_OPS_FORWARD_DECLS (MDiagArray2, ) |
1988 | 38 |
39 template <class T> | |
3585 | 40 class |
41 MDiagArray2 : public DiagArray2<T> | |
1988 | 42 { |
43 protected: | |
44 | |
5275 | 45 MDiagArray2 (T *d, octave_idx_type r, octave_idx_type c) : DiagArray2<T> (d, r, c) { } |
1988 | 46 |
47 public: | |
48 | |
49 MDiagArray2 (void) : DiagArray2<T> () { } | |
3585 | 50 |
5275 | 51 MDiagArray2 (octave_idx_type r, octave_idx_type c) : DiagArray2<T> (r, c) { } |
3585 | 52 |
5275 | 53 MDiagArray2 (octave_idx_type r, octave_idx_type c, const T& val) : DiagArray2<T> (r, c, val) { } |
3585 | 54 |
55 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { } | |
56 | |
1988 | 57 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { } |
3585 | 58 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
59 template <class U> |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
60 MDiagArray2 (const DiagArray2<U>& a) : DiagArray2<T> (a) { } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
61 |
3585 | 62 explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { } |
1988 | 63 |
64 ~MDiagArray2 (void) { } | |
65 | |
66 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) | |
67 { | |
68 DiagArray2<T>::operator = (a); | |
69 return *this; | |
70 } | |
71 | |
72 operator MArray2<T> () const | |
73 { | |
5275 | 74 octave_idx_type nr = DiagArray2<T>::dim1 (); |
75 octave_idx_type nc = DiagArray2<T>::dim2 (); | |
1988 | 76 |
4513 | 77 MArray2<T> retval (nr, nc, T (0)); |
78 | |
5275 | 79 octave_idx_type len = nr < nc ? nr : nc; |
1988 | 80 |
5275 | 81 for (octave_idx_type i = 0; i < len; i++) |
4645 | 82 retval.xelem (i, i) = this->xelem (i, i); |
1988 | 83 |
84 return retval; | |
85 } | |
86 | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
87 octave_idx_type nnz (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
88 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
89 octave_idx_type retval = 0; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
90 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
91 const T *d = this->Array<T>::data (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
92 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
93 octave_idx_type nel = this->Array<T>::numel (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
94 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
95 for (octave_idx_type i = 0; i < nel; i++) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
96 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
97 if (d[i] != T ()) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
98 retval++; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
99 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
100 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
101 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
102 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
103 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
104 MDiagArray2<T> transpose (void) const { return DiagArray2<T>::transpose (); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
105 MDiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const { return DiagArray2<T>::hermitian (fcn); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
106 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
107 bool is_multiple_of_identity (T val) const; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
108 |
4187 | 109 static MDiagArray2<T> nil_array; |
110 | |
3580 | 111 // Currently, the OPS functions don't need to be friends, but that |
112 // may change. | |
1988 | 113 |
3610 | 114 // MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2) |
3580 | 115 |
116 }; | |
1988 | 117 |
118 #endif | |
119 | |
120 /* | |
121 ;;; Local Variables: *** | |
122 ;;; mode: C++ *** | |
123 ;;; End: *** | |
124 */ |