annotate liboctave/Array.h @ 8523:ad3afaaa19c1

implement non-copying contiguous range indexing
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 15 Jan 2009 07:22:24 +0100
parents 8ba2ee57c594
children 937921654627
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
5 2004, 2005, 2006, 2007 John W. Eaton
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
6 Copyright (C) 2008, 2009 Jaroslav Hajek <highegg@gmail.com>
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
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
32 #include <iostream>
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
33 #include <algorithm>
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"
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents: 3585
diff changeset
37 #include "lo-utils.h"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
38 #include "oct-sort.h"
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
39 #include "quit.h"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
40
1359
a6994c934a50 [project @ 1995-09-05 21:30:26 by jwe]
jwe
parents: 1315
diff changeset
41 // One dimensional array class. Handles the reference counting for
a6994c934a50 [project @ 1995-09-05 21:30:26 by jwe]
jwe
parents: 1315
diff changeset
42 // all the derived classes.
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
43
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
44 template <class T>
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3569
diff changeset
45 class
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3569
diff changeset
46 Array
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
47 {
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
48 protected:
1619
1a35c8c91349 [project @ 1995-11-04 11:07:21 by jwe]
jwe
parents: 1574
diff changeset
49
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
50 //--------------------------------------------------------------------
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
51 // The real representation of all arrays.
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
52 //--------------------------------------------------------------------
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
53
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
54 class ArrayRep
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
55 {
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
56 public:
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
57
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
58 T *data;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
59 octave_idx_type len;
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
60 int count;
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
61
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
62 ArrayRep (T *d, octave_idx_type l, bool copy = false)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
63 : data (copy ? new T [l] : d), len (l), count (1)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
64 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
65 if (copy)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
66 std::copy (d, d + l, data);
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
67 }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
68
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
69 ArrayRep (void) : data (0), len (0), count (1) { }
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
70
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
71 explicit ArrayRep (octave_idx_type n) : data (new T [n]), len (n), count (1) { }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
72
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
73 explicit ArrayRep (octave_idx_type n, const T& val)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
74 : data (new T [n]), len (n), count (1)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
75 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
76 std::fill (data, data + n, val);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
77 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
78
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
79 ArrayRep (const ArrayRep& a)
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
80 : data (new T [a.len]), len (a.len), count (1)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
81 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
82 std::copy (a.data, a.data + a.len, data);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
83 }
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
84
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
85 ~ArrayRep (void) { delete [] data; }
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
86
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
87 octave_idx_type length (void) const { return len; }
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
88
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
89 private:
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
90
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
91 // No assignment!
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
92
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
93 ArrayRep& operator = (const ArrayRep& a);
1735
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
94 };
d2ee993d40cd [project @ 1996-01-12 07:46:09 by jwe]
jwe
parents: 1703
diff changeset
95
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
96 //--------------------------------------------------------------------
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
97
6884
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
98 public:
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
99
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
100 // !!! WARNING !!! -- these should be protected, not public. You
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
101 // should not access these methods directly!
1cbb8b606d63 [project @ 2007-09-10 20:43:26 by jwe]
jwe
parents: 6881
diff changeset
102
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
103 void make_unique (void)
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
104 {
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
105 if (rep->count > 1)
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
106 {
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
107 --rep->count;
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
108 rep = new ArrayRep (slice_data, slice_len, true);
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
109 slice_data = rep->data;
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
110 }
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
111 else if (slice_len != rep->len)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
112 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
113 // Possibly economize here.
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
114 ArrayRep *new_rep = new ArrayRep (slice_data, slice_len, true);
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
115 delete rep;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
116 rep = new_rep;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
117 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
118 }
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
119 }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
120
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
121 void make_unique (const T& val)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
122 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
123 if (rep->count > 1)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
124 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
125 --rep->count;
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
126 rep = new ArrayRep (slice_len, val);
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
127 slice_data = rep->data;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
128 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
129 else
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
130 std::fill (slice_data, slice_data + slice_len, val);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
131 }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
132
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
133 typedef T element_type;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
134
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
135 // !!! WARNING !!! -- these should be protected, not public. You
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
136 // should not access these data members directly!
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
137
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
138 typename Array<T>::ArrayRep *rep;
4518
382cb0ed8c14 [project @ 2003-09-20 18:08:40 by jwe]
jwe
parents: 4517
diff changeset
139
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
140 dim_vector dimensions;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
141
4518
382cb0ed8c14 [project @ 2003-09-20 18:08:40 by jwe]
jwe
parents: 4517
diff changeset
142 protected:
382cb0ed8c14 [project @ 2003-09-20 18:08:40 by jwe]
jwe
parents: 4517
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
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
147 Array (T *d, octave_idx_type n)
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
148 : rep (new typename Array<T>::ArrayRep (d, n)), dimensions (n)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
149 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
150 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
151 slice_len = rep->len;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
152 }
1619
1a35c8c91349 [project @ 1995-11-04 11:07:21 by jwe]
jwe
parents: 1574
diff changeset
153
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4585
diff changeset
154 Array (T *d, const dim_vector& dv)
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4585
diff changeset
155 : rep (new typename Array<T>::ArrayRep (d, get_size (dv))),
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
156 dimensions (dv)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
157 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
158 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
159 slice_len = rep->len;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
160 }
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
161
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
162 // slice constructor
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
163 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
164 octave_idx_type l, octave_idx_type u)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
165 : rep(a.rep), dimensions (dv)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
166 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
167 rep->count++;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
168 slice_data = a.slice_data + l;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
169 slice_len = std::min (u, a.slice_len) - l;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
170 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
171
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
172 private:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
173
4585
a1ac9ab474a1 [project @ 2003-11-08 06:07:33 by jwe]
jwe
parents: 4567
diff changeset
174 typename Array<T>::ArrayRep *nil_rep (void) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
175 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
176 static typename Array<T>::ArrayRep *nr
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
177 = new typename Array<T>::ArrayRep ();
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
178
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
179 return nr;
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
180 }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
181
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
182 template <class U>
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
183 T *
8118
311c9b36df8f replace int->octave_idx_type in Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
184 coerce (const U *a, octave_idx_type len)
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
185 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
186 T *retval = new T [len];
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
187
8118
311c9b36df8f replace int->octave_idx_type in Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
188 for (octave_idx_type i = 0; i < len; i++)
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
189 retval[i] = T (a[i]);
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
190
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
191 return retval;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
192 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
193
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
194 public:
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
195
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
196 Array (void)
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
197 : rep (nil_rep ()), dimensions ()
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
198 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
199 rep->count++;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
200 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
201 slice_len = rep->len;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
202 }
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
203
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
204 explicit Array (octave_idx_type n)
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
205 : rep (new typename Array<T>::ArrayRep (n)), dimensions (n)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
206 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
207 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
208 slice_len = rep->len;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
209 }
1619
1a35c8c91349 [project @ 1995-11-04 11:07:21 by jwe]
jwe
parents: 1574
diff changeset
210
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
211 explicit Array (octave_idx_type n, const T& val)
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
212 : rep (new typename Array<T>::ArrayRep (n)), dimensions (n)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
213 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
214 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
215 slice_len = rep->len;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
216 fill (val);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
217 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
218
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
219 // Type conversion case.
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
220 template <class U>
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
221 Array (const Array<U>& a)
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
222 : rep (new typename Array<T>::ArrayRep (coerce (a.data (), a.length ()), a.length ())),
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
223 dimensions (a.dimensions)
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
224 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
225 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
226 slice_len = rep->len;
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
227 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
228
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
229 // No type conversion case.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
230 Array (const Array<T>& a)
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
231 : rep (a.rep), dimensions (a.dimensions)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
232 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
233 rep->count++;
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
234 slice_data = a.slice_data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
235 slice_len = a.slice_len;
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
236 }
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
237
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
238 public:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
239
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4585
diff changeset
240 Array (const dim_vector& dv)
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4585
diff changeset
241 : rep (new typename Array<T>::ArrayRep (get_size (dv))),
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
242 dimensions (dv)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
243 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
244 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
245 slice_len = rep->len;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
246 }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
247
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4585
diff changeset
248 Array (const dim_vector& dv, const T& val)
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4585
diff changeset
249 : rep (new typename Array<T>::ArrayRep (get_size (dv))),
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
250 dimensions (dv)
1550
d89532de8e72 [project @ 1995-10-08 01:12:20 by jwe]
jwe
parents: 1366
diff changeset
251 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
252 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
253 slice_len = rep->len;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
254 fill (val);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
255 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
256
4834
8f669cc5a901 [project @ 2004-03-11 18:49:17 by jwe]
jwe
parents: 4806
diff changeset
257 Array (const Array<T>& a, const dim_vector& dv);
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
258
4979
ce4e3d39d05b [project @ 2004-09-08 23:25:05 by jwe]
jwe
parents: 4915
diff changeset
259 virtual ~Array (void);
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
260
7717
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
261 Array<T>& operator = (const Array<T>& a);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
262
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
263 void fill (const T& val) { make_unique (val); }
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
264
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
265 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
266 octave_idx_type length (void) const { return capacity (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
267 octave_idx_type nelem (void) const { return capacity (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
268 octave_idx_type numel (void) const { return nelem (); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
269
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
270 octave_idx_type dim1 (void) const { return dimensions(0); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
271 octave_idx_type dim2 (void) const { return dimensions(1); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
272 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
273
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
274 octave_idx_type rows (void) const { return dim1 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
275 octave_idx_type cols (void) const { return dim2 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
276 octave_idx_type columns (void) const { return dim2 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
277 octave_idx_type pages (void) const { return dim3 (); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
278
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
279 size_t byte_size (void) const { return numel () * sizeof (T); }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents: 4834
diff changeset
280
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
281 dim_vector dims (void) const { return dimensions; }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
282
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4530
diff changeset
283 Array<T> squeeze (void) const;
4703
72c28fd651c4 [project @ 2004-01-22 00:01:09 by jwe]
jwe
parents: 4625
diff changeset
284
72c28fd651c4 [project @ 2004-01-22 00:01:09 by jwe]
jwe
parents: 4625
diff changeset
285 void chop_trailing_singletons (void)
72c28fd651c4 [project @ 2004-01-22 00:01:09 by jwe]
jwe
parents: 4625
diff changeset
286 { dimensions.chop_trailing_singletons (); }
72c28fd651c4 [project @ 2004-01-22 00:01:09 by jwe]
jwe
parents: 4625
diff changeset
287
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
288 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
289 static octave_idx_type get_size (octave_idx_type r, octave_idx_type c, octave_idx_type p);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
290 static octave_idx_type get_size (const dim_vector& dv);
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
291
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
292 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
293
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
294 T range_error (const char *fcn, octave_idx_type n) const;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
295 T& range_error (const char *fcn, octave_idx_type n);
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3613
diff changeset
296
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
297 T range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
298 T& range_error (const char *fcn, octave_idx_type i, octave_idx_type j);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
299
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
300 T range_error (const char *fcn, octave_idx_type i, octave_idx_type j, octave_idx_type k) const;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
301 T& range_error (const char *fcn, octave_idx_type i, octave_idx_type j, octave_idx_type k);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
302
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
303 T range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) const;
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
304 T& range_error (const char *fcn, const Array<octave_idx_type>& ra_idx);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
305
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
306 // No checking, even for multiple references, ever.
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
307
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
308 T& xelem (octave_idx_type n) { return slice_data [n]; }
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
309 T 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
310
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
311 T& xelem (octave_idx_type i, octave_idx_type j) { return xelem (dim1()*j+i); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
312 T xelem (octave_idx_type i, octave_idx_type j) const { return xelem (dim1()*j+i); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
313
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
314 T& xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return xelem (i, dim2()*k+j); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
315 T xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return xelem (i, dim2()*k+j); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
316
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
317 T& xelem (const Array<octave_idx_type>& ra_idx)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
318 { return xelem (compute_index (ra_idx)); }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
319
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
320 T xelem (const Array<octave_idx_type>& ra_idx) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
321 { return xelem (compute_index (ra_idx)); }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
322
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5632
diff changeset
323 // FIXME -- would be nice to fix this so that we don't
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
324 // unnecessarily force a copy, but that is not so easy, and I see no
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
325 // clean way to do it.
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
326
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
327 T& checkelem (octave_idx_type n)
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
328 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
329 if (n < 0 || n >= slice_len)
2109
356f70c8fcbd [project @ 1996-04-30 12:31:30 by jwe]
jwe
parents: 2108
diff changeset
330 return range_error ("T& Array<T>::checkelem", n);
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
331 else
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
332 {
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
333 make_unique ();
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
334 return xelem (n);
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
335 }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
336 }
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
337
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
338 T& checkelem (octave_idx_type i, octave_idx_type j)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
339 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
340 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
341 return range_error ("T& Array<T>::checkelem", i, j);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
342 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
343 return elem (dim1()*j+i);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
344 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
345
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
346 T& checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
347 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
348 if (i < 0 || j < 0 || k < 0 || i >= dim1 () || j >= dim2 () || k >= dim3 ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
349 return range_error ("T& Array<T>::checkelem", i, j, k);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
350 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
351 return elem (i, dim2()*k+j);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
352 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
353
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
354 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
355 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
356 octave_idx_type i = compute_index (ra_idx);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
357
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
358 if (i < 0)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
359 return range_error ("T& Array<T>::checkelem", ra_idx);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
360 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
361 return elem (i);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
362 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
363
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
364 T& elem (octave_idx_type n)
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
365 {
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
366 make_unique ();
2109
356f70c8fcbd [project @ 1996-04-30 12:31:30 by jwe]
jwe
parents: 2108
diff changeset
367 return xelem (n);
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
368 }
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
369
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
370 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
371
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
372 T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, dim2()*k+j); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
373
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
374 T& elem (const Array<octave_idx_type>& ra_idx)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
375 { return Array<T>::elem (compute_index (ra_idx)); }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
376
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
377 #if defined (BOUNDS_CHECKING)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
378 T& operator () (octave_idx_type n) { return checkelem (n); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
379 T& operator () (octave_idx_type i, octave_idx_type j) { return checkelem (i, j); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
380 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return checkelem (i, j, k); }
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
381 T& operator () (const Array<octave_idx_type>& ra_idx) { return checkelem (ra_idx); }
2306
2fbf9bb1cd7a [project @ 1996-07-09 16:49:03 by jwe]
jwe
parents: 2109
diff changeset
382 #else
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
383 T& operator () (octave_idx_type n) { return elem (n); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
384 T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
385 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, j, k); }
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
386 T& operator () (const Array<octave_idx_type>& ra_idx) { return elem (ra_idx); }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
387 #endif
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
388
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
389 T checkelem (octave_idx_type n) const
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
390 {
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
391 if (n < 0 || n >= slice_len)
2109
356f70c8fcbd [project @ 1996-04-30 12:31:30 by jwe]
jwe
parents: 2108
diff changeset
392 return range_error ("T Array<T>::checkelem", n);
2049
468a96dd03fc [project @ 1996-03-29 20:09:05 by jwe]
jwe
parents: 2023
diff changeset
393 else
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
394 return xelem (n);
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
395 }
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
396
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
397 T checkelem (octave_idx_type i, octave_idx_type j) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
398 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
399 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
400 return range_error ("T Array<T>::checkelem", i, j);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
401 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
402 return elem (dim1()*j+i);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
403 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
404
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
405 T checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
406 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
407 if (i < 0 || j < 0 || k < 0 || i >= dim1 () || j >= dim2 () || k >= dim3 ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
408 return range_error ("T Array<T>::checkelem", i, j, k);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
409 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
410 return Array<T>::elem (i, Array<T>::dim1()*k+j);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
411 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
412
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
413 T 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
414 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
415 octave_idx_type i = compute_index (ra_idx);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
416
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
417 if (i < 0)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
418 return range_error ("T Array<T>::checkelem", ra_idx);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
419 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
420 return Array<T>::elem (i);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
421 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
422
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
423 T 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
424
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
425 T elem (octave_idx_type i, octave_idx_type j) const { return elem (dim1()*j+i); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
426
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
427 T elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return elem (i, dim2()*k+j); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
428
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
429 T elem (const Array<octave_idx_type>& ra_idx) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
430 { return Array<T>::elem (compute_index (ra_idx)); }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
431
2108
2b67abb63030 [project @ 1996-04-30 10:44:17 by jwe]
jwe
parents: 2049
diff changeset
432 #if defined (BOUNDS_CHECKING)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
433 T operator () (octave_idx_type n) const { return checkelem (n); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
434 T operator () (octave_idx_type i, octave_idx_type j) const { return checkelem (i, j); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
435 T operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return checkelem (i, j, k); }
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
436 T operator () (const Array<octave_idx_type>& ra_idx) const { return checkelem (ra_idx); }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
437 #else
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
438 T operator () (octave_idx_type n) const { return elem (n); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
439 T operator () (octave_idx_type i, octave_idx_type j) const { return elem (i, j); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
440 T operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const { return elem (i, j, k); }
6867
83619ae96c1d [project @ 2007-09-06 12:08:44 by dbateman]
dbateman
parents: 6708
diff changeset
441 T operator () (const Array<octave_idx_type>& ra_idx) const { return elem (ra_idx); }
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
442 #endif
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 2005
diff changeset
443
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4559
diff changeset
444 Array<T> reshape (const dim_vector& new_dims) const;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4559
diff changeset
445
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
446 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
447 Array<T> ipermute (const Array<octave_idx_type>& vec) const
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4587
diff changeset
448 { return permute (vec, true); }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4587
diff changeset
449
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
450 bool is_square (void) const { return (dim1 () == dim2 ()); }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
451
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
452 bool is_empty (void) const { return numel () == 0; }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
453
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
454 Array<T> transpose (void) const;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7717
diff changeset
455 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
456
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
457 const T *data (void) const { return slice_data; }
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
458
3952
945e8c160191 [project @ 2002-05-23 17:18:12 by jwe]
jwe
parents: 3944
diff changeset
459 const T *fortran_vec (void) const { return data (); }
945e8c160191 [project @ 2002-05-23 17:18:12 by jwe]
jwe
parents: 3944
diff changeset
460
238
780cbbc57b7c [project @ 1993-11-30 20:23:04 by jwe]
jwe
parents: 228
diff changeset
461 T *fortran_vec (void);
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
462
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
463 int ndims (void) const { return dimensions.length (); }
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
464
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
465 void maybe_delete_dims (void);
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
466
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
467 // Indexing without resizing.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
468
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
469 Array<T> index (const idx_vector& i) const;
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
470
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
471 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
472
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
473 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
474
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
475 static T resize_fill_value ();
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 // Resizing (with fill).
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 void resize_fill (octave_idx_type n, const T& rfv);
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
480
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
481 void resize_fill (octave_idx_type nr, octave_idx_type nc, const T& rfv);
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 void resize_fill (const dim_vector& dv, const T& rfv);
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
484
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
485 // Resizing with default fill.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
486 // Rationale:
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
487 // These use the default fill value rather than leaving memory uninitialized.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
488 // Resizing without fill leaves the resulting array in a rather weird state,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
489 // where part of the data is initialized an part isn't.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
490
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
491 void resize (octave_idx_type n)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
492 { resize_fill (n, resize_fill_value ()); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
493
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
494 // FIXME -- this method cannot be defined here because it would
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
495 // clash with
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
496 //
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
497 // void resize (octave_idx_type, const T&)
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
498 //
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
499 // (these become indistinguishable when T = octave_idx_type).
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
500 // In the future, I think the resize (.., const T& rfv) overloads
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
501 // should go away in favor of using resize_fill.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
502
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
503 // void resize (octave_idx_type nr, octave_idx_type nc)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
504 // { resize_fill (nr, nc, resize_fill_value ()); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
505
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
506 void resize (dim_vector dv)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
507 { resize_fill (dv, resize_fill_value ()); }
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
508
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
509 // FIXME -- these are here for backward compatibility. They should
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
510 // go away in favor of using resize_fill directly.
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
511 void resize (octave_idx_type n, const T& rfv)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
512 { resize_fill (n, static_cast<T> (rfv)); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
513
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
514 void resize (octave_idx_type nr, octave_idx_type nc, const T& rfv)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
515 { resize_fill (nr, nc, rfv); }
2382
58e5955495d7 [project @ 1996-10-12 17:45:06 by jwe]
jwe
parents: 2347
diff changeset
516
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
517 void resize (dim_vector dv, const T& rfv)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
518 { resize_fill (dv, rfv); }
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
519
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
520 // Indexing with possible resizing and fill
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
521 // FIXME -- this is really a corner case, that should better be
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
522 // handled directly in liboctinterp.
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
523
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
524 Array<T> index (const idx_vector& i, bool resize_ok,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
525 const T& rfv = resize_fill_value ()) const;
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 Array<T> index (const idx_vector& i, const idx_vector& j,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
528 bool resize_ok, const T& rfv = resize_fill_value ()) const;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
529
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
530 Array<T> index (const Array<idx_vector>& ia,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
531 bool resize_ok, const T& rfv = resize_fill_value ()) const;
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 // Indexed assignment (always with resize & fill).
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
534
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
535 void assign (const idx_vector& i, const Array<T>& rhs,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
536 const T& rfv = resize_fill_value ());
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
537
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
538 void assign (const idx_vector& i, const idx_vector& j, const Array<T>& rhs,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
539 const T& rfv = resize_fill_value ());
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
540
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
541 void assign (const Array<idx_vector>& ia, const Array<T>& rhs,
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
542 const T& rfv = resize_fill_value ());
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
543
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
544 // Deleting elements.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
545
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
546 // A(I) = [] (with a single subscript)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
547 void delete_elements (const idx_vector& i);
4530
e8d87fefd144 [project @ 2003-10-07 04:02:04 by jwe]
jwe
parents: 4518
diff changeset
548
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
549 // A(:,...,I,...,:) = [] (>= 2 subscripts, one of them is non-colon)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
550 void delete_elements (int dim, const idx_vector& i);
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 // Dispatcher to the above two.
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
553 void delete_elements (const Array<idx_vector>& ia);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
554
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
555 // FIXME -- are these required? What exactly are they supposed to do?.
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3836
diff changeset
556
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
557 Array<T>& insert (const Array<T>& a, octave_idx_type r, octave_idx_type c);
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
558 Array<T>& insert2 (const Array<T>& a, octave_idx_type r, octave_idx_type c);
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
559 Array<T>& insertN (const Array<T>& a, octave_idx_type r, octave_idx_type c);
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
560
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
561 Array<T>& insert (const Array<T>& a, const Array<octave_idx_type>& idx);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
562
8523
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
563 void maybe_economize (void)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
564 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
565 if (rep->count == 1 && slice_len != rep->len)
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
566 {
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
567 ArrayRep *new_rep = new ArrayRep (slice_data, slice_len, true);
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
568 delete rep;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
569 rep = new_rep;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
570 slice_data = rep->data;
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
571 }
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
572 }
ad3afaaa19c1 implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8503
diff changeset
573
4517
b4449b1193ac [project @ 2003-09-20 02:06:06 by jwe]
jwe
parents: 4513
diff changeset
574 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
575
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
576 // Unsafe. This function exists to support the MEX interface.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
577 // You should not use it anywhere else.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
578 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
579
7463
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
580 Array<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
581 Array<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
7463
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
582 sortmode mode = ASCENDING) const;
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
583
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7503
diff changeset
584 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
585
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
586 template <class U, class F>
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
587 Array<U>
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
588 map (F fcn) const
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
589 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
590 octave_idx_type len = length ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
591
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
592 const T *m = data ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
593
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
594 Array<U> result (dims ());
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
595 U *p = result.fortran_vec ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
596
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
597 for (octave_idx_type i = 0; i < len; i++)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
598 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
599 OCTAVE_QUIT;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
600
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
601 p[i] = fcn (m[i]);
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
602 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
603
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
604 return result;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
605 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4461
diff changeset
606 };
4459
75ee1995d2b4 [project @ 2003-07-11 17:46:41 by jwe]
jwe
parents: 4192
diff changeset
607
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
608 #define INSTANTIATE_ARRAY(T, API) \
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
609 template class API Array<T>
4518
382cb0ed8c14 [project @ 2003-09-20 18:08:40 by jwe]
jwe
parents: 4517
diff changeset
610
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
611 // FIXME -- these are here for compatibility. In the current
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
612 // implementation, only homogeneous array assignments are actually
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
613 // instantiated. I think heterogeneous indexed assignments are rare
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
614 // enough to be implemented via conversion first. This decision may
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
615 // still be revised, that's why these macros stay here.
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
616 #define INSTANTIATE_ARRAY_AND_ASSIGN(T, API) \
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
617 INSTANTIATE_ARRAY(T, API)
1560
27a03373de41 [project @ 1995-10-12 07:22:26 by jwe]
jwe
parents: 1550
diff changeset
618
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
619 #define INSTANTIATE_ARRAY_ASSIGN(LT, RT, API)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
620 // do nothing
4594
3a284f89aa41 [project @ 2003-11-12 02:27:28 by jwe]
jwe
parents: 4593
diff changeset
621
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
622 #define INSTANTIATE_ARRAY_SORT(T) \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
623 template class octave_sort<T>; \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
624 template class vec_index<T>; \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
625 template class octave_sort<vec_index<T> *>;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
626
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
627 #define NO_INSTANTIATE_ARRAY_SORT(T) \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
628 template class vec_index<T>; \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
629 template <> bool ascending_compare (T, T) { return true; } \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
630 template <> bool ascending_compare (vec_index<T> *, vec_index<T> *) \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
631 { return true; } \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
632 template <> bool descending_compare (T, T) { return true; } \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
633 template <> bool descending_compare (vec_index<T> *, vec_index<T> *) \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
634 { return true; } \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
635 template <> Array<T> Array<T>::sort \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
636 (octave_idx_type, sortmode) const { return *this; } \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
637 template <> Array<T> Array<T>::sort (Array<octave_idx_type> &sidx, \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
638 octave_idx_type, sortmode) const \
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
639 { sidx = Array<octave_idx_type> (); return *this; }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
640
228
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
641 #endif
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
642
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
643 /*
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
644 ;;; Local Variables: ***
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
645 ;;; mode: C++ ***
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
646 ;;; End: ***
ee01ac1c7acc [project @ 1993-11-16 09:56:54 by jwe]
jwe
parents:
diff changeset
647 */