Mercurial > octave
annotate liboctave/MDiagArray2.h @ 10363:a0728e81ed25
improve diag matrix interface & implementation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 26 Feb 2010 11:44:38 +0100 |
parents | b47ab50a6aa8 |
children | 96ed7c629bbd |
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" | |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
29 #include "MArray.h" |
1988 | 30 |
3580 | 31 // Two dimensional diagonal array with math ops. |
3107 | 32 |
3580 | 33 // But first, some preprocessor abuse... |
3107 | 34 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
35 #include "MArray-decl.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 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
64 MDiagArray2 (const Array<T>& a, octave_idx_type r, octave_idx_type c) |
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
65 : DiagArray2<T> (a, r, c) { } |
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
66 |
1988 | 67 ~MDiagArray2 (void) { } |
68 | |
69 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) | |
70 { | |
71 DiagArray2<T>::operator = (a); | |
72 return *this; | |
73 } | |
74 | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
75 MArray<T> array_value () const |
1988 | 76 { |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
77 return DiagArray2<T>::array_value (); |
1988 | 78 } |
79 | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
80 octave_idx_type nnz (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
81 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
82 octave_idx_type retval = 0; |
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 const T *d = this->data (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
85 |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
86 octave_idx_type nel = this->length (); |
8366
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 for (octave_idx_type i = 0; i < nel; i++) |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 if (d[i] != T ()) |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 retval++; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 } |
8366
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 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
95 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
96 |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
97 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
|
98 { return DiagArray2<T>::diag (k); } |
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
99 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
100 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
|
101 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
|
102 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
103 bool is_multiple_of_identity (T val) const; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
104 |
3580 | 105 // Currently, the OPS functions don't need to be friends, but that |
106 // may change. | |
1988 | 107 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
108 MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2, ) |
3580 | 109 |
110 }; | |
1988 | 111 |
112 #endif |