comparison liboctave/dDiagMatrix.h @ 458:38cb88095913

[project @ 1994-06-06 00:41:10 by jwe] Initial revision
author jwe
date Mon, 06 Jun 1994 00:41:10 +0000
parents
children 2ca256b77602
comparison
equal deleted inserted replaced
457:3d4b4f0fa5ba 458:38cb88095913
1 // -*- C++ -*-
2 /*
3
4 Copyright (C) 1992, 1993, 1994 John W. Eaton
5
6 This file is part of Octave.
7
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, write to the Free
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24 #if !defined (octave_DiagMatrix_h)
25 #define octave_DiagMatrix_h 1
26
27 #if defined (__GNUG__)
28 #pragma interface
29 #endif
30
31 #include "Array.h"
32
33 #include "dRowVector.h"
34 #include "dColVector.h"
35
36 #include "mx-defs.h"
37
38 extern "C++" {
39
40 class DiagMatrix : public DiagArray<double>
41 {
42 friend class SVD;
43 friend class ComplexSVD;
44
45 public:
46
47 DiagMatrix (void) : DiagArray<double> () { }
48 DiagMatrix (int n) : DiagArray<double> (n) { }
49 DiagMatrix (int n, double val) : DiagArray<double> (n, val) { }
50 DiagMatrix (int r, int c) : DiagArray<double> (r, c) { }
51 DiagMatrix (int r, int c, double val) : DiagArray<double> (r, c, val) { }
52 DiagMatrix (const RowVector& a) : DiagArray<double> (a) { }
53 DiagMatrix (const ColumnVector& a) : DiagArray<double> (a) { }
54 DiagMatrix (const DiagArray<double>& a) : DiagArray<double> (a) { }
55 DiagMatrix (const DiagMatrix& a) : DiagArray<double> (a) { }
56 // DiagMatrix (double a) : DiagArray<double> (1, a) { }
57
58 DiagMatrix& operator = (const DiagMatrix& a)
59 {
60 DiagArray<double>::operator = (a);
61 return *this;
62 }
63
64 // operator DiagArray<double>& () const { return *this; }
65
66 int operator == (const DiagMatrix& a) const;
67 int operator != (const DiagMatrix& a) const;
68
69 DiagMatrix& fill (double val);
70 DiagMatrix& fill (double val, int beg, int end);
71 DiagMatrix& fill (const ColumnVector& a);
72 DiagMatrix& fill (const RowVector& a);
73 DiagMatrix& fill (const ColumnVector& a, int beg);
74 DiagMatrix& fill (const RowVector& a, int beg);
75
76 DiagMatrix transpose (void) const;
77
78 // resize is the destructive analog for this one
79
80 Matrix extract (int r1, int c1, int r2, int c2) const;
81
82 // extract row or column i.
83
84 RowVector row (int i) const;
85 RowVector row (char *s) const;
86
87 ColumnVector column (int i) const;
88 ColumnVector column (char *s) const;
89
90 DiagMatrix inverse (void) const;
91 DiagMatrix inverse (int& info) const;
92
93 // diagonal matrix by diagonal matrix -> diagonal matrix operations
94
95 DiagMatrix& operator += (const DiagMatrix& a);
96 DiagMatrix& operator -= (const DiagMatrix& a);
97
98 // diagonal matrix by scalar -> matrix operations
99
100 friend Matrix operator + (const DiagMatrix& a, double s);
101 friend Matrix operator - (const DiagMatrix& a, double s);
102
103 friend ComplexMatrix operator + (const DiagMatrix& a, const Complex& s);
104 friend ComplexMatrix operator - (const DiagMatrix& a, const Complex& s);
105
106 // diagonal matrix by scalar -> diagonal matrix operations
107
108 friend ComplexDiagMatrix operator * (const DiagMatrix& a, const Complex& s);
109 friend ComplexDiagMatrix operator / (const DiagMatrix& a, const Complex& s);
110
111 // scalar by diagonal matrix -> matrix operations
112
113 friend Matrix operator + (double s, const DiagMatrix& a);
114 friend Matrix operator - (double s, const DiagMatrix& a);
115
116 friend ComplexMatrix operator + (const Complex& s, const DiagMatrix& a);
117 friend ComplexMatrix operator - (const Complex& s, const DiagMatrix& a);
118
119 // scalar by diagonal matrix -> diagonal matrix operations
120
121 friend ComplexDiagMatrix operator * (const Complex& s, const DiagMatrix& a);
122
123 // diagonal matrix by column vector -> column vector operations
124
125 friend ColumnVector operator * (const DiagMatrix& a, const ColumnVector& b);
126
127 friend ComplexColumnVector operator * (const DiagMatrix& a,
128 const ComplexColumnVector& b);
129
130 // diagonal matrix by diagonal matrix -> diagonal matrix operations
131
132 friend DiagMatrix operator * (const DiagMatrix& a,
133 const DiagMatrix& b);
134
135 friend ComplexDiagMatrix operator + (const DiagMatrix& a,
136 const ComplexDiagMatrix& b);
137 friend ComplexDiagMatrix operator - (const DiagMatrix& a,
138 const ComplexDiagMatrix& b);
139 friend ComplexDiagMatrix operator * (const DiagMatrix& a,
140 const ComplexDiagMatrix& b);
141
142 friend ComplexDiagMatrix product (const DiagMatrix& a,
143 const ComplexDiagMatrix& b);
144
145 // diagonal matrix by matrix -> matrix operations
146
147 friend Matrix operator + (const DiagMatrix& a, const Matrix& b);
148 friend Matrix operator - (const DiagMatrix& a, const Matrix& b);
149 friend Matrix operator * (const DiagMatrix& a, const Matrix& b);
150
151 friend ComplexMatrix operator + (const DiagMatrix& a,
152 const ComplexMatrix& b);
153 friend ComplexMatrix operator - (const DiagMatrix& a,
154 const ComplexMatrix& b);
155 friend ComplexMatrix operator * (const DiagMatrix& a,
156 const ComplexMatrix& b);
157
158 // other operations
159
160 ColumnVector diag (void) const;
161 ColumnVector diag (int k) const;
162
163 // i/o
164
165 friend ostream& operator << (ostream& os, const DiagMatrix& a);
166
167 #define KLUDGE_DIAG_MATRICES
168 #define TYPE double
169 #define KL_DMAT_TYPE DiagMatrix
170 #include "mx-kludge.h"
171 #undef KLUDGE_DIAG_MATRICES
172 #undef TYPE
173 #undef KL_DMAT_TYPE
174
175 private:
176
177 DiagMatrix (double *d, int nr, int nc) : DiagArray<double> (d, nr, nc) { }
178 };
179
180 } // extern "C++"
181
182 #endif
183
184 /*
185 ;;; Local Variables: ***
186 ;;; mode: C++ ***
187 ;;; page-delimiter: "^/\\*" ***
188 ;;; End: ***
189 */