Mercurial > hg > octave-nkf
annotate liboctave/MDiagArray2.h @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | b756ce0002db |
children | 66970dd627f6 |
rev | line source |
---|---|
1993 | 1 // Template array classes with like-type math ops |
1988 | 2 /* |
3 | |
8920 | 4 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009 |
7017 | 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" | |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
30 #include "MArray.h" |
1988 | 31 |
3580 | 32 // Two dimensional diagonal array with math ops. |
3107 | 33 |
3580 | 34 // But first, some preprocessor abuse... |
3107 | 35 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
36 #include "MArray-decl.h" |
3107 | 37 |
6708 | 38 MDIAGARRAY2_OPS_FORWARD_DECLS (MDiagArray2, ) |
1988 | 39 |
40 template <class T> | |
3585 | 41 class |
42 MDiagArray2 : public DiagArray2<T> | |
1988 | 43 { |
44 protected: | |
45 | |
5275 | 46 MDiagArray2 (T *d, octave_idx_type r, octave_idx_type c) : DiagArray2<T> (d, r, c) { } |
1988 | 47 |
48 public: | |
49 | |
50 MDiagArray2 (void) : DiagArray2<T> () { } | |
3585 | 51 |
5275 | 52 MDiagArray2 (octave_idx_type r, octave_idx_type c) : DiagArray2<T> (r, c) { } |
3585 | 53 |
5275 | 54 MDiagArray2 (octave_idx_type r, octave_idx_type c, const T& val) : DiagArray2<T> (r, c, val) { } |
3585 | 55 |
56 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { } | |
57 | |
1988 | 58 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { } |
3585 | 59 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
60 template <class U> |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
61 MDiagArray2 (const DiagArray2<U>& a) : DiagArray2<T> (a) { } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
62 |
3585 | 63 explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { } |
1988 | 64 |
65 ~MDiagArray2 (void) { } | |
66 | |
67 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) | |
68 { | |
69 DiagArray2<T>::operator = (a); | |
70 return *this; | |
71 } | |
72 | |
73 operator MArray2<T> () const | |
74 { | |
8524
937921654627
clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
75 return DiagArray2<T>::operator Array2<T> (); |
1988 | 76 } |
77 | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
78 octave_idx_type nnz (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
79 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
80 octave_idx_type retval = 0; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
81 |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
82 const T *d = this->data (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
83 |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
84 octave_idx_type nel = this->length (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
85 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
86 for (octave_idx_type i = 0; i < nel; i++) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
87 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
88 if (d[i] != T ()) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
89 retval++; |
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 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
92 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
93 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
94 |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
95 MArray<T> diag (octave_idx_type k = 0) const |
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
96 { return DiagArray2<T>::diag (k); } |
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
97 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
98 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
|
99 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
|
100 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
101 bool is_multiple_of_identity (T val) const; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
102 |
4187 | 103 static MDiagArray2<T> nil_array; |
104 | |
3580 | 105 // Currently, the OPS functions don't need to be friends, but that |
106 // may change. | |
1988 | 107 |
3610 | 108 // MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2) |
3580 | 109 |
110 }; | |
1988 | 111 |
112 #endif | |
113 | |
114 /* | |
115 ;;; Local Variables: *** | |
116 ;;; mode: C++ *** | |
117 ;;; End: *** | |
118 */ |