Mercurial > octave
annotate liboctave/array/idx-vector.h @ 21244:1473547f50f5
include octave-config.h in public header files
* mk-opts.pl, mkbuiltins, mk-ops.awk, sparse-mk-ops.awk:
Emit "#include octave-config.h" statement for generated header files.
* build-env.h, builtins.h, Cell.h, base-text-renderer.h,
c-file-ptr-stream.h, cdisplay.h, comment-list.h, data.h, debug.h,
defaults.in.h, defun-dld.h, defun-int.h, defun.h, dirfns.h, display.h,
dynamic-ld.h, error.h, errwarn.h, event-queue.h, file-io.h,
ft-text-renderer.h, gl-render.h, gl2ps-print.h, graphics.in.h,
gripes.h, help.h, hook-fcn.h, input.h, jit-ir.h, jit-typeinfo.h,
jit-util.h, load-path.h, load-save.h, ls-ascii-helper.h, ls-hdf5.h,
ls-mat-ascii.h, ls-mat4.h, ls-mat5.h, ls-oct-binary.h, ls-oct-text.h,
ls-utils.h, mex.h, mexproto.h, mxarray.in.h, oct-errno.h, oct-fstrm.h,
oct-handle.h, oct-hdf5-types.h, oct-hdf5.h, oct-hist.h, oct-iostrm.h,
oct-lvalue.h, oct-map.h, oct-obj.h, oct-opengl.h, oct-prcstrm.h,
oct-procbuf.h, oct-stdstrm.h, oct-stream.h, oct-strstrm.h, oct.h,
octave-default-image.h, octave-link.h, octave-preserve-stream-state.h,
pager.h, pr-output.h, procstream.h, profiler.h, pt-jit.h,
sighandlers.h, siglist.h, sparse-xdiv.h, sparse-xpow.h, symtab.h,
sysdep.h, text-renderer.h, toplev.h, txt-eng.h, utils.h, variables.h,
workspace-element.h, xdiv.h, xnorm.h, xpow.h, zfstream.h, oct-qhull.h,
ov-base-diag.h, ov-base-int.h, ov-base-mat.h, ov-base-scalar.h,
ov-base-sparse.h, ov-base.h, ov-bool-mat.h, ov-bool-sparse.h,
ov-bool.h, ov-builtin.h, ov-cell.h, ov-ch-mat.h, ov-class.h,
ov-classdef.h, ov-colon.h, ov-complex.h, ov-cs-list.h, ov-cx-diag.h,
ov-cx-mat.h, ov-cx-sparse.h, ov-dld-fcn.h, ov-fcn-handle.h,
ov-fcn-inline.h, ov-fcn.h, ov-float.h, ov-flt-complex.h,
ov-flt-cx-diag.h, ov-flt-cx-mat.h, ov-flt-re-diag.h, ov-flt-re-mat.h,
ov-int-traits.h, ov-int16.h, ov-int32.h, ov-int64.h, ov-int8.h,
ov-intx.h, ov-java.h, ov-lazy-idx.h, ov-mex-fcn.h, ov-null-mat.h,
ov-oncleanup.h, ov-perm.h, ov-range.h, ov-re-diag.h, ov-re-mat.h,
ov-re-sparse.h, ov-scalar.h, ov-str-mat.h, ov-struct.h,
ov-type-conv.h, ov-typeinfo.h, ov-uint16.h, ov-uint32.h, ov-uint64.h,
ov-uint8.h, ov-usr-fcn.h, ov.h, ovl.h, octave.h, op-int.h, ops.h,
options-usage.h, lex.h, parse.h, pt-all.h, pt-arg-list.h,
pt-array-list.h, pt-assign.h, pt-binop.h, pt-bp.h, pt-cbinop.h,
pt-cell.h, pt-check.h, pt-classdef.h, pt-cmd.h, pt-colon.h,
pt-const.h, pt-decl.h, pt-eval.h, pt-except.h, pt-exp.h,
pt-fcn-handle.h, pt-funcall.h, pt-id.h, pt-idx.h, pt-jump.h,
pt-loop.h, pt-mat.h, pt-misc.h, pt-pr-code.h, pt-select.h, pt-stmt.h,
pt-unop.h, pt-walk.h, pt.h, token.h, version.in.h, Array-util.h,
Array.h, CColVector.h, CDiagMatrix.h, CMatrix.h, CNDArray.h,
CRowVector.h, CSparse.h, DiagArray2.h, MArray.h, MDiagArray2.h,
MSparse.h, Matrix.h, MatrixType.h, PermMatrix.h, Range.h, Sparse.h,
boolMatrix.h, boolNDArray.h, boolSparse.h, chMatrix.h, chNDArray.h,
dColVector.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, dRowVector.h,
dSparse.h, dim-vector.h, fCColVector.h, fCDiagMatrix.h, fCMatrix.h,
fCNDArray.h, fCRowVector.h, fColVector.h, fDiagMatrix.h, fMatrix.h,
fNDArray.h, fRowVector.h, idx-vector.h, int16NDArray.h,
int32NDArray.h, int64NDArray.h, int8NDArray.h, intNDArray.h,
uint16NDArray.h, uint32NDArray.h, uint64NDArray.h, uint8NDArray.h,
f77-fcn.h, lo-error.h, quit.h, CmplxAEPBAL.h, CmplxCHOL.h,
CmplxGEPBAL.h, CmplxHESS.h, CmplxLU.h, CmplxQR.h, CmplxQRP.h,
CmplxSCHUR.h, CmplxSVD.h, CollocWt.h, DAE.h, DAEFunc.h, DAERT.h,
DAERTFunc.h, DASPK.h, DASRT.h, DASSL.h, DET.h, EIG.h, LSODE.h, ODE.h,
ODEFunc.h, ODES.h, ODESFunc.h, Quad.h, base-aepbal.h, base-dae.h,
base-de.h, base-lu.h, base-min.h, base-qr.h, bsxfun-decl.h, bsxfun.h,
dbleAEPBAL.h, dbleCHOL.h, dbleGEPBAL.h, dbleHESS.h, dbleLU.h,
dbleQR.h, dbleQRP.h, dbleSCHUR.h, dbleSVD.h, eigs-base.h,
fCmplxAEPBAL.h, fCmplxCHOL.h, fCmplxGEPBAL.h, fCmplxHESS.h,
fCmplxLU.h, fCmplxQR.h, fCmplxQRP.h, fCmplxSCHUR.h, fCmplxSVD.h,
fEIG.h, floatAEPBAL.h, floatCHOL.h, floatGEPBAL.h, floatHESS.h,
floatLU.h, floatQR.h, floatQRP.h, floatSCHUR.h, floatSVD.h,
lo-mappers.h, lo-specfun.h, oct-convn.h, oct-fftw.h, oct-norm.h,
oct-rand.h, oct-spparms.h, randgamma.h, randmtzig.h, randpoisson.h,
sparse-chol.h, sparse-dmsolve.h, sparse-lu.h, sparse-qr.h,
Sparse-diag-op-defs.h, Sparse-op-decls.h, Sparse-op-defs.h,
Sparse-perm-op-defs.h, mx-base.h, mx-defs.h, mx-ext.h, mx-op-decl.h,
mx-op-defs.h, dir-ops.h, file-ops.h, file-stat.h, lo-sysdep.h,
mach-info.h, oct-env.h, oct-group.h, oct-openmp.h, oct-passwd.h,
oct-syscalls.h, oct-time.h, oct-uname.h, pathlen.h, sysdir.h,
syswait.h, action-container.h, base-list.h, byte-swap.h,
caseless-str.h, cmd-edit.h, cmd-hist.h, data-conv.h, functor.h,
glob-match.h, lo-array-errwarn.h, lo-array-gripes.h, lo-cutils.h,
lo-ieee.h, lo-macros.h, lo-math.h, lo-regexp.h, lo-traits.h,
lo-utils.h, oct-alloc.h, oct-base64.h, oct-binmap.h, oct-cmplx.h,
oct-glob.h, oct-inttypes.h, oct-locbuf.h, oct-mutex.h, oct-refcount.h,
oct-rl-edit.h, oct-rl-hist.h, oct-shlib.h, oct-sort.h, oct-sparse.h,
pathsearch.h, singleton-cleanup.h, sparse-sort.h, sparse-util.h,
statdefs.h, str-vec.h, sun-utils.h, unwind-prot.h, url-transfer.h:
Include octave-config.h.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2016 14:25:53 -0500 |
parents | a83e7a384ee0 |
children | 61c96c37ce69 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
11523 | 4 Copyright (C) 2008-2009 Jaroslav Hajek |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague |
1 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1 | 22 |
23 */ | |
24 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
25 #if ! defined (octave_idx_vector_h) |
383 | 26 #define octave_idx_vector_h 1 |
1 | 27 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
28 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
29 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
30 #include <cassert> |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
31 #include <cstring> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
32 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
33 #include <algorithm> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8934
diff
changeset
|
34 #include <iosfwd> |
13735
2cd903770748
Fix broken gcc compilation due to changeset d13b6086aea9.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13729
diff
changeset
|
35 #include <memory> |
3503 | 36 |
4653 | 37 #include "dim-vector.h" |
4938 | 38 #include "oct-inttypes.h" |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
39 #include "oct-refcount.h" |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
40 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
41 template <typename T> class Array; |
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
42 template <typename T> class Sparse; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
43 class Range; |
4504 | 44 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
45 // Design rationale: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
46 // idx_vector is a reference-counting, polymorphic pointer, that can contain |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
47 // 4 types of index objects: a magic colon, a range, a scalar, or an index vector. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
48 // Polymorphic methods for single element access are provided, as well as |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
49 // templates implementing "early dispatch", i.e. hoisting the checks for index |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
50 // type out of loops. |
164 | 51 |
453 | 52 class |
6108 | 53 OCTAVE_API |
453 | 54 idx_vector |
1 | 55 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
56 public: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
58 enum idx_class_type |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 class_invalid = -1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 class_colon = 0, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 class_range, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 class_scalar, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 class_vector, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 class_mask |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 }; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
67 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
68 template <typename T> friend class std::auto_ptr; |
13729
d13b6086aea9
Make std::auto_ptr friend of idx_vector to allow access to private class idx_vector_rep.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
69 |
1560 | 70 private: |
71 | |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
72 class OCTAVE_API idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
73 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
74 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
75 idx_base_rep (void) : count (1), err (false) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
76 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
77 virtual ~idx_base_rep (void) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
78 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
79 // Non-range-checking element query. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
80 virtual octave_idx_type xelem (octave_idx_type i) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
81 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
82 // Range-checking element query. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
83 virtual octave_idx_type checkelem (octave_idx_type i) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
84 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
85 // Length of the index vector. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
86 virtual octave_idx_type length (octave_idx_type n) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
87 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
88 // The maximum index + 1. The actual dimension is passed in. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
89 virtual octave_idx_type extent (octave_idx_type n) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
90 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
91 // Index class. |
8333 | 92 virtual idx_class_type idx_class (void) const { return class_invalid; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
93 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
94 // Sorts, maybe uniqifies, and returns a clone object pointer. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
95 virtual idx_base_rep *sort_uniq_clone (bool uniq = false) = 0; |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
96 // Sorts, and returns a sorting permutation (aka Array::sort). |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
97 virtual idx_base_rep *sort_idx (Array<octave_idx_type>&) = 0; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
98 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
99 // Checks whether the index is colon or a range equivalent to colon. |
10487 | 100 virtual bool is_colon_equiv (octave_idx_type) const { return false; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
101 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 // The original dimensions of object (used when subscribing by matrices). |
10487 | 103 virtual dim_vector orig_dimensions (void) const { return dim_vector (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
104 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
105 // i/o |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
106 virtual std::ostream& print (std::ostream& os) const = 0; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
107 |
21137
623fc7d08cc6
maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents:
21131
diff
changeset
|
108 OCTAVE_NORETURN virtual Array<octave_idx_type> as_array (void); |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
109 |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
110 octave_refcount<int> count; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
111 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
112 bool err; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
113 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
114 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
115 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
116 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
117 idx_base_rep (const idx_base_rep&); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
118 idx_base_rep& operator = (const idx_base_rep&); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
119 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
120 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
121 // The magic colon index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
122 class OCTAVE_API idx_colon_rep : public idx_base_rep |
1879 | 123 { |
124 public: | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
125 idx_colon_rep (void) { } |
1879 | 126 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
127 idx_colon_rep (char c); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
128 |
10487 | 129 octave_idx_type xelem (octave_idx_type i) const { return i; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
130 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
131 octave_idx_type checkelem (octave_idx_type i) const; |
1560 | 132 |
10487 | 133 octave_idx_type length (octave_idx_type n) const { return n; } |
1560 | 134 |
10487 | 135 octave_idx_type extent (octave_idx_type n) const { return n; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
136 |
8333 | 137 idx_class_type idx_class (void) const { return class_colon; } |
1879 | 138 |
10487 | 139 idx_base_rep *sort_uniq_clone (bool = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
140 { count++; return this; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
141 |
21137
623fc7d08cc6
maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents:
21131
diff
changeset
|
142 OCTAVE_NORETURN idx_base_rep *sort_idx (Array<octave_idx_type>&); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
143 |
10487 | 144 bool is_colon_equiv (octave_idx_type) const { return true; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
145 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
146 std::ostream& print (std::ostream& os) const; |
4938 | 147 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
148 private: |
4938 | 149 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
150 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
151 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
152 idx_colon_rep (const idx_colon_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
153 idx_colon_rep& operator = (const idx_colon_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
154 }; |
2386 | 155 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
156 // To distinguish the "direct" constructors that blindly trust the data. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
157 enum direct { DIRECT }; |
2828 | 158 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
159 // The integer range index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
160 class OCTAVE_API idx_range_rep : public idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
161 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
162 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
163 idx_range_rep (octave_idx_type _start, octave_idx_type _len, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
164 octave_idx_type _step, direct) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
165 : idx_base_rep (), start(_start), len(_len), step(_step) { } |
4938 | 166 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
167 idx_range_rep (void) |
8298
7e87d3d76a56
fix extent query for empty ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
168 : start(0), len(0), step(1) { } |
1560 | 169 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
170 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
171 idx_range_rep (octave_idx_type _start, octave_idx_type _limit, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
172 octave_idx_type _step); |
1560 | 173 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
174 idx_range_rep (const Range&); |
1560 | 175 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
176 octave_idx_type xelem (octave_idx_type i) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 { return start + i * step; } |
1560 | 178 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
179 octave_idx_type checkelem (octave_idx_type i) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
180 |
10487 | 181 octave_idx_type length (octave_idx_type) const { return len; } |
1560 | 182 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
183 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
184 { return len ? std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1)))) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
185 : n; } |
1560 | 186 |
8333 | 187 idx_class_type idx_class (void) const { return class_range; } |
1879 | 188 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
189 idx_base_rep *sort_uniq_clone (bool uniq = false); |
1560 | 190 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
191 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
192 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
193 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
194 { return start == 0 && step == 1 && len == n; } |
1560 | 195 |
8333 | 196 dim_vector orig_dimensions (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 { return dim_vector (1, len); } |
1560 | 198 |
8333 | 199 octave_idx_type get_start (void) const { return start; } |
1560 | 200 |
8333 | 201 octave_idx_type get_step (void) const { return step; } |
1560 | 202 |
3504 | 203 std::ostream& print (std::ostream& os) const; |
1560 | 204 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
205 Range unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
206 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
207 Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
208 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
209 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
210 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
211 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
212 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
213 idx_range_rep (const idx_range_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
214 idx_range_rep& operator = (const idx_range_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
215 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
216 octave_idx_type start, len, step; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
217 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
218 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
219 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
220 // The integer scalar index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
221 class OCTAVE_API idx_scalar_rep : public idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
222 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
223 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
224 idx_scalar_rep (octave_idx_type i, direct) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
225 : data (i) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
226 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
227 idx_scalar_rep (void) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
228 : data (0) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
229 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
230 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
231 idx_scalar_rep (octave_idx_type i); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
232 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
233 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
234 idx_scalar_rep (T x); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
235 |
10487 | 236 octave_idx_type xelem (octave_idx_type) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
237 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
238 octave_idx_type checkelem (octave_idx_type i) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
239 |
10487 | 240 octave_idx_type length (octave_idx_type) const { return 1; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
241 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
242 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
243 { return std::max (n, data + 1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
244 |
8333 | 245 idx_class_type idx_class (void) const { return class_scalar; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
246 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
247 idx_base_rep *sort_uniq_clone (bool = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
248 { count++; return this; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
249 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
250 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
251 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
252 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
253 { return n == 1 && data == 0; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
254 |
10487 | 255 dim_vector orig_dimensions (void) const { return dim_vector (1, 1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
256 |
8333 | 257 octave_idx_type get_data (void) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
258 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
259 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
260 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
261 double unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
262 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
263 Array<octave_idx_type> as_array (void); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
264 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
265 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
266 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
267 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
268 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
269 idx_scalar_rep (const idx_scalar_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
270 idx_scalar_rep& operator = (const idx_scalar_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
271 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
272 octave_idx_type data; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
273 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
274 }; |
4504 | 275 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
276 // The integer vector index. |
8319
c374691576f6
Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8298
diff
changeset
|
277 class OCTAVE_API idx_vector_rep : public idx_base_rep |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
278 { |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
279 public: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
280 // Direct constructor. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
281 idx_vector_rep (octave_idx_type *_data, octave_idx_type _len, |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
282 octave_idx_type _ext, const dim_vector& od, direct) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
283 : data (_data), len (_len), ext (_ext), aowner (0), orig_dims (od) { } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
284 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
285 idx_vector_rep (void) |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
286 : data (0), len (0), ext (0), aowner (0), orig_dims () |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
287 { } |
5275 | 288 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
289 // Zero-based constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
290 idx_vector_rep (const Array<octave_idx_type>& inda); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
291 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
292 idx_vector_rep (const Array<octave_idx_type>& inda, |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
293 octave_idx_type _ext, direct); |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
294 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
295 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
296 idx_vector_rep (const Array<T>&); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
297 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
298 idx_vector_rep (bool); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
299 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
300 idx_vector_rep (const Array<bool>&, octave_idx_type = -1); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
301 |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
302 idx_vector_rep (const Sparse<bool>&); |
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
303 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
304 ~idx_vector_rep (void); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
305 |
10487 | 306 octave_idx_type xelem (octave_idx_type i) const { return data[i]; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
307 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
308 octave_idx_type checkelem (octave_idx_type i) const; |
4653 | 309 |
10487 | 310 octave_idx_type length (octave_idx_type) const { return len; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
311 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
312 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
313 { return std::max (n, ext); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
314 |
8333 | 315 idx_class_type idx_class (void) const { return class_vector; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
316 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
317 idx_base_rep *sort_uniq_clone (bool uniq = false); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
318 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
319 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
320 |
10487 | 321 dim_vector orig_dimensions (void) const { return orig_dims; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
322 |
8333 | 323 const octave_idx_type *get_data (void) const { return data; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
324 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
325 std::ostream& print (std::ostream& os) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
326 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
327 Array<double> unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
328 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
329 Array<octave_idx_type> as_array (void); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
330 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
331 private: |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
332 |
8680
a2bcd96b9344
use allocators for idx_vector_rep subclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
8384
diff
changeset
|
333 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
334 // No copying! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
335 idx_vector_rep (const idx_vector_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
336 idx_vector_rep& operator = (const idx_vector_rep& idx); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
337 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
338 const octave_idx_type *data; |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
339 octave_idx_type len; |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
340 octave_idx_type ext; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
341 |
10487 | 342 // This is a trick to allow user-given zero-based arrays to be used |
343 // as indices without copying. If the following pointer is nonzero, | |
344 // we do not own the data, but rather have an Array<octave_idx_type> | |
345 // object that provides us the data. Note that we need a pointer | |
346 // because we deferred the Array<T> declaration and we do not want | |
347 // it yet to be defined. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
348 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
349 Array<octave_idx_type> *aowner; |
1560 | 350 |
4653 | 351 dim_vector orig_dims; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
352 }; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
353 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
354 // The logical mask index. |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
355 class OCTAVE_API idx_mask_rep : public idx_base_rep |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
356 { |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
357 public: |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
358 // Direct constructor. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
359 idx_mask_rep (bool *_data, octave_idx_type _len, |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
360 octave_idx_type _ext, const dim_vector& od, direct) |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
361 : data (_data), len (_len), ext (_ext), lsti (-1), lste (-1), |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
362 aowner (0), orig_dims (od) { } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
363 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
364 idx_mask_rep (void) |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
365 : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0), |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
366 orig_dims () |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 { } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
368 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
369 idx_mask_rep (bool); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
370 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
371 idx_mask_rep (const Array<bool>&, octave_idx_type = -1); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
372 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
373 ~idx_mask_rep (void); |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
374 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
375 octave_idx_type xelem (octave_idx_type i) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
376 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
377 octave_idx_type checkelem (octave_idx_type i) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
378 |
10487 | 379 octave_idx_type length (octave_idx_type) const { return len; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
380 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
381 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
382 { return std::max (n, ext); } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
383 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
384 idx_class_type idx_class (void) const { return class_mask; } |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
385 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
386 idx_base_rep *sort_uniq_clone (bool = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
387 { count++; return this; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
388 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
389 idx_base_rep *sort_idx (Array<octave_idx_type>&); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
390 |
10487 | 391 dim_vector orig_dimensions (void) const { return orig_dims; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
392 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
393 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
394 { return len == n && ext == n; } |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
395 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
396 const bool *get_data (void) const { return data; } |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
397 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
398 std::ostream& print (std::ostream& os) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
399 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
400 Array<bool> unconvert (void) const; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
401 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10339
diff
changeset
|
402 Array<octave_idx_type> as_array (void); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
403 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
404 private: |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
405 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
406 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
407 // No copying! |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
408 idx_mask_rep (const idx_mask_rep& idx); |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
409 idx_mask_rep& operator = (const idx_mask_rep& idx); |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
410 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
411 const bool *data; |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
412 octave_idx_type len; |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
413 octave_idx_type ext; |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
414 |
10487 | 415 // FIXME: I'm not sure if this is a good design. Maybe it would be |
416 // better to employ some sort of generalized iteration scheme. | |
11503
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
417 mutable octave_idx_type lsti; |
b3f511c48b14
idx-vector.h, idx-vector.cc: data member initialization and constructor fixes
John W. Eaton <jwe@octave.org>
parents:
10516
diff
changeset
|
418 mutable octave_idx_type lste; |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
419 |
10487 | 420 // This is a trick to allow user-given mask arrays to be used as |
421 // indices without copying. If the following pointer is nonzero, we | |
422 // do not own the data, but rather have an Array<bool> object that | |
423 // provides us the data. Note that we need a pointer because we | |
424 // deferred the Array<T> declaration and we do not want it yet to be | |
425 // defined. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
426 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
427 Array<bool> *aowner; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
428 |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
429 dim_vector orig_dims; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
430 }; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
431 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
432 idx_vector (idx_base_rep *r) : rep (r) { } |
1560 | 433 |
10487 | 434 // The shared empty vector representation (for fast default |
435 // constructor). | |
8333 | 436 static idx_vector_rep *nil_rep (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
437 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
438 static idx_vector_rep ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
439 return &ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
440 } |
4938 | 441 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
442 // The shared empty vector representation with the error flag set. |
8333 | 443 static idx_vector_rep *err_rep (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
444 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
445 static idx_vector_rep ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
446 ivr.err = true; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
447 return &ivr; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
448 } |
4938 | 449 |
10487 | 450 // If there was an error in constructing the rep, replace it with |
451 // empty vector for safety. | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
452 void chkerr (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
453 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
454 if (rep->err) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
455 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
456 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
457 delete rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
458 rep = err_rep (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
459 rep->count++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
460 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
461 } |
1560 | 462 |
1 | 463 public: |
1551 | 464 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
465 // Fast empty constructor. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
466 idx_vector (void) : rep (nil_rep ()) { rep->count++; } |
1560 | 467 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
468 // Zero-based constructors (for use from C++). |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
469 idx_vector (octave_idx_type i) : rep (new idx_scalar_rep (i)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
470 { chkerr (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
471 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
472 idx_vector (octave_idx_type start, octave_idx_type limit, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
473 octave_idx_type step = 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
474 : rep (new idx_range_rep (start, limit, step)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
475 { chkerr (); } |
1560 | 476 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
477 static idx_vector |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
478 make_range (octave_idx_type start, octave_idx_type step, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 octave_idx_type len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
481 return idx_vector (new idx_range_rep (start, len, step, DIRECT)); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
482 } |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
483 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
484 idx_vector (const Array<octave_idx_type>& inda) |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
485 : rep (new idx_vector_rep (inda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
486 { chkerr (); } |
1560 | 487 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
488 // Directly pass extent, no checking. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
489 idx_vector (const Array<octave_idx_type>& inda, octave_idx_type ext) |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
490 : rep (new idx_vector_rep (inda, ext, DIRECT)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
491 { } |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10273
diff
changeset
|
492 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
493 // Colon is best constructed by simply copying (or referencing) this member. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
494 static const idx_vector colon; |
4938 | 495 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
496 // or passing ':' here |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
497 idx_vector (char c) : rep (new idx_colon_rep (c)) { chkerr (); } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
498 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
499 // Conversion constructors (used by interpreter). |
1560 | 500 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
501 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
502 idx_vector (octave_int<T> x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
503 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
504 idx_vector (double x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
2386 | 505 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
506 idx_vector (float x) : rep (new idx_scalar_rep (x)) { chkerr (); } |
3928 | 507 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
508 // A scalar bool does not necessarily map to scalar index. |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
509 idx_vector (bool x) : rep (new idx_mask_rep (x)) { chkerr (); } |
1560 | 510 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
511 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
512 idx_vector (const Array<octave_int<T> >& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
513 { chkerr (); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
514 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
515 idx_vector (const Array<double>& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
516 { chkerr (); } |
2828 | 517 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
518 idx_vector (const Array<float>& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
519 { chkerr (); } |
4938 | 520 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
521 idx_vector (const Array<bool>& nda); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
522 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
523 idx_vector (const Range& r) |
10489
d47802f0e557
Back out changeset 4e64fbbd5c58
Jaroslav Hajek <highegg@gmail.com>
parents:
10487
diff
changeset
|
524 : rep (new idx_range_rep (r)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
525 { chkerr (); } |
2828 | 526 |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
527 idx_vector (const Sparse<bool>& nda) : rep (new idx_vector_rep (nda)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
528 { chkerr (); } |
8384
a99b9113c58c
optimize sparse bool indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
529 |
4979 | 530 idx_vector (const idx_vector& a) : rep (a.rep) { rep->count++; } |
1551 | 531 |
2802 | 532 ~idx_vector (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
533 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
534 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
535 delete rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
536 } |
1 | 537 |
1560 | 538 idx_vector& operator = (const idx_vector& a) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
540 if (this != &a) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
541 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
542 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
543 delete rep; |
1 | 544 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
545 rep = a.rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
546 rep->count++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
547 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
548 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
549 } |
1551 | 550 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
551 idx_class_type idx_class (void) const { return rep->idx_class (); } |
1560 | 552 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
553 octave_idx_type length (octave_idx_type n = 0) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
554 { return rep->length (n); } |
191 | 555 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
556 octave_idx_type extent (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
557 { return rep->extent (n); } |
1 | 558 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
559 octave_idx_type xelem (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
560 { return rep->xelem (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
561 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
562 octave_idx_type checkelem (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
563 { return rep->checkelem (n); } |
1551 | 564 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
565 octave_idx_type operator () (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
566 { |
21229
a83e7a384ee0
create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
567 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
568 return rep->checkelem (n); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
569 #else |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
570 return rep->xelem (n); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
571 #endif |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
572 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
573 |
8333 | 574 operator bool (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
575 { return ! rep->err; } |
1 | 576 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
577 bool is_colon (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
578 { return rep->idx_class () == class_colon; } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
579 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
580 bool is_scalar (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
581 { return rep->idx_class () == class_scalar; } |
1 | 582 |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
583 bool is_range (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
584 { return rep->idx_class () == class_range; } |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
585 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
586 bool is_colon_equiv (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
587 { return rep->is_colon_equiv (n); } |
3079 | 588 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
589 idx_vector sorted (bool uniq = false) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
590 { return idx_vector (rep->sort_uniq_clone (uniq)); } |
208 | 591 |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
592 idx_vector sorted (Array<octave_idx_type>& sidx) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
593 { return idx_vector (rep->sort_idx (sidx)); } |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
594 |
4653 | 595 dim_vector orig_dimensions (void) const { return rep->orig_dimensions (); } |
4504 | 596 |
8333 | 597 octave_idx_type orig_rows (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
598 { return orig_dimensions () (0); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
599 |
8333 | 600 octave_idx_type orig_columns (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
601 { return orig_dimensions () (1); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
602 |
2663 | 603 int orig_empty (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
604 { return (! is_colon () && orig_dimensions ().any_zero ()); } |
2663 | 605 |
4653 | 606 // i/o |
1 | 607 |
3504 | 608 std::ostream& print (std::ostream& os) const { return rep->print (os); } |
1560 | 609 |
3504 | 610 friend std::ostream& operator << (std::ostream& os, const idx_vector& a) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
611 { return a.print (os); } |
1560 | 612 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
613 // Slice with specializations. No checking of bounds! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
614 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
615 // This is equivalent to the following loop (but much faster): |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
616 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
617 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
618 // dest[i] = src[idx(i)]; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
619 // return i; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
620 // |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
621 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
622 octave_idx_type |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
623 index (const T *src, octave_idx_type n, T *dest) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
624 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
625 octave_idx_type len = rep->length (n); |
10487 | 626 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
627 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
628 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
629 case class_colon: |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
630 std::copy (src, src + len, dest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
631 break; |
10487 | 632 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
633 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
634 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
635 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
636 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
637 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
638 const T *ssrc = src + start; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
639 if (step == 1) |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
640 std::copy (ssrc, ssrc + len, dest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
641 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
642 std::reverse_copy (ssrc - len + 1, ssrc + 1, dest); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
643 else if (step == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
644 std::fill_n (dest, len, *ssrc); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
645 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
646 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
647 for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
648 dest[i] = ssrc[j]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
649 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
650 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 break; |
10487 | 652 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
653 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
654 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
655 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
656 dest[0] = src[r->get_data ()]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
657 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
658 break; |
10487 | 659 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
660 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
661 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
662 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
663 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
664 for (octave_idx_type i = 0; i < len; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 dest[i] = src[data[i]]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
666 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
667 break; |
10487 | 668 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
669 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
670 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
671 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
672 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
673 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
674 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
675 if (data[i]) *dest++ = src[i]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
676 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
677 break; |
10487 | 678 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
679 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
680 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
681 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
682 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
683 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
684 return len; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
685 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
686 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
687 // Slice assignment with specializations. No checking of bounds! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
688 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
689 // This is equivalent to the following loop (but much faster): |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
690 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
691 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
692 // dest[idx(i)] = src[i]; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
693 // return i; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
694 // |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
695 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
696 octave_idx_type |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
697 assign (const T *src, octave_idx_type n, T *dest) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
698 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
699 octave_idx_type len = rep->length (n); |
10487 | 700 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
701 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
702 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
703 case class_colon: |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
704 std::copy (src, src + len, dest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
705 break; |
10487 | 706 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
707 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
708 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
709 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
710 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
711 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
712 T *sdest = dest + start; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
713 if (step == 1) |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18084
diff
changeset
|
714 std::copy (src, src + len, sdest); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
715 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
716 std::reverse_copy (src, src + len, sdest - len + 1); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
717 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
718 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
719 for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
720 sdest[j] = src[i]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
721 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
722 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
723 break; |
10487 | 724 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
725 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
726 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
727 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
728 dest[r->get_data ()] = src[0]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
729 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
730 break; |
10487 | 731 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
732 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
733 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
734 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
735 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
736 for (octave_idx_type i = 0; i < len; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
737 dest[data[i]] = src[i]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
738 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
739 break; |
10487 | 740 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
741 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
742 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
743 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
744 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
745 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
746 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
747 if (data[i]) dest[i] = *src++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
748 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
749 break; |
10487 | 750 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
751 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
752 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
753 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
754 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
755 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
756 return len; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
757 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
758 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
759 // Slice fill with specializations. No checking of bounds! |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
760 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
761 // This is equivalent to the following loop (but much faster): |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
762 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
763 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
764 // dest[idx(i)] = val; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
765 // return i; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
766 // |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
767 template <typename T> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
768 octave_idx_type |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
769 fill (const T& val, octave_idx_type n, T *dest) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
770 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
771 octave_idx_type len = rep->length (n); |
10487 | 772 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
773 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
774 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
775 case class_colon: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
776 std::fill (dest, dest + len, val); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
777 break; |
10487 | 778 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
779 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
780 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
781 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
782 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
783 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
784 T *sdest = dest + start; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
785 if (step == 1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
786 std::fill (sdest, sdest + len, val); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
787 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
788 std::fill (sdest - len + 1, sdest + 1, val); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
789 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
790 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
791 for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
792 sdest[j] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
793 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
794 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
795 break; |
10487 | 796 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
797 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
798 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
799 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
800 dest[r->get_data ()] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
801 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
802 break; |
10487 | 803 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
804 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
805 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
806 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
807 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
808 for (octave_idx_type i = 0; i < len; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
809 dest[data[i]] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
810 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
811 break; |
10487 | 812 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
813 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
814 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
815 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
816 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
817 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
818 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
819 if (data[i]) dest[i] = val; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
820 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
821 break; |
10487 | 822 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
823 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
824 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
825 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
826 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
827 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
828 return len; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
829 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
830 |
10487 | 831 // Generic non-breakable indexed loop. The loop body should be |
832 // encapsulated in a single functor body. This is equivalent to the | |
833 // following loop (but faster, at least for simple inlined bodies): | |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
834 // |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
835 // for (octave_idx_type i = 0; i < idx->length (n); i++) body (idx(i)); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
836 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
837 template <typename Functor> |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
838 void |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
839 loop (octave_idx_type n, Functor body) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
840 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
841 octave_idx_type len = rep->length (n); |
10487 | 842 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
843 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
844 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
845 case class_colon: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
846 for (octave_idx_type i = 0; i < len; i++) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
847 break; |
10487 | 848 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
849 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
850 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
851 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
852 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
853 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
854 octave_idx_type i, j; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
855 if (step == 1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
856 for (i = start, j = start + len; i < j; i++) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
857 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
858 for (i = start, j = start - len; i > j; i--) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
859 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
860 for (i = 0, j = start; i < len; i++, j += step) body (j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
861 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
862 break; |
10487 | 863 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
864 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
865 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
866 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
867 body (r->get_data ()); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
868 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
869 break; |
10487 | 870 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
871 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
872 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
873 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
874 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
875 for (octave_idx_type i = 0; i < len; i++) body (data[i]); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
876 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
877 break; |
10487 | 878 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
879 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
880 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
881 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
882 const bool *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
883 octave_idx_type ext = r->extent (0); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
884 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
885 if (data[i]) body (i); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
886 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
887 break; |
10487 | 888 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
889 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
890 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
891 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
892 } |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
893 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
894 } |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
895 |
10487 | 896 // Generic breakable indexed loop. The loop body should be |
897 // encapsulated in a single functor body. This is equivalent to the | |
898 // following loop (but faster, at least for simple inlined bodies): | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
899 // |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
900 // for (octave_idx_type i = 0; i < idx->length (n); i++) |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
901 // if (body (idx(i))) break; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
902 // return i; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
903 // |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
904 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21137
diff
changeset
|
905 template <typename Functor> |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
906 octave_idx_type |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
907 bloop (octave_idx_type n, Functor body) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
908 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
909 octave_idx_type len = rep->length (n), ret; |
10487 | 910 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
911 switch (rep->idx_class ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
912 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
913 case class_colon: |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
914 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
915 octave_idx_type i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
916 for (i = 0; i < len && body (i); i++) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
917 ret = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
918 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
919 break; |
10487 | 920 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
921 case class_range: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
922 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
923 idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
924 octave_idx_type start = r->get_start (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
925 octave_idx_type step = r->get_step (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
926 octave_idx_type i, j; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
927 if (step == 1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
928 for (i = start, j = start + len; i < j && body (i); i++) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
929 else if (step == -1) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
930 for (i = start, j = start - len; i > j && body (i); i--) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
931 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
932 for (i = 0, j = start; i < len && body (j); i++, j += step) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
933 ret = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
934 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
935 break; |
10487 | 936 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
937 case class_scalar: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
938 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
939 idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
940 ret = body (r->get_data ()) ? 1 : 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
941 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
942 break; |
10487 | 943 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
944 case class_vector: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
945 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
946 idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
947 const octave_idx_type *data = r->get_data (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
948 octave_idx_type i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
949 for (i = 0; i < len && body (data[i]); i++) ; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
950 ret = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
951 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
952 break; |
10487 | 953 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
954 case class_mask: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
955 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
956 idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
957 const bool *data = r->get_data (); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
958 octave_idx_type ext = r->extent (0); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
959 octave_idx_type j = 0; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
960 for (octave_idx_type i = 0; i < ext; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
961 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
962 if (data[i]) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
963 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
964 if (body (i)) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
965 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
966 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
967 j++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
968 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
969 } |
9985
43a29eeda994
fix idx_vector::loop for masks
Jaroslav Hajek <highegg@gmail.com>
parents:
9894
diff
changeset
|
970 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
971 ret = j; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
972 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
973 break; |
10487 | 974 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
975 default: |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
976 assert (false); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
977 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
978 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
979 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
980 return ret; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
981 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
982 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
983 // Rationale: |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
984 // This method is the key to "smart indexing". When indexing cartesian |
10487 | 985 // arrays, sometimes consecutive index vectors can be reduced into a |
986 // single index. If rows (A) = k and i.maybe_reduce (j) gives k, then | |
987 // A(i,j)(:) is equal to A(k)(:). | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
988 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
989 // If the next index can be reduced, returns true and updates this. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
990 bool maybe_reduce (octave_idx_type n, const idx_vector& j, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
991 octave_idx_type nj); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
992 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
993 bool is_cont_range (octave_idx_type n, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
994 octave_idx_type& l, octave_idx_type& u) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
995 |
9725 | 996 // Returns the increment for ranges and colon, 0 for scalars and empty |
997 // vectors, 1st difference otherwise. | |
998 octave_idx_type increment (void) const; | |
999 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1000 idx_vector |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1001 complement (octave_idx_type n) const; |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1002 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1003 bool is_permutation (octave_idx_type n) const; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1004 |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1005 // Returns the inverse permutation. If this is not a permutation on 1:n, the |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1006 // result is undefined (but no error unless extent () != n). |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1007 idx_vector inverse_permutation (octave_idx_type n) const; |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10489
diff
changeset
|
1008 |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1009 // Copies all the indices to a given array. Not allowed for colons. |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1010 void copy_data (octave_idx_type *data) const; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1011 |
9879
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
1012 // If the index is a mask, convert it to index vector. |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
1013 idx_vector unmask (void) const; |
034677ab6865
smarter treatment of mask indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9780
diff
changeset
|
1014 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
1015 // Unconverts the index to a scalar, Range, double array or a mask. |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
8972
diff
changeset
|
1016 void unconvert (idx_class_type& iclass, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1017 double& scalar, Range& range, |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9886
diff
changeset
|
1018 Array<double>& array, Array<bool>& mask) const; |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1019 |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1020 Array<octave_idx_type> as_array (void) const; |
10475
739109ef88ee
helper idx_vector methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1021 |
10487 | 1022 // Raw pointer to index array. This is non-const because it may be |
1023 // necessary to mutate the index. | |
10475
739109ef88ee
helper idx_vector methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1024 const octave_idx_type *raw (void); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1025 |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1026 bool is_vector (void) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1027 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1028 // FIXME: these are here for compatibility. They should be removed |
8333 | 1029 // when no longer in use. |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1030 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1031 octave_idx_type elem (octave_idx_type n) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1032 { return (*this) (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1033 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1034 bool is_colon_equiv (octave_idx_type n, int) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1035 { return is_colon_equiv (n); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1036 |
8333 | 1037 octave_idx_type |
1038 freeze (octave_idx_type z_len, const char *tag, bool resize_ok = false); | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1039 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1040 void sort (bool uniq = false) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1041 { *this = sorted (uniq); } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1042 |
8333 | 1043 octave_idx_type ones_count (void) const; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1044 |
8333 | 1045 octave_idx_type max (void) const { return extent (1) - 1; } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1046 |
1 | 1047 private: |
1048 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7573
diff
changeset
|
1049 idx_base_rep *rep; |
1 | 1050 |
1051 }; | |
1052 | |
1053 #endif |