annotate liboctave/array/Array.h @ 17769:49a5a4be04a1

maint: Use GNU style coding conventions for code in liboctave/ * liboctave/array/Array-C.cc, liboctave/array/Array-b.cc, liboctave/array/Array-ch.cc, liboctave/array/Array-d.cc, liboctave/array/Array-f.cc, liboctave/array/Array-fC.cc, liboctave/array/Array-util.cc, liboctave/array/Array-util.h, liboctave/array/Array.cc, liboctave/array/Array.h, liboctave/array/Array3.h, liboctave/array/CColVector.cc, liboctave/array/CColVector.h, liboctave/array/CDiagMatrix.cc, liboctave/array/CDiagMatrix.h, liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h, liboctave/array/CNDArray.cc, liboctave/array/CNDArray.h, liboctave/array/CRowVector.cc, liboctave/array/CRowVector.h, liboctave/array/CSparse.cc, liboctave/array/CSparse.h, liboctave/array/DiagArray2.h, liboctave/array/MArray.cc, liboctave/array/MArray.h, liboctave/array/MDiagArray2.cc, liboctave/array/MDiagArray2.h, liboctave/array/MSparse.cc, liboctave/array/MSparse.h, liboctave/array/MatrixType.cc, liboctave/array/MatrixType.h, liboctave/array/PermMatrix.h, liboctave/array/Range.cc, liboctave/array/Range.h, liboctave/array/Sparse.cc, liboctave/array/Sparse.h, liboctave/array/boolMatrix.cc, liboctave/array/boolMatrix.h, liboctave/array/boolNDArray.cc, liboctave/array/boolNDArray.h, liboctave/array/boolSparse.cc, liboctave/array/boolSparse.h, liboctave/array/chMatrix.cc, liboctave/array/chMatrix.h, liboctave/array/chNDArray.cc, liboctave/array/chNDArray.h, liboctave/array/dColVector.h, liboctave/array/dDiagMatrix.cc, liboctave/array/dDiagMatrix.h, liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h, liboctave/array/dNDArray.cc, liboctave/array/dNDArray.h, liboctave/array/dRowVector.h, liboctave/array/dSparse.cc, liboctave/array/dSparse.h, liboctave/array/dim-vector.cc, liboctave/array/dim-vector.h, liboctave/array/fCColVector.cc, liboctave/array/fCColVector.h, liboctave/array/fCDiagMatrix.cc, liboctave/array/fCDiagMatrix.h, liboctave/array/fCMatrix.cc, liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.cc, liboctave/array/fCNDArray.h, liboctave/array/fCRowVector.cc, liboctave/array/fCRowVector.h, liboctave/array/fColVector.h, liboctave/array/fDiagMatrix.cc, liboctave/array/fDiagMatrix.h, liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h, liboctave/array/fNDArray.cc, liboctave/array/fNDArray.h, liboctave/array/fRowVector.h, liboctave/array/idx-vector.cc, liboctave/array/idx-vector.h, liboctave/array/intNDArray.cc, liboctave/array/intNDArray.h, liboctave/cruft/misc/blaswrap.c, liboctave/cruft/misc/quit.cc, liboctave/numeric/CmplxCHOL.cc, liboctave/numeric/CmplxCHOL.h, liboctave/numeric/CmplxGEPBAL.cc, liboctave/numeric/CmplxGEPBAL.h, liboctave/numeric/CmplxHESS.h, liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxLU.h, liboctave/numeric/CmplxQR.cc, liboctave/numeric/CmplxQRP.cc, liboctave/numeric/CmplxQRP.h, liboctave/numeric/CmplxSCHUR.h, liboctave/numeric/CmplxSVD.cc, liboctave/numeric/CmplxSVD.h, liboctave/numeric/CollocWt.h, liboctave/numeric/DAE.h, liboctave/numeric/DAEFunc.h, liboctave/numeric/DAERT.h, liboctave/numeric/DAERTFunc.h, liboctave/numeric/DASPK.cc, liboctave/numeric/DASRT.cc, liboctave/numeric/DASRT.h, liboctave/numeric/DASSL.cc, liboctave/numeric/DET.h, liboctave/numeric/EIG.cc, liboctave/numeric/EIG.h, liboctave/numeric/LSODE.cc, liboctave/numeric/ODE.h, liboctave/numeric/ODEFunc.h, liboctave/numeric/ODES.h, liboctave/numeric/ODESFunc.h, liboctave/numeric/Quad.cc, liboctave/numeric/Quad.h, liboctave/numeric/SparseCmplxCHOL.h, liboctave/numeric/SparseCmplxLU.cc, liboctave/numeric/SparseCmplxLU.h, liboctave/numeric/SparseCmplxQR.cc, liboctave/numeric/SparseCmplxQR.h, liboctave/numeric/SparseQR.cc, liboctave/numeric/SparseQR.h, liboctave/numeric/SparsedbleCHOL.h, liboctave/numeric/SparsedbleLU.cc, liboctave/numeric/SparsedbleLU.h, liboctave/numeric/base-aepbal.h, liboctave/numeric/base-dae.h, liboctave/numeric/base-de.h, liboctave/numeric/base-lu.cc, liboctave/numeric/base-lu.h, liboctave/numeric/base-min.h, liboctave/numeric/base-qr.h, liboctave/numeric/bsxfun.h, liboctave/numeric/dbleCHOL.cc, liboctave/numeric/dbleCHOL.h, liboctave/numeric/dbleGEPBAL.h, liboctave/numeric/dbleHESS.h, liboctave/numeric/dbleLU.cc, liboctave/numeric/dbleLU.h, liboctave/numeric/dbleQR.cc, liboctave/numeric/dbleQRP.cc, liboctave/numeric/dbleQRP.h, liboctave/numeric/dbleSCHUR.cc, liboctave/numeric/dbleSCHUR.h, liboctave/numeric/dbleSVD.cc, liboctave/numeric/dbleSVD.h, liboctave/numeric/eigs-base.cc, liboctave/numeric/fCmplxAEPBAL.cc, liboctave/numeric/fCmplxAEPBAL.h, liboctave/numeric/fCmplxCHOL.cc, liboctave/numeric/fCmplxCHOL.h, liboctave/numeric/fCmplxGEPBAL.cc, liboctave/numeric/fCmplxGEPBAL.h, liboctave/numeric/fCmplxHESS.h, liboctave/numeric/fCmplxLU.cc, liboctave/numeric/fCmplxLU.h, liboctave/numeric/fCmplxQR.cc, liboctave/numeric/fCmplxQR.h, liboctave/numeric/fCmplxQRP.cc, liboctave/numeric/fCmplxQRP.h, liboctave/numeric/fCmplxSCHUR.cc, liboctave/numeric/fCmplxSCHUR.h, liboctave/numeric/fCmplxSVD.h, liboctave/numeric/fEIG.cc, liboctave/numeric/fEIG.h, liboctave/numeric/floatCHOL.cc, liboctave/numeric/floatCHOL.h, liboctave/numeric/floatGEPBAL.cc, liboctave/numeric/floatGEPBAL.h, liboctave/numeric/floatHESS.h, liboctave/numeric/floatLU.cc, liboctave/numeric/floatLU.h, liboctave/numeric/floatQR.cc, liboctave/numeric/floatQRP.cc, liboctave/numeric/floatQRP.h, liboctave/numeric/floatSCHUR.cc, liboctave/numeric/floatSCHUR.h, liboctave/numeric/floatSVD.cc, liboctave/numeric/floatSVD.h, liboctave/numeric/lo-mappers.cc, liboctave/numeric/lo-mappers.h, liboctave/numeric/lo-specfun.cc, liboctave/numeric/lo-specfun.h, liboctave/numeric/oct-convn.cc, liboctave/numeric/oct-fftw.cc, liboctave/numeric/oct-fftw.h, liboctave/numeric/oct-norm.cc, liboctave/numeric/oct-rand.cc, liboctave/numeric/oct-rand.h, liboctave/numeric/randgamma.c, liboctave/numeric/randgamma.h, liboctave/numeric/randmtzig.c, liboctave/numeric/randpoisson.c, liboctave/numeric/randpoisson.h, liboctave/numeric/sparse-base-chol.h, liboctave/numeric/sparse-base-lu.h, liboctave/numeric/sparse-dmsolve.cc, liboctave/operators/Sparse-diag-op-defs.h, liboctave/operators/Sparse-op-defs.h, liboctave/operators/mx-inlines.cc, liboctave/system/dir-ops.h, liboctave/system/file-ops.cc, liboctave/system/file-stat.cc, liboctave/system/file-stat.h, liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h, liboctave/system/mach-info.cc, liboctave/system/mach-info.h, liboctave/system/oct-env.cc, liboctave/system/oct-group.cc, liboctave/system/oct-syscalls.cc, liboctave/system/oct-syscalls.h, liboctave/system/oct-time.h, liboctave/system/tempname.c, liboctave/util/action-container.h, liboctave/util/base-list.h, liboctave/util/cmd-edit.cc, liboctave/util/cmd-edit.h, liboctave/util/cmd-hist.cc, liboctave/util/cmd-hist.h, liboctave/util/data-conv.cc, liboctave/util/data-conv.h, liboctave/util/kpse.cc, liboctave/util/lo-array-gripes.cc, liboctave/util/lo-cieee.c, liboctave/util/lo-regexp.cc, liboctave/util/lo-utils.cc, liboctave/util/oct-alloc.cc, liboctave/util/oct-base64.cc, liboctave/util/oct-binmap.h, liboctave/util/oct-cmplx.h, liboctave/util/oct-glob.cc, liboctave/util/oct-inttypes.cc, liboctave/util/oct-inttypes.h, liboctave/util/oct-locbuf.cc, liboctave/util/oct-locbuf.h, liboctave/util/oct-mem.h, liboctave/util/oct-mutex.cc, liboctave/util/oct-refcount.h, liboctave/util/oct-shlib.cc, liboctave/util/oct-shlib.h, liboctave/util/oct-sort.cc, liboctave/util/oct-sort.h, liboctave/util/pathsearch.cc, liboctave/util/pathsearch.h, liboctave/util/sparse-util.cc, liboctave/util/str-vec.cc, liboctave/util/str-vec.h, liboctave/util/unwind-prot.h, liboctave/util/url-transfer.cc, liboctave/util/url-transfer.h: Use GNU style coding conventions.
author Rik <rik@octave.org>
date Sat, 26 Oct 2013 18:57:05 -0700
parents d63878346099
children 96751a74bbbb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1993
1b57120c997b [project @ 1996-03-03 01:16:15 by jwe]
jwe
parents: 1989
diff changeset
1 // Template array classes
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
2 /*
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
3
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
4 Copyright (C) 1993-2013 John W. Eaton
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11507
diff changeset
5 Copyright (C) 2008-2009 Jaroslav Hajek
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10366
diff changeset
6 Copyright (C) 2010 VZLU Prague
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
7
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
9
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6884
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6884
diff changeset
13 option) any later version.
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
14
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
18 for more details.
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
19
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6884
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6884
diff changeset
22 <http://www.gnu.org/licenses/>.
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
23
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
24 */
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
25
382
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 376
diff changeset
26 #if !defined (octave_Array_h)
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 376
diff changeset
27 #define octave_Array_h 1
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 376
diff changeset
28
1366
f75432dff006 [project @ 1995-09-05 23:56:42 by jwe]
jwe
parents: 1359
diff changeset
29 #include <cassert>
4152
f14251d33b01 [project @ 2002-11-06 18:41:50 by jwe]
jwe
parents: 4066
diff changeset
30 #include <cstddef>
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents: 3585
diff changeset
31
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
32 #include <algorithm>
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
33 #include <iosfwd>
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
34
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
35 #include "dim-vector.h"
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
36 #include "idx-vector.h"
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
37 #include "lo-traits.h"
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents: 3585
diff changeset
38 #include "lo-utils.h"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
39 #include "oct-sort.h"
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
40 #include "quit.h"
9773
01f897d8a130 optimize memory manipulation by arrays & indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
41 #include "oct-mem.h"
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
42 #include "oct-refcount.h"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
43
1359
a6994c934a50 [project @ 1995-09-05 21:30:26 by jwe]
jwe
parents: 1315
diff changeset
44 // One dimensional array class. Handles the reference counting for
a6994c934a50 [project @ 1995-09-05 21:30:26 by jwe]
jwe
parents: 1315
diff changeset
45 // all the derived classes.
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
46
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
47 template <class T>
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3569
diff changeset
48 class
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3569
diff changeset
49 Array
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
50 {
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
51 protected:
1619
1a35c8c91349 [project @ 1995-11-04 11:07:21 by jwe]
jwe
parents: 1574
diff changeset
52
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
53 //--------------------------------------------------------------------
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
54 // The real representation of all arrays.
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
55 //--------------------------------------------------------------------
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
56
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
57 class ArrayRep
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
58 {
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
59 public:
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
60
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
61 T *data;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
62 octave_idx_type len;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
63 octave_refcount<int> count;
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
64
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
65 ArrayRep (T *d, octave_idx_type l)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
66 : data (no_ctor_new<T> (l)), len (l), count (1)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
67 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
68 copy_or_memcpy (l, d, data);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
69 }
10364
96ed7c629bbd remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents: 10358
diff changeset
70
96ed7c629bbd remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents: 10358
diff changeset
71 template <class U>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
72 ArrayRep (U *d, octave_idx_type l)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
73 : data (no_ctor_new<T> (l)), len (l), count (1)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
74 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
75 std::copy (d, d+l, data);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
76 }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
77
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
78 ArrayRep (void) : data (0), len (0), count (1) { }
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
79
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
80 explicit ArrayRep (octave_idx_type n)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
81 : data (no_ctor_new<T> (n)), len (n), count (1) { }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
82
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
83 explicit ArrayRep (octave_idx_type n, const T& val)
9780
6dafc60dde31 rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9773
diff changeset
84 : data (no_ctor_new<T> (n)), len (n), count (1)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
85 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
86 fill_or_memset (n, val, data);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
87 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
88
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
89 ArrayRep (const ArrayRep& a)
9780
6dafc60dde31 rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9773
diff changeset
90 : data (no_ctor_new<T> (a.len)), len (a.len), count (1)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
91 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 copy_or_memcpy (a.len, a.data, data);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
93 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
94
9780
6dafc60dde31 rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9773
diff changeset
95 ~ArrayRep (void) { no_ctor_delete<T> (data); }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
96
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
97 octave_idx_type length (void) const { return len; }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
98
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
99 private:
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
100
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
101 // No assignment!
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
102
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
103 ArrayRep& operator = (const ArrayRep& a);
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
104 };
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
105
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
106 //--------------------------------------------------------------------
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
107
6884
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
108 public:
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
109
9556
948795dc1974 make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents: 9546
diff changeset
110 void make_unique (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
111 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
112 if (rep->count > 1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
113 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
114 ArrayRep *r = new ArrayRep (slice_data, slice_len);
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 12125
diff changeset
115
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
116 if (--rep->count == 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
117 delete rep;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
118
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
119 rep = r;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
120 slice_data = rep->data;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
121 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
122 }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
123
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
124 typedef T element_type;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
125
10075
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
126 typedef typename ref_param<T>::type crefT;
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
127
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
128 typedef bool (*compare_fcn_type) (typename ref_param<T>::type,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
129 typename ref_param<T>::type);
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
130
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
131 protected:
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
132
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
133 dim_vector dimensions;
4518
382cb0ed8c14 [project @ 2003-09-20 18:08:40 by jwe]
jwe
parents: 4517
diff changeset
134
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
135 typename Array<T>::ArrayRep *rep;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
136
8531
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
137 // Rationale:
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
138 // slice_data is a pointer to rep->data, denoting together with slice_len the
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
139 // actual portion of the data referenced by this Array<T> object. This allows
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
140 // to make shallow copies not only of a whole array, but also of contiguous
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
141 // subranges. Every time rep is directly manipulated, slice_data and slice_len
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
142 // need to be properly updated.
b01fef323c24 add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents: 8524
diff changeset
143
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
144 T* slice_data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
145 octave_idx_type slice_len;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
146
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
147 // slice constructor
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
148 Array (const Array<T>& a, const dim_vector& dv,
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
149 octave_idx_type l, octave_idx_type u)
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
150 : dimensions (dv), rep(a.rep), slice_data (a.slice_data+l), slice_len (u-l)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
151 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
152 rep->count++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
153 dimensions.chop_trailing_singletons ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
155
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
156 private:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
157
4585
a1ac9ab474a1 [project @ 2003-11-08 06:07:33 by jwe]
jwe
parents: 4567
diff changeset
158 typename Array<T>::ArrayRep *nil_rep (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
159 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
160 // NR was originally allocated with new, but that does not seem
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
161 // to be necessary since it will never be deleted. So just use
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
162 // a static object instead.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
163
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
164 static typename Array<T>::ArrayRep nr;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
165 return &nr;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
166 }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
167
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
168 protected:
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
169
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
170 // For jit support
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
171 Array (T *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
172 : dimensions (adims),
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
173 rep (reinterpret_cast<typename Array<T>::ArrayRep *> (arep)),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
174 slice_data (sdata), slice_len (slen) { }
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
175
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
176 public:
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
177
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
178 // Empty ctor (0x0).
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
179
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
180 Array (void)
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
181 : dimensions (), rep (nil_rep ()), slice_data (rep->data),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
182 slice_len (rep->len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
183 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
184 rep->count++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
185 }
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
186
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
187 // Obsolete 1D ctor (there are no 1D arrays).
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
188 explicit Array (octave_idx_type n) GCC_ATTR_DEPRECATED
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
189 : dimensions (n, 1), rep (new typename Array<T>::ArrayRep (n)),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
190 slice_data (rep->data), slice_len (rep->len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
191 { }
1619
1a35c8c91349 [project @ 1995-11-04 11:07:21 by jwe]
jwe
parents: 1574
diff changeset
192
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
193 // Obsolete initialized 1D ctor (there are no 1D arrays).
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
194 explicit Array (octave_idx_type n, const T& val) GCC_ATTR_DEPRECATED
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
195 : dimensions (n, 1), rep (new typename Array<T>::ArrayRep (n)),
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
196 slice_data (rep->data), slice_len (rep->len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
197 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
198 fill (val);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
199 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
200
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
201 // nD uninitialized ctor.
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
202 explicit Array (const dim_vector& dv)
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
203 : dimensions (dv),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
204 rep (new typename Array<T>::ArrayRep (dv.safe_numel ())),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
205 slice_data (rep->data), slice_len (rep->len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
206 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
207 dimensions.chop_trailing_singletons ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
208 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
209
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
210 // nD initialized ctor.
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
211 explicit Array (const dim_vector& dv, const T& val)
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
212 : dimensions (dv),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
213 rep (new typename Array<T>::ArrayRep (dv.safe_numel ())),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
214 slice_data (rep->data), slice_len (rep->len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
215 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
216 fill (val);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
217 dimensions.chop_trailing_singletons ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
218 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
219
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
220 // Reshape constructor.
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
221 Array (const Array<T>& a, const dim_vector& dv);
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
222
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
223 // Type conversion case.
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
224 template <class U>
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
225 Array (const Array<U>& a)
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
226 : dimensions (a.dims ()),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
227 rep (new typename Array<T>::ArrayRep (a.data (), a.length ())),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
228 slice_data (rep->data), slice_len (rep->len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
229 { }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
230
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
231 // No type conversion case.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
232 Array (const Array<T>& a)
11507
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
233 : dimensions (a.dimensions), rep (a.rep), slice_data (a.slice_data),
c3ad80f4ce36 Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11010
diff changeset
234 slice_len (a.slice_len)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
235 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
236 rep->count++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
237 }
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
238
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
239 public:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
240
15216
dd7c37ceb800 avoid GCC warning by declaring Array destructor virtual
John W. Eaton <jwe@octave.org>
parents: 15212
diff changeset
241 virtual ~Array (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
242 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
243 if (--rep->count == 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
244 delete rep;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
245 }
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
246
9556
948795dc1974 make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents: 9546
diff changeset
247 Array<T>& operator = (const Array<T>& a)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
248 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
249 if (this != &a)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
250 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
251 if (--rep->count == 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
252 delete rep;
9556
948795dc1974 make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents: 9546
diff changeset
253
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
254 rep = a.rep;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
255 rep->count++;
9556
948795dc1974 make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents: 9546
diff changeset
256
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
257 dimensions = a.dimensions;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
258 slice_data = a.slice_data;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
259 slice_len = a.slice_len;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
260 }
9556
948795dc1974 make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents: 9546
diff changeset
261
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
262 return *this;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
263 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
264
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
265 void fill (const T& val);
9624
3fc7272937ce implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents: 9556
diff changeset
266
9546
1beb23d2b892 optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9341
diff changeset
267 void clear (void);
9624
3fc7272937ce implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents: 9556
diff changeset
268 void clear (const dim_vector& dv);
3fc7272937ce implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents: 9556
diff changeset
269
3fc7272937ce implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents: 9556
diff changeset
270 void clear (octave_idx_type r, octave_idx_type c)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
271 { clear (dim_vector (r, c)); }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
272
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
273 octave_idx_type capacity (void) const { return slice_len; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
274 octave_idx_type length (void) const { return capacity (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
275 octave_idx_type nelem (void) const { return capacity (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
276 octave_idx_type numel (void) const { return nelem (); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
277
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
278 octave_idx_type dim1 (void) const { return dimensions(0); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
279 octave_idx_type dim2 (void) const { return dimensions(1); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
280 octave_idx_type dim3 (void) const { return dimensions(2); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
281
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
282 // Return the array as a column vector.
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
283 Array<T> as_column (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
284 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
285 Array<T> retval (*this);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
286 if (dimensions.length () != 2 || dimensions(1) != 1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
287 retval.dimensions = dim_vector (numel (), 1);
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
288
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
289 return retval;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
290 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
291
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
292 // Return the array as a row vector.
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
293 Array<T> as_row (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
294 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
295 Array<T> retval (*this);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
296 if (dimensions.length () != 2 || dimensions(0) != 1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
297 retval.dimensions = dim_vector (1, numel ());
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
298
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
299 return retval;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
300 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
301
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
302 // Return the array as a matrix.
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
303 Array<T> as_matrix (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
304 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
305 Array<T> retval (*this);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
306 if (dimensions.length () != 2)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
307 retval.dimensions = dimensions.redim (2);
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
308
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
309 return retval;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
310 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10312
diff changeset
311
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
312 octave_idx_type rows (void) const { return dim1 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
313 octave_idx_type cols (void) const { return dim2 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
314 octave_idx_type columns (void) const { return dim2 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
315 octave_idx_type pages (void) const { return dim3 (); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
316
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
317 size_t byte_size (void) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
318 { return static_cast<size_t> (numel ()) * sizeof (T); }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
319
9026
6890d411a0b8 adjust some array dim query methods
Jaroslav Hajek <highegg@gmail.com>
parents: 9025
diff changeset
320 // Return a const-reference so that dims ()(i) works efficiently.
6890d411a0b8 adjust some array dim query methods
Jaroslav Hajek <highegg@gmail.com>
parents: 9025
diff changeset
321 const dim_vector& dims (void) const { return dimensions; }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
322
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4530
diff changeset
323 Array<T> squeeze (void) const;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
324
10095
eb8ac0eed9f1 always chop dimension vector when constructing Arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 10075
diff changeset
325 void chop_trailing_singletons (void) GCC_ATTR_DEPRECATED
4703
72c28fd651c4 [project @ 2004-01-22 00:01:09 by jwe]
jwe
parents: 4625
diff changeset
326 { dimensions.chop_trailing_singletons (); }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
327
10366
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
328 octave_idx_type compute_index (octave_idx_type i, octave_idx_type j) const;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
329 octave_idx_type compute_index (octave_idx_type i, octave_idx_type j,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
330 octave_idx_type k) const;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
331 octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const;
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
332
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
333 octave_idx_type compute_index_unchecked (const Array<octave_idx_type>& ra_idx)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
334 const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
335 { return dimensions.compute_index (ra_idx.data (), ra_idx.length ()); }
10645
8645b7087859 abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents: 10636
diff changeset
336
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
337 // No checking, even for multiple references, ever.
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
338
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14981
diff changeset
339 T& xelem (octave_idx_type n) { return slice_data[n]; }
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14981
diff changeset
340 crefT xelem (octave_idx_type n) const { return slice_data[n]; }
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
341
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
342 T& xelem (octave_idx_type i, octave_idx_type j)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
343 { return xelem (dim1 ()*j+i); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
344 crefT xelem (octave_idx_type i, octave_idx_type j) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
345 { return xelem (dim1 ()*j+i); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
346
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
347 T& xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
348 { return xelem (i, dim2 ()*k+j); }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
349 crefT xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
350 { return xelem (i, dim2 ()*k+j); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
351
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
352 T& xelem (const Array<octave_idx_type>& ra_idx)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
353 { return xelem (compute_index_unchecked (ra_idx)); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
354
10075
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
355 crefT xelem (const Array<octave_idx_type>& ra_idx) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
356 { return xelem (compute_index_unchecked (ra_idx)); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
357
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
358 // FIXME: would be nice to fix this so that we don't unnecessarily force
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
359 // a copy, but that is not so easy, and I see no clean way to do it.
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
360
10366
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
361 T& checkelem (octave_idx_type n);
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
362 T& checkelem (octave_idx_type i, octave_idx_type j);
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
363 T& checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k);
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
364 T& checkelem (const Array<octave_idx_type>& ra_idx);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
365
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
366 T& elem (octave_idx_type n)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
367 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
368 make_unique ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
369 return xelem (n);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
370 }
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
371
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14616
diff changeset
372 T& elem (octave_idx_type i, octave_idx_type j) { return elem (dim1 ()*j+i); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
373
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
374 T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
375 { return elem (i, dim2 ()*k+j); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
376
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
377 T& elem (const Array<octave_idx_type>& ra_idx)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
378 { return Array<T>::elem (compute_index_unchecked (ra_idx)); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
379
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
380 #if defined (BOUNDS_CHECKING)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
381 T& operator () (octave_idx_type n) { return checkelem (n); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
382 T& operator () (octave_idx_type i, octave_idx_type j)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
383 { return checkelem (i, j); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
384 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
385 { return checkelem (i, j, k); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
386 T& operator () (const Array<octave_idx_type>& ra_idx)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
387 { return checkelem (ra_idx); }
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
388 #else
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
389 T& operator () (octave_idx_type n) { return elem (n); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
390 T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
391 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
392 { return elem (i, j, k); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
393 T& operator () (const Array<octave_idx_type>& ra_idx)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
394 { return elem (ra_idx); }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
395 #endif
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
396
10366
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
397 crefT checkelem (octave_idx_type n) const;
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
398 crefT checkelem (octave_idx_type i, octave_idx_type j) const;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
399 crefT checkelem (octave_idx_type i, octave_idx_type j,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
400 octave_idx_type k) const;
10366
e5ae13b8b2c2 improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents: 10364
diff changeset
401 crefT checkelem (const Array<octave_idx_type>& ra_idx) const;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
402
10075
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
403 crefT elem (octave_idx_type n) const { return xelem (n); }
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
404
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
405 crefT elem (octave_idx_type i, octave_idx_type j) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
406 { return xelem (i, j); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
407
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
408 crefT elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
409 { return xelem (i, j, k); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
410
10075
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
411 crefT elem (const Array<octave_idx_type>& ra_idx) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
412 { return Array<T>::xelem (compute_index_unchecked (ra_idx)); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
413
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
414 #if defined (BOUNDS_CHECKING)
10075
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
415 crefT operator () (octave_idx_type n) const { return checkelem (n); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
416 crefT operator () (octave_idx_type i, octave_idx_type j) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
417 { return checkelem (i, j); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
418 crefT operator () (octave_idx_type i, octave_idx_type j,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
419 octave_idx_type k) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
420 { return checkelem (i, j, k); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
421 crefT operator () (const Array<octave_idx_type>& ra_idx) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
422 { return checkelem (ra_idx); }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
423 #else
10075
84b0725f4b09 return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9921
diff changeset
424 crefT operator () (octave_idx_type n) const { return elem (n); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
425 crefT operator () (octave_idx_type i, octave_idx_type j) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
426 { return elem (i, j); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
427 crefT operator () (octave_idx_type i, octave_idx_type j,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
428 octave_idx_type k) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
429 { return elem (i, j, k); }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
430 crefT operator () (const Array<octave_idx_type>& ra_idx) const
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
431 { return elem (ra_idx); }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
432 #endif
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
433
9731
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
434 // Fast extractors. All of these produce shallow copies.
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
435 // Warning: none of these do check bounds, unless BOUNDS_CHECKING is on!
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
436
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
437 // Extract column: A(:,k+1).
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
438 Array<T> column (octave_idx_type k) const;
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
439 // Extract page: A(:,:,k+1).
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
440 Array<T> page (octave_idx_type k) const;
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
441
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
442 // Extract a slice from this array as a column vector: A(:)(lo+1:up).
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
443 // Must be 0 <= lo && up <= numel. May be up < lo.
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
444 Array<T> linear_slice (octave_idx_type lo, octave_idx_type up) const;
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
445
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
446 Array<T> reshape (octave_idx_type nr, octave_idx_type nc) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
447 { return Array<T> (*this, dim_vector (nr, nc)); }
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
448
9731
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9725
diff changeset
449 Array<T> reshape (const dim_vector& new_dims) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
450 { return Array<T> (*this, new_dims); }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4559
diff changeset
451
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
452 Array<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
453 Array<T> ipermute (const Array<octave_idx_type>& vec) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
454 { return permute (vec, true); }
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4587
diff changeset
455
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
456 bool is_square (void) const { return (dim1 () == dim2 ()); }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
457
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
458 bool is_empty (void) const { return numel () == 0; }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
459
9026
6890d411a0b8 adjust some array dim query methods
Jaroslav Hajek <highegg@gmail.com>
parents: 9025
diff changeset
460 bool is_vector (void) const { return dimensions.is_vector (); }
6890d411a0b8 adjust some array dim query methods
Jaroslav Hajek <highegg@gmail.com>
parents: 9025
diff changeset
461
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
462 Array<T> transpose (void) const;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7717
diff changeset
463 Array<T> hermitian (T (*fcn) (const T&) = 0) const;
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
464
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
465 const T *data (void) const { return slice_data; }
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
466
3952
945e8c160191 [project @ 2002-05-23 17:18:12 by jwe]
jwe
parents: 3944
diff changeset
467 const T *fortran_vec (void) const { return data (); }
945e8c160191 [project @ 2002-05-23 17:18:12 by jwe]
jwe
parents: 3944
diff changeset
468
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
469 T *fortran_vec (void);
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
470
9546
1beb23d2b892 optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9341
diff changeset
471 bool is_shared (void) { return rep->count > 1; }
1beb23d2b892 optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9341
diff changeset
472
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
473 int ndims (void) const { return dimensions.length (); }
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
474
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
475 // Indexing without resizing.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
476
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
477 Array<T> index (const idx_vector& i) const;
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
478
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
479 Array<T> index (const idx_vector& i, const idx_vector& j) const;
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
480
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
481 Array<T> index (const Array<idx_vector>& ia) const;
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
482
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
483 virtual T resize_fill_value (void) const;
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
484
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
485 // Resizing (with fill).
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
486
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
487 void resize1 (octave_idx_type n, const T& rfv);
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
488 void resize1 (octave_idx_type n) { resize1 (n, resize_fill_value ()); }
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
489
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
490 void resize (octave_idx_type n) GCC_ATTR_DEPRECATED { resize1 (n); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
491
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
492 void resize (octave_idx_type nr, octave_idx_type nc,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
493 const T& rfv) GCC_ATTR_DEPRECATED
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
494 {
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
495 resize2 (nr, nc, rfv);
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
496 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
497
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
498 void resize (octave_idx_type nr, octave_idx_type nc) GCC_ATTR_DEPRECATED
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
499 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
500 resize2 (nr, nc, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
501 }
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
502
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
503 void resize (const dim_vector& dv, const T& rfv);
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
504 void resize (const dim_vector& dv) { resize (dv, resize_fill_value ()); }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
505
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
506 // Indexing with possible resizing and fill
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
507 // FIXME: this is really a corner case, that should better be
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
508 // handled directly in liboctinterp.
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
509
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
510 Array<T> index (const idx_vector& i, bool resize_ok, const T& rfv) const;
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
511 Array<T> index (const idx_vector& i, bool resize_ok) const
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
512 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
513 return index (i, resize_ok, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
514 }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
515
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
516 Array<T> index (const idx_vector& i, const idx_vector& j, bool resize_ok,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
517 const T& rfv) const;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
518 Array<T> index (const idx_vector& i, const idx_vector& j,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
519 bool resize_ok) const
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
520 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
521 return index (i, j, resize_ok, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
522 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
523
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
524 Array<T> index (const Array<idx_vector>& ia, bool resize_ok,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
525 const T& rfv) const;
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
526 Array<T> index (const Array<idx_vector>& ia, bool resize_ok) const
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
527 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
528 return index (ia, resize_ok, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
529 }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
530
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
531 // Indexed assignment (always with resize & fill).
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
532
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
533 void assign (const idx_vector& i, const Array<T>& rhs, const T& rfv);
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
534 void assign (const idx_vector& i, const Array<T>& rhs)
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
535 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
536 assign (i, rhs, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
537 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
538
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
539 void assign (const idx_vector& i, const idx_vector& j, const Array<T>& rhs,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
540 const T& rfv);
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
541 void assign (const idx_vector& i, const idx_vector& j, const Array<T>& rhs)
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
542 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
543 assign (i, j, rhs, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
544 }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
545
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
546 void assign (const Array<idx_vector>& ia, const Array<T>& rhs, const T& rfv);
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
547 void assign (const Array<idx_vector>& ia, const Array<T>& rhs)
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
548 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
549 assign (ia, rhs, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
550 }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
551
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
552 // Deleting elements.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
553
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
554 // A(I) = [] (with a single subscript)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
555 void delete_elements (const idx_vector& i);
4530
e8d87fefd144 [project @ 2003-10-07 04:02:04 by jwe]
jwe
parents: 4518
diff changeset
556
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
557 // A(:,...,I,...,:) = [] (>= 2 subscripts, one of them is non-colon)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
558 void delete_elements (int dim, const idx_vector& i);
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
559
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
560 // Dispatcher to the above two.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
561 void delete_elements (const Array<idx_vector>& ia);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
562
10115
ed49cef7e005 simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10095
diff changeset
563 // Insert an array into another at a specified position.
ed49cef7e005 simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10095
diff changeset
564 // If size (a) is [d1 d2 ... dN] and idx is [i1 i2 ... iN],
ed49cef7e005 simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10095
diff changeset
565 // this method is equivalent to
ed49cef7e005 simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10095
diff changeset
566 // x(i1:i1+d1-1, i2:i2+d2-1, ... , iN:iN+dN-1) = a.
ed49cef7e005 simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10095
diff changeset
567 Array<T>& insert (const Array<T>& a, const Array<octave_idx_type>& idx);
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3836
diff changeset
568
10115
ed49cef7e005 simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10095
diff changeset
569 // This is just a special case for idx = [r c 0 ...]
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
570 Array<T>& insert (const Array<T>& a, octave_idx_type r, octave_idx_type c);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
571
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
572 void maybe_economize (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
573 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
574 if (rep->count == 1 && slice_len != rep->len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
575 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
576 ArrayRep *new_rep = new ArrayRep (slice_data, slice_len);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
577 delete rep;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
578 rep = new_rep;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
579 slice_data = rep->data;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
580 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
581 }
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
582
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
583 void print_info (std::ostream& os, const std::string& prefix) const;
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
584
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
585 // Unsafe. This function exists to support the MEX interface.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
586 // You should not use it anywhere else.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
587 void *mex_get_data (void) const { return const_cast<T *> (data ()); }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
588
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9653
diff changeset
589 Array<T> sort (int dim = 0, sortmode mode = ASCENDING) const;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9653
diff changeset
590 Array<T> sort (Array<octave_idx_type> &sidx, int dim = 0,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
591 sortmode mode = ASCENDING) const;
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
592
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
593 // Ordering is auto-detected or can be specified.
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
594 sortmode is_sorted (sortmode mode = UNSORTED) const;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
595
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
596 // Sort by rows returns only indices.
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
597 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
598
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
599 // Ordering is auto-detected or can be specified.
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
600 sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
601
9921
7c8392a034e6 fix & improve lookup API
Jaroslav Hajek <highegg@gmail.com>
parents: 9878
diff changeset
602 // Do a binary lookup in a sorted array. Must not contain NaNs.
8814
de16ebeef93d improve lookup, provide Array<T>::lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8725
diff changeset
603 // Mode can be specified or is auto-detected by comparing 1st and last element.
de16ebeef93d improve lookup, provide Array<T>::lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8725
diff changeset
604 octave_idx_type lookup (const T& value, sortmode mode = UNSORTED) const;
de16ebeef93d improve lookup, provide Array<T>::lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8725
diff changeset
605
9921
7c8392a034e6 fix & improve lookup API
Jaroslav Hajek <highegg@gmail.com>
parents: 9878
diff changeset
606 // Ditto, but for an array of values, specializing on the case when values
7c8392a034e6 fix & improve lookup API
Jaroslav Hajek <highegg@gmail.com>
parents: 9878
diff changeset
607 // are sorted. NaNs get the value N.
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
608 Array<octave_idx_type> lookup (const Array<T>& values,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
609 sortmode mode = UNSORTED) const;
9341
9fd5c56ce57a extend lookup capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 9201
diff changeset
610
9878
ead4f9c82a9a implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents: 9840
diff changeset
611 // Count nonzero elements.
ead4f9c82a9a implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents: 9840
diff changeset
612 octave_idx_type nnz (void) const;
ead4f9c82a9a implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents: 9840
diff changeset
613
9025
484756d558d6 add Array<T>::find
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
614 // Find indices of (at most n) nonzero elements. If n is specified, backward
484756d558d6 add Array<T>::find
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
615 // specifies search from backward.
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
616 Array<octave_idx_type> find (octave_idx_type n = -1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
617 bool backward = false) const;
9025
484756d558d6 add Array<T>::find
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
618
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9653
diff changeset
619 // Returns the n-th element in increasing order, using the same ordering as
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9653
diff changeset
620 // used for sort. n can either be a scalar index or a contiguous range.
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9653
diff changeset
621 Array<T> nth_element (const idx_vector& n, int dim = 0) const;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9653
diff changeset
622
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7503
diff changeset
623 Array<T> diag (octave_idx_type k = 0) const;
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7503
diff changeset
624
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
625 Array<T> diag (octave_idx_type m, octave_idx_type n) const;
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
626
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10674
diff changeset
627 // Concatenation along a specified (0-based) dimension, equivalent to cat().
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10674
diff changeset
628 // dim = -1 corresponds to dim = 0 and dim = -2 corresponds to dim = 1,
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10674
diff changeset
629 // but apply the looser matching rules of vertcat/horzcat.
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
630 static Array<T>
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
631 cat (int dim, octave_idx_type n, const Array<T> *array_list);
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
632
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
633 template <class U, class F>
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
634 Array<U>
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
635 map (F fcn) const
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
636 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
637 octave_idx_type len = length ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
638
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
639 const T *m = data ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
640
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
641 Array<U> result (dims ());
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
642 U *p = result.fortran_vec ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
643
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
644 octave_idx_type i;
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
645 for (i = 0; i < len - 3; i += 4)
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
646 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
647 octave_quit ();
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
648
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
649 p[i] = fcn (m[i]);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
650 p[i+1] = fcn (m[i+1]);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
651 p[i+2] = fcn (m[i+2]);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
652 p[i+3] = fcn (m[i+3]);
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
653 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
654
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10115
diff changeset
655 octave_quit ();
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
656
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
657 for (; i < len; i++)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
658 p[i] = fcn (m[i]);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
659
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
660 return result;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
661 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
662
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
663 // Overloads for function references.
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
664 template <class U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
665 Array<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
666 map (U (&fcn) (T)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
667 { return map<U, U (&) (T)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
668
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
669 template <class U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
670 Array<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
671 map (U (&fcn) (const T&)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
672 { return map<U, U (&) (const T&)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
673
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
674 // Generic any/all test functionality with arbitrary predicate.
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
675 template <class F, bool zero>
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
676 bool test (F fcn) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
677 {
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15018
diff changeset
678 return any_all_test<F, T, zero> (fcn, data (), length ());
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
679 }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
680
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
681 // Simpler calls.
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
682 template <class F>
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
683 bool test_any (F fcn) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
684 { return test<F, false> (fcn); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
685
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
686 template <class F>
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
687 bool test_all (F fcn) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
688 { return test<F, true> (fcn); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
689
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
690 // Overloads for function references.
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
691 bool test_any (bool (&fcn) (T)) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
692 { return test<bool (&) (T), false> (fcn); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
693
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
694 bool test_any (bool (&fcn) (const T&)) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
695 { return test<bool (&) (const T&), false> (fcn); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
696
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
697 bool test_all (bool (&fcn) (T)) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
698 { return test<bool (&) (T), true> (fcn); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
699
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
700 bool test_all (bool (&fcn) (const T&)) const
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
701 { return test<bool (&) (const T&), true> (fcn); }
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
702
9046
88bf56bbccca make Array::find already return Matlab-compatible dimensions
Jaroslav Hajek <highegg@gmail.com>
parents: 9026
diff changeset
703 template <class U> friend class Array;
9201
472f0e22aa60 guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents: 9046
diff changeset
704
10674
e3064439d6b4 new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents: 10673
diff changeset
705 // Returns true if this->dims () == dv, and if so, replaces this->dimensions
e3064439d6b4 new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents: 10673
diff changeset
706 // by a shallow copy of dv. This is useful for maintaining several arrays with
e3064439d6b4 new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents: 10673
diff changeset
707 // supposedly equal dimensions (e.g. structs in the interpreter).
e3064439d6b4 new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents: 10673
diff changeset
708 bool optimize_dimensions (const dim_vector& dv);
e3064439d6b4 new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents: 10673
diff changeset
709
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
710 // WARNING: Only call these functions from jit
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
711
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
712 int *jit_ref_count (void) { return rep->count.get (); }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
713
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
714 T *jit_slice_data (void) const { return slice_data; }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
715
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
716 octave_idx_type *jit_dimensions (void) const { return dimensions.to_jit (); }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
717
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
718 void *jit_array_rep (void) const { return rep; }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14616
diff changeset
719
9201
472f0e22aa60 guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents: 9046
diff changeset
720 private:
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
721
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
722 void resize2 (octave_idx_type nr, octave_idx_type nc, const T& rfv);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
723 void resize2 (octave_idx_type nr, octave_idx_type nc)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
724 {
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
725 resize2 (nr, nc, resize_fill_value ());
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
726 }
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
727
9201
472f0e22aa60 guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents: 9046
diff changeset
728 static void instantiation_guard ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
729 };
4459
75ee1995d2b4 [project @ 2003-07-11 17:46:41 by jwe]
jwe
parents: 4192
diff changeset
730
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
731 // This is a simple wrapper template that will subclass an Array<T> type or any
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
732 // later type derived from it and override the default non-const operator() to
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
733 // not check for the array's uniqueness. It is, however, the user's
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
734 // responsibility to ensure the array is actually unaliased whenever elements
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
735 // are accessed.
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
736
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
737 template<class ArrayClass>
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
738 class NoAlias : public ArrayClass
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
739 {
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
740 typedef typename ArrayClass::element_type T;
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
741 public:
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
742 NoAlias () : ArrayClass () { }
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
743
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
744 // FIXME: this would be simpler once C++0x is available
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
745 template <class X>
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
746 explicit NoAlias (X x) : ArrayClass (x) { }
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
747
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
748 template <class X, class Y>
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
749 explicit NoAlias (X x, Y y) : ArrayClass (x, y) { }
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
750
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
751 template <class X, class Y, class Z>
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
752 explicit NoAlias (X x, Y y, Z z) : ArrayClass (x, y, z) { }
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
753
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
754 T& operator () (octave_idx_type n)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
755 { return ArrayClass::xelem (n); }
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
756 T& operator () (octave_idx_type i, octave_idx_type j)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
757 { return ArrayClass::xelem (i, j); }
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
758 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
759 { return ArrayClass::xelem (i, j, k); }
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
760 T& operator () (const Array<octave_idx_type>& ra_idx)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
761 { return ArrayClass::xelem (ra_idx); }
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
762 };
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9624
diff changeset
763
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
764 template <class T>
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
765 std::ostream&
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
766 operator << (std::ostream& os, const Array<T>& a);
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
767
9773
01f897d8a130 optimize memory manipulation by arrays & indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
768 #endif