Mercurial > hg > octave-lyh
annotate src/ov-range.cc @ 14899:f25d2224fa02
Initial JIT support
build-aux/common.mk: Add llvm flags.
configure.ac: Link with llvm.
src/Makefile: Add pt-jit.
src/link-deps.mk: Link with llvm.
src/oct-conf.in.h: Add llvm flags.
src/toplev.cc: Add llvm flags.
src/pt-eval.cc: Try to jit statements.
src/pt-jit.cc: New file.
src/pt-jit.h: New file
author | Max Brister <max@2bass.com> |
---|---|
date | Sun, 06 May 2012 20:17:30 -0600 |
parents | e8e86ae3abbc |
children | 13cc11418393 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14040
diff
changeset
|
3 Copyright (C) 1996-2012 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" |
35 #include "ops.h" | |
3933 | 36 #include "oct-obj.h" |
2376 | 37 #include "ov-range.h" |
38 #include "ov-re-mat.h" | |
2410 | 39 #include "ov-scalar.h" |
2376 | 40 #include "pr-output.h" |
41 | |
4687 | 42 #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
|
43 #include "ls-ascii-helper.h" |
4687 | 44 #include "ls-hdf5.h" |
45 #include "ls-utils.h" | |
46 | |
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
|
47 // If TRUE, allow ranges with non-integer elements as array indices. |
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
|
48 bool Vallow_noninteger_range_as_index = false; |
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 |
3219 | 50 DEFINE_OCTAVE_ALLOCATOR (octave_range); |
2376 | 51 |
4612 | 52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_range, "range", "double"); |
2376 | 53 |
5759 | 54 static octave_base_value * |
55 default_numeric_conversion_function (const octave_base_value& a) | |
2376 | 56 { |
57 CAST_CONV_ARG (const octave_range&); | |
58 | |
59 return new octave_matrix (v.matrix_value ()); | |
60 } | |
61 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
62 octave_base_value::type_conv_info |
2376 | 63 octave_range::numeric_conversion_function (void) const |
64 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
65 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
66 octave_matrix::static_type_id ()); |
2376 | 67 } |
68 | |
5759 | 69 octave_base_value * |
2410 | 70 octave_range::try_narrowing_conversion (void) |
71 { | |
5759 | 72 octave_base_value *retval = 0; |
2410 | 73 |
74 switch (range.nelem ()) | |
75 { | |
76 case 1: | |
77 retval = new octave_scalar (range.base ()); | |
78 break; | |
79 | |
80 case 0: | |
4417 | 81 retval = new octave_matrix (Matrix (1, 0)); |
2410 | 82 break; |
83 | |
8971 | 84 case -2: |
85 retval = new octave_matrix (range.matrix_value ()); | |
86 break; | |
87 | |
2410 | 88 default: |
89 break; | |
90 } | |
91 | |
92 return retval; | |
93 } | |
94 | |
2436 | 95 octave_value |
4247 | 96 octave_range::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 const std::list<octave_value_list>& idx) |
3933 | 98 { |
99 octave_value retval; | |
100 | |
101 switch (type[0]) | |
102 { | |
103 case '(': | |
104 retval = do_index_op (idx.front ()); | |
105 break; | |
106 | |
107 case '{': | |
108 case '.': | |
109 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 112 } |
113 break; | |
114 | |
115 default: | |
116 panic_impossible (); | |
117 } | |
118 | |
119 return retval.next_subsref (type, idx); | |
120 } | |
121 | |
122 octave_value | |
5885 | 123 octave_range::do_index_op (const octave_value_list& idx, bool resize_ok) |
2436 | 124 { |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
125 if (idx.length () == 1 && ! resize_ok) |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
126 { |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
127 octave_value retval; |
2436 | 128 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
129 // The range can handle a single subscript. |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
130 idx_vector i = idx(0).index_vector (); |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
131 if (! error_state) |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
132 { |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
133 if (i.is_scalar () && i(0) < range.nelem ()) |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
134 retval = range.elem (i(0)); |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
135 else |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
136 retval = range.index (i); |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
137 } |
2436 | 138 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
139 return retval; |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
140 } |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
141 else |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
142 { |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
143 octave_value tmp (new octave_matrix (range.matrix_value ())); |
2436 | 144 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
145 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
|
146 } |
2436 | 147 } |
148 | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
149 idx_vector |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
150 octave_range::index_vector (void) const |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
151 { |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
152 if (idx_cache) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
153 return *idx_cache; |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
154 else |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
155 { |
10616
d61caf612f1e
optimize order of conditions in octave_range::index_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
10613
diff
changeset
|
156 if (! Vallow_noninteger_range_as_index |
d61caf612f1e
optimize order of conditions in octave_range::index_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
10613
diff
changeset
|
157 || range.all_elements_are_ints ()) |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
158 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
|
159 else |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
160 { |
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
|
161 warning_with_id ("Octave:noninteger-range-as-index", |
10609
58bcda68ac11
improve warning/error message
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
162 "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
|
163 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
164 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
|
165 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
166 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
167 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
168 |
2376 | 169 double |
170 octave_range::double_value (bool) const | |
171 { | |
4102 | 172 double retval = lo_ieee_nan_value (); |
2376 | 173 |
5275 | 174 octave_idx_type nel = range.nelem (); |
2376 | 175 |
4455 | 176 if (nel > 0) |
177 { | |
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
|
178 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 "range", "real scalar"); |
4455 | 180 |
181 retval = range.base (); | |
182 } | |
2376 | 183 else |
184 gripe_invalid_conversion ("range", "real scalar"); | |
185 | |
186 return retval; | |
187 } | |
188 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
189 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
190 octave_range::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
191 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
192 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
193 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
194 octave_idx_type nel = range.nelem (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
195 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
196 if (nel > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
197 { |
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
|
198 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
199 "range", "real scalar"); |
7789
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 retval = range.base (); |
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 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
204 gripe_invalid_conversion ("range", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
205 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
206 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
207 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 |
9146
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
209 charNDArray |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
210 octave_range::char_array_value (bool) const |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
211 { |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
212 const Matrix matrix = range.matrix_value (); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
213 charNDArray retval (dims ()); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
214 |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
215 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
216 |
9146
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
217 for (octave_idx_type i = 0; i < nel; i++) |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
218 retval.elem (i) = static_cast<char>(matrix.elem (i)); |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
219 |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
220 return retval; |
a48c500e48e1
support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
221 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
222 |
2376 | 223 octave_value |
4017 | 224 octave_range::all (int dim) const |
2376 | 225 { |
5775 | 226 // FIXME -- this is a potential waste of memory. |
2436 | 227 |
228 Matrix m = range.matrix_value (); | |
229 | |
4017 | 230 return m.all (dim); |
2376 | 231 } |
232 | |
233 octave_value | |
4017 | 234 octave_range::any (int dim) const |
2376 | 235 { |
5775 | 236 // FIXME -- this is a potential waste of memory. |
4017 | 237 |
238 Matrix m = range.matrix_value (); | |
239 | |
240 return m.any (dim); | |
2376 | 241 } |
242 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
243 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
244 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
|
245 { |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
246 return (k == 0 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
247 ? octave_value (DiagMatrix (DiagArray2<double> (range.matrix_value ()))) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
248 : octave_value (range.diag (k))); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
249 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
250 |
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
|
251 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
|
252 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
|
253 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
254 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
|
255 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
256 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
|
257 } |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
258 |
2376 | 259 bool |
260 octave_range::is_true (void) const | |
261 { | |
262 bool retval = false; | |
2436 | 263 |
4478 | 264 if (range.nelem () != 0) |
2436 | 265 { |
5775 | 266 // FIXME -- this is a potential waste of memory. |
2436 | 267 |
268 Matrix m ((range.matrix_value () . all ()) . all ()); | |
269 | |
270 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); | |
271 } | |
272 | |
2376 | 273 return retval; |
274 } | |
275 | |
276 Complex | |
277 octave_range::complex_value (bool) const | |
278 { | |
4102 | 279 double tmp = lo_ieee_nan_value (); |
280 | |
281 Complex retval (tmp, tmp); | |
2376 | 282 |
5275 | 283 octave_idx_type nel = range.nelem (); |
2376 | 284 |
4455 | 285 if (nel > 0) |
286 { | |
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
|
287 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 "range", "complex scalar"); |
4455 | 289 |
290 retval = range.base (); | |
291 } | |
2376 | 292 else |
293 gripe_invalid_conversion ("range", "complex scalar"); | |
294 | |
295 return retval; | |
296 } | |
297 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
298 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
299 octave_range::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
300 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
301 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
302 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
303 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
304 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
305 octave_idx_type nel = range.nelem (); |
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 if (nel > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
308 { |
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
|
309 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 "range", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
311 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
312 retval = range.base (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
313 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
314 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
315 gripe_invalid_conversion ("range", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
316 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
317 return retval; |
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 |
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
|
320 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
|
321 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
|
322 { |
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
|
323 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
|
324 |
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 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
|
326 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
|
327 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
|
328 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
|
329 |
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
|
330 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
|
331 } |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
333 octave_value |
5731 | 334 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
|
335 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
336 NDArray retval = array_value (); |
5731 | 337 if (fill) |
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
|
338 retval.resize (dv, NDArray::resize_fill_value ()); |
5731 | 339 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
340 retval.resize (dv); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
341 return retval; |
5731 | 342 } |
343 | |
2376 | 344 octave_value |
5279 | 345 octave_range::convert_to_str_internal (bool pad, bool force, char type) const |
2449 | 346 { |
347 octave_value tmp (range.matrix_value ()); | |
5279 | 348 return tmp.convert_to_str (pad, force, type); |
2449 | 349 } |
350 | |
2376 | 351 void |
3523 | 352 octave_range::print (std::ostream& os, bool pr_as_read_syntax) const |
2901 | 353 { |
354 print_raw (os, pr_as_read_syntax); | |
355 newline (os); | |
356 } | |
357 | |
358 void | |
3523 | 359 octave_range::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
2901 | 360 { |
361 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
|
362 current_print_indent_level ()); |
2901 | 363 } |
364 | |
365 bool | |
3523 | 366 octave_range::print_name_tag (std::ostream& os, const std::string& name) const |
2376 | 367 { |
2901 | 368 bool retval = false; |
369 | |
5275 | 370 octave_idx_type n = range.nelem (); |
2901 | 371 |
372 indent (os); | |
373 | |
374 if (n == 0 || n == 1) | |
375 os << name << " = "; | |
376 else | |
377 { | |
378 os << name << " ="; | |
379 newline (os); | |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
380 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
381 newline (os); |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12863
diff
changeset
|
382 |
2901 | 383 retval = true; |
384 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
385 |
2901 | 386 return retval; |
2376 | 387 } |
388 | |
4687 | 389 // Skip white space and comments on stream IS. |
390 | |
391 static void | |
392 skip_comments (std::istream& is) | |
393 { | |
394 char c = '\0'; | |
395 while (is.get (c)) | |
396 { | |
397 if (c == ' ' || c == '\t' || c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 ; // Skip whitespace on way to beginning of next line. |
4687 | 399 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 break; |
4687 | 401 } |
402 | |
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
|
403 skip_until_newline (is, false); |
4687 | 404 } |
405 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
406 bool |
6974 | 407 octave_range::save_ascii (std::ostream& os) |
4687 | 408 { |
409 Range r = range_value (); | |
410 double base = r.base (); | |
411 double limit = r.limit (); | |
412 double inc = r.inc (); | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
413 octave_idx_type len = r.nelem (); |
4687 | 414 |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
415 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
416 os << "# base, limit, increment\n"; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
417 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
418 os << "# base, length, increment\n"; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
419 |
4687 | 420 octave_write_double (os, base); |
421 os << " "; | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
422 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
423 octave_write_double (os, limit); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
424 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
425 os << len; |
4687 | 426 os << " "; |
427 octave_write_double (os, inc); | |
428 os << "\n"; | |
429 | |
430 return true; | |
431 } | |
432 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
433 bool |
4687 | 434 octave_range::load_ascii (std::istream& is) |
435 { | |
436 // # base, limit, range comment added by save (). | |
437 skip_comments (is); | |
438 | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
439 double base, limit, inc; |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
440 is >> base >> limit >> inc; |
4687 | 441 |
442 if (!is) | |
443 { | |
444 error ("load: failed to load range constant"); | |
445 return false; | |
446 } | |
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 range = Range (base, limit, inc); |
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 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
|
452 |
4687 | 453 return true; |
454 } | |
455 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
456 bool |
4687 | 457 octave_range::save_binary (std::ostream& os, bool& /* save_as_floats */) |
458 { | |
5760 | 459 char tmp = LS_DOUBLE; |
460 os.write (reinterpret_cast<char *> (&tmp), 1); | |
4687 | 461 Range r = range_value (); |
462 double bas = r.base (); | |
463 double lim = r.limit (); | |
464 double inc = r.inc (); | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
465 if (inc == 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
466 lim = r.nelem (); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
467 |
5760 | 468 os.write (reinterpret_cast<char *> (&bas), 8); |
469 os.write (reinterpret_cast<char *> (&lim), 8); | |
470 os.write (reinterpret_cast<char *> (&inc), 8); | |
4687 | 471 |
472 return true; | |
473 } | |
474 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
475 bool |
4687 | 476 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
|
477 oct_mach_info::float_format /* fmt */) |
4687 | 478 { |
479 char tmp; | |
5760 | 480 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687 | 481 return false; |
482 double bas, lim, inc; | |
5760 | 483 if (! is.read (reinterpret_cast<char *> (&bas), 8)) |
4687 | 484 return false; |
485 if (swap) | |
4944 | 486 swap_bytes<8> (&bas); |
5760 | 487 if (! is.read (reinterpret_cast<char *> (&lim), 8)) |
4687 | 488 return false; |
489 if (swap) | |
4944 | 490 swap_bytes<8> (&lim); |
5760 | 491 if (! is.read (reinterpret_cast<char *> (&inc), 8)) |
4687 | 492 return false; |
493 if (swap) | |
4944 | 494 swap_bytes<8> (&inc); |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
495 if (inc != 0) |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
496 range = Range (bas, lim, inc); |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
497 else |
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
498 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
|
499 |
4687 | 500 return true; |
501 } | |
502 | |
503 #if defined (HAVE_HDF5) | |
4944 | 504 |
4687 | 505 // 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
|
506 // 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
|
507 // 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
|
508 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary |
4687 | 509 // conversions are handled automatically by HDF5. |
510 | |
511 static hid_t | |
512 hdf5_make_range_type (hid_t num_type) | |
513 { | |
514 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 3); | |
515 | |
516 H5Tinsert (type_id, "base", 0 * sizeof (double), num_type); | |
517 H5Tinsert (type_id, "limit", 1 * sizeof (double), num_type); | |
518 H5Tinsert (type_id, "increment", 2 * sizeof (double), num_type); | |
519 | |
520 return type_id; | |
521 } | |
522 | |
523 bool | |
524 octave_range::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 bool /* save_as_floats */) |
4687 | 526 { |
4792 | 527 hsize_t dimens[3]; |
4687 | 528 hid_t space_hid = -1, type_hid = -1, data_hid = -1; |
529 bool retval = true; | |
530 | |
4815 | 531 space_hid = H5Screate_simple (0, dimens, 0); |
4687 | 532 if (space_hid < 0) return false; |
533 | |
534 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
|
535 if (type_hid < 0) |
4687 | 536 { |
537 H5Sclose (space_hid); | |
538 return false; | |
539 } | |
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
|
540 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
541 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
542 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
543 #else |
4687 | 544 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, 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
|
545 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
546 if (data_hid < 0) |
4687 | 547 { |
548 H5Sclose (space_hid); | |
549 H5Tclose (type_hid); | |
550 return false; | |
551 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
552 |
4687 | 553 Range r = range_value (); |
554 double range_vals[3]; | |
555 range_vals[0] = r.base (); | |
10735
d899b2ee6a37
fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
556 range_vals[1] = r.inc () != 0 ? r.limit () : r.nelem (); |
4687 | 557 range_vals[2] = r.inc (); |
558 | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
559 if (H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
560 range_vals) >= 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
561 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
562 octave_idx_type nel = r.nelem (); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
563 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
|
564 "OCTAVE_RANGE_NELEM", &nel) >= 0; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
565 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
566 else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
567 retval = false; |
4687 | 568 |
569 H5Dclose (data_hid); | |
570 H5Tclose (type_hid); | |
571 H5Sclose (space_hid); | |
4837 | 572 |
4687 | 573 return retval; |
574 } | |
575 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
576 bool |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9146
diff
changeset
|
577 octave_range::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 578 { |
579 bool retval = false; | |
4837 | 580 |
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 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
582 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
583 #else |
4687 | 584 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
|
585 #endif |
4687 | 586 hid_t type_hid = H5Dget_type (data_hid); |
587 | |
588 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE); | |
589 | |
590 if (! hdf5_types_compatible (type_hid, range_type)) | |
591 { | |
4837 | 592 H5Tclose (range_type); |
4687 | 593 H5Dclose (data_hid); |
594 return false; | |
595 } | |
596 | |
597 hid_t space_hid = H5Dget_space (data_hid); | |
598 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
599 | |
600 if (rank != 0) | |
601 { | |
4837 | 602 H5Tclose (range_type); |
4687 | 603 H5Sclose (space_hid); |
604 H5Dclose (data_hid); | |
605 return false; | |
606 } | |
607 | |
608 double rangevals[3]; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
609 if (H5Dread (data_hid, range_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
610 rangevals) >= 0) |
4687 | 611 { |
612 retval = true; | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
613 octave_idx_type nel; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
614 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
|
615 "OCTAVE_RANGE_NELEM", &nel)) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
616 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
|
617 else |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
618 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
619 if (rangevals[2] != 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
11129
diff
changeset
|
620 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
|
621 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
622 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
|
623 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
|
624 } |
4687 | 625 } |
626 | |
4837 | 627 H5Tclose (range_type); |
4687 | 628 H5Sclose (space_hid); |
629 H5Dclose (data_hid); | |
4837 | 630 |
4687 | 631 return retval; |
632 } | |
4944 | 633 |
4687 | 634 #endif |
635 | |
5900 | 636 mxArray * |
637 octave_range::as_mxArray (void) const | |
638 { | |
639 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL); | |
640 | |
641 double *pr = static_cast<double *> (retval->get_data ()); | |
642 | |
6686 | 643 mwSize nel = numel (); |
5900 | 644 |
645 Matrix m = matrix_value (); | |
646 | |
647 const double *p = m.data (); | |
648 | |
6686 | 649 for (mwSize i = 0; i < nel; i++) |
5900 | 650 pr[i] = p[i]; |
651 | |
652 return retval; | |
653 } | |
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
|
654 |
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
|
655 DEFUN (allow_noninteger_range_as_index, args, nargout, |
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
|
656 "-*- texinfo -*-\n\ |
10840 | 657 @deftypefn {Built-in Function} {@var{val} =} allow_noninteger_range_as_index ()\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
|
658 @deftypefnx {Built-in Function} {@var{old_val} =} allow_noninteger_range_as_index (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
659 @deftypefnx {Built-in Function} {} 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
|
660 Query or set the internal variable that controls whether non-integer\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10616
diff
changeset
|
661 ranges are allowed as indices. This might be useful for @sc{matlab}\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
|
662 compatibility; however, it is still not entirely compatible because\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10616
diff
changeset
|
663 @sc{matlab} treats the range expression differently in different contexts.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
664 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
665 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
666 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13846
diff
changeset
|
667 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
|
668 @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
|
669 { |
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
|
670 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
|
671 } |
12863
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
672 |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
673 /* |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
674 %!test |
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
675 %! 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
|
676 %! 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
|
677 %! 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
|
678 %! unwind_protect |
14040
a64f8b6f63e9
test: simplify test for allow_noninteger_range_as_index
Rik <octave@nomad.inbox5.com>
parents:
13951
diff
changeset
|
679 %! 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
|
680 %! 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
|
681 %! 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
|
682 %! 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
|
683 %! 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
|
684 %! 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
|
685 %! 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
|
686 %! 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
|
687 %! 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
|
688 %! 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
|
689 %! 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
|
690 %! end_unwind_protect |
12863
8f9702abe3e3
test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
691 */ |