Mercurial > octave
annotate libinterp/octave-value/ov-cell.cc @ 17744:d63878346099
maint: Update copyright notices for release.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 Oct 2013 22:09:27 -0400 |
parents | 1785493171ac |
children | 175b392e91fe |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
3 Copyright (C) 1999-2013 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
3353 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3353 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3353 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
5850 | 28 #include <iomanip> |
3503 | 29 #include <iostream> |
5765 | 30 #include <sstream> |
5164 | 31 #include <vector> |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
32 #include <queue> |
3353 | 33 |
5360 | 34 #include "Array-util.h" |
35 #include "byte-swap.h" | |
3353 | 36 #include "lo-utils.h" |
4153 | 37 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
38 #include "oct-locbuf.h" |
3353 | 39 |
40 #include "defun.h" | |
41 #include "error.h" | |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
42 #include "mxarray.h" |
3353 | 43 #include "ov-cell.h" |
3354 | 44 #include "oct-obj.h" |
3353 | 45 #include "unwind-prot.h" |
3354 | 46 #include "utils.h" |
3928 | 47 #include "ov-base-mat.h" |
48 #include "ov-base-mat.cc" | |
49 #include "ov-re-mat.h" | |
50 #include "ov-scalar.h" | |
5360 | 51 #include "pr-output.h" |
52 #include "ov-scalar.h" | |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
53 #include "gripes.h" |
3928 | 54 |
4687 | 55 #include "ls-oct-ascii.h" |
56 #include "ls-oct-binary.h" | |
57 #include "ls-hdf5.h" | |
58 #include "ls-utils.h" | |
59 | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
60 // Cell is able to handle octave_value indexing by itself, so just forward |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
61 // everything. |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
62 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
63 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
64 octave_value |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
65 octave_base_matrix<Cell>::do_index_op (const octave_value_list& idx, |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
66 bool resize_ok) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
67 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
68 return matrix.index (idx, resize_ok); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
69 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
70 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
71 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
72 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
73 octave_base_matrix<Cell>::assign (const octave_value_list& idx, const Cell& rhs) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
74 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
75 matrix.assign (idx, rhs); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
76 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
77 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
78 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
79 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
80 octave_base_matrix<Cell>::assign (const octave_value_list& idx, octave_value rhs) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
81 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
82 // FIXME: Really? |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
83 if (rhs.is_cell ()) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
84 matrix.assign (idx, rhs.cell_value ()); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
85 else |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
86 matrix.assign (idx, Cell (rhs)); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
87 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
88 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
89 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
90 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
91 octave_base_matrix<Cell>::delete_elements (const octave_value_list& idx) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
92 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
93 matrix.delete_elements (idx); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
94 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
95 |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
96 // FIXME: this list of specializations is becoming so long that we should really ask |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
97 // whether octave_cell should inherit from octave_base_matrix at all. |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
98 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
99 template <> |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
100 octave_value |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
101 octave_base_matrix<Cell>::fast_elem_extract (octave_idx_type n) const |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
102 { |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
103 if (n < matrix.numel ()) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
104 return Cell (matrix(n)); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
105 else |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
106 return octave_value (); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
107 } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
108 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
109 template <> |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
110 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
111 octave_base_matrix<Cell>::fast_elem_insert (octave_idx_type n, |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
112 const octave_value& x) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
113 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
114 const octave_cell *xrep = |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
115 dynamic_cast<const octave_cell *> (&x.get_rep ()); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
116 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
117 bool retval = xrep && xrep->matrix.numel () == 1 && n < matrix.numel (); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
118 if (retval) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
119 matrix(n) = xrep->matrix(0); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
120 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
121 return retval; |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
122 } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
123 |
3928 | 124 template class octave_base_matrix<Cell>; |
3353 | 125 |
126 DEFINE_OCTAVE_ALLOCATOR (octave_cell); | |
127 | |
4612 | 128 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell"); |
3353 | 129 |
6833 | 130 static void |
131 gripe_failed_assignment (void) | |
132 { | |
133 error ("assignment to cell array failed"); | |
134 } | |
135 | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
136 octave_value_list |
4247 | 137 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 const std::list<octave_value_list>& idx, |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
139 int nargout, |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
140 const std::list<octave_lvalue> *lvalue_list) |
3933 | 141 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
142 octave_value_list retval; |
3933 | 143 |
144 switch (type[0]) | |
145 { | |
146 case '(': | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
147 retval(0) = do_index_op (idx.front ()); |
3933 | 148 break; |
149 | |
150 case '{': | |
151 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 octave_value tmp = do_index_op (idx.front ()); |
3933 | 153 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
156 Cell tcell = tmp.cell_value (); |
4582 | 157 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 if (tcell.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 retval(0) = tcell(0,0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
161 retval = octave_value (octave_value_list (tcell), true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 } |
3933 | 163 } |
164 break; | |
165 | |
166 case '.': | |
167 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 170 } |
171 break; | |
172 | |
173 default: | |
174 panic_impossible (); | |
175 } | |
176 | |
5775 | 177 // FIXME -- perhaps there should be an |
4994 | 178 // octave_value_list::next_subsref member function? See also |
179 // octave_user_function::subsref. | |
180 | |
181 if (idx.size () > 1) | |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
182 retval = (lvalue_list |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
183 ? retval(0).next_subsref (nargout, type, idx, lvalue_list) |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
184 : retval(0).next_subsref (nargout, type, idx)); |
4994 | 185 |
186 return retval; | |
3933 | 187 } |
188 | |
189 octave_value | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
190 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 bool auto_add) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
193 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
194 octave_value retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
195 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
196 switch (type[0]) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
197 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
198 case '(': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
199 retval = do_index_op (idx.front (), auto_add); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
200 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
201 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
202 case '{': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
203 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 octave_value tmp = do_index_op (idx.front (), auto_add); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
205 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 const Cell tcell = tmp.cell_value (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
209 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 if (tcell.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
211 retval = tcell(0,0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
212 else |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
213 retval = octave_value (octave_value_list (tcell), true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
214 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
215 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
216 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
217 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
218 case '.': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
219 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
220 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
221 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
222 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
223 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
224 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
225 default: |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
226 panic_impossible (); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
227 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
228 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
229 // FIXME -- perhaps there should be an |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
230 // octave_value_list::next_subsref member function? See also |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
231 // octave_user_function::subsref. |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
232 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
233 if (idx.size () > 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
234 retval = retval.next_subsref (auto_add, type, idx); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
235 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
236 return retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
237 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
238 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
239 octave_value |
4247 | 240 octave_cell::subsasgn (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 const octave_value& rhs) |
3933 | 243 { |
244 octave_value retval; | |
245 | |
246 int n = type.length (); | |
247 | |
248 octave_value t_rhs = rhs; | |
249 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
250 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
251 |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
252 if (idx.front ().empty ()) |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
253 { |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
254 error ("missing index in indexed assignment"); |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
255 return retval; |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
256 } |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
257 |
3933 | 258 if (n > 1) |
259 { | |
260 switch (type[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
262 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
263 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
264 if (is_empty () && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
265 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
266 // Allow conversion of empty cell array to some other |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
267 // type in cases like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 // |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
269 // x = {}; x(i).f = rhs |
3933 | 270 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 octave_value tmp = octave_value::empty_conv (type, rhs); |
3933 | 272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
273 return tmp.subsasgn (type, idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
274 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 octave_value tmp = do_index_op (idx.front (), true); |
3933 | 278 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 if (! tmp.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 tmp = octave_value::empty_conv (type.substr (1), rhs); |
3933 | 281 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
283 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 std::list<octave_value_list> next_idx (idx); |
4362 | 285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 next_idx.erase (next_idx.begin ()); |
6767 | 287 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 tmp.make_unique (); |
6767 | 289 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
290 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 } |
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 break; |
3933 | 295 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 { |
9106
1eb5b24186b6
fix nested cell assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
298 matrix.make_unique (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 Cell tmpc = matrix.index (idx.front (), true); |
3933 | 300 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 { |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
303 std::list<octave_value_list> next_idx (idx); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
304 |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
305 next_idx.erase (next_idx.begin ()); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
306 |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
307 std::string next_type = type.substr (1); |
3933 | 308 |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
309 if (tmpc.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 octave_value tmp = tmpc(0); |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
312 tmpc = Cell (); |
3933 | 313 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 if (! tmp.is_defined () || tmp.is_zero_by_zero ()) |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
315 { |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
316 tmp = octave_value::empty_conv (type.substr (1), rhs); |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
317 tmp.make_unique (); // probably a no-op. |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
318 } |
8452
d6a349c7bd39
fix {} assigment if error occurs on subsequent assignment component
Jaroslav Hajek <highegg@gmail.com>
parents:
8446
diff
changeset
|
319 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
320 // optimization: ignore the copy still stored inside our array. |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
321 tmp.make_unique (1); |
4519 | 322 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
323 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 t_rhs = tmp.subsasgn (next_type, next_idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
325 } |
8446
7b25349b32e6
avoid redundant copying in {} assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
326 else |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
327 gripe_indexed_cs_list (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
328 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 break; |
3933 | 331 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
332 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
333 { |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
334 if (is_empty ()) |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
335 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
336 // Do nothing; the next branch will handle it. |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
337 } |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
338 else |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
339 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
340 std::string nm = type_name (); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
341 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
342 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
344 break; |
3933 | 345 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 } |
3933 | 349 } |
350 | |
3940 | 351 if (! error_state) |
3933 | 352 { |
3940 | 353 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
356 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 octave_value_list i = idx.front (); |
3933 | 358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 if (t_rhs.is_cell ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 octave_base_matrix<Cell>::assign (i, t_rhs.cell_value ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
361 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 if (t_rhs.is_null_value ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 octave_base_matrix<Cell>::delete_elements (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 octave_base_matrix<Cell>::assign (i, Cell (t_rhs)); |
3933 | 366 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
373 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
375 break; |
3933 | 376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 case '{': |
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 octave_value_list idxf = idx.front (); |
3933 | 380 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 if (t_rhs.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
383 Cell tmp_cell = Cell (t_rhs.list_value ()); |
5846 | 384 |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
385 // Inquire the proper shape of the RHS. |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
386 |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
387 dim_vector didx = dims ().redim (idxf.length ()); |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
388 for (octave_idx_type k = 0; k < idxf.length (); k++) |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
389 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); |
7040 | 390 |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
391 if (didx.numel () == tmp_cell.numel ()) |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
392 tmp_cell = tmp_cell.reshape (didx); |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
393 |
5846 | 394 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 octave_base_matrix<Cell>::assign (idxf, tmp_cell); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
397 else if (idxf.all_scalars () || do_index_op (idxf, true).numel () == 1) |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8452
diff
changeset
|
398 // Regularize a null matrix if stored into a cell. |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
399 octave_base_matrix<Cell>::assign (idxf, Cell (t_rhs.storable_value ())); |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8452
diff
changeset
|
400 else if (! error_state) |
10030
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
401 gripe_nonbraced_cs_list_assignment (); |
3933 | 402 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
403 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
405 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
411 break; |
3933 | 412 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
414 { |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
415 if (is_empty ()) |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
416 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
417 // Allow conversion of empty cell array to some other |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
418 // type in cases like |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
419 // |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
420 // x = {}; x.f = rhs |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
421 |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
422 octave_value tmp = octave_value::empty_conv (type, rhs); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
423 |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
424 return tmp.subsasgn (type, idx, rhs); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
425 } |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
426 else |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
427 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
428 std::string nm = type_name (); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
429 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
430 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
431 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
432 break; |
3933 | 433 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
434 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
435 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
436 } |
3933 | 437 } |
438 | |
439 return retval; | |
440 } | |
441 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
442 bool |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
443 octave_cell::is_cellstr (void) const |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
444 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
445 bool retval; |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
446 if (cellstr_cache.get ()) |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
447 retval = true; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
448 else |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
449 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
450 retval = matrix.is_cellstr (); |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
451 // Allocate empty cache to mark that this is indeed a cellstr. |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
452 if (retval) |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
453 cellstr_cache.reset (new Array<std::string> ()); |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
454 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
455 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
456 return retval; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
457 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
458 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
459 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
460 octave_cell::assign (const octave_value_list& idx, const Cell& rhs) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
461 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
462 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
463 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
464 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
465 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
466 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
467 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
468 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
469 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
470 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
471 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
472 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
473 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
474 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
475 octave_cell::delete_elements (const octave_value_list& idx) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
476 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
477 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
478 octave_base_matrix<Cell>::delete_elements (idx); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
479 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
480 |
4791 | 481 size_t |
482 octave_cell::byte_size (void) const | |
483 { | |
484 size_t retval = 0; | |
485 | |
5275 | 486 for (octave_idx_type i = 0; i < numel (); i++) |
4791 | 487 retval += matrix(i).byte_size (); |
488 | |
489 return retval; | |
490 } | |
491 | |
8732 | 492 octave_value |
493 octave_cell::sort (octave_idx_type dim, sortmode mode) const | |
494 { | |
495 octave_value retval; | |
496 | |
497 if (is_cellstr ()) | |
498 { | |
499 Array<std::string> tmp = cellstr_value (); | |
500 | |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
501 tmp = tmp.sort (dim, mode); |
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
502 |
8825
c3445f1c8cb4
reuse cellstr cache in strcmp
Jaroslav Hajek <highegg@gmail.com>
parents:
8824
diff
changeset
|
503 // We already have the cache. |
c3445f1c8cb4
reuse cellstr cache in strcmp
Jaroslav Hajek <highegg@gmail.com>
parents:
8824
diff
changeset
|
504 retval = new octave_cell (tmp); |
8732 | 505 } |
506 else | |
507 error ("sort: only cell arrays of character strings may be sorted"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
508 |
8732 | 509 return retval; |
510 } | |
511 | |
512 octave_value | |
513 octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 sortmode mode) const |
8732 | 515 { |
516 octave_value retval; | |
517 | |
518 if (is_cellstr ()) | |
519 { | |
520 Array<std::string> tmp = cellstr_value (); | |
521 | |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
522 tmp = tmp.sort (sidx, dim, mode); |
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
523 |
9338
650c7efa7234
simplify octave_cell::sort
Jaroslav Hajek <highegg@gmail.com>
parents:
9286
diff
changeset
|
524 // We already have the cache. |
650c7efa7234
simplify octave_cell::sort
Jaroslav Hajek <highegg@gmail.com>
parents:
9286
diff
changeset
|
525 retval = new octave_cell (tmp); |
8732 | 526 } |
527 else | |
528 error ("sort: only cell arrays of character strings may be sorted"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
529 |
8732 | 530 return retval; |
531 } | |
532 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
533 sortmode |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
534 octave_cell::is_sorted (sortmode mode) const |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
535 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
536 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
537 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
538 if (is_cellstr ()) |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
539 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
540 Array<std::string> tmp = cellstr_value (); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
541 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
542 retval = tmp.is_sorted (mode); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
543 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
544 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
545 error ("issorted: A is not a cell array of strings"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
546 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
547 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
548 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
549 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
550 |
8732 | 551 Array<octave_idx_type> |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8732
diff
changeset
|
552 octave_cell::sort_rows_idx (sortmode mode) const |
8732 | 553 { |
554 Array<octave_idx_type> retval; | |
555 | |
556 if (is_cellstr ()) | |
557 { | |
558 Array<std::string> tmp = cellstr_value (); | |
559 | |
560 retval = tmp.sort_rows_idx (mode); | |
561 } | |
562 else | |
563 error ("sortrows: only cell arrays of character strings may be sorted"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
564 |
8732 | 565 return retval; |
566 } | |
567 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
568 sortmode |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
569 octave_cell::is_sorted_rows (sortmode mode) const |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
570 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
571 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
572 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
573 if (is_cellstr ()) |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
574 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
575 Array<std::string> tmp = cellstr_value (); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
576 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
577 retval = tmp.is_sorted_rows (mode); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
578 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
579 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
580 error ("issorted: A is not a cell array of strings"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
581 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
582 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
583 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
584 |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
585 bool |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
586 octave_cell::is_true (void) const |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
587 { |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
588 error ("invalid conversion from cell array to logical value"); |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
589 return false; |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
590 } |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
591 |
3933 | 592 octave_value_list |
593 octave_cell::list_value (void) const | |
594 { | |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
595 return octave_value_list (matrix); |
3933 | 596 } |
597 | |
4243 | 598 string_vector |
5715 | 599 octave_cell::all_strings (bool pad) const |
4243 | 600 { |
4358 | 601 string_vector retval; |
602 | |
7285 | 603 octave_idx_type nel = numel (); |
4243 | 604 |
4358 | 605 int n_elts = 0; |
606 | |
5275 | 607 octave_idx_type max_len = 0; |
4358 | 608 |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
609 std::queue<string_vector> strvec_queue; |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
610 |
7285 | 611 for (octave_idx_type i = 0; i < nel; i++) |
4358 | 612 { |
7285 | 613 string_vector s = matrix(i).all_strings (); |
614 | |
615 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
616 return retval; |
4358 | 617 |
7285 | 618 octave_idx_type s_len = s.length (); |
4358 | 619 |
7285 | 620 n_elts += s_len ? s_len : 1; |
4358 | 621 |
7285 | 622 octave_idx_type s_max_len = s.max_length (); |
4358 | 623 |
7285 | 624 if (s_max_len > max_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
625 max_len = s_max_len; |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
626 |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
627 strvec_queue.push (s); |
4358 | 628 } |
629 | |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
630 retval = string_vector (n_elts); |
4243 | 631 |
5275 | 632 octave_idx_type k = 0; |
4243 | 633 |
7285 | 634 for (octave_idx_type i = 0; i < nel; i++) |
4243 | 635 { |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
636 const string_vector s = strvec_queue.front (); |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
637 strvec_queue.pop (); |
7285 | 638 |
639 octave_idx_type s_len = s.length (); | |
4358 | 640 |
7285 | 641 if (s_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
642 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
643 for (octave_idx_type j = 0; j < s_len; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
644 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
645 std::string t = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
646 int t_len = t.length (); |
5715 | 647 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
648 if (pad && max_len > t_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
649 t += std::string (max_len - t_len, ' '); |
5715 | 650 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
651 retval[k++] = t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
653 } |
7285 | 654 else if (pad) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
655 retval[k++] = std::string (max_len, ' '); |
7285 | 656 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
657 retval[k++] = std::string (); |
4243 | 658 } |
659 | |
660 return retval; | |
661 } | |
662 | |
8732 | 663 Array<std::string> |
664 octave_cell::cellstr_value (void) const | |
665 { | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
666 Array<std::string> retval; |
8732 | 667 |
668 if (is_cellstr ()) | |
669 { | |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
670 if (cellstr_cache->is_empty ()) |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
671 *cellstr_cache = matrix.cellstr_value (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
672 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
673 return *cellstr_cache; |
8732 | 674 } |
675 else | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
676 error ("invalid conversion from cell array to array of strings"); |
8732 | 677 |
678 return retval; | |
679 } | |
680 | |
4604 | 681 bool |
682 octave_cell::print_as_scalar (void) const | |
683 { | |
11474 | 684 return true; |
4604 | 685 } |
686 | |
3933 | 687 void |
688 octave_cell::print (std::ostream& os, bool) const | |
689 { | |
690 print_raw (os); | |
691 } | |
692 | |
693 void | |
694 octave_cell::print_raw (std::ostream& os, bool) const | |
695 { | |
4587 | 696 int nd = matrix.ndims (); |
4513 | 697 |
4587 | 698 if (nd == 2) |
4513 | 699 { |
5275 | 700 octave_idx_type nr = rows (); |
701 octave_idx_type nc = columns (); | |
4513 | 702 |
703 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
704 { |
11474 | 705 newline (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
706 indent (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 os << "{"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
708 newline (os); |
4513 | 709 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
710 increment_indent_level (); |
4513 | 711 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
712 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
713 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
714 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
715 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
716 octave_quit (); |
4513 | 717 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
718 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
719 buf << "[" << i+1 << "," << j+1 << "]"; |
3933 | 720 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
721 octave_value val = matrix(i,j); |
4513 | 722 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
723 val.print_with_name (os, buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
725 } |
4513 | 726 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 decrement_indent_level (); |
4513 | 728 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
729 indent (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 os << "}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
731 newline (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
732 } |
4513 | 733 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
734 { |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
735 indent (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
736 os << "{}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 if (Vprint_empty_dimensions) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
738 os << "(" << nr << "x" << nc << ")"; |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
739 newline (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 } |
4513 | 741 } |
742 else | |
3933 | 743 { |
744 indent (os); | |
4513 | 745 dim_vector dv = matrix.dims (); |
4587 | 746 os << "{" << dv.str () << " Cell Array}"; |
3933 | 747 newline (os); |
748 } | |
749 } | |
750 | |
4687 | 751 #define CELL_ELT_TAG "<cell-element>" |
752 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
753 bool |
6974 | 754 octave_cell::save_ascii (std::ostream& os) |
4687 | 755 { |
756 dim_vector d = dims (); | |
757 if (d.length () > 2) | |
758 { | |
759 os << "# ndims: " << d.length () << "\n"; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
760 |
5275 | 761 for (int i = 0; i < d.length (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 os << " " << d (i); |
4687 | 763 os << "\n"; |
764 | |
765 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
766 |
5275 | 767 for (octave_idx_type i = 0; i < d.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
768 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
769 octave_value o_val = tmp.elem (i); |
4687 | 770 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
771 // Recurse to print sub-value. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
772 bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
773 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
774 if (! b) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
775 return os; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
776 } |
4687 | 777 } |
778 else | |
779 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
780 // Keep this case, rather than use generic code above for backward |
4687 | 781 // compatiability. Makes load_ascii much more complex!! |
782 os << "# rows: " << rows () << "\n" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
783 << "# columns: " << columns () << "\n"; |
4687 | 784 |
785 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
786 |
5275 | 787 for (octave_idx_type j = 0; j < tmp.cols (); j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
788 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
789 for (octave_idx_type i = 0; i < tmp.rows (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 octave_value o_val = tmp.elem (i, j); |
4687 | 792 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
793 // Recurse to print sub-value. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
794 bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
795 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
796 if (! b) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
797 return os; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
799 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
800 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
801 } |
4687 | 802 } |
803 | |
804 return true; | |
805 } | |
806 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
807 bool |
4687 | 808 octave_cell::load_ascii (std::istream& is) |
809 { | |
810 bool success = true; | |
5099 | 811 |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
812 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
813 |
5099 | 814 string_vector keywords(2); |
4687 | 815 |
5099 | 816 keywords[0] = "ndims"; |
817 keywords[1] = "rows"; | |
818 | |
819 std::string kw; | |
5275 | 820 octave_idx_type val = 0; |
5099 | 821 |
822 if (extract_keyword (is, keywords, kw, val, true)) | |
4687 | 823 { |
5099 | 824 if (kw == "ndims") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
825 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
826 int mdims = static_cast<int> (val); |
4687 | 827 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
828 if (mdims >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
829 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
830 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
831 dv.resize (mdims); |
5099 | 832 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
833 for (int i = 0; i < mdims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
834 is >> dv(i); |
4687 | 835 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
836 Cell tmp(dv); |
4687 | 837 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
838 for (octave_idx_type i = 0; i < dv.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
839 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
840 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
841 bool dummy; |
5099 | 842 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
843 // recurse to read cell elements |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
844 std::string nm = read_ascii_data (is, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 dummy, t2, i); |
4687 | 846 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
847 if (nm == CELL_ELT_TAG) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
848 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
849 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
850 tmp.elem (i) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
851 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
852 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
853 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
854 error ("load: cell array element had unexpected name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
855 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
856 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
857 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
858 } |
4687 | 859 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
860 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
861 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
863 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
864 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
868 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
869 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
870 error ("load: failed to extract number of rows and columns"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
873 } |
5099 | 874 else if (kw == "rows") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
875 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
876 octave_idx_type nr = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 octave_idx_type nc = 0; |
5099 | 878 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 if (nr > 0 && nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 Cell tmp (nr, nc); |
5099 | 884 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
885 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
886 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
888 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
890 bool dummy; |
5099 | 891 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
892 // recurse to read cell elements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
893 std::string nm = read_ascii_data (is, std::string (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
894 dummy, t2, i); |
5099 | 895 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 if (nm == CELL_ELT_TAG) |
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 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 tmp.elem (i, j) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
900 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
902 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 error ("load: cell array element had unexpected name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
904 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
905 goto cell_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
906 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
907 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
909 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 cell_read_error: |
5099 | 911 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
912 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
913 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
915 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
916 error ("load: failed to load cell element"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
918 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
919 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
920 else if (nr == 0 || nc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 matrix = Cell (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
922 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
924 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
925 else |
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 error ("load: failed to extract number of rows and columns for cell array"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
928 success = false; |
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 } |
4687 | 931 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
932 panic_impossible (); |
4687 | 933 } |
934 else | |
935 { | |
5099 | 936 error ("load: failed to extract number of rows and columns"); |
937 success = false; | |
4687 | 938 } |
939 | |
940 return success; | |
941 } | |
942 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
943 bool |
4687 | 944 octave_cell::save_binary (std::ostream& os, bool& save_as_floats) |
945 { | |
946 dim_vector d = dims (); | |
947 if (d.length () < 1) | |
948 return false; | |
949 | |
950 // Use negative value for ndims | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
951 int32_t di = - d.length (); |
5760 | 952 os.write (reinterpret_cast<char *> (&di), 4); |
5275 | 953 for (int i = 0; i < d.length (); i++) |
4687 | 954 { |
955 di = d(i); | |
5760 | 956 os.write (reinterpret_cast<char *> (&di), 4); |
4687 | 957 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
958 |
4687 | 959 Cell tmp = cell_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
960 |
5275 | 961 for (octave_idx_type i = 0; i < d.numel (); i++) |
4687 | 962 { |
963 octave_value o_val = tmp.elem (i); | |
964 | |
965 // Recurse to print sub-value. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
966 bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
967 save_as_floats); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
968 |
4687 | 969 if (! b) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
970 return false; |
4687 | 971 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
972 |
4687 | 973 return true; |
974 } | |
975 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
976 bool |
4687 | 977 octave_cell::load_binary (std::istream& is, bool swap, |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
978 oct_mach_info::float_format fmt) |
4687 | 979 { |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
980 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
981 |
4687 | 982 bool success = true; |
5828 | 983 int32_t mdims; |
5760 | 984 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 985 return false; |
986 if (swap) | |
4944 | 987 swap_bytes<4> (&mdims); |
4687 | 988 if (mdims >= 0) |
989 return false; | |
990 | |
991 mdims = -mdims; | |
5828 | 992 int32_t di; |
4687 | 993 dim_vector dv; |
994 dv.resize (mdims); | |
995 | |
996 for (int i = 0; i < mdims; i++) | |
997 { | |
5760 | 998 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
999 return false; |
4687 | 1000 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1001 swap_bytes<4> (&di); |
4687 | 1002 dv(i) = di; |
1003 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1004 |
5157 | 1005 // Convert an array with a single dimension to be a row vector. |
1006 // Octave should never write files like this, other software | |
1007 // might. | |
1008 | |
1009 if (mdims == 1) | |
1010 { | |
1011 mdims = 2; | |
1012 dv.resize (mdims); | |
1013 dv(1) = dv(0); | |
1014 dv(0) = 1; | |
1015 } | |
1016 | |
5275 | 1017 octave_idx_type nel = dv.numel (); |
4687 | 1018 Cell tmp(dv); |
1019 | |
5275 | 1020 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 1021 { |
1022 octave_value t2; | |
1023 bool dummy; | |
1024 std::string doc; | |
1025 | |
1026 // recurse to read cell elements | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1027 std::string nm = read_binary_data (is, swap, fmt, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1028 dummy, t2, doc); |
4687 | 1029 |
1030 if (nm == CELL_ELT_TAG) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1031 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1032 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1033 tmp.elem (i) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1034 } |
4687 | 1035 else |
10315
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 error ("load: cell array element had unexpected name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1038 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1039 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1040 } |
4687 | 1041 } |
1042 | |
1043 if (is) | |
1044 matrix = tmp; | |
1045 else | |
1046 { | |
1047 error ("load: failed to load matrix constant"); | |
1048 success = false; | |
1049 } | |
1050 | |
1051 return success; | |
1052 } | |
1053 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1054 void * |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1055 octave_cell::mex_get_data (void) const |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1056 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1057 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1058 return matrix.mex_get_data (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1059 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1060 |
4687 | 1061 #if defined (HAVE_HDF5) |
4815 | 1062 |
4687 | 1063 bool |
1064 octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
1065 { | |
4814 | 1066 dim_vector dv = dims (); |
4837 | 1067 int empty = save_hdf5_empty (loc_id, name, dv); |
1068 if (empty) | |
1069 return (empty > 0); | |
1070 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1071 hsize_t rank = dv.length (); |
4687 | 1072 hid_t space_hid = -1, data_hid = -1, size_hid = -1; |
1073 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1074 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1075 data_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1076 #else |
4687 | 1077 data_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1078 #endif |
4815 | 1079 |
1080 if (data_hid < 0) | |
1081 return false; | |
4687 | 1082 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1083 // Have to save cell array shape, since can't have a |
4814 | 1084 // dataset of groups.... |
4815 | 1085 |
1086 space_hid = H5Screate_simple (1, &rank, 0); | |
1087 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1088 if (space_hid < 0) |
4687 | 1089 { |
1090 H5Gclose (data_hid); | |
1091 return false; | |
1092 } | |
1093 | |
5351 | 1094 OCTAVE_LOCAL_BUFFER (octave_idx_type, hdims, rank); |
4814 | 1095 |
1096 // Octave uses column-major, while HDF5 uses row-major ordering | |
4933 | 1097 for (hsize_t i = 0; i < rank; i++) |
4815 | 1098 hdims[i] = dv(rank-i-1); |
4814 | 1099 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1100 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1101 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1102 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1103 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1104 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1105 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1106 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1107 if (size_hid < 0) |
4687 | 1108 { |
1109 H5Sclose (space_hid); | |
1110 H5Gclose (data_hid); | |
1111 return false; | |
1112 } | |
1113 | |
6276 | 1114 if (H5Dwrite (size_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1115 H5P_DEFAULT, hdims) < 0) |
4687 | 1116 { |
1117 H5Dclose (size_hid); | |
1118 H5Sclose (space_hid); | |
1119 H5Gclose (data_hid); | |
1120 return false; | |
1121 } | |
4815 | 1122 |
4687 | 1123 H5Dclose (size_hid); |
1124 H5Sclose (space_hid); | |
1125 | |
4815 | 1126 // Recursively add each element of the cell to this group. |
1127 | |
4687 | 1128 Cell tmp = cell_value (); |
5850 | 1129 |
1130 octave_idx_type nel = dv.numel (); | |
1131 | |
1132 for (octave_idx_type i = 0; i < nel; i++) | |
4687 | 1133 { |
5765 | 1134 std::ostringstream buf; |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
11431
diff
changeset
|
1135 int digits = static_cast<int> (gnulib::floor (::log10 (static_cast<double> (nel)) + 1.0)); |
5850 | 1136 buf << "_" << std::setw (digits) << std::setfill ('0') << i; |
5765 | 1137 std::string s = buf.str (); |
4687 | 1138 |
5850 | 1139 if (! add_hdf5_data (data_hid, tmp.elem (i), s.c_str (), "", false, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1140 save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1141 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1142 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1143 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1144 } |
4687 | 1145 } |
1146 | |
1147 H5Gclose (data_hid); | |
4815 | 1148 |
4687 | 1149 return true; |
1150 } | |
1151 | |
1152 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9813
diff
changeset
|
1153 octave_cell::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 1154 { |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1155 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1156 |
4687 | 1157 bool retval = false; |
4837 | 1158 |
1159 dim_vector dv; | |
1160 int empty = load_hdf5_empty (loc_id, name, dv); | |
1161 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1162 matrix.resize (dv); |
4837 | 1163 if (empty) |
1164 return (empty > 0); | |
1165 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1166 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1167 hid_t group_id = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1168 #else |
4687 | 1169 hid_t group_id = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1170 #endif |
4687 | 1171 |
1172 if (group_id < 0) | |
1173 return false; | |
1174 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1175 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1176 hid_t data_hid = H5Dopen (group_id, "dims", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1177 #else |
4814 | 1178 hid_t data_hid = H5Dopen (group_id, "dims"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1179 #endif |
4687 | 1180 hid_t space_hid = H5Dget_space (data_hid); |
1181 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1182 if (rank != 1) |
4687 | 1183 { |
4837 | 1184 H5Dclose (data_hid); |
1185 H5Gclose (group_id); | |
4687 | 1186 return false; |
1187 } | |
1188 | |
4814 | 1189 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
1190 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
4815 | 1191 |
4814 | 1192 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
4687 | 1193 |
4815 | 1194 // Octave uses column-major, while HDF5 uses row-major ordering. |
1195 | |
4814 | 1196 dv.resize (hdims[0]); |
4815 | 1197 |
5351 | 1198 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, hdims[0]); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1199 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1200 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1201 H5P_DEFAULT, tmp) < 0) |
4687 | 1202 { |
4837 | 1203 H5Dclose (data_hid); |
1204 H5Gclose (group_id); | |
4687 | 1205 return false; |
1206 } | |
4815 | 1207 |
4687 | 1208 H5Dclose (data_hid); |
1209 H5Gclose (group_id); | |
1210 | |
4815 | 1211 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--) |
4814 | 1212 dv(j) = tmp[i]; |
1213 | |
4687 | 1214 hdf5_callback_data dsub; |
1215 | |
1216 herr_t retval2 = -1; | |
4815 | 1217 |
4814 | 1218 Cell m (dv); |
4815 | 1219 |
4687 | 1220 int current_item = 0; |
4815 | 1221 |
4696 | 1222 hsize_t num_obj = 0; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1223 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1224 group_id = H5Gopen (loc_id, name, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1225 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1226 group_id = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1227 #endif |
5060 | 1228 H5Gget_num_objs (group_id, &num_obj); |
1229 H5Gclose (group_id); | |
4696 | 1230 |
5275 | 1231 for (octave_idx_type i = 0; i < dv.numel (); i++) |
4687 | 1232 { |
4696 | 1233 |
4814 | 1234 if (current_item >= static_cast<int> (num_obj)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1235 retval2 = -1; |
4814 | 1236 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1237 retval2 = H5Giterate (loc_id, name, ¤t_item, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1238 hdf5_read_next_data, &dsub); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1239 |
4687 | 1240 if (retval2 <= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1241 break; |
4814 | 1242 |
1243 octave_value ov = dsub.tc; | |
1244 m.elem (i) = ov; | |
1245 | |
4687 | 1246 } |
1247 | |
1248 if (retval2 >= 0) | |
1249 { | |
1250 matrix = m; | |
1251 retval = true; | |
1252 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1253 |
4687 | 1254 return retval; |
1255 } | |
4815 | 1256 |
4687 | 1257 #endif |
1258 | |
3354 | 1259 DEFUN (iscell, args, , |
3448 | 1260 "-*- texinfo -*-\n\ |
1261 @deftypefn {Built-in Function} {} iscell (@var{x})\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1262 Return true if @var{x} is a cell array object.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1263 @seealso{ismatrix, isstruct, iscellstr, isa}\n\ |
3448 | 1264 @end deftypefn") |
3354 | 1265 { |
1266 octave_value retval; | |
1267 | |
1268 if (args.length () == 1) | |
1269 retval = args(0).is_cell (); | |
1270 else | |
5823 | 1271 print_usage (); |
3354 | 1272 |
1273 return retval; | |
1274 } | |
1275 | |
1276 DEFUN (cell, args, , | |
3448 | 1277 "-*- texinfo -*-\n\ |
12715
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1278 @deftypefn {Built-in Function} {} cell (@var{n})\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1279 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n})\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1280 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n}, @var{k}, @dots{})\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1281 @deftypefnx {Built-in Function} {} cell ([@var{m} @var{n} @dots{}])\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1282 Create a new cell array object.\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1283 If invoked with a single scalar integer argument, return a square\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1284 @nospell{NxN} cell array. If invoked with two or more scalar\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1285 integer arguments, or a vector of integer values, return an array with\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1286 the given dimensions.\n\ |
3448 | 1287 @end deftypefn") |
3354 | 1288 { |
1289 octave_value retval; | |
1290 | |
1291 int nargin = args.length (); | |
1292 | |
4563 | 1293 dim_vector dims; |
1294 | |
3354 | 1295 switch (nargin) |
1296 { | |
4563 | 1297 case 0: |
1298 dims = dim_vector (0, 0); | |
3354 | 1299 break; |
1300 | |
4563 | 1301 case 1: |
1302 get_dimensions (args(0), "cell", dims); | |
3354 | 1303 break; |
1304 | |
1305 default: | |
4563 | 1306 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1307 dims.resize (nargin); |
4563 | 1308 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1309 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1311 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); |
4563 | 1312 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1313 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1314 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1315 error ("cell: expecting scalar arguments"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1316 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1317 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1318 } |
4563 | 1319 } |
3354 | 1320 break; |
1321 } | |
1322 | |
4563 | 1323 if (! error_state) |
1324 { | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1325 dims.chop_trailing_singletons (); |
4563 | 1326 |
1327 check_dimensions (dims, "cell"); | |
1328 | |
1329 if (! error_state) | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1330 retval = Cell (dims, Matrix ()); |
4563 | 1331 } |
1332 | |
3354 | 1333 return retval; |
1334 } | |
1335 | |
4610 | 1336 DEFUN (iscellstr, args, , |
1337 "-*- texinfo -*-\n\ | |
1338 @deftypefn {Built-in Function} {} iscellstr (@var{cell})\n\ | |
1339 Return true if every element of the cell array @var{cell} is a\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1340 character string.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1341 @seealso{ischar}\n\ |
4610 | 1342 @end deftypefn") |
1343 { | |
4699 | 1344 octave_value retval; |
4610 | 1345 |
1346 if (args.length () == 1) | |
6116 | 1347 retval = args(0).is_cellstr (); |
4610 | 1348 else |
5823 | 1349 print_usage (); |
4610 | 1350 |
1351 return retval; | |
1352 } | |
1353 | |
4817 | 1354 // Note that since Fcellstr calls Fiscellstr, we need to have |
1355 // Fiscellstr defined first (to provide a declaration) and also we | |
1356 // should keep it in the same file (so we don't have to provide a | |
1357 // declaration) and so we don't have to use feval to call it. | |
1358 | |
1359 DEFUN (cellstr, args, , | |
1360 "-*- texinfo -*-\n\ | |
1361 @deftypefn {Built-in Function} {} cellstr (@var{string})\n\ | |
1362 Create a new cell array object from the elements of the string\n\ | |
1363 array @var{string}.\n\ | |
1364 @end deftypefn") | |
1365 { | |
1366 octave_value retval; | |
1367 | |
1368 if (args.length () == 1) | |
1369 { | |
1370 octave_value_list tmp = Fiscellstr (args, 1); | |
1371 | |
1372 if (tmp(0).is_true ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1373 retval = args(0); |
4817 | 1374 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1375 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1376 string_vector s = args(0).all_strings (); |
4817 | 1377 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1378 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1379 retval = (s.is_empty () |
7813 | 1380 ? Cell (octave_value (std::string ())) |
1381 : Cell (s, true)); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1382 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1383 error ("cellstr: argument STRING must be a 2-D character array"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1384 } |
4817 | 1385 } |
1386 else | |
5823 | 1387 print_usage (); |
4817 | 1388 |
1389 return retval; | |
1390 } | |
1391 | |
4762 | 1392 DEFUN (struct2cell, args, , |
1393 "-*- texinfo -*-\n\ | |
1394 @deftypefn {Built-in Function} {} struct2cell (@var{S})\n\ | |
1395 Create a new cell array from the objects stored in the struct object.\n\ | |
4764 | 1396 If @var{f} is the number of fields in the structure, the resulting\n\ |
1397 cell array will have a dimension vector corresponding to\n\ | |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10670
diff
changeset
|
1398 @code{[@var{F} size(@var{S})]}. For example:\n\ |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1399 \n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1400 @example\n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1401 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1402 s = struct (\"name\", @{\"Peter\", \"Hannah\", \"Robert\"@},\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1403 \"age\", @{23, 16, 3@});\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1404 c = struct2cell (s)\n\ |
15877
596b26e11ddb
fix bug #38010 struct2cell documentation error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15195
diff
changeset
|
1405 @result{} c = @{2x1x3 Cell Array@}\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1406 c(1,1,:)(:)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1407 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1408 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1409 [1,1] = Peter\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1410 [2,1] = Hannah\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1411 [3,1] = Robert\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1412 @}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1413 c(2,1,:)(:)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1414 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1415 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1416 [1,1] = 23\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1417 [2,1] = 16\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1418 [3,1] = 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1419 @}\n\ |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1420 @end group\n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1421 @end example\n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1422 \n\ |
5642 | 1423 @seealso{cell2struct, fieldnames}\n\ |
1424 @end deftypefn") | |
4762 | 1425 { |
1426 octave_value retval; | |
4764 | 1427 |
4762 | 1428 int nargin = args.length (); |
4764 | 1429 |
4762 | 1430 if (nargin == 1) |
1431 { | |
10772 | 1432 const octave_map m = args(0).map_value (); |
4764 | 1433 |
4762 | 1434 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1435 { |
10772 | 1436 const dim_vector m_dv = m.dims (); |
4764 | 1437 |
10772 | 1438 octave_idx_type num_fields = m.nfields (); |
4764 | 1439 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1440 // The resulting dim_vector should have dimensions: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1441 // [numel(fields) size(struct)] |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1442 // except if the struct is a column vector. |
4764 | 1443 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1444 dim_vector result_dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1445 if (m_dv (m_dv.length () - 1) == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1446 result_dv.resize (m_dv.length ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1447 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1448 result_dv.resize (m_dv.length () + 1); // Add 1 for the fields. |
4764 | 1449 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1450 result_dv(0) = num_fields; |
4762 | 1451 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1452 for (int i = 1; i < result_dv.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1453 result_dv(i) = m_dv(i-1); |
4764 | 1454 |
10772 | 1455 NoAlias<Cell> c (result_dv); |
4764 | 1456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1457 octave_idx_type n_elts = m.numel (); |
4764 | 1458 |
10772 | 1459 // Fill c in one sweep. Note that thanks to octave_map structure, |
1460 // we don't need a key lookup at all. | |
1461 for (octave_idx_type j = 0; j < n_elts; j++) | |
1462 for (octave_idx_type i = 0; i < num_fields; i++) | |
1463 c(i,j) = m.contents(i)(j); | |
4762 | 1464 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1465 retval = c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1466 } |
4762 | 1467 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1468 error ("struct2cell: argument S must be a structure"); |
4762 | 1469 } |
1470 else | |
5823 | 1471 print_usage (); |
4764 | 1472 |
4762 | 1473 return retval; |
1474 } | |
1475 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1476 /* |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1477 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1478 %! keys = cellstr (char (floor (rand (11,10)*24+65)))'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1479 %! vals = cellfun (@(x) mat2cell (rand (19,1), ones (19,1), 1), ... |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1480 %! mat2cell ([1:11]', ones (11,1), 1), "uniformoutput", false)'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1481 %! s = struct ([keys; vals]{:}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1482 %! t = cell2struct ([vals{:}], keys, 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1483 %! assert (s, t); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1484 %! assert (struct2cell (s), [vals{:}]'); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1485 %! assert (fieldnames (s), keys'); |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1486 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1487 |
5900 | 1488 mxArray * |
1489 octave_cell::as_mxArray (void) const | |
1490 { | |
1491 mxArray *retval = new mxArray (dims ()); | |
1492 | |
1493 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); | |
1494 | |
6686 | 1495 mwSize nel = numel (); |
5900 | 1496 |
1497 const octave_value *p = matrix.data (); | |
1498 | |
6686 | 1499 for (mwIndex i = 0; i < nel; i++) |
5900 | 1500 elts[i] = new mxArray (p[i]); |
1501 | |
1502 return retval; | |
1503 } | |
1504 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1505 octave_value |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1506 octave_cell::map (unary_mapper_t umap) const |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1507 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1508 switch (umap) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1509 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1510 #define FORWARD_MAPPER(UMAP) \ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1511 case umap_ ## UMAP: \ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1512 return matrix.UMAP () |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1513 FORWARD_MAPPER (xisalnum); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1514 FORWARD_MAPPER (xisalpha); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1515 FORWARD_MAPPER (xisascii); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1516 FORWARD_MAPPER (xiscntrl); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1517 FORWARD_MAPPER (xisdigit); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1518 FORWARD_MAPPER (xisgraph); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1519 FORWARD_MAPPER (xislower); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1520 FORWARD_MAPPER (xisprint); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1521 FORWARD_MAPPER (xispunct); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1522 FORWARD_MAPPER (xisspace); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1523 FORWARD_MAPPER (xisupper); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1524 FORWARD_MAPPER (xisxdigit); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1525 FORWARD_MAPPER (xtoascii); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1526 FORWARD_MAPPER (xtolower); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1527 FORWARD_MAPPER (xtoupper); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1528 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1529 default: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1530 return octave_base_value::map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1531 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1532 } |