Mercurial > octave
annotate liboctave/array/CColVector.cc @ 21129:228b65504557
maint: Eliminate useless statements after err_XXX.
* Cell.cc, data.cc, eig.cc, hess.cc, oct-hist.cc, oct-stream.cc, rand.cc,
audioread.cc, ov-base.cc, ov-class.cc, ov.cc, op-int.h, ops.h, CColVector.cc,
CDiagMatrix.cc, CMatrix.cc, CRowVector.cc, DiagArray2.cc, MDiagArray2.cc,
PermMatrix.cc, dMatrix.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc,
fCRowVector.cc, fMatrix.cc, idx-vector.cc, CmplxGEPBAL.cc, dbleGEPBAL.cc,
fCmplxGEPBAL.cc, floatGEPBAL.cc, Sparse-diag-op-defs.h, Sparse-op-defs.h,
Sparse-perm-op-defs.h, mx-inlines.cc, mx-op-defs.h:
maint: Eliminate useless statements after err_XXX.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 21 Jan 2016 12:54:17 -0800 |
parents | 499b851fbfae |
children | 7cac4e7458f2 |
rev | line source |
---|---|
1993 | 1 // ColumnVector manipulations. |
458 | 2 /* |
3 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
4 Copyright (C) 1994-2015 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10363
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
458 | 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. | |
458 | 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/>. | |
458 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
1192 | 26 #include <config.h> |
458 | 27 #endif |
28 | |
3503 | 29 #include <iostream> |
458 | 30 |
4669 | 31 #include "Array-util.h" |
1847 | 32 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7482
diff
changeset
|
33 #include "functor.h" |
1368 | 34 #include "lo-error.h" |
458 | 35 #include "mx-base.h" |
36 #include "mx-inlines.cc" | |
1650 | 37 #include "oct-cmplx.h" |
458 | 38 |
39 // Fortran functions we call. | |
40 | |
41 extern "C" | |
42 { | |
4552 | 43 F77_RET_T |
44 F77_FUNC (zgemv, ZGEMV) (F77_CONST_CHAR_ARG_DECL, | |
11518 | 45 const octave_idx_type&, const octave_idx_type&, |
46 const Complex&, const Complex*, | |
47 const octave_idx_type&, const Complex*, | |
48 const octave_idx_type&, const Complex&, | |
49 Complex*, const octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
50 F77_CHAR_ARG_LEN_DECL); |
458 | 51 } |
52 | |
1360 | 53 // Complex Column Vector class |
458 | 54 |
55 ComplexColumnVector::ComplexColumnVector (const ColumnVector& a) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 : MArray<Complex> (a) |
458 | 57 { |
58 } | |
59 | |
2386 | 60 bool |
458 | 61 ComplexColumnVector::operator == (const ComplexColumnVector& a) const |
62 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
63 octave_idx_type len = numel (); |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
64 if (len != a.numel ()) |
458 | 65 return 0; |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
66 return mx_inline_equal (len, data (), a.data ()); |
458 | 67 } |
68 | |
2386 | 69 bool |
458 | 70 ComplexColumnVector::operator != (const ComplexColumnVector& a) const |
71 { | |
72 return !(*this == a); | |
73 } | |
74 | |
75 // destructive insert/delete/reorder operations | |
76 | |
77 ComplexColumnVector& | |
5275 | 78 ComplexColumnVector::insert (const ColumnVector& a, octave_idx_type r) |
458 | 79 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
80 octave_idx_type a_len = a.numel (); |
4316 | 81 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
82 if (r < 0 || r + a_len > numel ()) |
458 | 83 { |
84 (*current_liboctave_error_handler) ("range error for insert"); | |
85 return *this; | |
86 } | |
87 | |
4316 | 88 if (a_len > 0) |
89 { | |
90 make_unique (); | |
91 | |
5275 | 92 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 xelem (r+i) = a.elem (i); |
4316 | 94 } |
458 | 95 |
96 return *this; | |
97 } | |
98 | |
99 ComplexColumnVector& | |
5275 | 100 ComplexColumnVector::insert (const ComplexColumnVector& a, octave_idx_type r) |
458 | 101 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
102 octave_idx_type a_len = a.numel (); |
4316 | 103 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
104 if (r < 0 || r + a_len > numel ()) |
458 | 105 { |
106 (*current_liboctave_error_handler) ("range error for insert"); | |
107 return *this; | |
108 } | |
109 | |
4316 | 110 if (a_len > 0) |
111 { | |
112 make_unique (); | |
113 | |
5275 | 114 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 xelem (r+i) = a.elem (i); |
4316 | 116 } |
458 | 117 |
118 return *this; | |
119 } | |
120 | |
121 ComplexColumnVector& | |
122 ComplexColumnVector::fill (double val) | |
123 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
124 octave_idx_type len = numel (); |
4316 | 125 |
458 | 126 if (len > 0) |
4316 | 127 { |
128 make_unique (); | |
129 | |
5275 | 130 for (octave_idx_type i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 xelem (i) = val; |
4316 | 132 } |
133 | |
458 | 134 return *this; |
135 } | |
136 | |
137 ComplexColumnVector& | |
138 ComplexColumnVector::fill (const Complex& val) | |
139 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
140 octave_idx_type len = numel (); |
4316 | 141 |
458 | 142 if (len > 0) |
4316 | 143 { |
144 make_unique (); | |
145 | |
5275 | 146 for (octave_idx_type i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
147 xelem (i) = val; |
4316 | 148 } |
149 | |
150 | |
458 | 151 return *this; |
152 } | |
153 | |
154 ComplexColumnVector& | |
5275 | 155 ComplexColumnVector::fill (double val, octave_idx_type r1, octave_idx_type r2) |
458 | 156 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
157 octave_idx_type len = numel (); |
4316 | 158 |
458 | 159 if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) |
160 { | |
161 (*current_liboctave_error_handler) ("range error for fill"); | |
162 return *this; | |
163 } | |
164 | |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
165 if (r1 > r2) { std::swap (r1, r2); } |
458 | 166 |
4316 | 167 if (r2 >= r1) |
168 { | |
169 make_unique (); | |
170 | |
5275 | 171 for (octave_idx_type i = r1; i <= r2; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
172 xelem (i) = val; |
4316 | 173 } |
458 | 174 |
175 return *this; | |
176 } | |
177 | |
178 ComplexColumnVector& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 ComplexColumnVector::fill (const Complex& val, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
180 octave_idx_type r1, octave_idx_type r2) |
458 | 181 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
182 octave_idx_type len = numel (); |
4316 | 183 |
458 | 184 if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) |
185 { | |
186 (*current_liboctave_error_handler) ("range error for fill"); | |
187 return *this; | |
188 } | |
189 | |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
190 if (r1 > r2) { std::swap (r1, r2); } |
458 | 191 |
4316 | 192 if (r2 >= r1) |
193 { | |
194 make_unique (); | |
195 | |
5275 | 196 for (octave_idx_type i = r1; i <= r2; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
197 xelem (i) = val; |
4316 | 198 } |
458 | 199 |
200 return *this; | |
201 } | |
202 | |
203 ComplexColumnVector | |
204 ComplexColumnVector::stack (const ColumnVector& a) const | |
205 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
206 octave_idx_type len = numel (); |
5275 | 207 octave_idx_type nr_insert = len; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
208 ComplexColumnVector retval (len + a.numel ()); |
458 | 209 retval.insert (*this, 0); |
210 retval.insert (a, nr_insert); | |
211 return retval; | |
212 } | |
213 | |
214 ComplexColumnVector | |
215 ComplexColumnVector::stack (const ComplexColumnVector& a) const | |
216 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
217 octave_idx_type len = numel (); |
5275 | 218 octave_idx_type nr_insert = len; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
219 ComplexColumnVector retval (len + a.numel ()); |
458 | 220 retval.insert (*this, 0); |
221 retval.insert (a, nr_insert); | |
222 return retval; | |
223 } | |
224 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
225 ComplexRowVector |
458 | 226 ComplexColumnVector::hermitian (void) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
227 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
228 return MArray<Complex>::hermitian (std::conj); |
458 | 229 } |
230 | |
231 ComplexRowVector | |
232 ComplexColumnVector::transpose (void) const | |
233 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
234 return MArray<Complex>::transpose (); |
458 | 235 } |
236 | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
237 ColumnVector |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
238 ComplexColumnVector::abs (void) const |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
239 { |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
240 return do_mx_unary_map<double, Complex, std::abs> (*this); |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
241 } |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
242 |
458 | 243 ComplexColumnVector |
244 conj (const ComplexColumnVector& a) | |
245 { | |
13107
353c71c76f22
maint: fix compilation problem with g++ -std=c++0x option
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
11586
diff
changeset
|
246 return do_mx_unary_map<Complex, Complex, std::conj<double> > (a); |
458 | 247 } |
248 | |
249 // resize is the destructive equivalent for this one | |
250 | |
251 ComplexColumnVector | |
5275 | 252 ComplexColumnVector::extract (octave_idx_type r1, octave_idx_type r2) const |
458 | 253 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
254 if (r1 > r2) { std::swap (r1, r2); } |
458 | 255 |
5275 | 256 octave_idx_type new_r = r2 - r1 + 1; |
458 | 257 |
258 ComplexColumnVector result (new_r); | |
259 | |
5275 | 260 for (octave_idx_type i = 0; i < new_r; i++) |
458 | 261 result.elem (i) = elem (r1+i); |
262 | |
263 return result; | |
264 } | |
265 | |
4316 | 266 ComplexColumnVector |
5275 | 267 ComplexColumnVector::extract_n (octave_idx_type r1, octave_idx_type n) const |
4316 | 268 { |
269 ComplexColumnVector result (n); | |
270 | |
5275 | 271 for (octave_idx_type i = 0; i < n; i++) |
4316 | 272 result.elem (i) = elem (r1+i); |
273 | |
274 return result; | |
275 } | |
276 | |
458 | 277 // column vector by column vector -> column vector operations |
278 | |
279 ComplexColumnVector& | |
280 ComplexColumnVector::operator += (const ColumnVector& a) | |
281 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
282 octave_idx_type len = numel (); |
2386 | 283 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
284 octave_idx_type a_len = a.numel (); |
2386 | 285 |
286 if (len != a_len) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
287 err_nonconformant ("operator +=", len, a_len); |
458 | 288 |
289 if (len == 0) | |
290 return *this; | |
291 | |
292 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
293 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
294 mx_inline_add2 (len, d, a.data ()); |
458 | 295 return *this; |
296 } | |
297 | |
298 ComplexColumnVector& | |
299 ComplexColumnVector::operator -= (const ColumnVector& a) | |
300 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
301 octave_idx_type len = numel (); |
2386 | 302 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
303 octave_idx_type a_len = a.numel (); |
2386 | 304 |
305 if (len != a_len) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
306 err_nonconformant ("operator -=", len, a_len); |
458 | 307 |
308 if (len == 0) | |
309 return *this; | |
310 | |
311 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
312 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
313 mx_inline_sub2 (len, d, a.data ()); |
458 | 314 return *this; |
315 } | |
316 | |
1205 | 317 // matrix by column vector -> column vector operations |
318 | |
319 ComplexColumnVector | |
320 operator * (const ComplexMatrix& m, const ColumnVector& a) | |
321 { | |
322 ComplexColumnVector tmp (a); | |
323 return m * tmp; | |
324 } | |
325 | |
326 ComplexColumnVector | |
327 operator * (const ComplexMatrix& m, const ComplexColumnVector& a) | |
328 { | |
1947 | 329 ComplexColumnVector retval; |
330 | |
5275 | 331 octave_idx_type nr = m.rows (); |
332 octave_idx_type nc = m.cols (); | |
1947 | 333 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
334 octave_idx_type a_len = a.numel (); |
2386 | 335 |
336 if (nc != a_len) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
337 err_nonconformant ("operator *", nr, nc, a_len, 1); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
338 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
339 retval.clear (nr); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
340 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
341 if (nr != 0) |
458 | 342 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
343 if (nc == 0) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
344 retval.fill (0.0); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
345 else |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
346 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
347 Complex *y = retval.fortran_vec (); |
1947 | 348 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
349 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 ("N", 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
350 nr, nc, 1.0, m.data (), nr, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
351 a.data (), 1, 0.0, y, 1 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
352 F77_CHAR_ARG_LEN (1))); |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
353 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
354 } |
14394
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
355 |
458 | 356 |
1947 | 357 return retval; |
458 | 358 } |
359 | |
1205 | 360 // matrix by column vector -> column vector operations |
361 | |
362 ComplexColumnVector | |
363 operator * (const Matrix& m, const ComplexColumnVector& a) | |
364 { | |
365 ComplexMatrix tmp (m); | |
366 return tmp * a; | |
367 } | |
368 | |
369 // diagonal matrix by column vector -> column vector operations | |
370 | |
371 ComplexColumnVector | |
372 operator * (const DiagMatrix& m, const ComplexColumnVector& a) | |
373 { | |
5275 | 374 octave_idx_type nr = m.rows (); |
375 octave_idx_type nc = m.cols (); | |
2386 | 376 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
377 octave_idx_type a_len = a.numel (); |
2386 | 378 |
1205 | 379 if (nc != a_len) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
380 err_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 381 |
382 if (nc == 0 || nr == 0) | |
383 return ComplexColumnVector (0); | |
384 | |
385 ComplexColumnVector result (nr); | |
386 | |
5275 | 387 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 388 result.elem (i) = a.elem (i) * m.elem (i, i); |
389 | |
5275 | 390 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 391 result.elem (i) = 0.0; |
392 | |
393 return result; | |
394 } | |
395 | |
396 ComplexColumnVector | |
397 operator * (const ComplexDiagMatrix& m, const ColumnVector& a) | |
398 { | |
5275 | 399 octave_idx_type nr = m.rows (); |
400 octave_idx_type nc = m.cols (); | |
2386 | 401 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
402 octave_idx_type a_len = a.numel (); |
2386 | 403 |
1205 | 404 if (nc != a_len) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
405 err_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 406 |
407 if (nc == 0 || nr == 0) | |
408 return ComplexColumnVector (0); | |
409 | |
410 ComplexColumnVector result (nr); | |
411 | |
5275 | 412 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 413 result.elem (i) = a.elem (i) * m.elem (i, i); |
414 | |
5275 | 415 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 416 result.elem (i) = 0.0; |
417 | |
418 return result; | |
419 } | |
420 | |
421 ComplexColumnVector | |
422 operator * (const ComplexDiagMatrix& m, const ComplexColumnVector& a) | |
423 { | |
5275 | 424 octave_idx_type nr = m.rows (); |
425 octave_idx_type nc = m.cols (); | |
2386 | 426 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
427 octave_idx_type a_len = a.numel (); |
2386 | 428 |
1205 | 429 if (nc != a_len) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
430 err_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 431 |
432 if (nc == 0 || nr == 0) | |
433 return ComplexColumnVector (0); | |
434 | |
435 ComplexColumnVector result (nr); | |
436 | |
5275 | 437 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 438 result.elem (i) = a.elem (i) * m.elem (i, i); |
439 | |
5275 | 440 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 441 result.elem (i) = 0.0; |
442 | |
443 return result; | |
444 } | |
445 | |
458 | 446 // other operations |
447 | |
448 Complex | |
449 ComplexColumnVector::min (void) const | |
450 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
451 octave_idx_type len = numel (); |
458 | 452 if (len == 0) |
453 return 0.0; | |
454 | |
455 Complex res = elem (0); | |
5260 | 456 double absres = std::abs (res); |
458 | 457 |
5275 | 458 for (octave_idx_type i = 1; i < len; i++) |
5260 | 459 if (std::abs (elem (i)) < absres) |
458 | 460 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
461 res = elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 absres = std::abs (res); |
458 | 463 } |
464 | |
465 return res; | |
466 } | |
467 | |
468 Complex | |
469 ComplexColumnVector::max (void) const | |
470 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
471 octave_idx_type len = numel (); |
458 | 472 if (len == 0) |
473 return 0.0; | |
474 | |
475 Complex res = elem (0); | |
5260 | 476 double absres = std::abs (res); |
458 | 477 |
5275 | 478 for (octave_idx_type i = 1; i < len; i++) |
5260 | 479 if (std::abs (elem (i)) > absres) |
458 | 480 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 res = elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
482 absres = std::abs (res); |
458 | 483 } |
484 | |
485 return res; | |
486 } | |
487 | |
488 // i/o | |
489 | |
3504 | 490 std::ostream& |
491 operator << (std::ostream& os, const ComplexColumnVector& a) | |
458 | 492 { |
493 // int field_width = os.precision () + 7; | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
494 for (octave_idx_type i = 0; i < a.numel (); i++) |
458 | 495 os << /* setw (field_width) << */ a.elem (i) << "\n"; |
496 return os; | |
497 } | |
498 | |
3504 | 499 std::istream& |
500 operator >> (std::istream& is, ComplexColumnVector& a) | |
458 | 501 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
502 octave_idx_type len = a.numel (); |
458 | 503 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
504 if (len > 0) |
458 | 505 { |
506 double tmp; | |
5275 | 507 for (octave_idx_type i = 0; i < len; i++) |
458 | 508 { |
509 is >> tmp; | |
510 if (is) | |
511 a.elem (i) = tmp; | |
512 else | |
513 break; | |
514 } | |
515 } | |
532 | 516 return is; |
458 | 517 } |