Mercurial > octave
annotate liboctave/array/dColVector.cc @ 21301:40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
* mk-octave-config-h.sh, mk-opts.pl, Backend.cc, BaseControl.cc,
ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc, ContextMenu.cc,
EditControl.cc, Figure.cc, FigureWindow.cc, GLCanvas.cc, KeyMap.cc,
ListBoxControl.cc, Logger.cc, Menu.cc, MouseModeActionGroup.cc, Object.cc,
ObjectFactory.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc,
PushButtonControl.cc, PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc,
SliderControl.cc, TextControl.cc, TextEdit.cc, ToggleButtonControl.cc,
ToggleTool.cc, ToolBar.cc, ToolBarButton.cc, __init_qt__.cc,
annotation-dialog.cc, gl-select.cc, module.mk, kpty.cpp, color-picker.cc,
dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc,
find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc,
file-editor-tab.cc, file-editor-tab.h, file-editor.cc, find-dialog.cc,
marker.cc, octave-qscintilla.cc, octave-txt-lexer.cc, main-window.cc,
octave-cmd.cc, octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc,
octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc,
settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc,
thread-manager.cc, welcome-wizard.cc, workspace-model.cc, workspace-view.cc,
build-env-features.sh, build-env.in.cc, Cell.cc, __contourc__.cc,
__dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc, __lin_interpn__.cc,
__pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bitfcns.cc,
bsxfun.cc, c-file-ptr-stream.cc, cdisplay.c, cellfun.cc, coct-hdf5-types.c,
colloc.cc, comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
debug.cc, defaults.cc, defun.cc, det.cc, dirfns.cc, display.cc, dlmread.cc,
dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc, error.cc, errwarn.cc, event-queue.cc,
fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc,
gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc,
gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc, help.cc,
hess.cc, hex2num.cc, hook-fcn.cc, input.cc, inv.cc, jit-ir.cc, jit-typeinfo.cc,
jit-util.cc, kron.cc, load-path.cc, load-save.cc, lookup.cc,
ls-ascii-helper.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc,
ls-oct-binary.cc, ls-oct-text.cc, ls-utils.cc, lsode.cc, lu.cc, luinc.cc,
mappers.cc, matrix_type.cc, max.cc, mex.cc, mgorth.cc, nproc.cc,
oct-errno.in.cc, oct-fstrm.cc, oct-hdf5-types.cc, oct-hist.cc, oct-iostrm.cc,
oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stream.cc,
oct-strstrm.cc, oct-tex-lexer.in.ll, oct-tex-parser.in.yy, octave-link.cc,
ordschur.cc, pager.cc, pinv.cc, pr-output.cc, procstream.cc, profiler.cc,
psi.cc, pt-jit.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc,
schur.cc, sighandlers.cc, siglist.c, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc,
spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc, time.cc,
toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc, urlwrite.cc, utils.cc,
variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc, xpow.cc, zfstream.cc,
__delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc,
__init_fltk__.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc,
__voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc,
colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc,
mkbuiltins, mkops, 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-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.cc,
ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc,
ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc,
ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc, ov-range.cc,
ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc,
ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc,
ov-uint8.cc, ov-usr-fcn.cc, ov.cc, ovl.cc, octave.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-dm-template.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-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-pm-template.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, lex.ll, oct-parse.in.yy,
pt-arg-list.cc, pt-array-list.cc, pt-assign.cc, pt-binop.cc, pt-bp.cc,
pt-cbinop.cc, pt-cell.cc, pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc,
pt-const.cc, pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc,
pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-mat.cc,
pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, pt.cc,
token.cc, Array-jit.cc, Array-os.cc, Array-sym.cc, Array-tc.cc, version.cc,
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, 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, 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,
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, lo-error.c, quit.cc, CollocWt.cc, DASPK.cc, DASRT.cc,
DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc, chol.cc,
eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc, lo-mappers.cc, lo-specfun.cc,
lu.cc, oct-convn.cc, oct-fftw.cc, oct-norm.cc, oct-rand.cc, oct-spparms.cc,
qr.cc, qrp.cc, randgamma.c, randmtzig.c, randpoisson.c, schur.cc,
sparse-chol.cc, sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc,
mk-ops.awk, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc,
oct-env.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc,
oct-uname.cc, cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c,
glob-match.cc, kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c,
lo-ieee.cc, lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc,
oct-inttypes.cc, oct-locbuf.cc, oct-mutex.cc, 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, str-vec.cc, unwind-prot.cc, url-transfer.cc,
display-available.c, main-cli.cc, main-gui.cc, main.in.cc, mkoctfile.in.cc,
octave-config.in.cc:
Use '#include "config.h"' rather than <config.h>.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 18 Feb 2016 13:34:50 -0800 |
parents | f7121e111991 |
children | aba2e6293dd8 |
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:
17744
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 | |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
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 (dgemv, DGEMV) (F77_CONST_CHAR_ARG_DECL, | |
11518 | 45 const octave_idx_type&, const octave_idx_type&, |
46 const double&, const double*, | |
47 const octave_idx_type&, const double*, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
48 const octave_idx_type&, const double&, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
49 const octave_idx_type& |
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 // Column Vector class. |
458 | 54 |
2386 | 55 bool |
458 | 56 ColumnVector::operator == (const ColumnVector& a) const |
57 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
58 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
|
59 if (len != a.numel ()) |
458 | 60 return 0; |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
61 return mx_inline_equal (len, data (), a.data ()); |
458 | 62 } |
63 | |
2386 | 64 bool |
458 | 65 ColumnVector::operator != (const ColumnVector& a) const |
66 { | |
67 return !(*this == a); | |
68 } | |
69 | |
70 ColumnVector& | |
5275 | 71 ColumnVector::insert (const ColumnVector& a, octave_idx_type r) |
458 | 72 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
73 octave_idx_type a_len = a.numel (); |
4316 | 74 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
75 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:
21120
diff
changeset
|
76 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 77 |
4316 | 78 if (a_len > 0) |
79 { | |
80 make_unique (); | |
81 | |
5275 | 82 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
|
83 xelem (r+i) = a.elem (i); |
4316 | 84 } |
458 | 85 |
86 return *this; | |
87 } | |
88 | |
89 ColumnVector& | |
90 ColumnVector::fill (double val) | |
91 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
92 octave_idx_type len = numel (); |
4316 | 93 |
458 | 94 if (len > 0) |
4316 | 95 { |
96 make_unique (); | |
97 | |
5275 | 98 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
|
99 xelem (i) = val; |
4316 | 100 } |
101 | |
458 | 102 return *this; |
103 } | |
104 | |
105 ColumnVector& | |
5275 | 106 ColumnVector::fill (double val, octave_idx_type r1, octave_idx_type r2) |
458 | 107 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
108 octave_idx_type len = numel (); |
4316 | 109 |
458 | 110 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:
21120
diff
changeset
|
111 (*current_liboctave_error_handler) ("range error for fill"); |
458 | 112 |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
113 if (r1 > r2) { std::swap (r1, r2); } |
458 | 114 |
4316 | 115 if (r2 >= r1) |
116 { | |
117 make_unique (); | |
118 | |
5275 | 119 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
|
120 xelem (i) = val; |
4316 | 121 } |
458 | 122 |
123 return *this; | |
124 } | |
125 | |
126 ColumnVector | |
127 ColumnVector::stack (const ColumnVector& a) const | |
128 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
129 octave_idx_type len = numel (); |
5275 | 130 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
|
131 ColumnVector retval (len + a.numel ()); |
458 | 132 retval.insert (*this, 0); |
133 retval.insert (a, nr_insert); | |
134 return retval; | |
135 } | |
136 | |
137 RowVector | |
138 ColumnVector::transpose (void) const | |
139 { | |
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
|
140 return MArray<double>::transpose (); |
458 | 141 } |
142 | |
1205 | 143 ColumnVector |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
144 ColumnVector::abs (void) const |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
145 { |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
146 return do_mx_unary_map<double, double, std::abs> (*this); |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
147 } |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
148 |
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
149 ColumnVector |
1205 | 150 real (const ComplexColumnVector& a) |
151 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
152 return do_mx_unary_op<double, Complex> (a, mx_inline_real); |
1205 | 153 } |
154 | |
155 ColumnVector | |
156 imag (const ComplexColumnVector& a) | |
157 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
158 return do_mx_unary_op<double, Complex> (a, mx_inline_imag); |
1205 | 159 } |
160 | |
458 | 161 // resize is the destructive equivalent for this one |
162 | |
163 ColumnVector | |
5275 | 164 ColumnVector::extract (octave_idx_type r1, octave_idx_type r2) const |
458 | 165 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
166 if (r1 > r2) { std::swap (r1, r2); } |
458 | 167 |
5275 | 168 octave_idx_type new_r = r2 - r1 + 1; |
458 | 169 |
170 ColumnVector result (new_r); | |
171 | |
5275 | 172 for (octave_idx_type i = 0; i < new_r; i++) |
4316 | 173 result.xelem (i) = elem (r1+i); |
174 | |
175 return result; | |
176 } | |
177 | |
178 ColumnVector | |
5275 | 179 ColumnVector::extract_n (octave_idx_type r1, octave_idx_type n) const |
4316 | 180 { |
181 ColumnVector result (n); | |
182 | |
5275 | 183 for (octave_idx_type i = 0; i < n; i++) |
4316 | 184 result.xelem (i) = elem (r1+i); |
458 | 185 |
186 return result; | |
187 } | |
188 | |
1205 | 189 // matrix by column vector -> column vector operations |
458 | 190 |
1205 | 191 ColumnVector |
192 operator * (const Matrix& m, const ColumnVector& a) | |
458 | 193 { |
1947 | 194 ColumnVector retval; |
195 | |
5275 | 196 octave_idx_type nr = m.rows (); |
197 octave_idx_type nc = m.cols (); | |
1947 | 198 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
199 octave_idx_type a_len = a.numel (); |
2386 | 200 |
201 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
|
202 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
|
203 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
204 retval.clear (nr); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
205 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
206 if (nr != 0) |
458 | 207 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
208 if (nc == 0) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
209 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
|
210 else |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
211 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
212 double *y = retval.fortran_vec (); |
1947 | 213 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
214 F77_XFCN (dgemv, DGEMV, (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
|
215 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
|
216 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
|
217 F77_CHAR_ARG_LEN (1))); |
9625
cbabf50315ca
optimize Matrix*ColumnVector
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
218 } |
458 | 219 } |
220 | |
1947 | 221 return retval; |
458 | 222 } |
223 | |
1205 | 224 // diagonal matrix by column vector -> column vector operations |
225 | |
226 ColumnVector | |
227 operator * (const DiagMatrix& m, const ColumnVector& a) | |
458 | 228 { |
1947 | 229 ColumnVector retval; |
230 | |
5275 | 231 octave_idx_type nr = m.rows (); |
232 octave_idx_type nc = m.cols (); | |
1947 | 233 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
234 octave_idx_type a_len = a.numel (); |
1947 | 235 |
1205 | 236 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
|
237 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
|
238 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
239 if (nr == 0 || nc == 0) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
240 retval.resize (nr, 0.0); |
1947 | 241 else |
458 | 242 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
243 retval.resize (nr); |
1947 | 244 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
245 for (octave_idx_type i = 0; i < a_len; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
246 retval.elem (i) = a.elem (i) * m.elem (i, i); |
1947 | 247 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
248 for (octave_idx_type i = a_len; i < nr; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
249 retval.elem (i) = 0.0; |
458 | 250 } |
251 | |
1947 | 252 return retval; |
458 | 253 } |
254 | |
255 // other operations | |
256 | |
257 double | |
258 ColumnVector::min (void) const | |
259 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
260 octave_idx_type len = numel (); |
458 | 261 if (len == 0) |
262 return 0.0; | |
263 | |
264 double res = elem (0); | |
265 | |
5275 | 266 for (octave_idx_type i = 1; i < len; i++) |
458 | 267 if (elem (i) < res) |
268 res = elem (i); | |
269 | |
270 return res; | |
271 } | |
272 | |
273 double | |
274 ColumnVector::max (void) const | |
275 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
276 octave_idx_type len = numel (); |
458 | 277 if (len == 0) |
278 return 0.0; | |
279 | |
280 double res = elem (0); | |
281 | |
5275 | 282 for (octave_idx_type i = 1; i < len; i++) |
458 | 283 if (elem (i) > res) |
284 res = elem (i); | |
285 | |
286 return res; | |
287 } | |
288 | |
3504 | 289 std::ostream& |
290 operator << (std::ostream& os, const ColumnVector& a) | |
458 | 291 { |
292 // 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
|
293 for (octave_idx_type i = 0; i < a.numel (); i++) |
458 | 294 os << /* setw (field_width) << */ a.elem (i) << "\n"; |
295 return os; | |
296 } | |
297 | |
3504 | 298 std::istream& |
299 operator >> (std::istream& is, ColumnVector& a) | |
458 | 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 = a.numel (); |
458 | 302 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
303 if (len > 0) |
458 | 304 { |
305 double tmp; | |
5275 | 306 for (octave_idx_type i = 0; i < len; i++) |
458 | 307 { |
308 is >> tmp; | |
309 if (is) | |
310 a.elem (i) = tmp; | |
311 else | |
312 break; | |
313 } | |
314 } | |
532 | 315 return is; |
458 | 316 } |