Mercurial > hg > octave-nkf
annotate liboctave/array/Array.h @ 16583:e74ef19d2268
use octave_idx_type instead of int
* ls-mat-ascii.cc (looks_like_mat_ascii_file): USe octave_idx_type
instead of int for temporary variables.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 28 Apr 2013 23:21:43 -0400 |
parents | 648dabbb4c6b |
children | d63878346099 |
rev | line source |
---|---|
1993 | 1 // Template array classes |
228 | 2 /* |
3 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13990
diff
changeset
|
4 Copyright (C) 1993-2012 John W. Eaton |
11523 | 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 | 7 |
8 This file is part of Octave. | |
9 | |
10 Octave is free software; you can redistribute it and/or modify it | |
11 under the terms of the GNU General Public License as published by the | |
7016 | 12 Free Software Foundation; either version 3 of the License, or (at your |
13 option) any later version. | |
228 | 14 |
15 Octave is distributed in the hope that it will be useful, but WITHOUT | |
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
7016 | 21 along with Octave; see the file COPYING. If not, see |
22 <http://www.gnu.org/licenses/>. | |
228 | 23 |
24 */ | |
25 | |
382 | 26 #if !defined (octave_Array_h) |
27 #define octave_Array_h 1 | |
28 | |
1366 | 29 #include <cassert> |
4152 | 30 #include <cstddef> |
3613 | 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 | 34 |
4513 | 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 | 37 #include "lo-traits.h" |
3613 | 38 #include "lo-utils.h" |
7433 | 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 | 43 |
1359 | 44 // One dimensional array class. Handles the reference counting for |
45 // all the derived classes. | |
238 | 46 |
228 | 47 template <class T> |
3585 | 48 class |
49 Array | |
228 | 50 { |
3504 | 51 protected: |
1619 | 52 |
4513 | 53 //-------------------------------------------------------------------- |
54 // The real representation of all arrays. | |
55 //-------------------------------------------------------------------- | |
1735 | 56 |
57 class ArrayRep | |
58 { | |
59 public: | |
60 | |
61 T *data; | |
5275 | 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 | 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) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
67 { |
10364
96ed7c629bbd
remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents:
10358
diff
changeset
|
68 copy_or_memcpy (l, d, data); |
96ed7c629bbd
remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents:
10358
diff
changeset
|
69 } |
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) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
74 { |
10364
96ed7c629bbd
remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents:
10358
diff
changeset
|
75 std::copy (d, d+l, data); |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
76 } |
1735 | 77 |
78 ArrayRep (void) : data (0), len (0), count (1) { } | |
79 | |
9780
6dafc60dde31
rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9773
diff
changeset
|
80 explicit ArrayRep (octave_idx_type n) : data (no_ctor_new<T> (n)), len (n), count (1) { } |
1735 | 81 |
5275 | 82 explicit ArrayRep (octave_idx_type n, const T& val) |
9780
6dafc60dde31
rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9773
diff
changeset
|
83 : data (no_ctor_new<T> (n)), len (n), count (1) |
4513 | 84 { |
9780
6dafc60dde31
rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9773
diff
changeset
|
85 fill_or_memset (n, val, data); |
4513 | 86 } |
87 | |
1735 | 88 ArrayRep (const ArrayRep& a) |
9780
6dafc60dde31
rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9773
diff
changeset
|
89 : data (no_ctor_new<T> (a.len)), len (a.len), count (1) |
4513 | 90 { |
9780
6dafc60dde31
rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9773
diff
changeset
|
91 copy_or_memcpy (a.len, a.data, data); |
4513 | 92 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
93 |
9780
6dafc60dde31
rename oct-mem functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9773
diff
changeset
|
94 ~ArrayRep (void) { no_ctor_delete<T> (data); } |
1735 | 95 |
5275 | 96 octave_idx_type length (void) const { return len; } |
1735 | 97 |
4517 | 98 private: |
99 | |
100 // No assignment! | |
101 | |
102 ArrayRep& operator = (const ArrayRep& a); | |
1735 | 103 }; |
104 | |
4513 | 105 //-------------------------------------------------------------------- |
106 | |
6884 | 107 public: |
108 | |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
109 void make_unique (void) |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
110 { |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
111 if (rep->count > 1) |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
112 { |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
113 ArrayRep *r = new ArrayRep (slice_data, slice_len); |
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
114 |
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
115 if (--rep->count == 0) |
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
116 delete rep; |
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
117 |
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
118 rep = r; |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
119 slice_data = rep->data; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
120 } |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
121 } |
238 | 122 |
5900 | 123 typedef T element_type; |
124 | |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
125 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
|
126 |
8725 | 127 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
|
128 typename ref_param<T>::type); |
8725 | 129 |
8524
937921654627
clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
130 protected: |
4902 | 131 |
11507
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
132 dim_vector dimensions; |
4518 | 133 |
11507
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
134 typename Array<T>::ArrayRep *rep; |
4513 | 135 |
8531
b01fef323c24
add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
136 // Rationale: |
b01fef323c24
add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
137 // 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
|
138 // 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
|
139 // 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
|
140 // 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
|
141 // need to be properly updated. |
b01fef323c24
add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
142 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
143 T* slice_data; |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
144 octave_idx_type slice_len; |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
145 |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
146 // slice constructor |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
147 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
|
148 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
|
149 : dimensions (dv), rep(a.rep), slice_data (a.slice_data+l), slice_len (u-l) |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
150 { |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
151 rep->count++; |
10095
eb8ac0eed9f1
always chop dimension vector when constructing Arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10075
diff
changeset
|
152 dimensions.chop_trailing_singletons (); |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
153 } |
4513 | 154 |
155 private: | |
156 | |
4585 | 157 typename Array<T>::ArrayRep *nil_rep (void) const |
4513 | 158 { |
13990
c9a0e5343cd8
use static storage for array nil rep instead of allocating it with new
John W. Eaton <jwe@octave.org>
parents:
13985
diff
changeset
|
159 // NR was originally allocated with new, but that does not seem |
c9a0e5343cd8
use static storage for array nil rep instead of allocating it with new
John W. Eaton <jwe@octave.org>
parents:
13985
diff
changeset
|
160 // to be necessary since it will never be deleted. So just use |
c9a0e5343cd8
use static storage for array nil rep instead of allocating it with new
John W. Eaton <jwe@octave.org>
parents:
13985
diff
changeset
|
161 // a static object instead. |
4513 | 162 |
13990
c9a0e5343cd8
use static storage for array nil rep instead of allocating it with new
John W. Eaton <jwe@octave.org>
parents:
13985
diff
changeset
|
163 static typename Array<T>::ArrayRep nr; |
c9a0e5343cd8
use static storage for array nil rep instead of allocating it with new
John W. Eaton <jwe@octave.org>
parents:
13985
diff
changeset
|
164 return &nr; |
1550 | 165 } |
238 | 166 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
167 protected: |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
168 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
169 // For jit support |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
170 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
|
171 : dimensions (adims), |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
172 rep (reinterpret_cast<typename Array<T>::ArrayRep *> (arep)), |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
173 slice_data (sdata), slice_len (slen) {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
174 |
228 | 175 public: |
238 | 176 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
177 // Empty ctor (0x0). |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
178 |
1550 | 179 Array (void) |
11507
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
180 : 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
|
181 slice_len (rep->len) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
182 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
183 rep->count++; |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
184 } |
1550 | 185 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
186 // Obsolete 1D ctor (there are no 1D arrays). |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
187 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
|
188 : 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
|
189 slice_data (rep->data), slice_len (rep->len) |
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
190 { } |
1619 | 191 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
192 // 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
|
193 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
|
194 : 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
|
195 slice_data (rep->data), slice_len (rep->len) |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
196 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
197 fill (val); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
198 } |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
199 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
200 // nD uninitialized ctor. |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
201 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
|
202 : dimensions (dv), |
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
203 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
|
204 slice_data (rep->data), slice_len (rep->len) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
205 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
206 dimensions.chop_trailing_singletons (); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
207 } |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
208 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
209 // nD initialized ctor. |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
210 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
|
211 : dimensions (dv), |
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
212 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
|
213 slice_data (rep->data), slice_len (rep->len) |
4513 | 214 { |
215 fill (val); | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
216 dimensions.chop_trailing_singletons (); |
4513 | 217 } |
218 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
219 // Reshape constructor. |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
220 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
|
221 |
4902 | 222 // Type conversion case. |
223 template <class U> | |
224 Array (const Array<U>& a) | |
11507
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
225 : dimensions (a.dims ()), |
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
226 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
|
227 slice_data (rep->data), slice_len (rep->len) |
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
228 { } |
4902 | 229 |
230 // No type conversion case. | |
4513 | 231 Array (const Array<T>& a) |
11507
c3ad80f4ce36
Array.h, Array.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
232 : 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
|
233 slice_len (a.slice_len) |
4513 | 234 { |
235 rep->count++; | |
1550 | 236 } |
237 | |
4513 | 238 public: |
239 | |
15216
dd7c37ceb800
avoid GCC warning by declaring Array destructor virtual
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
240 virtual ~Array (void) |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
241 { |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
242 if (--rep->count == 0) |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
243 delete rep; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
244 } |
228 | 245 |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
246 Array<T>& operator = (const Array<T>& a) |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
247 { |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
248 if (this != &a) |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
249 { |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
250 if (--rep->count == 0) |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
251 delete rep; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
252 |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
253 rep = a.rep; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
254 rep->count++; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
255 |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
256 dimensions = a.dimensions; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
257 slice_data = a.slice_data; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
258 slice_len = a.slice_len; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
259 } |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
260 |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
261 return *this; |
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
262 } |
4513 | 263 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
264 void fill (const T& val); |
9624
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
265 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9341
diff
changeset
|
266 void clear (void); |
9624
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
267 void clear (const dim_vector& dv); |
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
268 |
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
269 void clear (octave_idx_type r, octave_idx_type c) |
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
270 { clear (dim_vector (r, c)); } |
238 | 271 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
272 octave_idx_type capacity (void) const { return slice_len; } |
5275 | 273 octave_idx_type length (void) const { return capacity (); } |
274 octave_idx_type nelem (void) const { return capacity (); } | |
275 octave_idx_type numel (void) const { return nelem (); } | |
4513 | 276 |
5275 | 277 octave_idx_type dim1 (void) const { return dimensions(0); } |
278 octave_idx_type dim2 (void) const { return dimensions(1); } | |
279 octave_idx_type dim3 (void) const { return dimensions(2); } | |
4513 | 280 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
281 // Return the array as a column vector. |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
282 Array<T> as_column (void) const |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
283 { |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
284 Array<T> retval (*this); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
285 if (dimensions.length () != 2 || dimensions(1) != 1) |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
286 retval.dimensions = dim_vector (numel (), 1); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
287 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
288 return retval; |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
289 } |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
290 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
291 // Return the array as a row vector. |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
292 Array<T> as_row (void) const |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
293 { |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
294 Array<T> retval (*this); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
295 if (dimensions.length () != 2 || dimensions(0) != 1) |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
296 retval.dimensions = dim_vector (1, numel ()); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
297 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
298 return retval; |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
299 } |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
300 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
301 // Return the array as a matrix. |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
302 Array<T> as_matrix (void) const |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
303 { |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
304 Array<T> retval (*this); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
305 if (dimensions.length () != 2) |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
306 retval.dimensions = dimensions.redim (2); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
307 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
308 return retval; |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
309 } |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
310 |
5275 | 311 octave_idx_type rows (void) const { return dim1 (); } |
312 octave_idx_type cols (void) const { return dim2 (); } | |
313 octave_idx_type columns (void) const { return dim2 (); } | |
314 octave_idx_type pages (void) const { return dim3 (); } | |
4513 | 315 |
10358
72fab01e5d68
improve some size_t queries
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
316 size_t byte_size (void) const { return static_cast<size_t> (numel ()) * sizeof (T); } |
4902 | 317 |
9026
6890d411a0b8
adjust some array dim query methods
Jaroslav Hajek <highegg@gmail.com>
parents:
9025
diff
changeset
|
318 // 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
|
319 const dim_vector& dims (void) const { return dimensions; } |
4513 | 320 |
4532 | 321 Array<T> squeeze (void) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
322 |
10095
eb8ac0eed9f1
always chop dimension vector when constructing Arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10075
diff
changeset
|
323 void chop_trailing_singletons (void) GCC_ATTR_DEPRECATED |
4703 | 324 { dimensions.chop_trailing_singletons (); } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
325 |
10366
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
326 octave_idx_type compute_index (octave_idx_type i, octave_idx_type j) const; |
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
327 octave_idx_type compute_index (octave_idx_type i, octave_idx_type j, octave_idx_type k) const; |
5275 | 328 octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const; |
4517 | 329 |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
330 octave_idx_type compute_index_unchecked (const Array<octave_idx_type>& ra_idx) const |
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
331 { return dimensions.compute_index (ra_idx.data (), ra_idx.length ()); } |
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
332 |
2108 | 333 // No checking, even for multiple references, ever. |
334 | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14981
diff
changeset
|
335 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
|
336 crefT xelem (octave_idx_type n) const { return slice_data[n]; } |
2108 | 337 |
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
|
338 T& xelem (octave_idx_type i, octave_idx_type j) { return xelem (dim1 ()*j+i); } |
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
|
339 crefT xelem (octave_idx_type i, octave_idx_type j) const { return xelem (dim1 ()*j+i); } |
4513 | 340 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
341 T& xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) |
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
|
342 { return xelem (i, dim2 ()*k+j); } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
343 crefT xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const |
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
|
344 { return xelem (i, dim2 ()*k+j); } |
4513 | 345 |
6867 | 346 T& xelem (const Array<octave_idx_type>& ra_idx) |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
347 { return xelem (compute_index_unchecked (ra_idx)); } |
4513 | 348 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
349 crefT xelem (const Array<octave_idx_type>& ra_idx) const |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
350 { return xelem (compute_index_unchecked (ra_idx)); } |
4513 | 351 |
5775 | 352 // FIXME -- would be nice to fix this so that we don't |
2006 | 353 // unnecessarily force a copy, but that is not so easy, and I see no |
354 // clean way to do it. | |
355 | |
10366
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
356 T& checkelem (octave_idx_type n); |
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
357 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
|
358 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
|
359 T& checkelem (const Array<octave_idx_type>& ra_idx); |
4513 | 360 |
5275 | 361 T& elem (octave_idx_type n) |
2108 | 362 { |
363 make_unique (); | |
2109 | 364 return xelem (n); |
2108 | 365 } |
2306 | 366 |
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
|
367 T& elem (octave_idx_type i, octave_idx_type j) { return elem (dim1 ()*j+i); } |
4513 | 368 |
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
|
369 T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, dim2 ()*k+j); } |
4513 | 370 |
6867 | 371 T& elem (const Array<octave_idx_type>& ra_idx) |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
372 { return Array<T>::elem (compute_index_unchecked (ra_idx)); } |
4513 | 373 |
2306 | 374 #if defined (BOUNDS_CHECKING) |
5275 | 375 T& operator () (octave_idx_type n) { return checkelem (n); } |
376 T& operator () (octave_idx_type i, octave_idx_type j) { return checkelem (i, j); } | |
377 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return checkelem (i, j, k); } | |
6867 | 378 T& operator () (const Array<octave_idx_type>& ra_idx) { return checkelem (ra_idx); } |
2306 | 379 #else |
5275 | 380 T& operator () (octave_idx_type n) { return elem (n); } |
381 T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); } | |
382 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, j, k); } | |
6867 | 383 T& operator () (const Array<octave_idx_type>& ra_idx) { return elem (ra_idx); } |
2006 | 384 #endif |
385 | |
10366
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
386 crefT checkelem (octave_idx_type n) const; |
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
387 crefT checkelem (octave_idx_type i, octave_idx_type j) const; |
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
388 crefT checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const; |
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
389 crefT checkelem (const Array<octave_idx_type>& ra_idx) const; |
4513 | 390 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
391 crefT elem (octave_idx_type n) const { return xelem (n); } |
2306 | 392 |
10366
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
393 crefT elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); } |
4513 | 394 |
10366
e5ae13b8b2c2
improve Array indexing error messages
Jaroslav Hajek <highegg@gmail.com>
parents:
10364
diff
changeset
|
395 crefT elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return xelem (i, j, k); } |
4513 | 396 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
397 crefT elem (const Array<octave_idx_type>& ra_idx) const |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
398 { return Array<T>::xelem (compute_index_unchecked (ra_idx)); } |
4513 | 399 |
2108 | 400 #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
|
401 crefT operator () (octave_idx_type n) const { return checkelem (n); } |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
402 crefT operator () (octave_idx_type i, octave_idx_type j) const { return checkelem (i, j); } |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
403 crefT operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return checkelem (i, j, k); } |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
404 crefT operator () (const Array<octave_idx_type>& ra_idx) const { return checkelem (ra_idx); } |
2006 | 405 #else |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
406 crefT operator () (octave_idx_type n) const { return elem (n); } |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
407 crefT operator () (octave_idx_type i, octave_idx_type j) const { return elem (i, j); } |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
408 crefT operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return elem (i, j, k); } |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
409 crefT operator () (const Array<octave_idx_type>& ra_idx) const { return elem (ra_idx); } |
2006 | 410 #endif |
411 | |
9731 | 412 // Fast extractors. All of these produce shallow copies. |
413 // Warning: none of these do check bounds, unless BOUNDS_CHECKING is on! | |
414 | |
415 // Extract column: A(:,k+1). | |
416 Array<T> column (octave_idx_type k) const; | |
417 // Extract page: A(:,:,k+1). | |
418 Array<T> page (octave_idx_type k) const; | |
419 | |
420 // Extract a slice from this array as a column vector: A(:)(lo+1:up). | |
421 // Must be 0 <= lo && up <= numel. May be up < lo. | |
422 Array<T> linear_slice (octave_idx_type lo, octave_idx_type up) const; | |
423 | |
10352 | 424 Array<T> reshape (octave_idx_type nr, octave_idx_type nc) const |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
425 { return Array<T> (*this, dim_vector (nr, nc)); } |
10352 | 426 |
9731 | 427 Array<T> reshape (const dim_vector& new_dims) const |
428 { return Array<T> (*this, new_dims); } | |
4567 | 429 |
5275 | 430 Array<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const; |
431 Array<T> ipermute (const Array<octave_idx_type>& vec) const | |
4593 | 432 { return permute (vec, true); } |
433 | |
4513 | 434 bool is_square (void) const { return (dim1 () == dim2 ()); } |
435 | |
4559 | 436 bool is_empty (void) const { return numel () == 0; } |
437 | |
9026
6890d411a0b8
adjust some array dim query methods
Jaroslav Hajek <highegg@gmail.com>
parents:
9025
diff
changeset
|
438 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
|
439 |
4513 | 440 Array<T> transpose (void) const; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7717
diff
changeset
|
441 Array<T> hermitian (T (*fcn) (const T&) = 0) const; |
238 | 442 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
443 const T *data (void) const { return slice_data; } |
228 | 444 |
3952 | 445 const T *fortran_vec (void) const { return data (); } |
446 | |
238 | 447 T *fortran_vec (void); |
1560 | 448 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9341
diff
changeset
|
449 bool is_shared (void) { return rep->count > 1; } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9341
diff
changeset
|
450 |
4513 | 451 int ndims (void) const { return dimensions.length (); } |
1560 | 452 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
453 // Indexing without resizing. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
454 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
455 Array<T> index (const idx_vector& i) const; |
1560 | 456 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
457 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
|
458 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
459 Array<T> index (const Array<idx_vector>& ia) const; |
1560 | 460 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
461 virtual T resize_fill_value (void) const; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
462 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
463 // Resizing (with fill). |
1560 | 464 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
465 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
|
466 void resize1 (octave_idx_type n) { resize1 (n, resize_fill_value ()); } |
1560 | 467 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
468 void resize (octave_idx_type n) GCC_ATTR_DEPRECATED { resize1 (n); } |
4513 | 469 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
470 void resize (octave_idx_type nr, octave_idx_type nc, 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
|
471 { |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
472 resize2 (nr, nc, rfv); |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
473 } |
4513 | 474 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
475 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
|
476 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
477 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
|
478 } |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
479 |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
480 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
|
481 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
|
482 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
483 // Indexing with possible resizing and fill |
8333 | 484 // FIXME -- this is really a corner case, that should better be |
485 // handled directly in liboctinterp. | |
3933 | 486 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
487 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
|
488 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
|
489 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
490 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
|
491 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
492 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
493 Array<T> index (const idx_vector& i, const idx_vector& j, 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
|
494 Array<T> index (const idx_vector& i, const idx_vector& j, bool resize_ok) const |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
495 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
496 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
|
497 } |
4513 | 498 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
499 Array<T> index (const Array<idx_vector>& ia, 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
|
500 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
|
501 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
502 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
|
503 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
504 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
505 // Indexed assignment (always with resize & fill). |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
506 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
507 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
|
508 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
|
509 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
510 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
|
511 } |
4513 | 512 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
513 void assign (const idx_vector& i, const idx_vector& j, 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
|
514 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
|
515 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
516 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
|
517 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
518 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
519 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
|
520 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
|
521 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
522 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
|
523 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
524 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
525 // Deleting elements. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
526 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
527 // A(I) = [] (with a single subscript) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
528 void delete_elements (const idx_vector& i); |
4530 | 529 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
530 // A(:,...,I,...,:) = [] (>= 2 subscripts, one of them is non-colon) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
531 void delete_elements (int dim, const idx_vector& i); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
532 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
533 // Dispatcher to the above two. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
534 void delete_elements (const Array<idx_vector>& ia); |
4513 | 535 |
10115
ed49cef7e005
simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10095
diff
changeset
|
536 // Insert an array into another at a specified position. |
ed49cef7e005
simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10095
diff
changeset
|
537 // 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
|
538 // this method is equivalent to |
ed49cef7e005
simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10095
diff
changeset
|
539 // 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
|
540 Array<T>& insert (const Array<T>& a, const Array<octave_idx_type>& idx); |
3928 | 541 |
10115
ed49cef7e005
simplify Array::insert methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10095
diff
changeset
|
542 // 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
|
543 Array<T>& insert (const Array<T>& a, octave_idx_type r, octave_idx_type c); |
3933 | 544 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
545 void maybe_economize (void) |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
546 { |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
547 if (rep->count == 1 && slice_len != rep->len) |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
548 { |
10364
96ed7c629bbd
remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents:
10358
diff
changeset
|
549 ArrayRep *new_rep = new ArrayRep (slice_data, slice_len); |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
550 delete rep; |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
551 rep = new_rep; |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
552 slice_data = rep->data; |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
553 } |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
554 } |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
555 |
4517 | 556 void print_info (std::ostream& os, const std::string& prefix) const; |
5900 | 557 |
558 // Unsafe. This function exists to support the MEX interface. | |
559 // You should not use it anywhere else. | |
560 void *mex_get_data (void) const { return const_cast<T *> (data ()); } | |
7433 | 561 |
9725 | 562 Array<T> sort (int dim = 0, sortmode mode = ASCENDING) const; |
563 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
|
564 sortmode mode = ASCENDING) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
565 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
566 // Ordering is auto-detected or can be specified. |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
567 sortmode is_sorted (sortmode mode = UNSORTED) const; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
568 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
569 // Sort by rows returns only indices. |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
570 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
|
571 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
572 // Ordering is auto-detected or can be specified. |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
573 sortmode is_sorted_rows (sortmode mode = UNSORTED) const; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
574 |
9921
7c8392a034e6
fix & improve lookup API
Jaroslav Hajek <highegg@gmail.com>
parents:
9878
diff
changeset
|
575 // 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
|
576 // 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
|
577 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
|
578 |
9921
7c8392a034e6
fix & improve lookup API
Jaroslav Hajek <highegg@gmail.com>
parents:
9878
diff
changeset
|
579 // 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
|
580 // are sorted. NaNs get the value N. |
7c8392a034e6
fix & improve lookup API
Jaroslav Hajek <highegg@gmail.com>
parents:
9878
diff
changeset
|
581 Array<octave_idx_type> lookup (const Array<T>& values, sortmode mode = UNSORTED) const; |
9341
9fd5c56ce57a
extend lookup capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
9201
diff
changeset
|
582 |
9878
ead4f9c82a9a
implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
583 // Count nonzero elements. |
ead4f9c82a9a
implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
584 octave_idx_type nnz (void) const; |
ead4f9c82a9a
implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
585 |
9025 | 586 // Find indices of (at most n) nonzero elements. If n is specified, backward |
587 // specifies search from backward. | |
588 Array<octave_idx_type> find (octave_idx_type n = -1, bool backward = false) const; | |
589 | |
9725 | 590 // Returns the n-th element in increasing order, using the same ordering as |
591 // used for sort. n can either be a scalar index or a contiguous range. | |
592 Array<T> nth_element (const idx_vector& n, int dim = 0) const; | |
593 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
594 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
|
595 |
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
|
596 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
|
597 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10674
diff
changeset
|
598 // 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
|
599 // 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
|
600 // 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
|
601 static Array<T> |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
602 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
|
603 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
604 template <class U, class F> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
605 Array<U> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
606 map (F fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
607 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
608 octave_idx_type len = length (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
609 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
610 const T *m = data (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
611 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
612 Array<U> result (dims ()); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
613 U *p = result.fortran_vec (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
614 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
615 octave_idx_type i; |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
616 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
|
617 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
618 octave_quit (); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
619 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
620 p[i] = fcn (m[i]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
621 p[i+1] = fcn (m[i+1]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
622 p[i+2] = fcn (m[i+2]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
623 p[i+3] = fcn (m[i+3]); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
624 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
625 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10115
diff
changeset
|
626 octave_quit (); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
627 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
628 for (; i < len; i++) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
629 p[i] = fcn (m[i]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
630 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
631 return result; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
632 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
633 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
634 // Overloads for function references. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
635 template <class U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
636 Array<U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
637 map (U (&fcn) (T)) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
638 { return map<U, U (&) (T)> (fcn); } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
639 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
640 template <class U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
641 Array<U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
642 map (U (&fcn) (const T&)) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
643 { return map<U, U (&) (const T&)> (fcn); } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
644 |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
645 // Generic any/all test functionality with arbitrary predicate. |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
646 template <class F, bool zero> |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
647 bool test (F fcn) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
648 { |
15212
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15018
diff
changeset
|
649 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
|
650 } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
651 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
652 // Simpler calls. |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
653 template <class F> |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
654 bool test_any (F fcn) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
655 { return test<F, false> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
656 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
657 template <class F> |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
658 bool test_all (F fcn) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
659 { return test<F, true> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
660 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
661 // Overloads for function references. |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
662 bool test_any (bool (&fcn) (T)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
663 { return test<bool (&) (T), false> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
664 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
665 bool test_any (bool (&fcn) (const T&)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
666 { return test<bool (&) (const T&), false> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
667 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
668 bool test_all (bool (&fcn) (T)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
669 { return test<bool (&) (T), true> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
670 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
671 bool test_all (bool (&fcn) (const T&)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
672 { return test<bool (&) (const T&), true> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
673 |
9046
88bf56bbccca
make Array::find already return Matlab-compatible dimensions
Jaroslav Hajek <highegg@gmail.com>
parents:
9026
diff
changeset
|
674 template <class U> friend class Array; |
9201
472f0e22aa60
guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents:
9046
diff
changeset
|
675 |
10674
e3064439d6b4
new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents:
10673
diff
changeset
|
676 // 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
|
677 // 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
|
678 // 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
|
679 bool optimize_dimensions (const dim_vector& dv); |
e3064439d6b4
new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents:
10673
diff
changeset
|
680 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
681 // WARNING: Only call these functions from jit |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
682 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
683 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
|
684 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
685 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
|
686 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
687 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
|
688 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14616
diff
changeset
|
689 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
|
690 |
9201
472f0e22aa60
guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents:
9046
diff
changeset
|
691 private: |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
692 |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
693 void resize2 (octave_idx_type nr, octave_idx_type nc, const T& rfv); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
694 void resize2 (octave_idx_type nr, octave_idx_type nc) |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
695 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
696 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
|
697 } |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
698 |
9201
472f0e22aa60
guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents:
9046
diff
changeset
|
699 static void instantiation_guard (); |
4513 | 700 }; |
4459 | 701 |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
702 // 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
|
703 // 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
|
704 // 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
|
705 // responsibility to ensure the array is actually unaliased whenever elements |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
706 // are accessed. |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
707 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
708 template<class ArrayClass> |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
709 class NoAlias : public ArrayClass |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
710 { |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
711 typedef typename ArrayClass::element_type T; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
712 public: |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
713 NoAlias () : ArrayClass () { } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
714 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
715 // FIXME: this would be simpler once C++0x is available |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
716 template <class X> |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
717 explicit NoAlias (X x) : ArrayClass (x) { } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
718 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
719 template <class X, class Y> |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
720 explicit NoAlias (X x, Y y) : ArrayClass (x, y) { } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
721 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
722 template <class X, class Y, class Z> |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
723 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
|
724 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
725 T& operator () (octave_idx_type n) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
726 { return ArrayClass::xelem (n); } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
727 T& operator () (octave_idx_type i, octave_idx_type j) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
728 { return ArrayClass::xelem (i, j); } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
729 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
730 { return ArrayClass::xelem (i, j, k); } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
731 T& operator () (const Array<octave_idx_type>& ra_idx) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
732 { return ArrayClass::xelem (ra_idx); } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
733 }; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9624
diff
changeset
|
734 |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9731
diff
changeset
|
735 template <class T> |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9731
diff
changeset
|
736 std::ostream& |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9731
diff
changeset
|
737 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
|
738 |
9773
01f897d8a130
optimize memory manipulation by arrays & indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
739 #endif |