Mercurial > octave
annotate liboctave/array/CColVector.cc @ 21202:f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
* Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc,
Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc,
Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, CSparse.h, DiagArray2.cc, MArray-C.cc,
MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc,
MDiagArray2.cc, MSparse-C.cc, MSparse-d.cc, MSparse.h, MatrixType.cc,
PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, Sparse.cc,
boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc,
dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
dSparse.cc, dSparse.h, dim-vector.cc, fCColVector.cc, fCDiagMatrix.cc,
fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc,
int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, intNDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc,
blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, f77-fcn.h, lo-error.c, quit.cc,
quit.h, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc, CmplxLU.cc,
CmplxQR.cc, CmplxQRP.cc, CmplxSCHUR.cc, CmplxSVD.cc, CollocWt.cc, DASPK.cc,
DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, base-lu.cc, base-qr.cc,
dbleAEPBAL.cc, dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc,
dbleQRP.cc, dbleSCHUR.cc, dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc,
fCmplxCHOL.cc, fCmplxGEPBAL.cc, fCmplxHESS.cc, fCmplxLU.cc, fCmplxQR.cc,
fCmplxQRP.cc, fCmplxSCHUR.cc, fCmplxSVD.cc, fEIG.cc, floatAEPBAL.cc,
floatCHOL.cc, floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc,
floatQRP.cc, floatSCHUR.cc, floatSVD.cc, lo-mappers.cc, lo-specfun.cc,
oct-convn.cc, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-rand.cc,
oct-spparms.cc, randgamma.c, randmtzig.c, randpoisson.c, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, mx-defs.h, dir-ops.cc,
file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc,
oct-group.cc, oct-openmp.h, oct-passwd.cc, oct-syscalls.cc, oct-time.cc,
oct-uname.cc, pathlen.h, sysdir.h, syswait.h, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, f2c-main.c, glob-match.cc, lo-array-errwarn.cc,
lo-array-gripes.cc, lo-cutils.c, lo-cutils.h, lo-ieee.cc, lo-math.h,
lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.cc, oct-mutex.cc, oct-refcount.h, oct-rl-edit.c,
oct-rl-hist.c, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc,
sparse-sort.cc, sparse-util.cc, statdefs.h, str-vec.cc, unwind-prot.cc,
url-transfer.cc, display-available.h, main-cli.cc, main-gui.cc, main.in.cc,
mkoctfile.in.cc, octave-config.in.cc, shared-fcns.h:
indent #ifdef blocks in liboctave and src directories.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 06 Feb 2016 06:40:13 -0800 |
parents | 7cac4e7458f2 |
children | 40de9f8f23a6 |
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 | |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
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 ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
83 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 84 |
4316 | 85 if (a_len > 0) |
86 { | |
87 make_unique (); | |
88 | |
5275 | 89 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
|
90 xelem (r+i) = a.elem (i); |
4316 | 91 } |
458 | 92 |
93 return *this; | |
94 } | |
95 | |
96 ComplexColumnVector& | |
5275 | 97 ComplexColumnVector::insert (const ComplexColumnVector& a, octave_idx_type r) |
458 | 98 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
99 octave_idx_type a_len = a.numel (); |
4316 | 100 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
101 if (r < 0 || r + a_len > numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
102 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 103 |
4316 | 104 if (a_len > 0) |
105 { | |
106 make_unique (); | |
107 | |
5275 | 108 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
|
109 xelem (r+i) = a.elem (i); |
4316 | 110 } |
458 | 111 |
112 return *this; | |
113 } | |
114 | |
115 ComplexColumnVector& | |
116 ComplexColumnVector::fill (double val) | |
117 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
118 octave_idx_type len = numel (); |
4316 | 119 |
458 | 120 if (len > 0) |
4316 | 121 { |
122 make_unique (); | |
123 | |
5275 | 124 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
|
125 xelem (i) = val; |
4316 | 126 } |
127 | |
458 | 128 return *this; |
129 } | |
130 | |
131 ComplexColumnVector& | |
132 ComplexColumnVector::fill (const Complex& val) | |
133 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
134 octave_idx_type len = numel (); |
4316 | 135 |
458 | 136 if (len > 0) |
4316 | 137 { |
138 make_unique (); | |
139 | |
5275 | 140 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
|
141 xelem (i) = val; |
4316 | 142 } |
143 | |
144 | |
458 | 145 return *this; |
146 } | |
147 | |
148 ComplexColumnVector& | |
5275 | 149 ComplexColumnVector::fill (double val, octave_idx_type r1, octave_idx_type r2) |
458 | 150 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
151 octave_idx_type len = numel (); |
4316 | 152 |
458 | 153 if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
154 (*current_liboctave_error_handler) ("range error for fill"); |
458 | 155 |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
156 if (r1 > r2) { std::swap (r1, r2); } |
458 | 157 |
4316 | 158 if (r2 >= r1) |
159 { | |
160 make_unique (); | |
161 | |
5275 | 162 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
|
163 xelem (i) = val; |
4316 | 164 } |
458 | 165 |
166 return *this; | |
167 } | |
168 | |
169 ComplexColumnVector& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
170 ComplexColumnVector::fill (const Complex& val, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
171 octave_idx_type r1, octave_idx_type r2) |
458 | 172 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
173 octave_idx_type len = numel (); |
4316 | 174 |
458 | 175 if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
176 (*current_liboctave_error_handler) ("range error for fill"); |
458 | 177 |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
178 if (r1 > r2) { std::swap (r1, r2); } |
458 | 179 |
4316 | 180 if (r2 >= r1) |
181 { | |
182 make_unique (); | |
183 | |
5275 | 184 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
|
185 xelem (i) = val; |
4316 | 186 } |
458 | 187 |
188 return *this; | |
189 } | |
190 | |
191 ComplexColumnVector | |
192 ComplexColumnVector::stack (const ColumnVector& a) const | |
193 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
194 octave_idx_type len = numel (); |
5275 | 195 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
|
196 ComplexColumnVector retval (len + a.numel ()); |
458 | 197 retval.insert (*this, 0); |
198 retval.insert (a, nr_insert); | |
199 return retval; | |
200 } | |
201 | |
202 ComplexColumnVector | |
203 ComplexColumnVector::stack (const ComplexColumnVector& a) const | |
204 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
205 octave_idx_type len = numel (); |
5275 | 206 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
|
207 ComplexColumnVector retval (len + a.numel ()); |
458 | 208 retval.insert (*this, 0); |
209 retval.insert (a, nr_insert); | |
210 return retval; | |
211 } | |
212 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
213 ComplexRowVector |
458 | 214 ComplexColumnVector::hermitian (void) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
215 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
216 return MArray<Complex>::hermitian (std::conj); |
458 | 217 } |
218 | |
219 ComplexRowVector | |
220 ComplexColumnVector::transpose (void) const | |
221 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
222 return MArray<Complex>::transpose (); |
458 | 223 } |
224 | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
225 ColumnVector |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
226 ComplexColumnVector::abs (void) const |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
227 { |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
228 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
|
229 } |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
230 |
458 | 231 ComplexColumnVector |
232 conj (const ComplexColumnVector& a) | |
233 { | |
13107
353c71c76f22
maint: fix compilation problem with g++ -std=c++0x option
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
11586
diff
changeset
|
234 return do_mx_unary_map<Complex, Complex, std::conj<double> > (a); |
458 | 235 } |
236 | |
237 // resize is the destructive equivalent for this one | |
238 | |
239 ComplexColumnVector | |
5275 | 240 ComplexColumnVector::extract (octave_idx_type r1, octave_idx_type r2) const |
458 | 241 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
242 if (r1 > r2) { std::swap (r1, r2); } |
458 | 243 |
5275 | 244 octave_idx_type new_r = r2 - r1 + 1; |
458 | 245 |
246 ComplexColumnVector result (new_r); | |
247 | |
5275 | 248 for (octave_idx_type i = 0; i < new_r; i++) |
458 | 249 result.elem (i) = elem (r1+i); |
250 | |
251 return result; | |
252 } | |
253 | |
4316 | 254 ComplexColumnVector |
5275 | 255 ComplexColumnVector::extract_n (octave_idx_type r1, octave_idx_type n) const |
4316 | 256 { |
257 ComplexColumnVector result (n); | |
258 | |
5275 | 259 for (octave_idx_type i = 0; i < n; i++) |
4316 | 260 result.elem (i) = elem (r1+i); |
261 | |
262 return result; | |
263 } | |
264 | |
458 | 265 // column vector by column vector -> column vector operations |
266 | |
267 ComplexColumnVector& | |
268 ComplexColumnVector::operator += (const ColumnVector& a) | |
269 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
270 octave_idx_type len = numel (); |
2386 | 271 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
272 octave_idx_type a_len = a.numel (); |
2386 | 273 |
274 if (len != a_len) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
275 err_nonconformant ("operator +=", len, a_len); |
458 | 276 |
277 if (len == 0) | |
278 return *this; | |
279 | |
280 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
281 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
282 mx_inline_add2 (len, d, a.data ()); |
458 | 283 return *this; |
284 } | |
285 | |
286 ComplexColumnVector& | |
287 ComplexColumnVector::operator -= (const ColumnVector& a) | |
288 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
289 octave_idx_type len = numel (); |
2386 | 290 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
291 octave_idx_type a_len = a.numel (); |
2386 | 292 |
293 if (len != a_len) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
294 err_nonconformant ("operator -=", len, a_len); |
458 | 295 |
296 if (len == 0) | |
297 return *this; | |
298 | |
299 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
300 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
301 mx_inline_sub2 (len, d, a.data ()); |
458 | 302 return *this; |
303 } | |
304 | |
1205 | 305 // matrix by column vector -> column vector operations |
306 | |
307 ComplexColumnVector | |
308 operator * (const ComplexMatrix& m, const ColumnVector& a) | |
309 { | |
310 ComplexColumnVector tmp (a); | |
311 return m * tmp; | |
312 } | |
313 | |
314 ComplexColumnVector | |
315 operator * (const ComplexMatrix& m, const ComplexColumnVector& a) | |
316 { | |
1947 | 317 ComplexColumnVector retval; |
318 | |
5275 | 319 octave_idx_type nr = m.rows (); |
320 octave_idx_type nc = m.cols (); | |
1947 | 321 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
322 octave_idx_type a_len = a.numel (); |
2386 | 323 |
324 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
|
325 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
|
326 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
327 retval.clear (nr); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
328 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
329 if (nr != 0) |
458 | 330 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
331 if (nc == 0) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
332 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
|
333 else |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
334 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
335 Complex *y = retval.fortran_vec (); |
1947 | 336 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 F77_CHAR_ARG_LEN (1))); |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
341 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
342 } |
14394
ed8c4921bf61
correctly fill result for M * v for Nx0 * 0x1 operations
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
343 |
458 | 344 |
1947 | 345 return retval; |
458 | 346 } |
347 | |
1205 | 348 // matrix by column vector -> column vector operations |
349 | |
350 ComplexColumnVector | |
351 operator * (const Matrix& m, const ComplexColumnVector& a) | |
352 { | |
353 ComplexMatrix tmp (m); | |
354 return tmp * a; | |
355 } | |
356 | |
357 // diagonal matrix by column vector -> column vector operations | |
358 | |
359 ComplexColumnVector | |
360 operator * (const DiagMatrix& m, const ComplexColumnVector& a) | |
361 { | |
5275 | 362 octave_idx_type nr = m.rows (); |
363 octave_idx_type nc = m.cols (); | |
2386 | 364 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
365 octave_idx_type a_len = a.numel (); |
2386 | 366 |
1205 | 367 if (nc != a_len) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
368 err_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 369 |
370 if (nc == 0 || nr == 0) | |
371 return ComplexColumnVector (0); | |
372 | |
373 ComplexColumnVector result (nr); | |
374 | |
5275 | 375 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 376 result.elem (i) = a.elem (i) * m.elem (i, i); |
377 | |
5275 | 378 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 379 result.elem (i) = 0.0; |
380 | |
381 return result; | |
382 } | |
383 | |
384 ComplexColumnVector | |
385 operator * (const ComplexDiagMatrix& m, const ColumnVector& a) | |
386 { | |
5275 | 387 octave_idx_type nr = m.rows (); |
388 octave_idx_type nc = m.cols (); | |
2386 | 389 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
390 octave_idx_type a_len = a.numel (); |
2386 | 391 |
1205 | 392 if (nc != a_len) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
393 err_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 394 |
395 if (nc == 0 || nr == 0) | |
396 return ComplexColumnVector (0); | |
397 | |
398 ComplexColumnVector result (nr); | |
399 | |
5275 | 400 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 401 result.elem (i) = a.elem (i) * m.elem (i, i); |
402 | |
5275 | 403 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 404 result.elem (i) = 0.0; |
405 | |
406 return result; | |
407 } | |
408 | |
409 ComplexColumnVector | |
410 operator * (const ComplexDiagMatrix& m, const ComplexColumnVector& a) | |
411 { | |
5275 | 412 octave_idx_type nr = m.rows (); |
413 octave_idx_type nc = m.cols (); | |
2386 | 414 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
415 octave_idx_type a_len = a.numel (); |
2386 | 416 |
1205 | 417 if (nc != a_len) |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
418 err_nonconformant ("operator *", nr, nc, a_len, 1); |
1205 | 419 |
420 if (nc == 0 || nr == 0) | |
421 return ComplexColumnVector (0); | |
422 | |
423 ComplexColumnVector result (nr); | |
424 | |
5275 | 425 for (octave_idx_type i = 0; i < a_len; i++) |
1205 | 426 result.elem (i) = a.elem (i) * m.elem (i, i); |
427 | |
5275 | 428 for (octave_idx_type i = a_len; i < nr; i++) |
1205 | 429 result.elem (i) = 0.0; |
430 | |
431 return result; | |
432 } | |
433 | |
458 | 434 // other operations |
435 | |
436 Complex | |
437 ComplexColumnVector::min (void) const | |
438 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
439 octave_idx_type len = numel (); |
458 | 440 if (len == 0) |
441 return 0.0; | |
442 | |
443 Complex res = elem (0); | |
5260 | 444 double absres = std::abs (res); |
458 | 445 |
5275 | 446 for (octave_idx_type i = 1; i < len; i++) |
5260 | 447 if (std::abs (elem (i)) < absres) |
458 | 448 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
449 res = elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 absres = std::abs (res); |
458 | 451 } |
452 | |
453 return res; | |
454 } | |
455 | |
456 Complex | |
457 ComplexColumnVector::max (void) const | |
458 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
459 octave_idx_type len = numel (); |
458 | 460 if (len == 0) |
461 return 0.0; | |
462 | |
463 Complex res = elem (0); | |
5260 | 464 double absres = std::abs (res); |
458 | 465 |
5275 | 466 for (octave_idx_type i = 1; i < len; i++) |
5260 | 467 if (std::abs (elem (i)) > absres) |
458 | 468 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 res = elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 absres = std::abs (res); |
458 | 471 } |
472 | |
473 return res; | |
474 } | |
475 | |
476 // i/o | |
477 | |
3504 | 478 std::ostream& |
479 operator << (std::ostream& os, const ComplexColumnVector& a) | |
458 | 480 { |
481 // 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
|
482 for (octave_idx_type i = 0; i < a.numel (); i++) |
458 | 483 os << /* setw (field_width) << */ a.elem (i) << "\n"; |
484 return os; | |
485 } | |
486 | |
3504 | 487 std::istream& |
488 operator >> (std::istream& is, ComplexColumnVector& a) | |
458 | 489 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
490 octave_idx_type len = a.numel (); |
458 | 491 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
492 if (len > 0) |
458 | 493 { |
494 double tmp; | |
5275 | 495 for (octave_idx_type i = 0; i < len; i++) |
458 | 496 { |
497 is >> tmp; | |
498 if (is) | |
499 a.elem (i) = tmp; | |
500 else | |
501 break; | |
502 } | |
503 } | |
532 | 504 return is; |
458 | 505 } |