Mercurial > octave
annotate liboctave/array/CColVector.cc @ 21100:e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
* libinterp/corefcn/errwarn.h, libinterp/corefcn/errwarn.cc: New header and .cc
file with common errors and warnings for libinterp.
* libinterp/corefcn/module.mk: Add errwarn.h, errwarn.cc to build system.
* liboctave/util/lo-array-errwarn.h, liboctave/util/lo-array-errwarn.cc: New
header and .cc file with common errors and warnings for liboctave.
* liboctave/util/module.mk: Add lo-array-errwarn.h, lo-array-errwarn.cc to
build system.
* lo-array-gripes.h: #include "lo-array-errwarn.h" for access to class
index_exception. Remove const char *error_id_XXX prototypes.
* lo-array-gripes.cc: Remove const char *error_id_XXX initializations.
Remove index_exception method definitions.
* Cell.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, betainc.cc, cellfun.cc,
daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, det.cc,
dirfns.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, find.cc, gammainc.cc, gcd.cc,
getgrent.cc, getpwent.cc, graphics.in.h, help.cc, hess.cc, hex2num.cc,
input.cc, inv.cc, jit-typeinfo.cc, load-save.cc, lookup.cc, ls-hdf5.cc,
ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc,
lsode.cc, lu.cc, luinc.cc, max.cc, mgorth.cc, oct-hist.cc, oct-procbuf.cc,
oct-stream.cc, oct.h, pager.cc, pinv.cc, pr-output.cc, quad.cc, qz.cc, rand.cc,
rcond.cc, regexp.cc, schur.cc, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc,
spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, syscalls.cc, typecast.cc, utils.cc, variables.cc, xdiv.cc,
xnorm.cc, xpow.cc, __eigs__.cc, __glpk__.cc, __magick_read__.cc,
__osmesa_print__.cc, audiodevinfo.cc, audioread.cc, chol.cc, dmperm.cc,
fftw.cc, qr.cc, symbfact.cc, symrcm.cc, ov-base-diag.cc, ov-base-int.cc,
ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc,
ov-ch-mat.cc, ov-class.cc, ov-complex.cc, ov-complex.h, ov-cs-list.cc,
ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h,
ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-mex-fcn.cc, ov-perm.cc,
ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h,
ov-str-mat.cc, ov-struct.cc, ov-type-conv.h, ov-uint16.cc, ov-uint32.cc,
ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dms-template.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fdm.cc,
op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc,
op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc,
op-float-conv.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int-conv.cc,
op-int.h, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc,
op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-cm.cc,
op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc,
op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc,
op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc,
op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc,
op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
ops.h, lex.ll, pt-assign.cc, pt-eval.cc, pt-idx.cc, pt-loop.cc, pt-mat.cc,
pt-stmt.cc, Array-util.cc, Array-util.h, Array.cc, CColVector.cc,
CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc,
DiagArray2.cc, MDiagArray2.cc, MSparse.cc, PermMatrix.cc, Range.cc, Sparse.cc,
dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
dSparse.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc,
fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc,
fRowVector.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, oct-binmap.h:
Replace 'include "gripes.h"' with 'include "errwarn.h". Change all gripe_XXX
to err_XXX or warn_XXX or errwarn_XXX.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Jan 2016 18:28:06 -0800 |
parents | a9574e3c6e9e |
children | 499b851fbfae |
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) | |
458 | 287 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
288 err_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 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
304 octave_idx_type len = numel (); |
2386 | 305 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
306 octave_idx_type a_len = a.numel (); |
2386 | 307 |
308 if (len != a_len) | |
458 | 309 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
310 err_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 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
340 octave_idx_type a_len = a.numel (); |
2386 | 341 |
342 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
|
343 err_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 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
385 octave_idx_type a_len = a.numel (); |
2386 | 386 |
1205 | 387 if (nc != a_len) |
388 { | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
389 err_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 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
413 octave_idx_type a_len = a.numel (); |
2386 | 414 |
1205 | 415 if (nc != a_len) |
416 { | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
417 err_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 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
441 octave_idx_type a_len = a.numel (); |
2386 | 442 |
1205 | 443 if (nc != a_len) |
444 { | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
445 err_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 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
468 octave_idx_type len = numel (); |
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 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
488 octave_idx_type len = numel (); |
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; | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
511 for (octave_idx_type i = 0; i < a.numel (); 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 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
519 octave_idx_type len = a.numel (); |
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 } |