Mercurial > octave-nkf
annotate src/Cell.cc @ 11037:e7864673c31f
new Cell (std::list<std::string>&) constructor
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Sep 2010 18:12:12 -0400 |
parents | 64472dd48517 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1999, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
4 2009 John W. Eaton | |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
5 Copyright (C) 2009, 2010 VZLU Prague |
3353 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
3353 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
3353 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
4513 | 29 #include "idx-vector.h" |
30 | |
3353 | 31 #include "Cell.h" |
4919 | 32 #include "error.h" |
5602 | 33 #include "gripes.h" |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
34 #include "oct-obj.h" |
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
35 |
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
36 Cell::Cell (const octave_value_list& ovl) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
37 : Array<octave_value> (ovl.cell_value ()) |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
38 { |
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
39 } |
3353 | 40 |
5805 | 41 Cell::Cell (const string_vector& sv, bool trim) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
42 : Array<octave_value> () |
4216 | 43 { |
5275 | 44 octave_idx_type n = sv.length (); |
4216 | 45 |
46 if (n > 0) | |
47 { | |
4625 | 48 resize (dim_vector (n, 1)); |
4216 | 49 |
5275 | 50 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
51 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
52 std::string s = sv[i]; |
5805 | 53 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
54 if (trim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
55 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
56 size_t pos = s.find_last_not_of (' '); |
5805 | 57 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
58 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
59 } |
5805 | 60 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
61 elem(i,0) = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
62 } |
4216 | 63 } |
64 } | |
3354 | 65 |
11037
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
66 Cell::Cell (const std::list<std::string>& lst) |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
67 : Array<octave_value> () |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
68 { |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
69 size_t n = lst.size (); |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
70 |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
71 if (n > 0) |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
72 { |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
73 resize (dim_vector (n, 1)); |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
74 |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
75 octave_idx_type i = 0; |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
76 |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
77 for (std::list<std::string>::const_iterator it = lst.begin (); |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
78 it != lst.end (); it++) |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
79 { |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
80 elem(i++,0) = *it; |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
81 } |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
82 } |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
83 } |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
84 |
8732 | 85 Cell::Cell (const Array<std::string>& sa) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
86 : Array<octave_value> (sa.dims ()) |
8732 | 87 { |
88 octave_idx_type n = sa.numel (); | |
89 | |
90 octave_value *dst = fortran_vec (); | |
91 const std::string *src = sa.data (); | |
92 | |
93 for (octave_idx_type i = 0; i < n; i++) | |
94 dst[i] = src[i]; | |
95 } | |
96 | |
6116 | 97 // Set size to DV, filling with []. Then fill with as many elements of |
98 // SV as possible. | |
7209 | 99 |
6116 | 100 Cell::Cell (const dim_vector& dv, const string_vector& sv, bool trim) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
101 : Array<octave_value> (dv, resize_fill_value ()) |
6116 | 102 { |
103 octave_idx_type n = sv.length (); | |
104 | |
105 if (n > 0) | |
106 { | |
107 octave_idx_type m = numel (); | |
108 | |
109 octave_idx_type len = n > m ? m : n; | |
110 | |
111 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 std::string s = sv[i]; |
6116 | 114 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 if (trim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
116 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 size_t pos = s.find_last_not_of (' '); |
6116 | 118 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 } |
6116 | 121 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 elem(i) = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
123 } |
6116 | 124 } |
125 } | |
126 | |
127 bool | |
128 Cell::is_cellstr (void) const | |
129 { | |
130 bool retval = true; | |
131 | |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
132 octave_idx_type n = numel (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
133 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
134 for (octave_idx_type i = 0; i < n; i++) |
6116 | 135 { |
136 if (! elem(i).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
140 } |
6116 | 141 } |
142 | |
143 return retval; | |
144 } | |
145 | |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
146 Array<std::string> |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
147 Cell::cellstr_value (void) const |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
148 { |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
149 Array<std::string> retval (dims ()); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
150 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
151 octave_idx_type n = numel (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
152 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
153 for (octave_idx_type i = 0; i < n; i++) |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
154 retval.xelem (i) = elem (i).string_value (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
155 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
156 return retval; |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
157 } |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
158 |
4513 | 159 Cell |
4587 | 160 Cell::index (const octave_value_list& idx_arg, bool resize_ok) const |
4513 | 161 { |
162 Cell retval; | |
163 | |
5275 | 164 octave_idx_type n = idx_arg.length (); |
4513 | 165 |
166 switch (n) | |
167 { | |
5539 | 168 case 0: |
169 retval = *this; | |
170 break; | |
171 | |
4513 | 172 case 1: |
173 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 idx_vector i = idx_arg(0).index_vector (); |
4513 | 175 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
176 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 retval = Array<octave_value>::index (i, resize_ok, resize_fill_value ()); |
4513 | 178 } |
179 break; | |
180 | |
181 case 2: | |
182 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
183 idx_vector i = idx_arg(0).index_vector (); |
4513 | 184 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
186 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
187 idx_vector j = idx_arg(1).index_vector (); |
4919 | 188 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
189 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 retval = Array<octave_value>::index (i, j, resize_ok, |
9415
f16079069972
use proper empty value in Cell::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
191 resize_fill_value ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 } |
4513 | 193 } |
194 break; | |
195 | |
196 default: | |
197 { | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
198 Array<idx_vector> iv (n, 1); |
4513 | 199 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
200 for (octave_idx_type i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
201 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 iv(i) = idx_arg(i).index_vector (); |
4513 | 203 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 } |
4919 | 207 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 if (!error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
209 retval = Array<octave_value>::index (iv, resize_ok, |
9415
f16079069972
use proper empty value in Cell::index
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
210 resize_fill_value ()); |
4513 | 211 } |
212 break; | |
213 } | |
214 | |
215 return retval; | |
216 } | |
217 | |
10649
64472dd48517
cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
218 void |
4587 | 219 Cell::assign (const octave_value_list& idx_arg, const Cell& rhs, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
220 const octave_value& fill_val) |
4513 | 221 |
222 { | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
223 octave_idx_type len = idx_arg.length (); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
224 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
225 Array<idx_vector> ra_idx (len, 1); |
4513 | 226 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
227 for (octave_idx_type i = 0; i < len; i++) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
228 ra_idx(i) = idx_arg(i).index_vector (); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
229 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
230 Array<octave_value>::assign (ra_idx, rhs, fill_val); |
4513 | 231 } |
232 | |
10649
64472dd48517
cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
233 void |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
234 Cell::delete_elements (const octave_value_list& idx_arg) |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
235 |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
236 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
237 octave_idx_type len = idx_arg.length (); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
238 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
239 Array<idx_vector> ra_idx (len, 1); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
240 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
241 for (octave_idx_type i = 0; i < len; i++) |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
242 ra_idx.xelem (i) = idx_arg(i).index_vector (); |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
243 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
244 Array<octave_value>::delete_elements (ra_idx); |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
245 } |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
246 |
5602 | 247 octave_idx_type |
248 Cell::nnz (void) const | |
249 { | |
250 gripe_wrong_type_arg ("nnz", "cell array"); | |
251 return -1; | |
252 } | |
253 | |
4915 | 254 Cell |
5570 | 255 Cell::column (octave_idx_type i) const |
256 { | |
257 Cell retval; | |
258 | |
259 if (ndims () < 3) | |
260 { | |
261 if (i < 0 || i >= cols ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
262 error ("invalid column selection"); |
5570 | 263 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
264 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
265 octave_idx_type nr = rows (); |
5570 | 266 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
267 retval.resize (dim_vector (nr, 1)); |
5570 | 268 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
269 for (octave_idx_type j = 0; j < nr; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
270 retval.xelem (j) = elem (j, i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 } |
5570 | 272 } |
273 else | |
274 error ("Cell::column: requires 2-d cell array"); | |
275 | |
276 return retval; | |
277 } | |
278 | |
279 Cell | |
5275 | 280 Cell::concat (const Cell& rb, const Array<octave_idx_type>& ra_idx) |
4806 | 281 { |
5073 | 282 return insert (rb, ra_idx); |
4915 | 283 } |
284 | |
285 Cell& | |
5275 | 286 Cell::insert (const Cell& a, octave_idx_type r, octave_idx_type c) |
4915 | 287 { |
288 Array<octave_value>::insert (a, r, c); | |
289 return *this; | |
290 } | |
291 | |
292 Cell& | |
5275 | 293 Cell::insert (const Cell& a, const Array<octave_idx_type>& ra_idx) |
4915 | 294 { |
295 Array<octave_value>::insert (a, ra_idx); | |
296 return *this; | |
4806 | 297 } |
298 | |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
299 Cell |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
300 Cell::map (ctype_mapper fcn) const |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
301 { |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
302 Cell retval (dims ()); |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
303 octave_value *r = retval.fortran_vec (); |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
304 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
305 const octave_value *p = data (); |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
306 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
307 for (octave_idx_type i = 0; i < numel (); i++) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
308 r[i] = ((p++)->*fcn) (); |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
309 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
310 return retval; |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
311 } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
312 |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
313 Cell |
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
314 Cell::diag (octave_idx_type k) const |
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
315 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
316 return Array<octave_value>::diag (k); |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
317 } |