annotate libinterp/octave-value/ov-range.cc @ 20163:075a5e2e1ba5 stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed build-aux, libinterp/dldfcn, libinterp/octave-value, libinterp/parse-tree directories. * build-aux/mk-opts.pl, libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/amd.cc, libinterp/dldfcn/audiodevinfo.cc, libinterp/dldfcn/audioread.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc, libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-bool-mat.cc, libinterp/octave-value/ov-cell.cc, libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov.cc, libinterp/parse-tree/lex.ll, libinterp/parse-tree/oct-parse.in.yy, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-mat.cc: doc: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Sun, 03 May 2015 21:52:42 -0700
parents 09ed6f7538dd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
1 /*
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
4
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
6
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
10 option) any later version.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
11
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
15 for more details.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
16
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
19 <http://www.gnu.org/licenses/>.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
20
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
21 */
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
22
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
25 #endif
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3219
diff changeset
27 #include <iostream>
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
28
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
29 #include "lo-ieee.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
30 #include "lo-utils.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
34 #include "gripes.h"
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
35 #include "mxarray.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
36 #include "ops.h"
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
37 #include "oct-obj.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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
39 #include "ov-range.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
40 #include "ov-re-mat.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
41 #include "ov-scalar.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
42 #include "pr-output.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
43
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
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
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
46 #include "ls-hdf5.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
47 #include "ls-utils.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
52
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4478
diff changeset
53 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_range, "range", "double");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
54
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5731
diff changeset
55 static octave_base_value *
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5731
diff changeset
56 default_numeric_conversion_function (const octave_base_value& a)
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
57 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
58 CAST_CONV_ARG (const octave_range&);
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
59
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
60 return new octave_matrix (v.matrix_value ());
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
61 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
62
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
63 octave_base_value::type_conv_info
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
64 octave_range::numeric_conversion_function (void) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
68 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
69
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5731
diff changeset
70 octave_base_value *
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
71 octave_range::try_narrowing_conversion (void)
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
72 {
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5731
diff changeset
73 octave_base_value *retval = 0;
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
74
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
75 switch (range.nelem ())
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
76 {
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
77 case 1:
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
78 retval = new octave_scalar (range.base ());
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
79 break;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
80
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
81 case 0:
4417
5cca7b5d6b34 [project @ 2003-05-25 02:40:35 by jwe]
jwe
parents: 4358
diff changeset
82 retval = new octave_matrix (Matrix (1, 0));
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
83 break;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
84
8971
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
85 case -2:
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
86 retval = new octave_matrix (range.matrix_value ());
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
87 break;
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8946
diff changeset
88
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
89 default:
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
90 break;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
91 }
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
92
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
93 return retval;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
94 }
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
95
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
96 octave_value
4247
fc9a075d10fb [project @ 2002-12-30 23:05:27 by jwe]
jwe
parents: 4219
diff changeset
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
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
99 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
100 octave_value retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
101
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
102 switch (type[0])
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
103 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
104 case '(':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
105 retval = do_index_op (idx.front ());
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
106 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
107
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
108 case '{':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
109 case '.':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
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
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
113 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
114 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
115
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
116 default:
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
117 panic_impossible ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
118 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
119
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
120 return retval.next_subsref (type, idx);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
121 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
122
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
123 octave_value
5885
bd3041e30d97 [project @ 2006-07-14 20:29:35 by jwe]
jwe
parents: 5781
diff changeset
124 octave_range::do_index_op (const octave_value_list& idx, bool resize_ok)
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
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
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
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.
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
131 idx_vector i = idx(0).index_vector ();
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
132 if (! error_state)
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
133 {
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
134 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
135 retval = range.elem (i(0));
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
136 else
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
137 retval = range.index (i);
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
138 }
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
139
9986
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
140 return retval;
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
141 }
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
142 else
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
143 {
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
144 octave_value tmp (new octave_matrix (range.matrix_value ()));
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
145
9986
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
146 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
147 }
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
148 }
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
149
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
150 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
151 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
152 {
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
153 if (idx_cache)
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
154 return *idx_cache;
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
155 else
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
156 {
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17870
diff changeset
157 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
158 || ! 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
159 || range.all_elements_are_ints ())
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
160 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
161 else
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
162 {
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
163 warning_with_id ("Octave:noninteger-range-as-index",
10609
58bcda68ac11 improve warning/error message
John W. Eaton <jwe@octave.org>
parents: 10605
diff changeset
164 "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
165
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
166 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
167 }
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
168 }
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
169 }
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
170
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
171 double
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
172 octave_range::double_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
173 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
174 double retval = lo_ieee_nan_value ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
175
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
176 octave_idx_type nel = range.nelem ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
177
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
178 if (nel > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
179 {
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
180 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
181 "range", "real scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
182
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
183 retval = range.base ();
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
184 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
185 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
186 gripe_invalid_conversion ("range", "real scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
187
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
188 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
189 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
190
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
191 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
192 octave_range::float_value (bool) const
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 float retval = lo_ieee_float_nan_value ();
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 octave_idx_type nel = range.nelem ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
197
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
198 if (nel > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
199 {
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
200 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
201 "range", "real scalar");
7789
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 retval = range.base ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
204 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
205 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
206 gripe_invalid_conversion ("range", "real scalar");
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 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
209 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
210
9146
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
211 charNDArray
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
212 octave_range::char_array_value (bool) const
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
213 {
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
214 const Matrix matrix = range.matrix_value ();
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
215 charNDArray retval (dims ());
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
216
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
217 octave_idx_type nel = numel ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
218
9146
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
219 for (octave_idx_type i = 0; i < nel; i++)
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
220 retval.elem (i) = static_cast<char>(matrix.elem (i));
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 return retval;
a48c500e48e1 support range->string conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
223 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
224
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
225 octave_value
4017
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
226 octave_range::all (int dim) const
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
227 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
228 // FIXME: this is a potential waste of memory.
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
229
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
230 Matrix m = range.matrix_value ();
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
231
4017
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
232 return m.all (dim);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
233 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
234
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
235 octave_value
4017
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
236 octave_range::any (int dim) const
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
237 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
238 // FIXME: this is a potential waste of memory.
4017
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
239
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
240 Matrix m = range.matrix_value ();
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
241
0eb247b9cc9b [project @ 2002-08-03 04:07:14 by jwe]
jwe
parents: 3933
diff changeset
242 return m.any (dim);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
243 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
244
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
245 octave_value
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
246 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
247 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
248 return
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
249 (k == 0
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
250 ? 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
251 : octave_value (range.diag (k)));
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
252 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
253
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
254 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
255 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
256 {
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 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
258
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 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
260 }
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
261
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
262 bool
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
263 octave_range::is_true (void) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
264 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
265 bool retval = false;
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
266
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
267 if (range.nelem () != 0)
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
268 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
269 // FIXME: this is a potential waste of memory.
2436
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
270
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
271 Matrix m ((range.matrix_value () . all ()) . all ());
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
272
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
273 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0);
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
274 }
a628e881be66 [project @ 1996-10-29 22:08:28 by jwe]
jwe
parents: 2427
diff changeset
275
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
276 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
277 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
278
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
279 Complex
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
280 octave_range::complex_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
281 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
282 double tmp = lo_ieee_nan_value ();
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
283
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
284 Complex retval (tmp, tmp);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
285
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
286 octave_idx_type nel = range.nelem ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
287
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
288 if (nel > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
289 {
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
290 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
291 "range", "complex scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
292
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
293 retval = range.base ();
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4452
diff changeset
294 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
295 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
296 gripe_invalid_conversion ("range", "complex scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
297
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
298 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
299 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
300
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
301 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
302 octave_range::float_complex_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
303 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
304 float tmp = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
305
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
306 FloatComplex retval (tmp, tmp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
307
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
308 octave_idx_type nel = range.nelem ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
309
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
310 if (nel > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
311 {
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
312 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313 "range", "complex scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
314
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
315 retval = range.base ();
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 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
318 gripe_invalid_conversion ("range", "complex scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
319
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
320 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
321 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
322
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
323 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
324 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
325 {
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 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
327
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 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
329 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
330 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
331 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
332
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 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
334 }
e103fb2182ce use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents: 10609
diff changeset
335
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
336 octave_value
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5307
diff changeset
337 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
338 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
339 NDArray retval = array_value ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5307
diff changeset
340 if (fill)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
341 retval.resize (dv, 0);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5307
diff changeset
342 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
343 retval.resize (dv);
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
344 return retval;
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5307
diff changeset
345 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5307
diff changeset
346
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
347 octave_value
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
348 octave_range::convert_to_str_internal (bool pad, bool force, char type) const
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2436
diff changeset
349 {
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2436
diff changeset
350 octave_value tmp (range.matrix_value ());
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
351 return tmp.convert_to_str (pad, force, type);
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2436
diff changeset
352 }
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2436
diff changeset
353
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
354 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18132
diff changeset
355 octave_range::print (std::ostream& os, bool pr_as_read_syntax)
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
356 {
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
357 print_raw (os, pr_as_read_syntax);
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
358 newline (os);
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
359 }
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
360
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
361 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
362 octave_range::print_raw (std::ostream& os, bool pr_as_read_syntax) const
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
363 {
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
364 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
365 current_print_indent_level ());
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
366 }
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
367
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
368 bool
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
369 octave_range::print_name_tag (std::ostream& os, const std::string& name) const
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
370 {
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
371 bool retval = false;
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
372
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
373 octave_idx_type n = range.nelem ();
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
374
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
375 indent (os);
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
376
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
377 if (n == 0 || n == 1)
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
378 os << name << " = ";
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
379 else
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
380 {
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
381 os << name << " =";
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
382 newline (os);
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12863
diff changeset
383 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12863
diff changeset
384 newline (os);
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12863
diff changeset
385
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
386 retval = true;
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
387 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
388
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
389 return retval;
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
390 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
391
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
392 void
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
393 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
394 {
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
395 octave_idx_type len = range.nelem ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
396
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
397 if (len == 0)
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
398 os << "[]";
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
399 else
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
400 {
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
401 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
402
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
403 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
404 {
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
405 if (range.inc () != 1)
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
406 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
407
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
408 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
409 }
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
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
413 // Skip white space and comments on stream IS.
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
414
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
415 static void
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
416 skip_comments (std::istream& is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
417 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
418 char c = '\0';
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
419 while (is.get (c))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
420 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
421 if (c == ' ' || c == '\t' || c == '\n')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
422 ; // Skip whitespace on way to beginning of next line.
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
423 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
424 break;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
425 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
426
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
427 skip_until_newline (is, false);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
428 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
429
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
430 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6686
diff changeset
431 octave_range::save_ascii (std::ostream& os)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
432 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
433 Range r = range_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
434 double base = r.base ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
435 double limit = r.limit ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
436 double inc = r.inc ();
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
437 octave_idx_type len = r.nelem ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
438
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
439 if (inc != 0)
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
440 os << "# base, limit, increment\n";
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
441 else
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
442 os << "# base, length, increment\n";
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
443
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
444 octave_write_double (os, base);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
445 os << " ";
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
446 if (inc != 0)
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
447 octave_write_double (os, limit);
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
448 else
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
449 os << len;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
450 os << " ";
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
451 octave_write_double (os, inc);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
452 os << "\n";
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
453
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
454 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
455 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
456
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
457 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
458 octave_range::load_ascii (std::istream& is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
459 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
460 // # base, limit, range comment added by save ().
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
461 skip_comments (is);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
462
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
463 double base, limit, inc;
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
464 is >> base >> limit >> inc;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
465
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
466 if (!is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
467 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
468 error ("load: failed to load range constant");
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
469 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
470 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
471
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
472 if (inc != 0)
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
473 range = Range (base, limit, inc);
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
474 else
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
475 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
476
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
477 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
478 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
479
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
480 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
481 octave_range::save_binary (std::ostream& os, bool& /* save_as_floats */)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
482 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
483 char tmp = LS_DOUBLE;
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
484 os.write (reinterpret_cast<char *> (&tmp), 1);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
485 Range r = range_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
486 double bas = r.base ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
487 double lim = r.limit ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
488 double inc = r.inc ();
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
489 if (inc == 0)
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
490 lim = r.nelem ();
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
491
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
492 os.write (reinterpret_cast<char *> (&bas), 8);
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
493 os.write (reinterpret_cast<char *> (&lim), 8);
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
494 os.write (reinterpret_cast<char *> (&inc), 8);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
495
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
496 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
497 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
498
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
499 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
500 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
501 oct_mach_info::float_format /* fmt */)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
502 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
503 char tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
504 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
505 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
506 double bas, lim, inc;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
507 if (! is.read (reinterpret_cast<char *> (&bas), 8))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
508 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
509 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
510 swap_bytes<8> (&bas);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
511 if (! is.read (reinterpret_cast<char *> (&lim), 8))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
512 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
513 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
514 swap_bytes<8> (&lim);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
515 if (! is.read (reinterpret_cast<char *> (&inc), 8))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
516 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
517 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
518 swap_bytes<8> (&inc);
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
519 if (inc != 0)
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
520 range = Range (bas, lim, inc);
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
521 else
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
522 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
523
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
524 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
525 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
526
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
527 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
528
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
529 // 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
530 // 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
531 // 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
532 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
533 // conversions are handled automatically by HDF5.
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
534
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
535 static hid_t
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
536 hdf5_make_range_type (hid_t num_type)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
537 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
538 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 3);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
539
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
540 H5Tinsert (type_id, "base", 0 * sizeof (double), num_type);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
541 H5Tinsert (type_id, "limit", 1 * sizeof (double), num_type);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
542 H5Tinsert (type_id, "increment", 2 * sizeof (double), num_type);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
543
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
544 return type_id;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
545 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
546
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
547 #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
548
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
549 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
550 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
551 bool /* save_as_floats */)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
552 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19861
diff changeset
553 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
554
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
555 #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
556
4792
d2038299c683 [project @ 2004-02-20 18:44:43 by jwe]
jwe
parents: 4687
diff changeset
557 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
558 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
559 space_hid = type_hid = data_hid = -1;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
560
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4792
diff changeset
561 space_hid = H5Screate_simple (0, dimens, 0);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
562 if (space_hid < 0) return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
563
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
564 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
565 if (type_hid < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
566 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
567 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
568 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
569 }
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
570 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
571 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
572 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
573 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
574 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
575 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
576 if (data_hid < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
577 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
578 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
579 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
580 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
581 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
582
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
583 Range r = range_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
584 double range_vals[3];
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
585 range_vals[0] = r.base ();
10735
d899b2ee6a37 fix saving/loading of constant ranges (bug #30289)
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
586 range_vals[1] = r.inc () != 0 ? r.limit () : r.nelem ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
587 range_vals[2] = r.inc ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
588
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
589 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
590 range_vals) >= 0)
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
591 {
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
592 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
593 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
594 "OCTAVE_RANGE_NELEM", &nel) >= 0;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
595 }
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
596 else
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
597 retval = false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
598
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
599 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
600 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
601 H5Sclose (space_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
602
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 #else
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19861
diff changeset
604 gripe_save ("hdf5");
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19861
diff changeset
605 #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
606
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
607 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
608 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
609
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
610 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
611 octave_range::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
612 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
613 bool retval = false;
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
614
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
615 #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
616
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 #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
618 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
619 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
620 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
621 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
622 hid_t type_hid = H5Dget_type (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
623
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
624 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
625
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
626 if (! hdf5_types_compatible (type_hid, range_type))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
627 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
628 H5Tclose (range_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
629 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
630 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
631 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
632
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
633 hid_t space_hid = H5Dget_space (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
634 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
635
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
636 if (rank != 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
637 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
638 H5Tclose (range_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
639 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
640 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
641 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
642 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
643
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
644 double rangevals[3];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
645 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
646 rangevals) >= 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
647 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
648 retval = true;
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
649 octave_idx_type nel;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
650 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
651 "OCTAVE_RANGE_NELEM", &nel))
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
652 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
653 else
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
654 {
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
655 if (rangevals[2] != 0)
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 11129
diff changeset
656 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
657 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
658 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
659 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
660 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
661 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
662
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
663 H5Tclose (range_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
664 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
665 H5Dclose (data_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
666
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 #else
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19861
diff changeset
668 gripe_load ("hdf5");
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19861
diff changeset
669 #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
670
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
671 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4612
diff changeset
672 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
673
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
674 mxArray *
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
675 octave_range::as_mxArray (void) const
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
676 {
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
677 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL);
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
678
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
679 double *pr = static_cast<double *> (retval->get_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
680
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5958
diff changeset
681 mwSize nel = numel ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
682
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
683 Matrix m = matrix_value ();
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
684
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
685 const double *p = m.data ();
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
686
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5958
diff changeset
687 for (mwSize i = 0; i < nel; i++)
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
688 pr[i] = p[i];
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
689
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
690 return retval;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
691 }
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
692
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18416
diff changeset
693 octave_value
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18416
diff changeset
694 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
695 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
696 return (n < range.nelem ()) ? octave_value (range.elem (n))
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
697 : octave_value ();
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18416
diff changeset
698 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18416
diff changeset
699
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
700 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
701 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10735
diff changeset
702 @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
703 @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
704 @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
705 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
706 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
707 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19863
diff changeset
708 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
709 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
710 differently in different contexts.\n\
13951
79aa00a94e9e doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents: 13846
diff changeset
711 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16468
diff changeset
712 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
713 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
714 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
715 @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
716 {
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17870
diff changeset
717 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
718 if (! warned)
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17870
diff changeset
719 {
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17870
diff changeset
720 warned = true;
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17870
diff changeset
721 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
722 "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
723 }
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17870
diff changeset
724
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
725 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
726 }
12863
8f9702abe3e3 test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
727
8f9702abe3e3 test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
728 /*
8f9702abe3e3 test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
729 %!test
8f9702abe3e3 test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
730 %! 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
731 %! 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
732 %! 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
733 %! unwind_protect
14040
a64f8b6f63e9 test: simplify test for allow_noninteger_range_as_index
Rik <octave@nomad.inbox5.com>
parents: 13951
diff changeset
734 %! 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
735 %! 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
736 %! 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
737 %! 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
738 %! 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
739 %! 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
740 %! 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
741 %! 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
742 %! 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
743 %! 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
744 %! 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
745 %! end_unwind_protect
12863
8f9702abe3e3 test: Add validation for allow_noninteger_range_as_index()
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
746 */