Mercurial > octave
annotate libinterp/corefcn/Cell.cc @ 20555:f90c8372b7ba
eliminate many more simple uses of error_state
* Cell.cc, __ichol__.cc, __ilu__.cc, balance.cc, bsxfun.cc, colloc.cc,
det.cc, dlmread.cc, dynamic-ld.cc, eig.cc, fft.cc, fft2.cc, fftn.cc,
gcd.cc, getgrent.cc, getpwent.cc, givens.cc, hess.cc, input.cc,
levenshtein.cc, load-path.cc, lookup.cc, ls-mat-ascii.cc, ls-mat4.cc,
lsode.cc, lu.cc, max.cc, md5sum.cc, mex.cc, pager.cc, pinv.cc,
pr-output.cc, qz.cc, schur.cc, sparse.cc, sqrtm.cc, str2double.cc,
strfns.cc, sub2ind.cc, sysdep.cc, time.cc, toplev.cc, tril.cc,
tsearch.cc, typecast.cc, __init_gnuplot__.cc, __magick_read__.cc,
__osmesa_print__.cc, amd.cc, audiodevinfo.cc, dmperm.cc, fftw.cc,
symrcm.cc, ov-base-diag.cc, ov-base-sparse.cc, ov-base.cc,
ov-bool-sparse.cc, ov-builtin.cc, ov-complex.cc, ov-cx-diag.cc,
ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc,
ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-lazy-idx.cc, ov-mex-fcn.cc,
ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, op-bm-b.cc, op-bm-bm.cc, op-sbm-b.cc,
op-sbm-bm.cc, op-str-m.cc, op-str-s.cc, oct-parse.in.yy, pt-cbinop.cc,
pt-colon.cc, pt-decl.cc, pt-exp.cc, pt-id.cc, pt-misc.cc,
pt-select.cc, pt-unop.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 19:29:36 -0400 |
parents | dd6345fd8a97 |
children | 8742e0b1cc49 |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19140
diff
changeset
|
3 Copyright (C) 1999-2015 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 | |
4513 | 28 #include "idx-vector.h" |
29 | |
3353 | 30 #include "Cell.h" |
4919 | 31 #include "error.h" |
5602 | 32 #include "gripes.h" |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
33 #include "oct-obj.h" |
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
34 |
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
35 Cell::Cell (const octave_value_list& ovl) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
36 : Array<octave_value> (ovl.cell_value ()) |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
37 { |
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
38 } |
3353 | 39 |
5805 | 40 Cell::Cell (const string_vector& sv, bool trim) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
41 : Array<octave_value> () |
4216 | 42 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
43 octave_idx_type n = sv.numel (); |
4216 | 44 |
45 if (n > 0) | |
46 { | |
4625 | 47 resize (dim_vector (n, 1)); |
4216 | 48 |
5275 | 49 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
50 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
51 std::string s = sv[i]; |
5805 | 52 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
53 if (trim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
54 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
55 size_t pos = s.find_last_not_of (' '); |
5805 | 56 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
57 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
58 } |
5805 | 59 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 elem(i,0) = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
61 } |
4216 | 62 } |
63 } | |
3354 | 64 |
11037
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
65 Cell::Cell (const std::list<std::string>& lst) |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
66 : Array<octave_value> () |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
67 { |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
68 size_t n = lst.size (); |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
69 |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
70 if (n > 0) |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
71 { |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
72 resize (dim_vector (n, 1)); |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
73 |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
74 octave_idx_type i = 0; |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
75 |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
76 for (std::list<std::string>::const_iterator it = lst.begin (); |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
77 it != lst.end (); it++) |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
78 { |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
79 elem(i++,0) = *it; |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
80 } |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
81 } |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
82 } |
e7864673c31f
new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents:
10649
diff
changeset
|
83 |
8732 | 84 Cell::Cell (const Array<std::string>& sa) |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
85 : Array<octave_value> (sa.dims ()) |
8732 | 86 { |
87 octave_idx_type n = sa.numel (); | |
88 | |
89 octave_value *dst = fortran_vec (); | |
90 const std::string *src = sa.data (); | |
91 | |
92 for (octave_idx_type i = 0; i < n; i++) | |
93 dst[i] = src[i]; | |
94 } | |
95 | |
6116 | 96 // Set size to DV, filling with []. Then fill with as many elements of |
97 // SV as possible. | |
7209 | 98 |
6116 | 99 Cell::Cell (const dim_vector& dv, const string_vector& sv, bool trim) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
100 : Array<octave_value> (dv, Matrix ()) |
6116 | 101 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
102 octave_idx_type n = sv.numel (); |
6116 | 103 |
104 if (n > 0) | |
105 { | |
106 octave_idx_type m = numel (); | |
107 | |
108 octave_idx_type len = n > m ? m : n; | |
109 | |
110 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 std::string s = sv[i]; |
6116 | 113 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 if (trim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
116 size_t pos = s.find_last_not_of (' '); |
6116 | 117 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 } |
6116 | 120 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 elem(i) = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 } |
6116 | 123 } |
124 } | |
125 | |
126 bool | |
127 Cell::is_cellstr (void) const | |
128 { | |
129 bool retval = true; | |
130 | |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
131 octave_idx_type n = numel (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
132 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
133 for (octave_idx_type i = 0; i < n; i++) |
6116 | 134 { |
135 if (! elem(i).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 } |
6116 | 140 } |
141 | |
142 return retval; | |
143 } | |
144 | |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
145 Array<std::string> |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
146 Cell::cellstr_value (void) const |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
147 { |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
148 Array<std::string> retval (dims ()); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
149 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
150 octave_idx_type n = numel (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
151 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
152 for (octave_idx_type i = 0; i < n; i++) |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
153 retval.xelem (i) = elem (i).string_value (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
154 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
155 return retval; |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
156 } |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
157 |
4513 | 158 Cell |
4587 | 159 Cell::index (const octave_value_list& idx_arg, bool resize_ok) const |
4513 | 160 { |
161 Cell retval; | |
162 | |
5275 | 163 octave_idx_type n = idx_arg.length (); |
4513 | 164 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
165 // If we catch an indexing error in index_vector, we flag an error |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
166 // in index k. Ensure it is the right value befor each idx_vector |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
167 // call. Same variable as used in for loop in default case. |
5539 | 168 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
169 octave_idx_type k = 0; |
4513 | 170 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
171 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
172 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
173 switch (n) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
174 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
175 case 0: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
176 retval = *this; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
177 break; |
4513 | 178 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
179 case 1: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
180 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
181 idx_vector i = idx_arg(0).index_vector (); |
4513 | 182 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
183 retval = Array<octave_value>::index (i, resize_ok, Matrix ()); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
184 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
185 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
186 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
187 case 2: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
189 idx_vector i = idx_arg(0).index_vector (); |
4919 | 190 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
191 k = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
192 idx_vector j = idx_arg(1).index_vector (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
193 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
194 if (! error_state) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
195 retval = Array<octave_value>::index (i, j, resize_ok, Matrix ()); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
196 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
197 break; |
4513 | 198 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
199 default: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
200 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
201 Array<idx_vector> iv (dim_vector (n, 1)); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
202 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
203 for (k = 0; k < n; k++) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
204 iv(k) = idx_arg(k).index_vector (); |
4513 | 205 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
206 retval = Array<octave_value>::index (iv, resize_ok, Matrix ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
208 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
209 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
210 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
211 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
212 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
213 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
214 e.set_pos_if_unset (n, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
215 throw; |
4513 | 216 } |
217 | |
218 return retval; | |
219 } | |
220 | |
19140
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
221 /* |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
222 %!test |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
223 %! a = {"foo", "bar"}; |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
224 %! assert (a(), a) |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
225 */ |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
226 |
10649
64472dd48517
cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
227 void |
4587 | 228 Cell::assign (const octave_value_list& idx_arg, const Cell& rhs, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
229 const octave_value& fill_val) |
4513 | 230 |
231 { | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
232 octave_idx_type len = idx_arg.length (); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
233 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
234 Array<idx_vector> ra_idx (dim_vector (len, 1)); |
4513 | 235 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
236 for (octave_idx_type i = 0; i < len; i++) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
237 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
238 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
239 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
240 ra_idx(i) = idx_arg(i).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
241 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
242 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
243 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
244 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
245 e.set_pos (len, i+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
246 throw; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
247 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
248 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
249 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
250 Array<octave_value>::assign (ra_idx, rhs, fill_val); |
4513 | 251 } |
252 | |
10649
64472dd48517
cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
253 void |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
254 Cell::delete_elements (const octave_value_list& idx_arg) |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
255 |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
256 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
257 octave_idx_type len = idx_arg.length (); |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
258 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
259 Array<idx_vector> ra_idx (dim_vector (len, 1)); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
260 |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
261 for (octave_idx_type i = 0; i < len; i++) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
262 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
263 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
264 ra_idx.xelem (i) = idx_arg(i).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
265 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
266 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
267 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
268 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
269 e.set_pos (len, i+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
270 throw; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
271 } |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
272 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
273 Array<octave_value>::delete_elements (ra_idx); |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
274 } |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
275 |
5602 | 276 octave_idx_type |
277 Cell::nnz (void) const | |
278 { | |
279 gripe_wrong_type_arg ("nnz", "cell array"); | |
280 return -1; | |
281 } | |
282 | |
19140
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
283 /* |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
284 %!error <wrong type argument 'cell array'> nnz ({0, 1, 2}) |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
285 %!error <wrong type argument 'cell array'> nnz (cell ()) |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
286 %!error <wrong type argument 'cell array'> nnz ({"foo", "bar"}) |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
287 */ |
b5a0f11db158
Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents:
17744
diff
changeset
|
288 |
4915 | 289 Cell |
5570 | 290 Cell::column (octave_idx_type i) const |
291 { | |
292 Cell retval; | |
293 | |
294 if (ndims () < 3) | |
295 { | |
296 if (i < 0 || i >= cols ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 error ("invalid column selection"); |
5570 | 298 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 octave_idx_type nr = rows (); |
5570 | 301 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 retval.resize (dim_vector (nr, 1)); |
5570 | 303 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
304 for (octave_idx_type j = 0; j < nr; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 retval.xelem (j) = elem (j, i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 } |
5570 | 307 } |
308 else | |
309 error ("Cell::column: requires 2-d cell array"); | |
310 | |
311 return retval; | |
312 } | |
313 | |
314 Cell | |
5275 | 315 Cell::concat (const Cell& rb, const Array<octave_idx_type>& ra_idx) |
4806 | 316 { |
5073 | 317 return insert (rb, ra_idx); |
4915 | 318 } |
319 | |
320 Cell& | |
5275 | 321 Cell::insert (const Cell& a, octave_idx_type r, octave_idx_type c) |
4915 | 322 { |
323 Array<octave_value>::insert (a, r, c); | |
324 return *this; | |
325 } | |
326 | |
327 Cell& | |
5275 | 328 Cell::insert (const Cell& a, const Array<octave_idx_type>& ra_idx) |
4915 | 329 { |
330 Array<octave_value>::insert (a, ra_idx); | |
331 return *this; | |
4806 | 332 } |
333 | |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
334 Cell |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
335 Cell::map (ctype_mapper fcn) const |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
336 { |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
337 Cell retval (dims ()); |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
338 octave_value *r = retval.fortran_vec (); |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
339 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
340 const octave_value *p = data (); |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
341 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
342 for (octave_idx_type i = 0; i < numel (); i++) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
343 r[i] = ((p++)->*fcn) (); |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
344 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
345 return retval; |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
346 } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
347 |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
348 Cell |
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
349 Cell::diag (octave_idx_type k) const |
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
350 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9415
diff
changeset
|
351 return Array<octave_value>::diag (k); |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
352 } |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
353 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
354 Cell |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
355 Cell::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
356 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
357 return Array<octave_value>::diag (m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
358 } |