Mercurial > octave
annotate libinterp/octave-value/ov-range.cc @ 21211:2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
* configure.ac (HAVE_HDF5_INT2FLOAT_CONVERSIONS): AC_DEFINE here.
* ls-hdf5.cc (HAVE_HDF5_INT2FLOAT_CONVERSION): Delete definition.
* ls-hdf5.cc, ls-hdf5.h, ccolamd.cc, dmperm.cc, 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-java.cc, ov-range.cc,
ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc,
ov-struct.cc, pt-eval.cc:
Use #if defined (HAVE_FOO) instead of #if HAVE_FOO.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Feb 2016 08:48:47 -0500 |
parents | fcac5dbbf9ed |
children | 40de9f8f23a6 |
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 | |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
24 # include <config.h> |
2376 | 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" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
34 #include "errwarn.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 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
187 if (nel == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
188 err_invalid_conversion ("range", "real scalar"); |
4455 | 189 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
190 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
191 "range", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
192 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
193 retval = range.base (); |
2376 | 194 |
195 return retval; | |
196 } | |
197 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
198 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
199 octave_range::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
200 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
201 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
202 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
203 octave_idx_type nel = range.numel (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
204 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
205 if (nel == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
206 err_invalid_conversion ("range", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
207 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
208 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
209 "range", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
210 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
211 retval = range.base (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
212 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
213 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
214 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
215 |
9146
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
216 charNDArray |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
217 octave_range::char_array_value (bool) const |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
218 { |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
219 const Matrix matrix = range.matrix_value (); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
220 charNDArray retval (dims ()); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
221 |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
222 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
223 |
9146
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
224 for (octave_idx_type i = 0; i < nel; i++) |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
225 retval.elem (i) = static_cast<char>(matrix.elem (i)); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
226 |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
227 return retval; |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
228 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
229 |
2376 | 230 octave_value |
4017 | 231 octave_range::all (int dim) const |
2376 | 232 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
233 // FIXME: this is a potential waste of memory. |
2436 | 234 |
235 Matrix m = range.matrix_value (); | |
236 | |
4017 | 237 return m.all (dim); |
2376 | 238 } |
239 | |
240 octave_value | |
4017 | 241 octave_range::any (int dim) const |
2376 | 242 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
243 // FIXME: this is a potential waste of memory. |
4017 | 244 |
245 Matrix m = range.matrix_value (); | |
246 | |
247 return m.any (dim); | |
2376 | 248 } |
249 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
250 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
251 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
|
252 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
253 return |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
254 (k == 0 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
255 ? 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
|
256 : octave_value (range.diag (k))); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
257 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
258 |
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
|
259 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
|
260 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
|
261 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
262 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
|
263 |
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 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
|
265 } |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
266 |
2376 | 267 bool |
268 octave_range::is_true (void) const | |
269 { | |
270 bool retval = false; | |
2436 | 271 |
20988
8b8d8c6c0e64
Add new member function is_empty to Range type. Use it.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
272 if (! range.is_empty ()) |
2436 | 273 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
274 // FIXME: this is a potential waste of memory. |
2436 | 275 |
276 Matrix m ((range.matrix_value () . all ()) . all ()); | |
277 | |
278 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); | |
279 } | |
280 | |
2376 | 281 return retval; |
282 } | |
283 | |
284 Complex | |
285 octave_range::complex_value (bool) const | |
286 { | |
4102 | 287 double tmp = lo_ieee_nan_value (); |
288 | |
289 Complex retval (tmp, tmp); | |
2376 | 290 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
291 octave_idx_type nel = range.numel (); |
2376 | 292 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
293 if (nel == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
294 err_invalid_conversion ("range", "complex scalar"); |
4455 | 295 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
296 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
297 "range", "complex scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
298 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
299 retval = range.base (); |
2376 | 300 |
301 return retval; | |
302 } | |
303 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
304 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
305 octave_range::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
306 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
307 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
308 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
309 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
310 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
311 octave_idx_type nel = range.numel (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
312 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
313 if (nel == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
314 err_invalid_conversion ("range", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
315 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
316 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
317 "range", "complex scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
318 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
319 retval = range.base (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
320 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
321 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
322 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
323 |
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
|
324 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
|
325 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
|
326 { |
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
|
327 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
|
328 |
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
|
329 if (m.any_element_is_nan ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
330 err_nan_to_logical_conversion (); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
331 if (warn && m.any_element_not_one_or_zero ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
332 warn_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
|
333 |
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 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
|
335 } |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
337 octave_value |
5731 | 338 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
|
339 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
340 NDArray retval = array_value (); |
5731 | 341 if (fill) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
342 retval.resize (dv, 0); |
5731 | 343 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
344 retval.resize (dv); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
345 return retval; |
5731 | 346 } |
347 | |
2376 | 348 octave_value |
5279 | 349 octave_range::convert_to_str_internal (bool pad, bool force, char type) const |
2449 | 350 { |
351 octave_value tmp (range.matrix_value ()); | |
5279 | 352 return tmp.convert_to_str (pad, force, type); |
2449 | 353 } |
354 | |
2376 | 355 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18132
diff
changeset
|
356 octave_range::print (std::ostream& os, bool pr_as_read_syntax) |
2901 | 357 { |
358 print_raw (os, pr_as_read_syntax); | |
359 newline (os); | |
360 } | |
361 | |
362 void | |
3523 | 363 octave_range::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
2901 | 364 { |
365 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
|
366 current_print_indent_level ()); |
2901 | 367 } |
368 | |
369 bool | |
3523 | 370 octave_range::print_name_tag (std::ostream& os, const std::string& name) const |
2376 | 371 { |
2901 | 372 bool retval = false; |
373 | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
374 octave_idx_type n = range.numel (); |
2901 | 375 |
376 indent (os); | |
377 | |
378 if (n == 0 || n == 1) | |
379 os << name << " = "; | |
380 else | |
381 { | |
382 os << name << " ="; | |
383 newline (os); | |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
384 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
385 newline (os); |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
386 |
2901 | 387 retval = true; |
388 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
389 |
2901 | 390 return retval; |
2376 | 391 } |
392 | |
17870 | 393 void |
394 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
|
395 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
396 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
|
397 |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
398 if (len == 0) |
17870 | 399 os << "[]"; |
16468
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
400 else |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
401 { |
17870 | 402 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
|
403 |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
404 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
|
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 (range.inc () != 1) |
17870 | 407 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
|
408 |
17870 | 409 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
|
410 } |
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 } |
0f143f68078d
use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
413 |
4687 | 414 // Skip white space and comments on stream IS. |
415 | |
416 static void | |
417 skip_comments (std::istream& is) | |
418 { | |
419 char c = '\0'; | |
420 while (is.get (c)) | |
421 { | |
422 if (c == ' ' || c == '\t' || c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
423 ; // Skip whitespace on way to beginning of next line. |
4687 | 424 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
425 break; |
4687 | 426 } |
427 | |
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
|
428 skip_until_newline (is, false); |
4687 | 429 } |
430 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
431 bool |
6974 | 432 octave_range::save_ascii (std::ostream& os) |
4687 | 433 { |
434 Range r = range_value (); | |
435 double base = r.base (); | |
436 double limit = r.limit (); | |
437 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
|
438 octave_idx_type len = r.numel (); |
4687 | 439 |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
440 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
441 os << "# base, limit, increment\n"; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
442 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
443 os << "# base, length, increment\n"; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
444 |
4687 | 445 octave_write_double (os, base); |
446 os << " "; | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
447 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
448 octave_write_double (os, limit); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
449 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
450 os << len; |
4687 | 451 os << " "; |
452 octave_write_double (os, inc); | |
453 os << "\n"; | |
454 | |
455 return true; | |
456 } | |
457 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
458 bool |
4687 | 459 octave_range::load_ascii (std::istream& is) |
460 { | |
461 // # base, limit, range comment added by save (). | |
462 skip_comments (is); | |
463 | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
464 double base, limit, inc; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
465 is >> base >> limit >> inc; |
4687 | 466 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
467 if (! is) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
468 error ("load: failed to load range constant"); |
4687 | 469 |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
470 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
471 range = Range (base, limit, inc); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
472 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
473 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
|
474 |
4687 | 475 return true; |
476 } | |
477 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
478 bool |
4687 | 479 octave_range::save_binary (std::ostream& os, bool& /* save_as_floats */) |
480 { | |
5760 | 481 char tmp = LS_DOUBLE; |
482 os.write (reinterpret_cast<char *> (&tmp), 1); | |
4687 | 483 Range r = range_value (); |
484 double bas = r.base (); | |
485 double lim = r.limit (); | |
486 double inc = r.inc (); | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
487 if (inc == 0) |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
488 lim = r.numel (); |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
489 |
5760 | 490 os.write (reinterpret_cast<char *> (&bas), 8); |
491 os.write (reinterpret_cast<char *> (&lim), 8); | |
492 os.write (reinterpret_cast<char *> (&inc), 8); | |
4687 | 493 |
494 return true; | |
495 } | |
496 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
497 bool |
4687 | 498 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
|
499 oct_mach_info::float_format /* fmt */) |
4687 | 500 { |
501 char tmp; | |
5760 | 502 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687 | 503 return false; |
504 double bas, lim, inc; | |
5760 | 505 if (! is.read (reinterpret_cast<char *> (&bas), 8)) |
4687 | 506 return false; |
507 if (swap) | |
4944 | 508 swap_bytes<8> (&bas); |
5760 | 509 if (! is.read (reinterpret_cast<char *> (&lim), 8)) |
4687 | 510 return false; |
511 if (swap) | |
4944 | 512 swap_bytes<8> (&lim); |
5760 | 513 if (! is.read (reinterpret_cast<char *> (&inc), 8)) |
4687 | 514 return false; |
515 if (swap) | |
4944 | 516 swap_bytes<8> (&inc); |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
517 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
518 range = Range (bas, lim, inc); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
519 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
520 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
|
521 |
4687 | 522 return true; |
523 } | |
524 | |
525 #if defined (HAVE_HDF5) | |
4944 | 526 |
4687 | 527 // 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
|
528 // 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
|
529 // 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
|
530 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary |
4687 | 531 // conversions are handled automatically by HDF5. |
532 | |
533 static hid_t | |
534 hdf5_make_range_type (hid_t num_type) | |
535 { | |
536 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 3); | |
537 | |
538 H5Tinsert (type_id, "base", 0 * sizeof (double), num_type); | |
539 H5Tinsert (type_id, "limit", 1 * sizeof (double), num_type); | |
540 H5Tinsert (type_id, "increment", 2 * sizeof (double), num_type); | |
541 | |
542 return type_id; | |
543 } | |
544 | |
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
|
545 #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
|
546 |
4687 | 547 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
|
548 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
|
549 bool /* save_as_floats */) |
4687 | 550 { |
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
|
551 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
|
552 |
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 #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
|
554 |
4792 | 555 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
|
556 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
|
557 space_hid = type_hid = data_hid = -1; |
4687 | 558 |
4815 | 559 space_hid = H5Screate_simple (0, dimens, 0); |
4687 | 560 if (space_hid < 0) return false; |
561 | |
562 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
|
563 if (type_hid < 0) |
4687 | 564 { |
565 H5Sclose (space_hid); | |
566 return false; | |
567 } | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
568 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
569 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
|
570 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
|
571 #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
|
572 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
|
573 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
574 if (data_hid < 0) |
4687 | 575 { |
576 H5Sclose (space_hid); | |
577 H5Tclose (type_hid); | |
578 return false; | |
579 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
580 |
4687 | 581 Range r = range_value (); |
582 double range_vals[3]; | |
583 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
|
584 range_vals[1] = r.inc () != 0 ? r.limit () : r.numel (); |
4687 | 585 range_vals[2] = r.inc (); |
586 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20988
diff
changeset
|
587 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
|
588 range_vals) >= 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
589 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
590 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
|
591 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
|
592 "OCTAVE_RANGE_NELEM", &nel) >= 0; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
593 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
594 else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
595 retval = false; |
4687 | 596 |
597 H5Dclose (data_hid); | |
598 H5Tclose (type_hid); | |
599 H5Sclose (space_hid); | |
4837 | 600 |
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
|
601 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
602 warn_save ("hdf5"); |
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
|
603 #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
|
604 |
4687 | 605 return retval; |
606 } | |
607 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
608 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
|
609 octave_range::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 610 { |
611 bool retval = false; | |
4837 | 612 |
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
|
613 #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
|
614 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
615 #if defined (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
|
616 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
|
617 #else |
4687 | 618 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
|
619 #endif |
4687 | 620 hid_t type_hid = H5Dget_type (data_hid); |
621 | |
622 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE); | |
623 | |
624 if (! hdf5_types_compatible (type_hid, range_type)) | |
625 { | |
4837 | 626 H5Tclose (range_type); |
4687 | 627 H5Dclose (data_hid); |
628 return false; | |
629 } | |
630 | |
631 hid_t space_hid = H5Dget_space (data_hid); | |
632 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
633 | |
634 if (rank != 0) | |
635 { | |
4837 | 636 H5Tclose (range_type); |
4687 | 637 H5Sclose (space_hid); |
638 H5Dclose (data_hid); | |
639 return false; | |
640 } | |
641 | |
642 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
|
643 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
|
644 rangevals) >= 0) |
4687 | 645 { |
646 retval = true; | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
647 octave_idx_type nel; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
648 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
|
649 "OCTAVE_RANGE_NELEM", &nel)) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
650 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
|
651 else |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
652 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
653 if (rangevals[2] != 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
654 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
|
655 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
656 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
|
657 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
|
658 } |
4687 | 659 } |
660 | |
4837 | 661 H5Tclose (range_type); |
4687 | 662 H5Sclose (space_hid); |
663 H5Dclose (data_hid); | |
4837 | 664 |
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
|
665 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
666 warn_load ("hdf5"); |
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
|
667 #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
|
668 |
4687 | 669 return retval; |
670 } | |
4944 | 671 |
5900 | 672 mxArray * |
673 octave_range::as_mxArray (void) const | |
674 { | |
675 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL); | |
676 | |
677 double *pr = static_cast<double *> (retval->get_data ()); | |
678 | |
6686 | 679 mwSize nel = numel (); |
5900 | 680 |
681 Matrix m = matrix_value (); | |
682 | |
683 const double *p = m.data (); | |
684 | |
6686 | 685 for (mwSize i = 0; i < nel; i++) |
5900 | 686 pr[i] = p[i]; |
687 | |
688 return retval; | |
689 } | |
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
|
690 |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
691 octave_value |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
692 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
|
693 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
694 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
|
695 : octave_value (); |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
696 } |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
18416
diff
changeset
|
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 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
|
699 "-*- 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
|
700 @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
|
701 @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
|
702 @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
|
703 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
|
704 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
|
705 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
706 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
|
707 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
|
708 differently in different contexts.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
709 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16468
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 @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
|
714 { |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
715 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
|
716 if (! warned) |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
717 { |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
718 warned = true; |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
719 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
|
720 "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
|
721 } |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17870
diff
changeset
|
722 |
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
|
723 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
|
724 } |
12863
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
725 |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
726 /* |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
727 %!test |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
728 %! 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
|
729 %! 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
|
730 %! 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
|
731 %! unwind_protect |
14040
a64f8b6f63e9
test: simplify test for allow_noninteger_range_as_index
Rik <octave@nomad.inbox5.com>
parents:
13951
diff
changeset
|
732 %! 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
|
733 %! 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
|
734 %! 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
|
735 %! 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
|
736 %! 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
|
737 %! 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
|
738 %! 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
|
739 %! 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
|
740 %! 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
|
741 %! 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
|
742 %! 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
|
743 %! end_unwind_protect |
12863
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
744 */ |