Mercurial > hg > octave-nkf
annotate liboctave/array/CColVector.cc @ 19576:af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
* Array.h: replaced copy_or_memcpy, fill_or_memset, and no_ctor_new
* Array.cc: replaced copy_or_memcpy, and fill_or_memset
* idx-vector.h: replaced copy_or_memcpy, and fill_or_memset
* idx-vector.cc: replaced copy_or_memcpy
* boolSparse.cc: replaced copy_or_memcpy, and fill_or_memset
* Sparse.h: replaced copy_or_memcpy
* Sparse.cc: replaced copy_or_memcpy, and fill_or_memset
* oct-binmap.h: replaced copy_or_memcpy
* mx-inlines.cc: new standard header dependency
* module.mk: removed header entry
* oct-mem.h: removed unused header
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Fri, 05 Dec 2014 13:08:36 +0100 |
parents | 49a5a4be04a1 |
children | 4197fc428c7d |
rev | line source |
---|---|
1993 | 1 // ColumnVector manipulations. |
458 | 2 /* |
3 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17663
diff
changeset
|
4 Copyright (C) 1994-2013 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 { | |
5275 | 63 octave_idx_type len = length (); |
458 | 64 if (len != a.length ()) |
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 { |
5275 | 80 octave_idx_type a_len = a.length (); |
4316 | 81 |
1699 | 82 if (r < 0 || r + a_len > length ()) |
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 { |
5275 | 102 octave_idx_type a_len = a.length (); |
4316 | 103 |
1699 | 104 if (r < 0 || r + a_len > length ()) |
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 { | |
5275 | 124 octave_idx_type len = length (); |
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 { | |
5275 | 140 octave_idx_type len = length (); |
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 { |
5275 | 157 octave_idx_type len = length (); |
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 { |
5275 | 182 octave_idx_type len = length (); |
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 { | |
5275 | 206 octave_idx_type len = length (); |
207 octave_idx_type nr_insert = len; | |
458 | 208 ComplexColumnVector retval (len + a.length ()); |
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 { | |
5275 | 217 octave_idx_type len = length (); |
218 octave_idx_type nr_insert = len; | |
458 | 219 ComplexColumnVector retval (len + a.length ()); |
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 { | |
5275 | 282 octave_idx_type len = length (); |
2386 | 283 |
5275 | 284 octave_idx_type a_len = a.length (); |
2386 | 285 |
286 if (len != a_len) | |
458 | 287 { |
2386 | 288 gripe_nonconformant ("operator +=", len, a_len); |
458 | 289 return *this; |
290 } | |
291 | |
292 if (len == 0) | |
293 return *this; | |
294 | |
295 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
296 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
297 mx_inline_add2 (len, d, a.data ()); |
458 | 298 return *this; |
299 } | |
300 | |
301 ComplexColumnVector& | |
302 ComplexColumnVector::operator -= (const ColumnVector& a) | |
303 { | |
5275 | 304 octave_idx_type len = length (); |
2386 | 305 |
5275 | 306 octave_idx_type a_len = a.length (); |
2386 | 307 |
308 if (len != a_len) | |
458 | 309 { |
2386 | 310 gripe_nonconformant ("operator -=", len, a_len); |
458 | 311 return *this; |
312 } | |
313 | |
314 if (len == 0) | |
315 return *this; | |
316 | |
317 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
318 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
319 mx_inline_sub2 (len, d, a.data ()); |
458 | 320 return *this; |
321 } | |
322 | |
1205 | 323 // matrix by column vector -> column vector operations |
324 | |
325 ComplexColumnVector | |
326 operator * (const ComplexMatrix& m, const ColumnVector& a) | |
327 { | |
328 ComplexColumnVector tmp (a); | |
329 return m * tmp; | |
330 } | |
331 | |
332 ComplexColumnVector | |
333 operator * (const ComplexMatrix& m, const ComplexColumnVector& a) | |
334 { | |
1947 | 335 ComplexColumnVector retval; |
336 | |
5275 | 337 octave_idx_type nr = m.rows (); |
338 octave_idx_type nc = m.cols (); | |
1947 | 339 |
5275 | 340 octave_idx_type a_len = a.length (); |
2386 | 341 |
342 if (nc != a_len) | |
343 gripe_nonconformant ("operator *", nr, nc, a_len, 1); | |
1947 | 344 else |
458 | 345 { |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
346 retval.clear (nr); |
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
347 |
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
348 if (nr != 0) |
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
349 { |
14394
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
350 if (nc == 0) |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
351 retval.fill (0.0); |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
352 else |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
353 { |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
354 Complex *y = retval.fortran_vec (); |
1947 | 355 |
14394
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
356 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 ("N", 1), |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
357 nr, nc, 1.0, m.data (), nr, |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
358 a.data (), 1, 0.0, y, 1 |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
359 F77_CHAR_ARG_LEN (1))); |
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
360 } |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
361 } |
14394
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
362 |
458 | 363 } |
364 | |
1947 | 365 return retval; |
458 | 366 } |
367 | |
1205 | 368 // matrix by column vector -> column vector operations |
369 | |
370 ComplexColumnVector | |
371 operator * (const Matrix& m, const ComplexColumnVector& a) | |
372 { | |
373 ComplexMatrix tmp (m); | |
374 return tmp * a; | |
375 } | |
376 | |
377 // diagonal matrix by column vector -> column vector operations | |
378 | |
379 ComplexColumnVector | |
380 operator * (const DiagMatrix& m, const ComplexColumnVector& a) | |
381 { | |
5275 | 382 octave_idx_type nr = m.rows (); |
383 octave_idx_type nc = m.cols (); | |
2386 | 384 |
5275 | 385 octave_idx_type a_len = a.length (); |
2386 | 386 |
1205 | 387 if (nc != a_len) |
388 { | |
2386 | 389 gripe_nonconformant ("operator *", nr, nc, a_len, 1); |
3585 | 390 return ComplexColumnVector (); |
1205 | 391 } |
392 | |
393 if (nc == 0 || nr == 0) | |
394 return ComplexColumnVector (0); | |
395 | |
396 ComplexColumnVector result (nr); | |
397 | |
5275 | 398 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 399 result.elem (i) = a.elem (i) * m.elem (i, i); |
400 | |
5275 | 401 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 402 result.elem (i) = 0.0; |
403 | |
404 return result; | |
405 } | |
406 | |
407 ComplexColumnVector | |
408 operator * (const ComplexDiagMatrix& m, const ColumnVector& a) | |
409 { | |
5275 | 410 octave_idx_type nr = m.rows (); |
411 octave_idx_type nc = m.cols (); | |
2386 | 412 |
5275 | 413 octave_idx_type a_len = a.length (); |
2386 | 414 |
1205 | 415 if (nc != a_len) |
416 { | |
2386 | 417 gripe_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 418 return ComplexColumnVector (); |
419 } | |
420 | |
421 if (nc == 0 || nr == 0) | |
422 return ComplexColumnVector (0); | |
423 | |
424 ComplexColumnVector result (nr); | |
425 | |
5275 | 426 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 427 result.elem (i) = a.elem (i) * m.elem (i, i); |
428 | |
5275 | 429 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 430 result.elem (i) = 0.0; |
431 | |
432 return result; | |
433 } | |
434 | |
435 ComplexColumnVector | |
436 operator * (const ComplexDiagMatrix& m, const ComplexColumnVector& a) | |
437 { | |
5275 | 438 octave_idx_type nr = m.rows (); |
439 octave_idx_type nc = m.cols (); | |
2386 | 440 |
5275 | 441 octave_idx_type a_len = a.length (); |
2386 | 442 |
1205 | 443 if (nc != a_len) |
444 { | |
2386 | 445 gripe_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 446 return ComplexColumnVector (); |
447 } | |
448 | |
449 if (nc == 0 || nr == 0) | |
450 return ComplexColumnVector (0); | |
451 | |
452 ComplexColumnVector result (nr); | |
453 | |
5275 | 454 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 455 result.elem (i) = a.elem (i) * m.elem (i, i); |
456 | |
5275 | 457 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 458 result.elem (i) = 0.0; |
459 | |
460 return result; | |
461 } | |
462 | |
458 | 463 // other operations |
464 | |
465 Complex | |
466 ComplexColumnVector::min (void) const | |
467 { | |
5275 | 468 octave_idx_type len = length (); |
458 | 469 if (len == 0) |
470 return 0.0; | |
471 | |
472 Complex res = elem (0); | |
5260 | 473 double absres = std::abs (res); |
458 | 474 |
5275 | 475 for (octave_idx_type i = 1; i < len; i++) |
5260 | 476 if (std::abs (elem (i)) < absres) |
458 | 477 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 res = elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 absres = std::abs (res); |
458 | 480 } |
481 | |
482 return res; | |
483 } | |
484 | |
485 Complex | |
486 ComplexColumnVector::max (void) const | |
487 { | |
5275 | 488 octave_idx_type len = length (); |
458 | 489 if (len == 0) |
490 return 0.0; | |
491 | |
492 Complex res = elem (0); | |
5260 | 493 double absres = std::abs (res); |
458 | 494 |
5275 | 495 for (octave_idx_type i = 1; i < len; i++) |
5260 | 496 if (std::abs (elem (i)) > absres) |
458 | 497 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
498 res = elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
499 absres = std::abs (res); |
458 | 500 } |
501 | |
502 return res; | |
503 } | |
504 | |
505 // i/o | |
506 | |
3504 | 507 std::ostream& |
508 operator << (std::ostream& os, const ComplexColumnVector& a) | |
458 | 509 { |
510 // int field_width = os.precision () + 7; | |
5275 | 511 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 512 os << /* setw (field_width) << */ a.elem (i) << "\n"; |
513 return os; | |
514 } | |
515 | |
3504 | 516 std::istream& |
517 operator >> (std::istream& is, ComplexColumnVector& a) | |
458 | 518 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14394
diff
changeset
|
519 octave_idx_type len = a.length (); |
458 | 520 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
521 if (len > 0) |
458 | 522 { |
523 double tmp; | |
5275 | 524 for (octave_idx_type i = 0; i < len; i++) |
458 | 525 { |
526 is >> tmp; | |
527 if (is) | |
528 a.elem (i) = tmp; | |
529 else | |
530 break; | |
531 } | |
532 } | |
532 | 533 return is; |
458 | 534 } |