Mercurial > octave
annotate libinterp/corefcn/oct-map.cc @ 21200:fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
* builtins.h, 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, c-file-ptr-stream.h, cellfun.cc, colloc.cc,
comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc,
defaults.cc, defaults.in.h, defun-dld.h, defun.cc, defun.h, 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, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc,
givens.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, gripes.cc,
hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc,
jit-typeinfo.cc, jit-util.cc, jit-util.h, 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-oct-text.h, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, luinc.cc, mappers.cc, matrix_type.cc, max.cc,
mex.h, mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc,
oct-hdf5-types.cc, oct-hdf5.h, oct-hist.cc, oct-iostrm.cc, oct-lvalue.cc,
oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stream.cc, oct-strstrm.cc,
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, 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, sysdep.h, time.cc, toplev.cc,
tril.cc, tsearch.cc, txt-eng-ft.cc, txt-eng.cc, typecast.cc, urlwrite.cc,
utils.cc, variables.cc, xdiv.cc, 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, oct-qhull.h, qr.cc, symbfact.cc,
symrcm.cc, oct-conf.in.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-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, 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-colon.h,
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:
Indent #ifdef blocks in libinterp.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 05 Feb 2016 16:29:08 -0800 |
parents | 538b57866b90 |
children | 40de9f8f23a6 |
rev | line source |
---|---|
1278 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
3 Copyright (C) 1995-2015 John W. Eaton |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
4 Copyright (C) 2010 VZLU Prague |
1278 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1278 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1278 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
25 # include <config.h> |
1278 | 26 #endif |
27 | |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18538
diff
changeset
|
28 #include "Array-util.h" |
3932 | 29 #include "error.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18538
diff
changeset
|
30 #include "oct-locbuf.h" |
1755 | 31 #include "str-vec.h" |
32 | |
1278 | 33 #include "oct-map.h" |
34 #include "utils.h" | |
35 | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
36 octave_fields::octave_fields (const string_vector& fields) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
37 : rep (new fields_rep) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
38 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
39 octave_idx_type n = fields.numel (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
40 for (octave_idx_type i = 0; i < n; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
41 (*rep)[fields(i)] = i; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
42 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
43 |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
44 octave_fields::octave_fields (const char * const *fields) |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
45 : rep (new fields_rep) |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
46 { |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
47 octave_idx_type n = 0; |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
48 while (*fields) |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
49 (*rep)[std::string (*fields++)] = n++; |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
50 } |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
51 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
52 bool |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
53 octave_fields::isfield (const std::string& field) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
54 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
55 return rep->find (field) != rep->end (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
56 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
57 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
58 octave_idx_type |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
59 octave_fields::getfield (const std::string& field) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
60 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
61 fields_rep::iterator p = rep->find (field); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
62 return (p != rep->end ()) ? p->second : -1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
63 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
64 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
65 octave_idx_type |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
66 octave_fields::getfield (const std::string& field) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
67 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
68 fields_rep::iterator p = rep->find (field); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
69 if (p != rep->end ()) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
70 return p->second; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
71 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
72 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
73 make_unique (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
74 octave_idx_type n = rep->size (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
75 return (*rep)[field] = n; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
76 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
77 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
78 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
79 octave_idx_type |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
80 octave_fields::rmfield (const std::string& field) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
81 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
82 fields_rep::iterator p = rep->find (field); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
83 if (p == rep->end ()) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
84 return -1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
85 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
86 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
87 octave_idx_type n = p->second; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
88 make_unique (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
89 rep->erase (field); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
90 for (fields_rep::iterator q = rep->begin (); q != rep->end (); q++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
91 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
92 if (q->second >= n) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
93 q->second--; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
94 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
95 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
96 return n; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
97 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
98 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
99 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
100 void |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
101 octave_fields::orderfields (Array<octave_idx_type>& perm) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
102 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
103 octave_idx_type n = rep->size (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
104 perm.clear (n, 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
105 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
106 make_unique (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
107 octave_idx_type i = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
108 for (fields_rep::iterator q = rep->begin (); q != rep->end (); q++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
109 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
110 octave_idx_type j = q->second; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
111 q->second = i; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
112 perm(i++) = j; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
113 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
114 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
115 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
116 bool |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
117 octave_fields::equal_up_to_order (const octave_fields& other, |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
118 octave_idx_type* perm) const |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
119 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
120 bool retval = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
121 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
122 iterator p = begin (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
123 iterator q = other.begin (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
124 for (; p != end () && q != other.end (); p++, q++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
125 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
126 if (p->first == q->first) |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
127 perm[p->second] = q->second; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
128 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
129 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
130 retval = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
131 break; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
132 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
133 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
134 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
135 retval = (p == end () && q == other.end ()); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
136 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
137 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
138 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
139 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
140 bool |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
141 octave_fields::equal_up_to_order (const octave_fields& other, |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
142 Array<octave_idx_type>& perm) const |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
143 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
144 octave_idx_type n = nfields (); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
145 if (perm.numel () != n) |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
146 perm.clear (1, n); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
147 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
148 return equal_up_to_order (other, perm.fortran_vec ()); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
149 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
150 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
151 string_vector |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
152 octave_fields::fieldnames (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
153 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
154 octave_idx_type n = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
155 string_vector retval(n); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
156 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
157 for (iterator p = begin (); p != end (); p++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
158 retval.xelem (p->second) = p->first; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
159 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
160 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
161 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
162 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
163 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
164 octave_scalar_map::getfield (const std::string& k) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
165 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
166 octave_idx_type idx = xkeys.getfield (k); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
167 return (idx >= 0) ? xvals[idx] : octave_value (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
168 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
169 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
170 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
171 octave_scalar_map::setfield (const std::string& k, const octave_value& val) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
172 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
173 octave_idx_type idx = xkeys.getfield (k); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
174 if (idx < static_cast<octave_idx_type> (xvals.size ())) |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
175 xvals[idx] = val; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
176 else |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
177 xvals.push_back (val); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
178 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
179 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
180 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
181 octave_scalar_map::rmfield (const std::string& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
182 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
183 octave_idx_type idx = xkeys.rmfield (k); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
184 if (idx >= 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
185 xvals.erase (xvals.begin () + idx); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
186 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
187 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
188 octave_scalar_map |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
189 octave_scalar_map::orderfields (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
190 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
191 Array<octave_idx_type> perm; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
192 return orderfields (perm); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
193 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
194 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
195 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
196 octave_scalar_map::orderfields (Array<octave_idx_type>& perm) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
197 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
198 octave_scalar_map retval (xkeys); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
199 retval.xkeys.orderfields (perm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
200 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
201 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
202 for (octave_idx_type i = 0; i < nf; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
203 retval.xvals[i] = xvals[perm.xelem (i)]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
204 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
205 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
206 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
207 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
208 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
209 octave_scalar_map::orderfields (const octave_scalar_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
210 Array<octave_idx_type>& perm) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
211 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
212 if (xkeys.is_same (other.xkeys)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
213 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
214 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
215 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
216 octave_scalar_map retval (other.xkeys); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
217 if (! other.xkeys.equal_up_to_order (xkeys, perm)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
218 error ("orderfields: structs must have same fields up to order"); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
219 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
220 octave_idx_type nf = nfields (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
221 for (octave_idx_type i = 0; i < nf; i++) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
222 retval.xvals[i] = xvals[perm.xelem (i)]; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
223 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
224 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
225 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
226 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
227 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
228 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
229 octave_scalar_map::contents (const std::string& k) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
230 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
231 return getfield (k); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
232 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
233 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
234 octave_value& |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
235 octave_scalar_map::contents (const std::string& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
236 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
237 octave_idx_type idx = xkeys.getfield (k); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
238 if (idx >= static_cast<octave_idx_type> (xvals.size ())) |
11055
b721e12140cc
fix off-by-1 error in octave_scalar_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
239 xvals.resize (idx+1); |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
240 return xvals[idx]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
241 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
242 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
243 octave_map::octave_map (const octave_scalar_map& m) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
244 : xkeys (m.xkeys), xvals (), dimensions (1, 1) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
245 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
246 octave_idx_type nf = m.nfields (); |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
247 xvals.reserve (nf); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
248 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
249 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
250 xvals.push_back (Cell (dimensions)); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
251 xvals[i].xelem (0) = m.xvals[i]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
252 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
253 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
254 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
255 Cell |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
256 octave_map::getfield (const std::string& k) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
257 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
258 octave_idx_type idx = xkeys.getfield (k); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
259 return (idx >= 0) ? xvals[idx] : Cell (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
260 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
261 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
262 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
263 octave_map::setfield (const std::string& k, const Cell& val) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
264 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
265 if (nfields () == 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
266 dimensions = val.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
267 |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
268 if (val.dims () != dimensions) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
269 error ("octave_map::setfield: internal error"); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
270 |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
271 octave_idx_type idx = xkeys.getfield (k); |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
272 if (idx < static_cast<octave_idx_type> (xvals.size ())) |
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
273 xvals[idx] = val; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
274 else |
20982
d27f66b4b8e6
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
275 xvals.push_back (val); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
276 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
277 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
278 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
279 octave_map::rmfield (const std::string& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
280 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
281 octave_idx_type idx = xkeys.rmfield (k); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
282 if (idx >= 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
283 xvals.erase (xvals.begin () + idx); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
284 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
285 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
286 octave_map |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
287 octave_map::orderfields (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
288 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
289 Array<octave_idx_type> perm; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
290 return orderfields (perm); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
291 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
292 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
293 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
294 octave_map::orderfields (Array<octave_idx_type>& perm) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
295 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
296 octave_map retval (xkeys); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
297 retval.xkeys.orderfields (perm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
298 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
299 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
300 for (octave_idx_type i = 0; i < nf; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
301 retval.xvals[i] = xvals[perm.xelem (i)]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
302 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
303 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
304 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
305 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
306 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
307 octave_map::orderfields (const octave_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
308 Array<octave_idx_type>& perm) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
309 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
310 if (xkeys.is_same (other.xkeys)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
311 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
312 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
313 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
314 octave_map retval (other.xkeys); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
315 if (! other.xkeys.equal_up_to_order (xkeys, perm)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
316 error ("orderfields: structs must have same fields up to order"); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
317 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
318 octave_idx_type nf = nfields (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
319 for (octave_idx_type i = 0; i < nf; i++) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
320 retval.xvals[i] = xvals[perm.xelem (i)]; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
321 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
322 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
323 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
324 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
325 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
326 Cell |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
327 octave_map::contents (const std::string& k) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
328 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
329 return getfield (k); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
330 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
331 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
332 Cell& |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
333 octave_map::contents (const std::string& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
334 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
335 octave_idx_type idx = xkeys.getfield (k); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
336 if (idx >= static_cast<octave_idx_type> (xvals.size ())) |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
337 xvals.push_back (Cell (dimensions)); // auto-set correct dims. |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
338 return xvals[idx]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
339 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
340 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
341 void |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
342 octave_map::extract_scalar (octave_scalar_map& dest, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
343 octave_idx_type idx) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
344 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
345 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
346 for (octave_idx_type i = 0; i < nf; i++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
347 dest.xvals[i] = xvals[i](idx); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
348 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
349 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
350 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
351 octave_map::checkelem (octave_idx_type n) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
352 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
353 octave_scalar_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
354 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
355 // Optimize this so that there is just one check. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
356 extract_scalar (retval, compute_index (n, dimensions)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
357 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
358 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
359 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
360 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
361 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
362 octave_map::checkelem (octave_idx_type i, octave_idx_type j) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
363 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
364 octave_scalar_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
365 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
366 // Optimize this so that there is just one check. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
367 extract_scalar (retval, compute_index (i, j, dimensions)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
368 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
369 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
370 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
371 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
372 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
373 octave_map::checkelem (const Array<octave_idx_type>& ra_idx) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
374 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
375 octave_scalar_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
376 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
377 // Optimize this so that there is just one check. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
378 extract_scalar (retval, compute_index (ra_idx, dimensions)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
379 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
380 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
381 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
382 |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
383 octave_scalar_map |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
384 octave_map::fast_elem_extract (octave_idx_type n) const |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
385 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
386 octave_scalar_map retval (xkeys); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
387 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
388 extract_scalar (retval, n); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
389 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
390 return retval; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
391 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
392 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
393 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
394 octave_map::fast_elem_insert (octave_idx_type n, |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
395 const octave_scalar_map& rhs) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
396 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
397 bool retval = false; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
398 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
399 octave_idx_type nf = nfields (); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
400 if (rhs.xkeys.is_same (xkeys)) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
401 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
402 for (octave_idx_type i = 0; i < nf; i++) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
403 xvals[i](n) = rhs.xvals[i]; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
404 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
405 retval = true; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
406 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
407 else |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
408 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
409 OCTAVE_LOCAL_BUFFER (octave_idx_type, perm, nf); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
410 if (xkeys.equal_up_to_order (rhs.xkeys, perm)) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
411 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
412 for (octave_idx_type i = 0; i < nf; i++) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
413 xvals[i](n) = rhs.xvals[perm[i]]; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
414 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
415 retval = true; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
416 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
417 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
418 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
419 return retval; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
420 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
421 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
422 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
423 octave_map::squeeze (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
424 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
425 octave_map retval (*this); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
426 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
427 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
428 retval.dimensions = dimensions.squeeze (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
429 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
430 for (octave_idx_type i = 0; i < nf; i++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
431 retval.xvals[i] = xvals[i].squeeze (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
432 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
433 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
434 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
435 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
436 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
437 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
438 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
439 ## test preservation of xkeys by squeeze |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
440 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
441 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
442 %! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"}); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
443 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
444 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
445 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
446 octave_map::permute (const Array<int>& vec, bool inv) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
447 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
448 octave_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
449 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
450 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
451 for (octave_idx_type i = 0; i < nf; i++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
452 retval.xvals[i] = xvals[i].permute (vec, inv); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
453 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
454 // FIXME: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
455 // There is no dim_vector::permute for technical reasons. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
456 // We pick the dim vector from results if possible, otherwise use a dummy |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
457 // array to get it. Need (?) a better solution to this problem. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
458 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
459 retval.dimensions = retval.xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
460 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
461 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
462 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
463 dummy = dummy.permute (vec, inv); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
464 retval.dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
465 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
466 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
467 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
468 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
469 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
470 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
471 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
472 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
473 ## test preservation of key order by permute |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
474 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
475 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
476 %! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"}); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
477 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
478 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
479 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
480 octave_map::transpose (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
481 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
482 assert (ndims () == 2); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
483 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
484 octave_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
485 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
486 retval.dimensions = dim_vector (dimensions (1), dimensions (0)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
487 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
488 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
489 for (octave_idx_type i = 0; i < nf; i++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
490 retval.xvals[i] = xvals[i].transpose (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
491 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
492 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
493 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
494 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
495 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
496 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
497 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
498 ## test preservation of key order by transpose |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
499 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
500 %! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
501 %! assert (fieldnames (transpose (x)), {"d"; "a"; "f"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
502 %! assert (fieldnames (x'), {"d"; "a"; "f"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
503 %! assert (fieldnames (x.'), {"d"; "a"; "f"}); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
504 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
505 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
506 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
507 octave_map::reshape (const dim_vector& dv) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
508 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
509 octave_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
510 retval.dimensions = dv; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
511 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
512 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
513 if (nf > 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
514 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
515 retval.xvals.reserve (nf); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
516 for (octave_idx_type i = 0; i < nf; i++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
517 retval.xvals[i] = xvals[i].reshape (dv); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
518 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
519 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
520 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
521 // FIXME: Do it with a dummy array, to reuse error message. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
522 // Need (?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
523 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
524 dummy.reshape (dv); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
525 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
526 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
527 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
528 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
529 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
530 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
531 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
532 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
533 ## test preservation of key order by reshape |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
534 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
535 %! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
536 %! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"}); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
537 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
538 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
539 void |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
540 octave_map::resize (const dim_vector& dv, bool fill) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
541 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
542 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
543 if (nf > 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
544 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
545 for (octave_idx_type i = 0; i < nf; i++) |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
546 { |
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
547 if (fill) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14569
diff
changeset
|
548 xvals[i].resize (dv, Matrix ()); |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
549 else |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
550 xvals[i].resize (dv); |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
551 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
552 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
553 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
554 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
555 // FIXME: Do it with a dummy array, to reuse error message. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
556 // Need (?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
557 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
558 dummy.resize (dv); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
559 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
560 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
561 dimensions = dv; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
562 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
563 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
564 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
565 void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
566 octave_map::do_cat (int dim, octave_idx_type n, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
567 const octave_scalar_map *map_list, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
568 octave_map& retval) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
569 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
570 octave_idx_type nf = retval.nfields (); |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
571 retval.xvals.reserve (nf); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
572 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
573 dim_vector& rd = retval.dimensions; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
574 rd.resize (dim+1, 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
575 rd(0) = rd(1) = 1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
576 rd(dim) = n; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
577 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
578 for (octave_idx_type j = 0; j < nf; j++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
579 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
580 retval.xvals.push_back (Cell (rd)); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
581 assert (retval.xvals[j].numel () == n); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
582 for (octave_idx_type i = 0; i < n; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
583 retval.xvals[j].xelem (i) = map_list[i].xvals[j]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
584 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
585 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
586 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
587 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
588 octave_map::do_cat (int dim, octave_idx_type n, const octave_map *map_list, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
589 octave_map& retval) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
590 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
591 octave_idx_type nf = retval.nfields (); |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
592 retval.xvals.reserve (nf); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
593 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
594 OCTAVE_LOCAL_BUFFER (Array<octave_value>, field_list, n); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
595 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
596 for (octave_idx_type j = 0; j < nf; j++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
597 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
598 for (octave_idx_type i = 0; i < n; i++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
599 field_list[i] = map_list[i].xvals[j]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
600 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
601 retval.xvals.push_back (Array<octave_value>::cat (dim, n, field_list)); |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10763
diff
changeset
|
602 if (j == 0) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10763
diff
changeset
|
603 retval.dimensions = retval.xvals[j].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
604 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
605 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
606 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
607 // This is just a wrapper. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
608 void permute_to_correct_order1 (const octave_scalar_map& ref, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
609 const octave_scalar_map& src, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
610 octave_scalar_map& dest, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
611 Array<octave_idx_type>& perm) |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
612 { |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
613 dest = src.orderfields (ref, perm); |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
614 } |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
615 |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
616 // In non-scalar case, we also promote empty structs without fields. |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
617 void permute_to_correct_order1 (const octave_map& ref, const octave_map& src, |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
618 octave_map& dest, Array<octave_idx_type>& perm) |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
619 { |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
620 if (src.nfields () == 0 && src.is_empty ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
621 dest = octave_map (src.dims (), ref.keys ()); |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
622 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
623 dest = src.orderfields (ref, perm); |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
624 } |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
625 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20982
diff
changeset
|
626 template <typename map> |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
627 static void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
628 permute_to_correct_order (octave_idx_type n, octave_idx_type nf, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
629 octave_idx_type idx, const map *map_list, |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
630 map *new_map_list) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
631 { |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
632 new_map_list[idx] = map_list[idx]; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
633 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
634 Array<octave_idx_type> perm (dim_vector (1, nf)); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
635 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
636 try |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
637 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
638 for (octave_idx_type i = 0; i < n; i++) |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
639 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
640 if (i == idx) |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
641 continue; |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
642 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
643 permute_to_correct_order1 (map_list[idx], map_list[i], |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
644 new_map_list[i], perm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
645 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
646 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
647 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
648 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
649 error (e, "cat: field names mismatch in concatenating structs"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
650 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
651 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
652 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
653 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
654 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
655 octave_map::cat (int dim, octave_idx_type n, const octave_scalar_map *map_list) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
656 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
657 octave_map retval; |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
658 |
10763
b397b8edd8c5
fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10760
diff
changeset
|
659 // Allow dim = -1, -2 for compatibility, though it makes no difference here. |
b397b8edd8c5
fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10760
diff
changeset
|
660 if (dim == -1 || dim == -2) |
b397b8edd8c5
fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10760
diff
changeset
|
661 dim = -dim - 1; |
b397b8edd8c5
fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10760
diff
changeset
|
662 else if (dim < 0) |
20650
a6a452346c42
use error and error_with_id directly in libinterp code
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
663 error ("cat: invalid dimension"); |
10763
b397b8edd8c5
fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10760
diff
changeset
|
664 |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
665 if (n == 1) |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
666 retval = map_list[0]; |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
667 else if (n > 1) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
668 { |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
669 octave_idx_type idx, nf = 0; |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
670 for (idx = 0; idx < n; idx++) |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
671 { |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
672 nf = map_list[idx].nfields (); |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
673 if (nf > 0) |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
674 { |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
675 retval.xkeys = map_list[idx].xkeys; |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
676 break; |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
677 } |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
678 } |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
679 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
680 if (nf > 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
681 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
682 // Try the fast case. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
683 bool all_same = true; |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
684 for (octave_idx_type i = 0; i < n; i++) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
685 { |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
686 all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
687 if (! all_same) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
688 break; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
689 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
690 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
691 if (all_same) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
692 do_cat (dim, n, map_list, retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
693 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
694 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
695 // permute all structures to common order. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
696 OCTAVE_LOCAL_BUFFER (octave_scalar_map, new_map_list, n); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
697 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
698 permute_to_correct_order (n, nf, idx, map_list, new_map_list); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
699 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
700 do_cat (dim, n, new_map_list, retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
701 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
702 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
703 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
704 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
705 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
706 dim_vector& rd = retval.dimensions; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
707 rd.resize (dim+1, 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
708 rd(0) = rd(1) = 1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
709 rd(dim) = n; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
710 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
711 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
712 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
713 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
714 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
715 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
716 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
717 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
718 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
719 octave_map::cat (int dim, octave_idx_type n, const octave_map *map_list) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
720 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
721 octave_map retval; |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
722 |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
723 // Allow dim = -1, -2 for compatibility, though it makes no difference here. |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
724 if (dim == -1 || dim == -2) |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
725 dim = -dim - 1; |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
726 else if (dim < 0) |
20650
a6a452346c42
use error and error_with_id directly in libinterp code
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
727 error ("cat: invalid dimension"); |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
728 |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
729 if (n == 1) |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
730 retval = map_list[0]; |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
731 else if (n > 1) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
732 { |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
733 octave_idx_type idx, nf = 0; |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
734 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
735 for (idx = 0; idx < n; idx++) |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
736 { |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
737 nf = map_list[idx].nfields (); |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
738 if (nf > 0) |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
739 { |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
740 retval.xkeys = map_list[idx].xkeys; |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
741 break; |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
742 } |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
743 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
744 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
745 // Try the fast case. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
746 bool all_same = true; |
13968
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
747 |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
748 if (nf > 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
749 { |
13968
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
750 for (octave_idx_type i = 0; i < n; i++) |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
751 { |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
752 all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys); |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
753 |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
754 if (! all_same) |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
755 break; |
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
756 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
757 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
758 |
13968
241f68fb48c3
octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents:
13754
diff
changeset
|
759 if (all_same && nf > 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
760 do_cat (dim, n, map_list, retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
761 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
762 { |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
763 if (nf > 0) |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
764 { |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
765 // permute all structures to correct order. |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
766 OCTAVE_LOCAL_BUFFER (octave_map, new_map_list, n); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
767 |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
768 permute_to_correct_order (n, nf, idx, map_list, new_map_list); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
769 |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
770 do_cat (dim, n, new_map_list, retval); |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
771 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
772 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
773 { |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
774 dim_vector dv = map_list[0].dimensions; |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
775 |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
776 for (octave_idx_type i = 1; i < n; i++) |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
777 { |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
778 if (! dv.concat (map_list[i].dimensions, dim)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
779 error ("dimension mismatch in struct concatenation"); |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
780 } |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
781 |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
782 retval.dimensions = dv; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
783 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
784 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
785 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
786 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
787 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
788 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
789 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
790 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
791 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
792 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
793 ## test preservation of key order by concatenation |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
794 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
795 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
796 %! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
797 %! assert (fieldnames ([x; y]), {"d"; "a"; "f"}); |
13754
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
798 |
e652ff4d1522
don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
799 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
800 %! s = struct (); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
801 %! sr = [s,s]; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
802 %! sc = [s;s]; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
803 %! sm = [s,s;s,s]; |
18538
fcd87f68af4f
Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents:
18402
diff
changeset
|
804 %! assert (numfields (sr), 0); |
fcd87f68af4f
Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents:
18402
diff
changeset
|
805 %! assert (numfields (sc), 0); |
fcd87f68af4f
Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents:
18402
diff
changeset
|
806 %! assert (numfields (sm), 0); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
807 %! assert (size (sr), [1, 2]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
808 %! assert (size (sc), [2, 1]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
809 %! assert (size (sm), [2, 2]); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
810 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
811 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
812 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
813 octave_map::index (const idx_vector& i, bool resize_ok) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
814 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
815 octave_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
816 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
817 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
818 for (octave_idx_type k = 0; k < nf; k++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
819 retval.xvals[k] = xvals[k].index (i, resize_ok); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
820 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
821 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
822 retval.dimensions = retval.xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
823 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
824 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
825 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
826 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
827 dummy = dummy.index (i, resize_ok); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
828 retval.dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
829 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
830 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
831 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
832 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
833 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
834 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
835 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
836 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
837 octave_map::index (const idx_vector& i, const idx_vector& j, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
838 bool resize_ok) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
839 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
840 octave_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
841 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
842 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
843 for (octave_idx_type k = 0; k < nf; k++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
844 retval.xvals[k] = xvals[k].index (i, j, resize_ok); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
845 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
846 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
847 retval.dimensions = retval.xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
848 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
849 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
850 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
851 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
852 dummy = dummy.index (i, j, resize_ok); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
853 retval.dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
854 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
855 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
856 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
857 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
858 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
859 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
860 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
861 octave_map |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
862 octave_map::index (const Array<idx_vector>& ia, bool resize_ok) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
863 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
864 octave_map retval (xkeys); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
865 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
866 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
867 for (octave_idx_type k = 0; k < nf; k++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
868 retval.xvals[k] = xvals[k].index (ia, resize_ok); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
869 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
870 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
871 retval.dimensions = retval.xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
872 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
873 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
874 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
875 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
876 dummy = dummy.index (ia, resize_ok); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
877 retval.dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
878 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
879 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
880 retval.optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
881 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
882 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
883 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
884 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
885 octave_map |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
886 octave_map::index (const octave_value_list& idx, bool resize_ok) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
887 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
888 octave_idx_type n_idx = idx.length (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
889 octave_map retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
890 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
891 // If we catch an indexing error in index_vector, we flag an error in |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
892 // index k. Ensure it is the right value befor each idx_vector call. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
893 // Same variable as used in the for loop in the default case. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
894 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
895 octave_idx_type k = 0; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
896 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
897 try |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
898 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
899 switch (n_idx) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
900 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
901 case 1: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
902 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
903 idx_vector i = idx(0).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
904 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
905 retval = index (i, resize_ok); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
906 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
907 break; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
908 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
909 case 2: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
910 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
911 idx_vector i = idx(0).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
912 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
913 k = 1; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
914 idx_vector j = idx(1).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
915 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
916 retval = index (i, j, resize_ok); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
917 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
918 break; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
919 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
920 default: |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
921 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
922 Array<idx_vector> ia (dim_vector (n_idx, 1)); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
923 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
924 for (k = 0; k < n_idx; k++) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
925 ia(k) = idx(k).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
926 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
927 retval = index (ia, resize_ok); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
928 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
929 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
930 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
931 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
932 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
933 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
934 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
935 e.set_pos_if_unset (n_idx, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
936 throw; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
937 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
938 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
939 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
940 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
941 |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
942 // Perhaps one day these will be optimized. Right now, they just call index. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
943 octave_map |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
944 octave_map::column (octave_idx_type k) const |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
945 { |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
946 return index (idx_vector::colon, k); |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
947 } |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
948 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
949 octave_map |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
950 octave_map::page (octave_idx_type k) const |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
951 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
952 static Array<idx_vector> ia (dim_vector (3, 1), idx_vector::colon); |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
953 |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
954 ia(2) = k; |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
955 return index (ia); |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
956 } |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
957 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
958 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
959 octave_map::assign (const idx_vector& i, const octave_map& rhs) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
960 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
961 if (rhs.xkeys.is_same (xkeys)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
962 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
963 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
964 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
965 for (octave_idx_type k = 0; k < nf; k++) |
14568
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
966 xvals[k].assign (i, rhs.xvals[k], Matrix ()); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
967 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
968 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
969 dimensions = xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
970 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
971 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
972 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
973 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
974 dummy.assign (i, rhs_dummy);; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
975 dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
976 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
977 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
978 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
979 } |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
980 else if (nfields () == 0) |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
981 { |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
982 octave_map tmp (dimensions, rhs.xkeys); |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
983 tmp.assign (i, rhs); |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
984 *this = tmp; |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
985 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
986 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
987 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
988 Array<octave_idx_type> perm; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
989 octave_map rhs1; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
990 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
991 try |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
992 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
993 rhs1 = rhs.orderfields (*this, perm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
994 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
995 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
996 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
997 error (e, "incompatible fields in struct assignment"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
998 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
999 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1000 assert (rhs1.xkeys.is_same (xkeys)); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1001 assign (i, rhs1); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1002 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1003 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1004 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1005 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1006 octave_map::assign (const idx_vector& i, const idx_vector& j, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1007 const octave_map& rhs) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1008 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1009 if (rhs.xkeys.is_same (xkeys)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1010 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1011 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1012 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1013 for (octave_idx_type k = 0; k < nf; k++) |
14568
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1014 xvals[k].assign (i, j, rhs.xvals[k], Matrix ()); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1015 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1016 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1017 dimensions = xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1018 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1019 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1020 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1021 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1022 dummy.assign (i, j, rhs_dummy);; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1023 dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1024 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1025 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1026 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1027 } |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1028 else if (nfields () == 0) |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1029 { |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1030 octave_map tmp (dimensions, rhs.xkeys); |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1031 tmp.assign (i, j, rhs); |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1032 *this = tmp; |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1033 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1034 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1035 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1036 Array<octave_idx_type> perm; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1037 octave_map rhs1; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1038 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1039 try |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1040 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1041 rhs1 = rhs.orderfields (*this, perm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1042 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1043 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1044 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1045 error (e, "incompatible fields in struct assignment"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1046 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1047 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1048 assert (rhs1.xkeys.is_same (xkeys)); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1049 assign (i, j, rhs1); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1050 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1051 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1052 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1053 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1054 octave_map::assign (const Array<idx_vector>& ia, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1055 const octave_map& rhs) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1056 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1057 if (rhs.xkeys.is_same (xkeys)) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1058 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1059 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1060 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1061 for (octave_idx_type k = 0; k < nf; k++) |
14568
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1062 xvals[k].assign (ia, rhs.xvals[k], Matrix ()); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1063 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1064 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1065 dimensions = xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1066 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1067 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1068 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1069 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1070 dummy.assign (ia, rhs_dummy);; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1071 dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1072 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1073 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1074 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1075 } |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1076 else if (nfields () == 0) |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1077 { |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1078 octave_map tmp (dimensions, rhs.xkeys); |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1079 tmp.assign (ia, rhs); |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1080 *this = tmp; |
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10750
diff
changeset
|
1081 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1082 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1083 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1084 Array<octave_idx_type> perm; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1085 octave_map rhs1; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1086 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1087 try |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1088 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1089 rhs1 = rhs.orderfields (*this, perm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1090 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1091 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1092 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1093 error (e, "incompatible fields in struct assignment"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1094 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1095 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1096 assert (rhs1.xkeys.is_same (xkeys)); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1097 assign (ia, rhs1); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1098 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1099 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1100 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1101 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1102 octave_map::assign (const octave_value_list& idx, const octave_map& rhs) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1103 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1104 octave_idx_type n_idx = idx.length (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1105 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1106 // If we catch an indexing error in index_vector, we flag an error in |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1107 // index k. Ensure it is the right value befor each idx_vector call. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1108 // Same variable as used in the for loop in the default case. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1109 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1110 octave_idx_type k = 0; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1111 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1112 try |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1113 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1114 switch (n_idx) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1115 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1116 case 1: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1117 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1118 idx_vector i = idx(0).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1119 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1120 assign (i, rhs); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1121 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1122 break; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1123 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1124 case 2: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1125 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1126 idx_vector i = idx(0).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1127 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1128 k = 1; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1129 idx_vector j = idx(1).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1130 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1131 assign (i, j, rhs); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1132 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1133 break; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1134 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1135 default: |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1136 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1137 Array<idx_vector> ia (dim_vector (n_idx, 1)); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1138 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1139 for (k = 0; k < n_idx; k++) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1140 ia(k) = idx(k).index_vector (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1141 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1142 assign (ia, rhs); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1143 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1144 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1145 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1146 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1147 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1148 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1149 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1150 e.set_pos_if_unset (n_idx, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1151 throw; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1152 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1153 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1154 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1155 void |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1156 octave_map::assign (const octave_value_list& idx, const std::string& k, |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1157 const Cell& rhs) |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1158 { |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1159 Cell tmp; |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1160 iterator p = seek (k); |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1161 Cell& ref = p != end () ? contents (p) : tmp; |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1162 |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1163 if (&ref == &tmp) |
10750
f75e827649a5
struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents:
10749
diff
changeset
|
1164 ref = Cell (dimensions); |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1165 |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1166 ref.assign (idx, rhs); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1167 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1168 if (ref.dims () != dimensions) |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1169 { |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1170 dimensions = ref.dims (); |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1171 |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1172 octave_idx_type nf = nfields (); |
10750
f75e827649a5
struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents:
10749
diff
changeset
|
1173 for (octave_idx_type i = 0; i < nf; i++) |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1174 { |
10750
f75e827649a5
struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents:
10749
diff
changeset
|
1175 if (&xvals[i] != &ref) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14569
diff
changeset
|
1176 xvals[i].resize (dimensions, Matrix ()); |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1177 } |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1178 |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1179 optimize_dimensions (); |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1180 } |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1181 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1182 if (&ref == &tmp) |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1183 setfield (k, tmp); |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1184 } |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1185 |
14568
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1186 /* |
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1187 %!test |
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1188 %! rhs.b = 1; |
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1189 %! a(3) = rhs; |
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1190 %! assert ({a.b}, {[], [], 1}) |
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1191 */ |
82449d607d20
correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1192 |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
1193 void |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1194 octave_map::delete_elements (const idx_vector& i) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1195 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1196 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1197 for (octave_idx_type k = 0; k < nf; k++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1198 xvals[k].delete_elements (i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1199 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1200 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1201 dimensions = xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1202 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1203 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1204 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1205 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1206 dummy.delete_elements (i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1207 dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1208 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1209 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1210 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1211 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1212 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1213 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1214 octave_map::delete_elements (int dim, const idx_vector& i) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1215 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1216 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1217 for (octave_idx_type k = 0; k < nf; k++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1218 xvals[k].delete_elements (dim, i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1219 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1220 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1221 dimensions = xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1222 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1223 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1224 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1225 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1226 dummy.delete_elements (dim, i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1227 dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1228 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1229 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1230 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1231 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1232 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1233 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1234 octave_map::delete_elements (const Array<idx_vector>& ia) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1235 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1236 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1237 for (octave_idx_type k = 0; k < nf; k++) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1238 xvals[k].delete_elements (ia); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1239 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1240 if (nf > 0) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1241 dimensions = xvals[0].dims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1242 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1243 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1244 // Use dummy array. FIXME: Need(?) a better solution. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1245 Array<char> dummy (dimensions); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1246 dummy.delete_elements (ia); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1247 dimensions = dummy.dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1248 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1249 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1250 optimize_dimensions (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1251 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1252 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1253 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1254 octave_map::delete_elements (const octave_value_list& idx) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1255 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1256 octave_idx_type n_idx = idx.length (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1257 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1258 Array<idx_vector> ia (dim_vector (n_idx, 1)); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1259 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1260 for (octave_idx_type i = 0; i < n_idx; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1261 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1262 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1263 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1264 ia(i) = idx(i).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1265 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1266 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1267 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1268 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1269 e.set_pos_if_unset (n_idx, i+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1270 throw; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
1271 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1272 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1273 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1274 delete_elements (ia); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1275 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1276 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1277 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1278 ## test preservation of key order by indexing |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1279 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1280 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1281 %! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"}); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1282 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1283 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1284 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1285 octave_map::concat (const octave_map& rb, const Array<octave_idx_type>& ra_idx) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1286 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1287 if (nfields () == rb.nfields ()) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1288 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1289 for (const_iterator pa = begin (); pa != end (); pa++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1290 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1291 const_iterator pb = rb.seek (key(pa)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1292 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1293 if (pb == rb.end ()) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1294 error ("field name mismatch in structure concatenation"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1295 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1296 contents(pa).insert (rb.contents (pb), ra_idx); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1297 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1298 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1299 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1300 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1301 dim_vector dv = dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1302 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1303 if (dv.all_zero ()) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1304 *this = rb; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1305 else if (! rb.dims ().all_zero ()) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1306 error ("invalid structure concatenation"); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1307 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1308 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1309 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1310 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1311 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1312 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1313 octave_map::optimize_dimensions (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1314 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1315 octave_idx_type nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1316 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1317 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1318 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
1319 if (! xvals[i].optimize_dimensions (dimensions)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1320 error ("internal error: dimension mismatch across fields in struct"); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1321 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1322 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1323 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10649
diff
changeset
|
1324 |