Mercurial > octave
annotate libinterp/octave-value/ov-range.cc @ 21022:ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
* oct-hdf5-types.h (octave_H5E_DEFAULT, octave_H5P_DEFAULT,
octave_H5S_ALL): New global variable declarations.
* coct-hdf5-types.c: New file.
* libinterp/corefcn/module.mk (COREFCN_SRC): Add it to the list.
* ls-hdf5.cc, oct-hdf5.h, ov-base-int.cc, ov-bool-mat.cc,
ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc, ov-class.cc, ov-complex.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-mat.cc, ov-flt-re-mat.cc,
ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc,
ov-str-mat.cc, ov-struct.cc:
Use new variables in place of the corresponding HDF5 macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 31 Dec 2015 13:45:43 -0500 |
parents | 8b8d8c6c0e64 |
children | e39e05d90788 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2376 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2376 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2376 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3503 | 27 #include <iostream> |
2901 | 28 |
2376 | 29 #include "lo-ieee.h" |
30 #include "lo-utils.h" | |
31 | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
32 #include "defun.h" |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
33 #include "variables.h" |
2376 | 34 #include "gripes.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
|
35 #include "mxarray.h" |
2376 | 36 #include "ops.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
37 #include "ovl.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
38 #include "oct-hdf5.h" |
2376 | 39 #include "ov-range.h" |
40 #include "ov-re-mat.h" | |
2410 | 41 #include "ov-scalar.h" |
2376 | 42 #include "pr-output.h" |
43 | |
4687 | 44 #include "byte-swap.h" |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
45 #include "ls-ascii-helper.h" |
4687 | 46 #include "ls-hdf5.h" |
47 #include "ls-utils.h" | |
48 | |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
49 // If TRUE, allow ranges with non-integer elements as array indices. |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
50 static bool Vallow_noninteger_range_as_index = true; |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
51 |
2376 | 52 |
4612 | 53 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_range, "range", "double"); |
2376 | 54 |
5759 | 55 static octave_base_value * |
56 default_numeric_conversion_function (const octave_base_value& a) | |
2376 | 57 { |
58 CAST_CONV_ARG (const octave_range&); | |
59 | |
60 return new octave_matrix (v.matrix_value ()); | |
61 } | |
62 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
63 octave_base_value::type_conv_info |
2376 | 64 octave_range::numeric_conversion_function (void) const |
65 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
66 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
67 octave_matrix::static_type_id ()); |
2376 | 68 } |
69 | |
5759 | 70 octave_base_value * |
2410 | 71 octave_range::try_narrowing_conversion (void) |
72 { | |
5759 | 73 octave_base_value *retval = 0; |
2410 | 74 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
75 switch (range.numel ()) |
2410 | 76 { |
77 case 1: | |
78 retval = new octave_scalar (range.base ()); | |
79 break; | |
80 | |
81 case 0: | |
4417 | 82 retval = new octave_matrix (Matrix (1, 0)); |
2410 | 83 break; |
84 | |
8971 | 85 case -2: |
86 retval = new octave_matrix (range.matrix_value ()); | |
87 break; | |
88 | |
2410 | 89 default: |
90 break; | |
91 } | |
92 | |
93 return retval; | |
94 } | |
95 | |
2436 | 96 octave_value |
4247 | 97 octave_range::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 const std::list<octave_value_list>& idx) |
3933 | 99 { |
100 octave_value retval; | |
101 | |
102 switch (type[0]) | |
103 { | |
104 case '(': | |
105 retval = do_index_op (idx.front ()); | |
106 break; | |
107 | |
108 case '{': | |
109 case '.': | |
110 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 113 } |
114 break; | |
115 | |
116 default: | |
117 panic_impossible (); | |
118 } | |
119 | |
120 return retval.next_subsref (type, idx); | |
121 } | |
122 | |
123 octave_value | |
5885 | 124 octave_range::do_index_op (const octave_value_list& idx, bool resize_ok) |
2436 | 125 { |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
126 if (idx.length () == 1 && ! resize_ok) |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
127 { |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
128 octave_value retval; |
2436 | 129 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
130 // The range can handle a single subscript. |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
131 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
132 try |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
133 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
134 idx_vector i = idx(0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
135 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
136 if (i.is_scalar () && i(0) < range.numel ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
137 retval = range.elem (i(0)); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
138 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
139 retval = range.index (i); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
140 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
141 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
142 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
143 // More info may be added later before displaying error. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
144 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
145 e.set_pos_if_unset (1, 1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20228
diff
changeset
|
146 throw; |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
147 } |
2436 | 148 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
149 return retval; |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
150 } |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
151 else |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
152 { |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
153 octave_value tmp (new octave_matrix (range.matrix_value ())); |
2436 | 154 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
155 return tmp.do_index_op (idx, resize_ok); |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
156 } |
2436 | 157 } |
158 | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
159 idx_vector |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
160 octave_range::index_vector (bool require_integers) const |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
161 { |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
162 if (idx_cache) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
163 return *idx_cache; |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
164 else |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
165 { |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
166 if (require_integers |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
167 || ! Vallow_noninteger_range_as_index |
10616
d61caf612f1e
optimize order of conditions in octave_range::index_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
10613
diff
changeset
|
168 || range.all_elements_are_ints ()) |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
169 return set_idx_cache (idx_vector (range)); |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
170 else |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
171 { |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
172 warning_with_id ("Octave:noninteger-range-as-index", |
10609
58bcda68ac11
improve warning/error message
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
173 "non-integer range used as index"); |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
174 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
175 return octave_value (matrix_value ()).round ().index_vector (); |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
176 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
177 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
178 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
179 |
2376 | 180 double |
181 octave_range::double_value (bool) const | |
182 { | |
4102 | 183 double retval = lo_ieee_nan_value (); |
2376 | 184 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
185 octave_idx_type nel = range.numel (); |
2376 | 186 |
4455 | 187 if (nel > 0) |
188 { | |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
189 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 "range", "real scalar"); |
4455 | 191 |
192 retval = range.base (); | |
193 } | |
2376 | 194 else |
195 gripe_invalid_conversion ("range", "real scalar"); | |
196 | |
197 return retval; | |
198 } | |
199 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
200 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
201 octave_range::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
202 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
203 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
204 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
205 octave_idx_type nel = range.numel (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
206 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
207 if (nel > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
209 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 "range", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
211 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
212 retval = range.base (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
213 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
214 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
215 gripe_invalid_conversion ("range", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
216 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
217 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
218 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
219 |
9146
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
220 charNDArray |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
221 octave_range::char_array_value (bool) const |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
222 { |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
223 const Matrix matrix = range.matrix_value (); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
224 charNDArray retval (dims ()); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
225 |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
226 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
227 |
9146
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
228 for (octave_idx_type i = 0; i < nel; i++) |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
229 retval.elem (i) = static_cast<char>(matrix.elem (i)); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
230 |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
231 return retval; |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
232 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
233 |
2376 | 234 octave_value |
4017 | 235 octave_range::all (int dim) const |
2376 | 236 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
237 // FIXME: this is a potential waste of memory. |
2436 | 238 |
239 Matrix m = range.matrix_value (); | |
240 | |
4017 | 241 return m.all (dim); |
2376 | 242 } |
243 | |
244 octave_value | |
4017 | 245 octave_range::any (int dim) const |
2376 | 246 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
247 // FIXME: this is a potential waste of memory. |
4017 | 248 |
249 Matrix m = range.matrix_value (); | |
250 | |
251 return m.any (dim); | |
2376 | 252 } |
253 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
254 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
255 octave_range::diag (octave_idx_type k) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
256 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
257 return |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
258 (k == 0 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
259 ? octave_value (DiagMatrix (DiagArray2<double> (range.matrix_value ()))) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
260 : octave_value (range.diag (k))); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
261 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
262 |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
263 octave_value |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
264 octave_range::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:
14469
diff
changeset
|
265 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
266 Matrix mat = range.matrix_value (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
267 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
268 return mat.diag (m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
269 } |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
270 |
2376 | 271 bool |
272 octave_range::is_true (void) const | |
273 { | |
274 bool retval = false; | |
2436 | 275 |
20988
8b8d8c6c0e64
Add new member function is_empty to Range type. Use it.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
276 if (! range.is_empty ()) |
2436 | 277 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
278 // FIXME: this is a potential waste of memory. |
2436 | 279 |
280 Matrix m ((range.matrix_value () . all ()) . all ()); | |
281 | |
282 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); | |
283 } | |
284 | |
2376 | 285 return retval; |
286 } | |
287 | |
288 Complex | |
289 octave_range::complex_value (bool) const | |
290 { | |
4102 | 291 double tmp = lo_ieee_nan_value (); |
292 | |
293 Complex retval (tmp, tmp); | |
2376 | 294 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
295 octave_idx_type nel = range.numel (); |
2376 | 296 |
4455 | 297 if (nel > 0) |
298 { | |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
299 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 "range", "complex scalar"); |
4455 | 301 |
302 retval = range.base (); | |
303 } | |
2376 | 304 else |
305 gripe_invalid_conversion ("range", "complex scalar"); | |
306 | |
307 return retval; | |
308 } | |
309 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
310 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
311 octave_range::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
312 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
313 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
314 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
315 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
316 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
317 octave_idx_type nel = range.numel (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
318 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
319 if (nel > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
320 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
321 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
322 "range", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
323 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
324 retval = range.base (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
325 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
326 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
327 gripe_invalid_conversion ("range", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
328 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
329 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
330 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
331 |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
332 boolNDArray |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
333 octave_range::bool_array_value (bool warn) const |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
334 { |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
335 Matrix m = range.matrix_value (); |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
336 |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
337 if (m.any_element_is_nan ()) |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
338 gripe_nan_to_logical_conversion (); |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
339 else if (warn && m.any_element_not_one_or_zero ()) |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
340 gripe_logical_conversion (); |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
341 |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
342 return boolNDArray (m); |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
343 } |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
344 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
345 octave_value |
5731 | 346 octave_range::resize (const dim_vector& dv, bool fill) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
347 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
348 NDArray retval = array_value (); |
5731 | 349 if (fill) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
350 retval.resize (dv, 0); |
5731 | 351 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
352 retval.resize (dv); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
353 return retval; |
5731 | 354 } |
355 | |
2376 | 356 octave_value |
5279 | 357 octave_range::convert_to_str_internal (bool pad, bool force, char type) const |
2449 | 358 { |
359 octave_value tmp (range.matrix_value ()); | |
5279 | 360 return tmp.convert_to_str (pad, force, type); |
2449 | 361 } |
362 | |
2376 | 363 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18132
diff
changeset
|
364 octave_range::print (std::ostream& os, bool pr_as_read_syntax) |
2901 | 365 { |
366 print_raw (os, pr_as_read_syntax); | |
367 newline (os); | |
368 } | |
369 | |
370 void | |
3523 | 371 octave_range::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
2901 | 372 { |
373 octave_print_internal (os, range, pr_as_read_syntax, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 current_print_indent_level ()); |
2901 | 375 } |
376 | |
377 bool | |
3523 | 378 octave_range::print_name_tag (std::ostream& os, const std::string& name) const |
2376 | 379 { |
2901 | 380 bool retval = false; |
381 | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
382 octave_idx_type n = range.numel (); |
2901 | 383 |
384 indent (os); | |
385 | |
386 if (n == 0 || n == 1) | |
387 os << name << " = "; | |
388 else | |
389 { | |
390 os << name << " ="; | |
391 newline (os); | |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
392 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
393 newline (os); |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
394 |
2901 | 395 retval = true; |
396 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
397 |
2901 | 398 return retval; |
2376 | 399 } |
400 | |
17870 | 401 void |
402 octave_range::short_disp (std::ostream& os) const | |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
403 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
404 octave_idx_type len = range.numel (); |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
405 |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
406 if (len == 0) |
17870 | 407 os << "[]"; |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
408 else |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
409 { |
17870 | 410 os << range.base () << ":"; |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
411 |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
412 if (len > 1) |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
413 { |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
414 if (range.inc () != 1) |
17870 | 415 os << range.inc () << ":"; |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
416 |
17870 | 417 os << range.limit (); |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
418 } |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
419 } |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
420 } |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
421 |
4687 | 422 // Skip white space and comments on stream IS. |
423 | |
424 static void | |
425 skip_comments (std::istream& is) | |
426 { | |
427 char c = '\0'; | |
428 while (is.get (c)) | |
429 { | |
430 if (c == ' ' || c == '\t' || c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
431 ; // Skip whitespace on way to beginning of next line. |
4687 | 432 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
433 break; |
4687 | 434 } |
435 | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
436 skip_until_newline (is, false); |
4687 | 437 } |
438 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
439 bool |
6974 | 440 octave_range::save_ascii (std::ostream& os) |
4687 | 441 { |
442 Range r = range_value (); | |
443 double base = r.base (); | |
444 double limit = r.limit (); | |
445 double inc = r.inc (); | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
446 octave_idx_type len = r.numel (); |
4687 | 447 |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
448 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
449 os << "# base, limit, increment\n"; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
450 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
451 os << "# base, length, increment\n"; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
452 |
4687 | 453 octave_write_double (os, base); |
454 os << " "; | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
455 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
456 octave_write_double (os, limit); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
457 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
458 os << len; |
4687 | 459 os << " "; |
460 octave_write_double (os, inc); | |
461 os << "\n"; | |
462 | |
463 return true; | |
464 } | |
465 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
466 bool |
4687 | 467 octave_range::load_ascii (std::istream& is) |
468 { | |
469 // # base, limit, range comment added by save (). | |
470 skip_comments (is); | |
471 | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
472 double base, limit, inc; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
473 is >> base >> limit >> inc; |
4687 | 474 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
475 if (! is) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
476 error ("load: failed to load range constant"); |
4687 | 477 |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
478 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
479 range = Range (base, limit, inc); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
480 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
481 range = Range (base, inc, static_cast<octave_idx_type> (limit)); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
482 |
4687 | 483 return true; |
484 } | |
485 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
486 bool |
4687 | 487 octave_range::save_binary (std::ostream& os, bool& /* save_as_floats */) |
488 { | |
5760 | 489 char tmp = LS_DOUBLE; |
490 os.write (reinterpret_cast<char *> (&tmp), 1); | |
4687 | 491 Range r = range_value (); |
492 double bas = r.base (); | |
493 double lim = r.limit (); | |
494 double inc = r.inc (); | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
495 if (inc == 0) |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
496 lim = r.numel (); |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
497 |
5760 | 498 os.write (reinterpret_cast<char *> (&bas), 8); |
499 os.write (reinterpret_cast<char *> (&lim), 8); | |
500 os.write (reinterpret_cast<char *> (&inc), 8); | |
4687 | 501 |
502 return true; | |
503 } | |
504 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
505 bool |
4687 | 506 octave_range::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 oct_mach_info::float_format /* fmt */) |
4687 | 508 { |
509 char tmp; | |
5760 | 510 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687 | 511 return false; |
512 double bas, lim, inc; | |
5760 | 513 if (! is.read (reinterpret_cast<char *> (&bas), 8)) |
4687 | 514 return false; |
515 if (swap) | |
4944 | 516 swap_bytes<8> (&bas); |
5760 | 517 if (! is.read (reinterpret_cast<char *> (&lim), 8)) |
4687 | 518 return false; |
519 if (swap) | |
4944 | 520 swap_bytes<8> (&lim); |
5760 | 521 if (! is.read (reinterpret_cast<char *> (&inc), 8)) |
4687 | 522 return false; |
523 if (swap) | |
4944 | 524 swap_bytes<8> (&inc); |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
525 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
526 range = Range (bas, lim, inc); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
527 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
528 range = Range (bas, inc, static_cast<octave_idx_type> (lim)); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
529 |
4687 | 530 return true; |
531 } | |
532 | |
533 #if defined (HAVE_HDF5) | |
4944 | 534 |
4687 | 535 // The following subroutines creates an HDF5 representation of the way |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
536 // we will store Octave range types (triplets of floating-point numbers). |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
537 // NUM_TYPE is the HDF5 numeric type to use for storage (e.g. |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
538 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary |
4687 | 539 // conversions are handled automatically by HDF5. |
540 | |
541 static hid_t | |
542 hdf5_make_range_type (hid_t num_type) | |
543 { | |
544 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 3); | |
545 | |
546 H5Tinsert (type_id, "base", 0 * sizeof (double), num_type); | |
547 H5Tinsert (type_id, "limit", 1 * sizeof (double), num_type); | |
548 H5Tinsert (type_id, "increment", 2 * sizeof (double), num_type); | |
549 | |
550 return type_id; | |
551 } | |
552 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
553 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
554 |
4687 | 555 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
556 octave_range::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 bool /* save_as_floats */) |
4687 | 558 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
559 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
560 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
561 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
562 |
4792 | 563 hsize_t dimens[3]; |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17870
diff
changeset
|
564 hid_t space_hid, type_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17870
diff
changeset
|
565 space_hid = type_hid = data_hid = -1; |
4687 | 566 |
4815 | 567 space_hid = H5Screate_simple (0, dimens, 0); |
4687 | 568 if (space_hid < 0) return false; |
569 | |
570 type_hid = hdf5_make_range_type (H5T_NATIVE_DOUBLE); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
571 if (type_hid < 0) |
4687 | 572 { |
573 H5Sclose (space_hid); | |
574 return false; | |
575 } | |
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
|
576 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
577 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20988
diff
changeset
|
578 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
579 #else |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20988
diff
changeset
|
580 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, octave_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
|
581 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
582 if (data_hid < 0) |
4687 | 583 { |
584 H5Sclose (space_hid); | |
585 H5Tclose (type_hid); | |
586 return false; | |
587 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
588 |
4687 | 589 Range r = range_value (); |
590 double range_vals[3]; | |
591 range_vals[0] = r.base (); | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
592 range_vals[1] = r.inc () != 0 ? r.limit () : r.numel (); |
4687 | 593 range_vals[2] = r.inc (); |
594 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20988
diff
changeset
|
595 if (H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
596 range_vals) >= 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
597 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
598 octave_idx_type nel = r.numel (); |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
599 retval = hdf5_add_scalar_attr (data_hid, H5T_NATIVE_IDX, |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
600 "OCTAVE_RANGE_NELEM", &nel) >= 0; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
601 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
602 else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
603 retval = false; |
4687 | 604 |
605 H5Dclose (data_hid); | |
606 H5Tclose (type_hid); | |
607 H5Sclose (space_hid); | |
4837 | 608 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
609 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
610 gripe_save ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
611 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
612 |
4687 | 613 return retval; |
614 } | |
615 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
616 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
617 octave_range::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 618 { |
619 bool retval = false; | |
4837 | 620 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
621 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
622 |
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
|
623 #if HAVE_HDF5_18 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20988
diff
changeset
|
624 hid_t data_hid = H5Dopen (loc_id, name, octave_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
|
625 #else |
4687 | 626 hid_t data_hid = H5Dopen (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
|
627 #endif |
4687 | 628 hid_t type_hid = H5Dget_type (data_hid); |
629 | |
630 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE); | |
631 | |
632 if (! hdf5_types_compatible (type_hid, range_type)) | |
633 { | |
4837 | 634 H5Tclose (range_type); |
4687 | 635 H5Dclose (data_hid); |
636 return false; | |
637 } | |
638 | |
639 hid_t space_hid = H5Dget_space (data_hid); | |
640 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
641 | |
642 if (rank != 0) | |
643 { | |
4837 | 644 H5Tclose (range_type); |
4687 | 645 H5Sclose (space_hid); |
646 H5Dclose (data_hid); | |
647 return false; | |
648 } | |
649 | |
650 double rangevals[3]; | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20988
diff
changeset
|
651 if (H5Dread (data_hid, range_type, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 rangevals) >= 0) |
4687 | 653 { |
654 retval = true; | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
655 octave_idx_type nel; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
656 if (hdf5_get_scalar_attr (data_hid, H5T_NATIVE_IDX, |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
657 "OCTAVE_RANGE_NELEM", &nel)) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
658 range = Range (rangevals[0], rangevals[2], nel); |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
659 else |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
660 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
661 if (rangevals[2] != 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
662 range = Range (rangevals[0], rangevals[1], rangevals[2]); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
663 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
664 range = Range (rangevals[0], rangevals[2], |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
665 static_cast<octave_idx_type> (rangevals[1])); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
666 } |
4687 | 667 } |
668 | |
4837 | 669 H5Tclose (range_type); |
4687 | 670 H5Sclose (space_hid); |
671 H5Dclose (data_hid); | |
4837 | 672 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
673 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
674 gripe_load ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
675 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
676 |
4687 | 677 return retval; |
678 } | |
4944 | 679 |
5900 | 680 mxArray * |
681 octave_range::as_mxArray (void) const | |
682 { | |
683 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL); | |
684 | |
685 double *pr = static_cast<double *> (retval->get_data ()); | |
686 | |
6686 | 687 mwSize nel = numel (); |
5900 | 688 |
689 Matrix m = matrix_value (); | |
690 | |
691 const double *p = m.data (); | |
692 | |
6686 | 693 for (mwSize i = 0; i < nel; i++) |
5900 | 694 pr[i] = p[i]; |
695 | |
696 return retval; | |
697 } | |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
698 |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
699 octave_value |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
700 octave_range::fast_elem_extract (octave_idx_type n) const |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
701 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
702 return (n < range.numel ()) ? octave_value (range.elem (n)) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
703 : octave_value (); |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
704 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
705 |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
706 DEFUN (allow_noninteger_range_as_index, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
707 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
708 @deftypefn {} {@var{val} =} allow_noninteger_range_as_index ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
709 @deftypefnx {} {@var{old_val} =} allow_noninteger_range_as_index (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
710 @deftypefnx {} {} allow_noninteger_range_as_index (@var{new_val}, \"local\")\n\ |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
711 Query or set the internal variable that controls whether non-integer\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
712 ranges are allowed as indices.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
713 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
714 This might be useful for @sc{matlab} compatibility; however, it is still not\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
715 entirely compatible because @sc{matlab} treats the range expression\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
716 differently in different contexts.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
717 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16468
diff
changeset
|
718 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
719 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16468
diff
changeset
|
720 The original variable value is restored when exiting the function.\n\ |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
721 @end deftypefn") |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
722 { |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
723 static bool warned = false; |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
724 if (! warned) |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
725 { |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
726 warned = true; |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
727 warning_with_id ("Octave:deprecated-function", |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
728 "allow_noninteger_range_as_index is obsolete and will be removed from a future version of Octave"); |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
729 } |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
730 |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
731 return SET_INTERNAL_VARIABLE (allow_noninteger_range_as_index); |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10609
diff
changeset
|
732 } |
12863
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
733 |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
734 /* |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
735 %!test |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
736 %! x = 0:10; |
13846
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
737 %! save = allow_noninteger_range_as_index (); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
738 %! warn_state = warning ("query", "Octave:noninteger-range-as-index"); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
739 %! unwind_protect |
14040
a64f8b6f63e9
test: simplify test for allow_noninteger_range_as_index
Rik <octave@nomad.inbox5.com>
parents:
13951
diff
changeset
|
740 %! allow_noninteger_range_as_index (false); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
741 %! fail ("x(2.1:5)"); |
13846
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
742 %! assert (x(2:5), 1:4); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
743 %! allow_noninteger_range_as_index (true); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
744 %! warning ("off", "Octave:noninteger-range-as-index"); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
745 %! assert (x(2.49:5), 1:3); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
746 %! assert (x(2.5:5), 2:4); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
747 %! assert (x(2.51:5), 2:4); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
748 %! unwind_protect_cleanup |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
749 %! allow_noninteger_range_as_index (save); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
750 %! warning (warn_state.state, warn_state.identifier); |
10a5c8155756
* ov-range.cc: Also disable warning for noninteger index in test.
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
751 %! end_unwind_protect |
12863
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
752 */ |