Mercurial > hg > octave-nkf
annotate src/pt-mat.cc @ 12842:a52b4e9f45e3
codesprint: new tests for pt-mat.cc
* pt-mat.cc (Fstring_fill_char): New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 16 Jul 2011 18:05:35 -0400 |
parents | 7a5aacf65f81 |
children | 213c791292a6 |
rev | line source |
---|---|
1741 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
1741 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1741 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1741 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3503 | 27 #include <iostream> |
1741 | 28 |
5502 | 29 #include "quit.h" |
30 | |
2172 | 31 #include "defun.h" |
1741 | 32 #include "error.h" |
33 #include "oct-obj.h" | |
2982 | 34 #include "pt-arg-list.h" |
3770 | 35 #include "pt-bp.h" |
1741 | 36 #include "pt-exp.h" |
37 #include "pt-mat.h" | |
2124 | 38 #include "pt-walk.h" |
2201 | 39 #include "utils.h" |
2371 | 40 #include "ov.h" |
41 #include "variables.h" | |
1741 | 42 |
9460
1fddcf651559
avoid complex -> real conversion when constructing arrays with []
John W. Eaton <jwe@octave.org>
parents:
9389
diff
changeset
|
43 #include "ov-cx-mat.h" |
1fddcf651559
avoid complex -> real conversion when constructing arrays with []
John W. Eaton <jwe@octave.org>
parents:
9389
diff
changeset
|
44 #include "ov-flt-cx-mat.h" |
5630 | 45 #include "ov-re-sparse.h" |
46 #include "ov-cx-sparse.h" | |
47 | |
2254 | 48 // The character to fill with when creating string arrays. |
3836 | 49 char Vstring_fill_char = ' '; |
2254 | 50 |
1741 | 51 // General matrices. This list type is much more work to handle than |
52 // constant matrices, but it allows us to construct matrices from | |
53 // other matrices, variables, and functions. | |
54 | |
1827 | 55 // But first, some internal classes that make our job much easier. |
1741 | 56 |
1827 | 57 class |
58 tm_row_const | |
1741 | 59 { |
1827 | 60 private: |
61 | |
62 class | |
4219 | 63 tm_row_const_rep : public octave_base_list<octave_value> |
1827 | 64 { |
65 public: | |
66 | |
67 tm_row_const_rep (void) | |
5514 | 68 : count (1), dv (0, 0), all_str (false), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 all_sq_str (false), all_dq_str (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
70 some_str (false), all_real (false), all_cmplx (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 all_mt (true), any_sparse (false), any_class (false), |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
72 all_1x1 (false), class_nm (), ok (false) |
5533 | 73 { } |
1827 | 74 |
2971 | 75 tm_row_const_rep (const tree_argument_list& row) |
5514 | 76 : count (1), dv (0, 0), all_str (false), all_sq_str (false), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
77 some_str (false), all_real (false), all_cmplx (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 all_mt (true), any_sparse (false), any_class (false), |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
79 all_1x1 (! row.empty ()), class_nm (), ok (false) |
3110 | 80 { init (row); } |
1827 | 81 |
82 ~tm_row_const_rep (void) { } | |
83 | |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
84 octave_refcount<int> count; |
1827 | 85 |
4765 | 86 dim_vector dv; |
1741 | 87 |
1827 | 88 bool all_str; |
5280 | 89 bool all_sq_str; |
90 bool all_dq_str; | |
3110 | 91 bool some_str; |
5502 | 92 bool all_real; |
93 bool all_cmplx; | |
2602 | 94 bool all_mt; |
5630 | 95 bool any_sparse; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
96 bool any_class; |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
97 bool all_1x1; |
1827 | 98 |
5533 | 99 std::string class_nm; |
100 | |
1827 | 101 bool ok; |
102 | |
4501 | 103 bool do_init_element (tree_expression *, const octave_value&, bool&); |
104 | |
2971 | 105 void init (const tree_argument_list&); |
1827 | 106 |
107 private: | |
108 | |
109 tm_row_const_rep (const tm_row_const_rep&); | |
110 | |
2971 | 111 tm_row_const_rep& operator = (const tm_row_const_rep&); |
2419 | 112 |
113 void eval_warning (const char *msg, int l, int c) const; | |
1827 | 114 }; |
115 | |
116 public: | |
117 | |
4219 | 118 typedef tm_row_const_rep::iterator iterator; |
119 typedef tm_row_const_rep::const_iterator const_iterator; | |
120 | |
2990 | 121 tm_row_const (void) |
122 : rep (0) { } | |
1827 | 123 |
2971 | 124 tm_row_const (const tree_argument_list& row) |
125 : rep (new tm_row_const_rep (row)) { } | |
1827 | 126 |
2990 | 127 tm_row_const (const tm_row_const& x) |
128 : rep (x.rep) | |
129 { | |
130 if (rep) | |
131 rep->count++; | |
132 } | |
1827 | 133 |
134 tm_row_const& operator = (const tm_row_const& x) | |
2990 | 135 { |
136 if (this != &x && rep != x.rep) | |
137 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 if (rep && --rep->count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 delete rep; |
1741 | 140 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
141 rep = x.rep; |
1827 | 142 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 if (rep) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 rep->count++; |
2990 | 145 } |
1741 | 146 |
2990 | 147 return *this; |
148 } | |
1827 | 149 |
150 ~tm_row_const (void) | |
2990 | 151 { |
152 if (rep && --rep->count == 0) | |
153 delete rep; | |
154 } | |
1741 | 155 |
5514 | 156 octave_idx_type rows (void) { return rep->dv(0); } |
157 octave_idx_type cols (void) { return rep->dv(1); } | |
4765 | 158 |
6200 | 159 bool empty (void) const { return rep->empty (); } |
160 | |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
161 size_t length (void) const { return rep->length (); } |
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
162 |
4765 | 163 dim_vector dims (void) { return rep->dv; } |
1827 | 164 |
2868 | 165 bool all_strings_p (void) const { return rep->all_str; } |
5280 | 166 bool all_sq_strings_p (void) const { return rep->all_sq_str; } |
167 bool all_dq_strings_p (void) const { return rep->all_dq_str; } | |
3110 | 168 bool some_strings_p (void) const { return rep->some_str; } |
5502 | 169 bool all_real_p (void) const { return rep->all_real; } |
170 bool all_complex_p (void) const { return rep->all_cmplx; } | |
2868 | 171 bool all_empty_p (void) const { return rep->all_mt; } |
5630 | 172 bool any_sparse_p (void) const { return rep->any_sparse; } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
173 bool any_class_p (void) const { return rep->any_class; } |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
174 bool all_1x1_p (void) const { return rep->all_1x1; } |
1827 | 175 |
5533 | 176 std::string class_name (void) const { return rep->class_nm; } |
177 | |
4219 | 178 operator bool () const { return (rep && rep->ok); } |
1827 | 179 |
4219 | 180 iterator begin (void) { return rep->begin (); } |
181 const_iterator begin (void) const { return rep->begin (); } | |
182 | |
183 iterator end (void) { return rep->end (); } | |
184 const_iterator end (void) const { return rep->end (); } | |
1827 | 185 |
186 private: | |
187 | |
188 tm_row_const_rep *rep; | |
189 }; | |
190 | |
8107
8655dc0906e6
Special case single type conacation in Fcat. Rework cell2mat to take advantage
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
191 std::string |
5533 | 192 get_concat_class (const std::string& c1, const std::string& c2) |
193 { | |
194 std::string retval = octave_base_value::static_class_name (); | |
195 | |
196 if (c1 == c2) | |
197 retval = c1; | |
9389
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
198 else if (c1.empty ()) |
9145
53364bb317d4
fix concatenation with all-zero matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
199 retval = c2; |
9389
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
200 else if (c2.empty ()) |
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
201 retval = c1; |
5533 | 202 else |
203 { | |
204 bool c1_is_int = (c1 == "int8" || c1 == "uint8" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 || c1 == "int16" || c1 == "uint16" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 || c1 == "int32" || c1 == "uint32" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 || c1 == "int64" || c1 == "uint64"); |
5533 | 208 bool c2_is_int = (c2 == "int8" || c2 == "uint8" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
209 || c2 == "int16" || c2 == "uint16" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 || c2 == "int32" || c2 == "uint32" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
211 || c2 == "int64" || c2 == "uint64"); |
5533 | 212 |
213 bool c1_is_char = (c1 == "char"); | |
214 bool c2_is_char = (c2 == "char"); | |
215 | |
216 bool c1_is_double = (c1 == "double"); | |
217 bool c2_is_double = (c2 == "double"); | |
218 | |
219 bool c1_is_single = (c1 == "single"); | |
220 bool c2_is_single = (c2 == "single"); | |
221 | |
222 bool c1_is_logical = (c1 == "logical"); | |
223 bool c2_is_logical = (c2 == "logical"); | |
224 | |
225 bool c1_is_built_in_type | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
226 = (c1_is_int || c1_is_char || c1_is_double || c1_is_single |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
227 || c1_is_logical); |
5533 | 228 |
229 bool c2_is_built_in_type | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
230 = (c2_is_int || c2_is_char || c2_is_double || c2_is_single |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
231 || c2_is_logical); |
5533 | 232 |
233 // Order is important here... | |
234 | |
235 if (c1_is_char && c2_is_built_in_type) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 retval = c1; |
5533 | 237 else if (c2_is_char && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 retval = c2; |
5533 | 239 else if (c1_is_int && c2_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 retval = c1; |
5533 | 241 else if (c2_is_int && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 retval = c2; |
5533 | 243 else if (c1_is_single && c2_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 retval = c1; |
5533 | 245 else if (c2_is_single && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 retval = c2; |
5533 | 247 else if (c1_is_double && c2_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
248 retval = c1; |
5533 | 249 else if (c2_is_double && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
250 retval = c2; |
5533 | 251 else if (c1_is_logical && c2_is_logical) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 retval = c1; |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10715
diff
changeset
|
253 else if (c1 == "struct" && c2 == c1) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10715
diff
changeset
|
254 retval = c1; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10715
diff
changeset
|
255 else if (c1 == "cell" && c2 == c1) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10715
diff
changeset
|
256 retval = c1; |
5533 | 257 } |
258 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
259 return retval; |
5533 | 260 } |
261 | |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
262 static void |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
263 eval_error (const char *msg, int l, int c, |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
264 const dim_vector& x, const dim_vector& y) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
265 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
266 if (l == -1 && c == -1) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
267 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
268 ::error ("%s (%s vs %s)", msg, x.str ().c_str (), y.str ().c_str ()); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
269 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
270 else |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
271 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
272 ::error ("%s (%s vs %s) near line %d, column %d", msg, |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
273 x.str ().c_str (), y.str ().c_str (), l, c); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
274 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
275 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
276 |
4501 | 277 bool |
278 tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 const octave_value& val, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 bool& first_elem) |
4501 | 281 { |
5533 | 282 std::string this_elt_class_nm = val.class_name (); |
283 | |
4765 | 284 dim_vector this_elt_dv = val.dims (); |
285 | |
9145
53364bb317d4
fix concatenation with all-zero matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
286 class_nm = get_concat_class (class_nm, this_elt_class_nm); |
53364bb317d4
fix concatenation with all-zero matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
287 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
288 if (! this_elt_dv.zero_by_zero ()) |
4501 | 289 { |
290 all_mt = false; | |
291 | |
292 if (first_elem) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 first_elem = false; |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
295 dv = this_elt_dv; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 } |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
297 else if (! dv.hvcat (this_elt_dv, 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
299 eval_error ("horizontal dimensions mismatch", elt->line (), elt->column (), dv, this_elt_dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
300 return false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 } |
4501 | 302 } |
303 | |
4915 | 304 append (val); |
305 | |
4501 | 306 if (all_str && ! val.is_string ()) |
307 all_str = false; | |
308 | |
5280 | 309 if (all_sq_str && ! val.is_sq_string ()) |
310 all_sq_str = false; | |
311 | |
312 if (all_dq_str && ! val.is_dq_string ()) | |
313 all_dq_str = false; | |
314 | |
4501 | 315 if (! some_str && val.is_string ()) |
316 some_str = true; | |
317 | |
5502 | 318 if (all_real && ! val.is_real_type ()) |
319 all_real = false; | |
320 | |
321 if (all_cmplx && ! (val.is_complex_type () || val.is_real_type ())) | |
322 all_cmplx = false; | |
4501 | 323 |
5631 | 324 if (!any_sparse && val.is_sparse_type ()) |
5630 | 325 any_sparse = true; |
326 | |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
327 if (!any_class && val.is_object ()) |
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
328 any_class = true; |
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
329 |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
330 all_1x1 = all_1x1 && val.numel () == 1; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
331 |
4501 | 332 return true; |
333 } | |
334 | |
1827 | 335 void |
2971 | 336 tm_row_const::tm_row_const_rep::init (const tree_argument_list& row) |
1827 | 337 { |
338 all_str = true; | |
5280 | 339 all_sq_str = true; |
340 all_dq_str = true; | |
5502 | 341 all_real = true; |
342 all_cmplx = true; | |
5630 | 343 any_sparse = false; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
344 any_class = false; |
1827 | 345 |
346 bool first_elem = true; | |
347 | |
4219 | 348 for (tree_argument_list::const_iterator p = row.begin (); |
349 p != row.end (); | |
350 p++) | |
1827 | 351 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
352 octave_quit (); |
5502 | 353 |
4219 | 354 tree_expression *elt = *p; |
1827 | 355 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8147
diff
changeset
|
356 octave_value tmp = elt->rvalue1 (); |
1827 | 357 |
358 if (error_state || tmp.is_undefined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 break; |
1827 | 360 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
361 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 if (tmp.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 octave_value_list tlst = tmp.list_value (); |
2602 | 365 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 for (octave_idx_type i = 0; i < tlst.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 octave_quit (); |
5502 | 369 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 if (! do_init_element (elt, tlst(i), first_elem)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
373 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
375 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
376 if (! do_init_element (elt, tmp, first_elem)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
378 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
379 } |
1827 | 380 } |
381 | |
4501 | 382 done: |
383 | |
1827 | 384 ok = ! error_state; |
1741 | 385 } |
386 | |
2419 | 387 void |
388 tm_row_const::tm_row_const_rep::eval_warning (const char *msg, int l, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
389 int c) const |
2419 | 390 { |
391 if (l == -1 && c == -1) | |
5781 | 392 warning_with_id ("Octave:empty-list-elements", "%s", msg); |
2419 | 393 else |
5781 | 394 warning_with_id ("Octave:empty-list-elements", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 "%s near line %d, column %d", msg, l, c); |
2419 | 396 } |
397 | |
1827 | 398 class |
4219 | 399 tm_const : public octave_base_list<tm_row_const> |
1827 | 400 { |
401 public: | |
402 | |
403 tm_const (const tree_matrix& tm) | |
5514 | 404 : dv (0, 0), all_str (false), all_sq_str (false), all_dq_str (false), |
5502 | 405 some_str (false), all_real (false), all_cmplx (false), |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
406 all_mt (true), any_sparse (false), any_class (false), |
9389
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
407 class_nm (), ok (false) |
5533 | 408 { init (tm); } |
1827 | 409 |
410 ~tm_const (void) { } | |
411 | |
5514 | 412 octave_idx_type rows (void) const { return dv.elem (0); } |
413 octave_idx_type cols (void) const { return dv.elem (1); } | |
4765 | 414 |
415 dim_vector dims (void) const { return dv; } | |
1827 | 416 |
2868 | 417 bool all_strings_p (void) const { return all_str; } |
5280 | 418 bool all_sq_strings_p (void) const { return all_sq_str; } |
419 bool all_dq_strings_p (void) const { return all_dq_str; } | |
3110 | 420 bool some_strings_p (void) const { return some_str; } |
5502 | 421 bool all_real_p (void) const { return all_real; } |
422 bool all_complex_p (void) const { return all_cmplx; } | |
2868 | 423 bool all_empty_p (void) const { return all_mt; } |
5630 | 424 bool any_sparse_p (void) const { return any_sparse; } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
425 bool any_class_p (void) const { return any_class; } |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
426 bool all_1x1_p (void) const { return all_1x1; } |
1827 | 427 |
5533 | 428 std::string class_name (void) const { return class_nm; } |
429 | |
3145 | 430 operator bool () const { return ok; } |
1827 | 431 |
432 private: | |
433 | |
4765 | 434 dim_vector dv; |
1827 | 435 |
436 bool all_str; | |
5280 | 437 bool all_sq_str; |
438 bool all_dq_str; | |
3110 | 439 bool some_str; |
5502 | 440 bool all_real; |
441 bool all_cmplx; | |
2602 | 442 bool all_mt; |
5630 | 443 bool any_sparse; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
444 bool any_class; |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
445 bool all_1x1; |
1827 | 446 |
5533 | 447 std::string class_nm; |
448 | |
1827 | 449 bool ok; |
450 | |
451 tm_const (void); | |
452 | |
453 tm_const (const tm_const&); | |
454 | |
455 tm_const& operator = (const tm_const&); | |
456 | |
457 void init (const tree_matrix& tm); | |
458 }; | |
459 | |
460 void | |
461 tm_const::init (const tree_matrix& tm) | |
1741 | 462 { |
1827 | 463 all_str = true; |
5280 | 464 all_sq_str = true; |
465 all_dq_str = true; | |
5502 | 466 all_real = true; |
467 all_cmplx = true; | |
5630 | 468 any_sparse = false; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
469 any_class = false; |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
470 all_1x1 = ! empty (); |
1827 | 471 |
472 bool first_elem = true; | |
473 | |
474 // Just eval and figure out if what we have is complex or all | |
475 // strings. We can't check columns until we know that this is a | |
476 // numeric matrix -- collections of strings can have elements of | |
477 // different lengths. | |
478 | |
4219 | 479 for (tree_matrix::const_iterator p = tm.begin (); p != tm.end (); p++) |
1827 | 480 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
481 octave_quit (); |
5502 | 482 |
4219 | 483 tree_argument_list *elt = *p; |
1827 | 484 |
485 tm_row_const tmp (*elt); | |
486 | |
6200 | 487 if (tmp && ! tmp.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
488 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 if (all_str && ! tmp.all_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
490 all_str = false; |
1827 | 491 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
492 if (all_sq_str && ! tmp.all_sq_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
493 all_sq_str = false; |
5280 | 494 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
495 if (all_dq_str && ! tmp.all_dq_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
496 all_dq_str = false; |
5280 | 497 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 if (! some_str && tmp.some_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
499 some_str = true; |
3110 | 500 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
501 if (all_real && ! tmp.all_real_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
502 all_real = false; |
5502 | 503 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
504 if (all_cmplx && ! tmp.all_complex_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
505 all_cmplx = false; |
1827 | 506 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 if (all_mt && ! tmp.all_empty_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 all_mt = false; |
2602 | 509 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
510 if (!any_sparse && tmp.any_sparse_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
511 any_sparse = true; |
5630 | 512 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
513 if (!any_class && tmp.any_class_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 any_class = true; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
515 |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
516 all_1x1 = all_1x1 && tmp.all_1x1_p (); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
517 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 append (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
519 } |
1827 | 520 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
521 break; |
1827 | 522 } |
523 | |
524 if (! error_state) | |
525 { | |
4219 | 526 for (iterator p = begin (); p != end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
527 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
528 octave_quit (); |
5502 | 529 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
530 tm_row_const elt = *p; |
1827 | 531 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
532 octave_idx_type this_elt_nr = elt.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
533 octave_idx_type this_elt_nc = elt.cols (); |
1827 | 534 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
535 std::string this_elt_class_nm = elt.class_name (); |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
536 class_nm = get_concat_class (class_nm, this_elt_class_nm); |
5533 | 537 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
538 dim_vector this_elt_dv = elt.dims (); |
4765 | 539 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
540 all_mt = false; |
4765 | 541 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
542 if (first_elem) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
543 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
544 first_elem = false; |
4765 | 545 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
546 dv = this_elt_dv; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
547 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
548 else if (all_str && dv.length () == 2 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
549 && this_elt_dv.length () == 2) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
550 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
551 // FIXME: this is Octave's specialty. Character matrices allow |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
552 // rows of unequal length. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
553 if (this_elt_nc > cols ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
554 dv(1) = this_elt_nc; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
555 dv(0) += this_elt_nr; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
556 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
557 else if (! dv.hvcat (this_elt_dv, 0)) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
558 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
559 eval_error ("vertical dimensions mismatch", -1, -1, |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
560 dv, this_elt_dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
561 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
562 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 } |
1827 | 564 } |
565 | |
566 ok = ! error_state; | |
1741 | 567 } |
568 | |
2990 | 569 tree_matrix::~tree_matrix (void) |
570 { | |
4219 | 571 while (! empty ()) |
2990 | 572 { |
4219 | 573 iterator p = begin (); |
574 delete *p; | |
575 erase (p); | |
2990 | 576 } |
577 } | |
578 | |
1827 | 579 bool |
4267 | 580 tree_matrix::has_magic_end (void) const |
581 { | |
582 for (const_iterator p = begin (); p != end (); p++) | |
583 { | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
584 octave_quit (); |
5502 | 585 |
4267 | 586 tree_argument_list *elt = *p; |
587 | |
588 if (elt && elt->has_magic_end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
589 return true; |
4267 | 590 } |
591 | |
592 return false; | |
593 } | |
594 | |
595 bool | |
2529 | 596 tree_matrix::all_elements_are_constant (void) const |
1827 | 597 { |
4219 | 598 for (const_iterator p = begin (); p != end (); p++) |
1827 | 599 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
600 octave_quit (); |
5502 | 601 |
4219 | 602 tree_argument_list *elt = *p; |
1827 | 603 |
2529 | 604 if (! elt->all_elements_are_constant ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
605 return false; |
1827 | 606 } |
607 | |
608 return true; | |
609 } | |
610 | |
2971 | 611 octave_value_list |
612 tree_matrix::rvalue (int nargout) | |
613 { | |
614 octave_value_list retval; | |
615 | |
616 if (nargout > 1) | |
617 error ("invalid number of output arguments for matrix list"); | |
618 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8147
diff
changeset
|
619 retval = rvalue1 (nargout); |
2971 | 620 |
621 return retval; | |
622 } | |
623 | |
8107
8655dc0906e6
Special case single type conacation in Fcat. Rework cell2mat to take advantage
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
624 void |
5280 | 625 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p) |
626 { | |
5781 | 627 if (! (all_dq_strings_p || all_sq_strings_p)) |
628 warning_with_id ("Octave:string-concat", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
629 "concatenation of different character string types may have unintended consequences"); |
5280 | 630 } |
631 | |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
632 template<class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
633 static void |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
634 single_type_concat (Array<T>& result, |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
635 tm_const& tmp) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
636 { |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
637 octave_idx_type r = 0, c = 0; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
638 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
639 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
640 { |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
641 tm_row_const row = *p; |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
642 // Skip empty arrays to allow looser rules. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
643 if (row.dims ().any_zero ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
644 continue; |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
645 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
646 for (tm_row_const::iterator q = row.begin (); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
647 q != row.end (); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
648 q++) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
649 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
650 octave_quit (); |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
651 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
652 TYPE ra = octave_value_extract<TYPE> (*q); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
653 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
654 // Skip empty arrays to allow looser rules. |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
655 if (! error_state) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
656 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
657 if (! ra.is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
658 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
659 result.insert (ra, r, c); |
5502 | 660 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
661 if (! error_state) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
662 c += ra.columns (); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
663 else |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
664 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
665 } |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
666 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
667 else |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
668 return; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
669 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
670 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
671 r += row.rows (); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
672 c = 0; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
673 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
674 } |
5533 | 675 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
676 template<class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
677 static void |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
678 single_type_concat (Array<T>& result, |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
679 const dim_vector& dv, |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
680 tm_const& tmp) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
681 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
682 if (dv.any_zero ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
683 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
684 result = Array<T> (dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
685 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
686 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
687 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
688 if (tmp.length () == 1) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
689 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
690 // If possible, forward the operation to liboctave. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
691 // Single row. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
692 tm_row_const& row = tmp.front (); |
10939
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
693 if (! (equal_types<T, char>::value || equal_types<T, octave_value>::value) |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
694 && row.all_1x1_p ()) |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
695 { |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
696 // Optimize all scalars case. |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
697 result.clear (dv); |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
698 assert (result.numel () == row.length ()); |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
699 octave_idx_type i = 0; |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
700 for (tm_row_const::iterator q = row.begin (); |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
701 q != row.end () && ! error_state; q++) |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
702 result(i++) = octave_value_extract<T> (*q); |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
703 |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
704 return; |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
705 } |
c07cb4ef80db
optimize [a{:}] when a{i} are all scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10937
diff
changeset
|
706 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
707 octave_idx_type ncols = row.length (), i = 0; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
708 OCTAVE_LOCAL_BUFFER (Array<T>, array_list, ncols); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
709 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
710 for (tm_row_const::iterator q = row.begin (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
711 q != row.end () && ! error_state; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
712 q++) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
713 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
714 octave_quit (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
715 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
716 array_list[i] = octave_value_extract<TYPE> (*q); |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
717 i++; |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
718 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
719 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
720 if (! error_state) |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
721 result = Array<T>::cat (-2, ncols, array_list); |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
722 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
723 else |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
724 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
725 result = Array<T> (dv); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
726 single_type_concat<TYPE> (result, tmp); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
727 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
728 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
729 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
730 template<class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
731 static void |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
732 single_type_concat (Sparse<T>& result, |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
733 const dim_vector& dv, |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
734 tm_const& tmp) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
735 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
736 if (dv.any_zero ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
737 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
738 result = Sparse<T> (dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
739 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
740 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
741 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
742 // Sparse matrices require preallocation for efficient indexing; besides, |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
743 // only horizontal concatenation can be efficiently handled by indexing. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
744 // So we just cat all rows through liboctave, then cat the final column. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
745 octave_idx_type nrows = tmp.length (), j = 0; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
746 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_row_list, nrows); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
747 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
748 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
749 tm_row_const row = *p; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
750 octave_idx_type ncols = row.length (), i = 0; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
751 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_list, ncols); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
752 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
753 for (tm_row_const::iterator q = row.begin (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
754 q != row.end () && ! error_state; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
755 q++) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
756 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
757 octave_quit (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
758 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
759 sparse_list[i] = octave_value_extract<TYPE> (*q); |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
760 i++; |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
761 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
762 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
763 Sparse<T> stmp = Sparse<T>::cat (-2, ncols, sparse_list); |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
764 sparse_row_list[j] = stmp; |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
765 j++; |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
766 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
767 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
768 result = Sparse<T>::cat (-1, nrows, sparse_row_list); |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
769 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
770 |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
771 template<class MAP> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
772 static void |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
773 single_type_concat (octave_map& result, |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
774 const dim_vector& dv, |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
775 tm_const& tmp) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
776 { |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
777 if (dv.any_zero ()) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
778 { |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
779 result = octave_map (dv); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
780 return; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
781 } |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
782 |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
783 octave_idx_type nrows = tmp.length (), j = 0; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
784 OCTAVE_LOCAL_BUFFER (octave_map, map_row_list, nrows); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
785 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
786 { |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
787 tm_row_const row = *p; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
788 octave_idx_type ncols = row.length (), i = 0; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
789 OCTAVE_LOCAL_BUFFER (MAP, map_list, ncols); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
790 |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
791 for (tm_row_const::iterator q = row.begin (); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
792 q != row.end () && ! error_state; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
793 q++) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
794 { |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
795 octave_quit (); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
796 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
797 map_list[i] = octave_value_extract<MAP> (*q); |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
798 i++; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
799 } |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
800 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
801 octave_map mtmp = octave_map::cat (-2, ncols, map_list); |
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
802 map_row_list[j] = mtmp; |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
803 j++; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
804 } |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
805 |
10937
f42e8c6196c3
tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
806 result = octave_map::cat (-1, nrows, map_row_list); |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
807 } |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
808 |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
809 template<class TYPE> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
810 static octave_value |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
811 do_single_type_concat (const dim_vector& dv, |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
812 tm_const& tmp) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
813 { |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
814 TYPE result; |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
815 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
816 single_type_concat<TYPE> (result, dv, tmp); |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
817 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
818 return result; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
819 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
820 |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
821 template<> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
822 octave_value |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
823 do_single_type_concat<octave_map> (const dim_vector& dv, |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
824 tm_const& tmp) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
825 { |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
826 octave_map result; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
827 |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
828 if (tmp.all_1x1_p ()) |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
829 single_type_concat<octave_scalar_map> (result, dv, tmp); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
830 else |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
831 single_type_concat<octave_map> (result, dv, tmp); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
832 |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
833 return result; |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
834 } |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
835 |
2086 | 836 octave_value |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8147
diff
changeset
|
837 tree_matrix::rvalue1 (int) |
1741 | 838 { |
6200 | 839 octave_value retval = Matrix (); |
1741 | 840 |
4915 | 841 bool all_strings_p = false; |
5280 | 842 bool all_sq_strings_p = false; |
843 bool all_dq_strings_p = false; | |
4915 | 844 bool all_empty_p = false; |
5502 | 845 bool all_real_p = false; |
846 bool all_complex_p = false; | |
5630 | 847 bool any_sparse_p = false; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
848 bool any_class_p = false; |
4915 | 849 bool frc_str_conv = false; |
1741 | 850 |
4915 | 851 tm_const tmp (*this); |
3110 | 852 |
6200 | 853 if (tmp && ! tmp.empty ()) |
1827 | 854 { |
4765 | 855 dim_vector dv = tmp.dims (); |
4915 | 856 all_strings_p = tmp.all_strings_p (); |
5280 | 857 all_sq_strings_p = tmp.all_sq_strings_p (); |
858 all_dq_strings_p = tmp.all_dq_strings_p (); | |
4915 | 859 all_empty_p = tmp.all_empty_p (); |
5502 | 860 all_real_p = tmp.all_real_p (); |
861 all_complex_p = tmp.all_complex_p (); | |
5630 | 862 any_sparse_p = tmp.any_sparse_p (); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
863 any_class_p = tmp.any_class_p (); |
4915 | 864 frc_str_conv = tmp.some_strings_p (); |
1741 | 865 |
5502 | 866 // Try to speed up the common cases. |
4915 | 867 |
5533 | 868 std::string result_type = tmp.class_name (); |
869 | |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
870 if (any_class_p) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 octave_value_list tmp3 (tmp.length (), octave_value ()); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
873 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 int j = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
875 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 octave_quit (); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
878 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 tm_row_const row = *p; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
880 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 if (row.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 tmp3 (j++) = *(row.begin ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
885 octave_value_list tmp1 (row.length (), octave_value ()); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
886 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 int i = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
888 for (tm_row_const::iterator q = row.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 q != row.end (); q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
890 tmp1 (i++) = *q; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
891 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
892 octave_value_list tmp2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
893 octave_value fcn = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
894 symbol_table::find_function ("horzcat", tmp1); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
895 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 if (fcn.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
897 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
898 tmp2 = fcn.do_multi_index_op (1, tmp1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
899 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
900 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 goto done; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
902 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 tmp3 (j++) = tmp2 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
904 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
905 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
906 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12125
diff
changeset
|
907 ::error ("cannot find overloaded horzcat function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
909 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
912 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
913 if (tmp.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 retval = tmp3 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
915 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
916 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 octave_value_list tmp2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
918 octave_value fcn = symbol_table::find_function ("vertcat", tmp3); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
919 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
920 if (fcn.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
922 tmp2 = fcn.do_multi_index_op (1, tmp3); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
923 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
924 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
925 retval = tmp2 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
926 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
927 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12125
diff
changeset
|
928 ::error ("cannot find overloaded vertcat function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
929 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
930 } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
931 else if (result_type == "double") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
932 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
933 if (any_sparse_p) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
934 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
935 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
936 retval = do_single_type_concat<SparseMatrix> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
937 else |
10814
83896a06adaf
don't skip narrowing when concatenating complex matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
938 retval = do_single_type_concat<SparseComplexMatrix> (dv, tmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
939 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
940 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
941 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
942 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
943 retval = do_single_type_concat<NDArray> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
944 else |
10814
83896a06adaf
don't skip narrowing when concatenating complex matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
945 retval = do_single_type_concat<ComplexNDArray> (dv, tmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
946 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
947 } |
5533 | 948 else if (result_type == "single") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
949 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
950 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
951 retval = do_single_type_concat<FloatNDArray> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
952 else |
10814
83896a06adaf
don't skip narrowing when concatenating complex matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
953 retval = do_single_type_concat<FloatComplexNDArray> (dv, tmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
954 } |
5533 | 955 else if (result_type == "char") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
956 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
957 char type = all_dq_strings_p ? '"' : '\''; |
5280 | 958 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
959 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); |
5280 | 960 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
961 charNDArray result (dv, Vstring_fill_char); |
5502 | 962 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
963 single_type_concat<charNDArray> (result, tmp); |
5502 | 964 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
965 retval = octave_value (result, type); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
966 } |
5533 | 967 else if (result_type == "logical") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
968 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
969 if (any_sparse_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
970 retval = do_single_type_concat<SparseBoolMatrix> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
971 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
972 retval = do_single_type_concat<boolNDArray> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
973 } |
5533 | 974 else if (result_type == "int8") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
975 retval = do_single_type_concat<int8NDArray> (dv, tmp); |
5533 | 976 else if (result_type == "int16") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
977 retval = do_single_type_concat<int16NDArray> (dv, tmp); |
5533 | 978 else if (result_type == "int32") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
979 retval = do_single_type_concat<int32NDArray> (dv, tmp); |
5533 | 980 else if (result_type == "int64") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
981 retval = do_single_type_concat<int64NDArray> (dv, tmp); |
5533 | 982 else if (result_type == "uint8") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
983 retval = do_single_type_concat<uint8NDArray> (dv, tmp); |
5533 | 984 else if (result_type == "uint16") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
985 retval = do_single_type_concat<uint16NDArray> (dv, tmp); |
5533 | 986 else if (result_type == "uint32") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
987 retval = do_single_type_concat<uint32NDArray> (dv, tmp); |
5533 | 988 else if (result_type == "uint64") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
989 retval = do_single_type_concat<uint64NDArray> (dv, tmp); |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
990 else if (result_type == "cell") |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
991 retval = do_single_type_concat<Cell> (dv, tmp); |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
992 else if (result_type == "struct") |
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10758
diff
changeset
|
993 retval = do_single_type_concat<octave_map> (dv, tmp); |
4915 | 994 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
995 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
996 // The line below might seem crazy, since we take a copy of |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 // the first argument, resize it to be empty and then resize |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
998 // it to be full. This is done since it means that there is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
999 // no recopying of data, as would happen if we used a single |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1000 // resize. It should be noted that resize operation is also |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1001 // significantly slower than the do_cat_op function, so it |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1002 // makes sense to have an empty matrix and copy all data. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1003 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1004 // We might also start with a empty octave_value using |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1005 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1006 // ctmp = octave_value_typeinfo::lookup_type |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1007 // (tmp.begin() -> begin() -> type_name()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1008 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1009 // and then directly resize. However, for some types there |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1010 // might be some additional setup needed, and so this should |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1011 // be avoided. |
5502 | 1012 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1013 octave_value ctmp; |
5502 | 1014 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1015 // Find the first non-empty object |
5502 | 1016 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1017 if (any_sparse_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1018 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1019 // Start with sparse matrix to avoid issues memory issues |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1020 // with things like [ones(1,4),sprandn(1e8,4,1e-4)] |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1021 if (all_real_p) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1022 ctmp = octave_sparse_matrix ().resize (dv); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1023 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1024 ctmp = octave_sparse_complex_matrix ().resize (dv); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1025 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1026 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1028 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1029 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1030 octave_quit (); |
5502 | 1031 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1032 tm_row_const row = *p; |
5502 | 1033 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1034 for (tm_row_const::iterator q = row.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1035 q != row.end (); q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1036 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1037 octave_quit (); |
5630 | 1038 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1039 ctmp = *q; |
5164 | 1040 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1041 if (! ctmp.all_zero_dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1042 goto found_non_empty; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1043 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1044 } |
5164 | 1045 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1046 ctmp = (*(tmp.begin() -> begin())); |
5630 | 1047 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1048 found_non_empty: |
5502 | 1049 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1050 if (! all_empty_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1051 ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1052 } |
4915 | 1053 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1054 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1055 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1056 // Now, extract the values from the individual elements and |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1057 // insert them in the result matrix. |
5502 | 1058 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1059 int dv_len = dv.length (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1060 octave_idx_type ntmp = dv_len > 1 ? dv_len : 2; |
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1061 Array<octave_idx_type> ra_idx (dim_vector (ntmp, 1), 0); |
5502 | 1062 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1063 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1064 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1065 octave_quit (); |
5502 | 1066 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1067 tm_row_const row = *p; |
5502 | 1068 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1069 for (tm_row_const::iterator q = row.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1070 q != row.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1071 q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1072 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1073 octave_quit (); |
1741 | 1074 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1075 octave_value elt = *q; |
5502 | 1076 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
1077 if (elt.is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
1078 continue; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
1079 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1080 ctmp = do_cat_op (ctmp, elt, ra_idx); |
5502 | 1081 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1082 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1083 goto done; |
5502 | 1084 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1085 ra_idx (1) += elt.columns (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1086 } |
5502 | 1087 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1088 ra_idx (0) += row.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1089 ra_idx (1) = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1090 } |
5502 | 1091 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1092 retval = ctmp; |
5502 | 1093 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1094 if (frc_str_conv && ! retval.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1095 retval = retval.convert_to_str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1096 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1097 } |
1741 | 1098 } |
1099 | |
1827 | 1100 done: |
1741 | 1101 return retval; |
1102 } | |
1103 | |
5861 | 1104 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
1105 tree_matrix::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1106 symbol_table::context_id context) const |
5861 | 1107 { |
1108 tree_matrix *new_matrix = new tree_matrix (0, line (), column ()); | |
1109 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
1110 for (const_iterator p = begin (); p != end (); p++) |
5861 | 1111 { |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
1112 const tree_argument_list *elt = *p; |
5861 | 1113 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
1114 new_matrix->append (elt ? elt->dup (scope, context) : 0); |
5861 | 1115 } |
1116 | |
1117 new_matrix->copy_base (*this); | |
1118 | |
1119 return new_matrix; | |
1120 } | |
1121 | |
1741 | 1122 void |
2124 | 1123 tree_matrix::accept (tree_walker& tw) |
1741 | 1124 { |
2124 | 1125 tw.visit_matrix (*this); |
1741 | 1126 } |
1127 | |
5794 | 1128 DEFUN (string_fill_char, args, nargout, |
1129 "-*- texinfo -*-\n\ | |
10840 | 1130 @deftypefn {Built-in Function} {@var{val} =} string_fill_char ()\n\ |
5794 | 1131 @deftypefnx {Built-in Function} {@var{old_val} =} string_fill_char (@var{new_val})\n\ |
1132 Query or set the internal variable used to pad all rows of a character\n\ | |
1133 matrix to the same length. It must be a single character. The default\n\ | |
10840 | 1134 value is @code{\" \"} (a single space). For example:\n\ |
3361 | 1135 \n\ |
1136 @example\n\ | |
1137 @group\n\ | |
5794 | 1138 string_fill_char (\"X\");\n\ |
3361 | 1139 [ \"these\"; \"are\"; \"strings\" ]\n\ |
1140 @result{} \"theseXX\"\n\ | |
1141 \"areXXXX\"\n\ | |
1142 \"strings\"\n\ | |
1143 @end group\n\ | |
1144 @end example\n\ | |
5794 | 1145 @end deftypefn") |
1146 { | |
1147 return SET_INTERNAL_VARIABLE (string_fill_char); | |
2172 | 1148 } |
12842
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1149 |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1150 /* |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1151 %!error (string_fill_char (1, 2)); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1152 %!test |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1153 %! orig_val = string_fill_char (); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1154 %! old_val = string_fill_char ("X"); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1155 %! assert (orig_val, old_val); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1156 %! assert (string_fill_char (), "X"); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1157 %! assert (["these"; "are"; "strings"], ["theseXX"; "areXXXX"; "strings"]); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1158 %! string_fill_char (orig_val); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1159 %! assert (string_fill_char (), orig_val); |
a52b4e9f45e3
codesprint: new tests for pt-mat.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1160 */ |