Mercurial > hg > octave-nkf
annotate src/ov-scalar.h @ 8437:f00578b495e9
remove valid_as_scalar_index
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 27 Dec 2008 17:01:52 +0100 |
parents | c777f3ce02d8 |
children | 97d146d1648b |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
4 2007 John W. Eaton | |
2376 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_scalar_h) | |
25 #define octave_scalar_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
3503 | 29 #include <iostream> |
2376 | 30 #include <string> |
31 | |
5110 | 32 #include "lo-ieee.h" |
2889 | 33 #include "lo-mappers.h" |
2376 | 34 #include "lo-utils.h" |
35 #include "mx-base.h" | |
2477 | 36 #include "oct-alloc.h" |
2376 | 37 #include "str-vec.h" |
38 | |
5943 | 39 #include "gripes.h" |
2376 | 40 #include "ov-base.h" |
4749 | 41 #include "ov-re-mat.h" |
3223 | 42 #include "ov-base-scalar.h" |
2376 | 43 #include "ov-typeinfo.h" |
44 | |
45 class Octave_map; | |
46 class octave_value_list; | |
47 | |
48 class tree_walker; | |
49 | |
50 // Real scalar values. | |
51 | |
52 class | |
6153 | 53 OCTINTERP_API |
3223 | 54 octave_scalar : public octave_base_scalar<double> |
2376 | 55 { |
56 public: | |
57 | |
58 octave_scalar (void) | |
3223 | 59 : octave_base_scalar<double> (0.0) { } |
2376 | 60 |
61 octave_scalar (double d) | |
3223 | 62 : octave_base_scalar<double> (d) { } |
2376 | 63 |
64 octave_scalar (const octave_scalar& s) | |
3223 | 65 : octave_base_scalar<double> (s) { } |
2376 | 66 |
67 ~octave_scalar (void) { } | |
68 | |
5759 | 69 octave_base_value *clone (void) const { return new octave_scalar (*this); } |
4749 | 70 |
71 // We return an octave_matrix here instead of an octave_scalar so | |
72 // that in expressions like A(2,2,2) = 2 (for A previously | |
73 // undefined), A will be empty instead of a 1x1 object. | |
5759 | 74 octave_base_value *empty_clone (void) const { return new octave_matrix (); } |
2376 | 75 |
5885 | 76 octave_value do_index_op (const octave_value_list& idx, |
77 bool resize_ok = false); | |
2376 | 78 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
79 type_conv_info numeric_demotion_function (void) const; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
80 |
2376 | 81 idx_vector index_vector (void) const { return idx_vector (scalar); } |
82 | |
5110 | 83 octave_value any (int = 0) const |
84 { return (scalar != 0 && ! lo_ieee_isnan (scalar)); } | |
85 | |
2376 | 86 bool is_real_scalar (void) const { return true; } |
87 | |
88 bool is_real_type (void) const { return true; } | |
89 | |
5895 | 90 bool is_double_type (void) const { return true; } |
91 | |
7576 | 92 bool is_float_type (void) const { return true; } |
93 | |
5533 | 94 int8NDArray |
95 int8_array_value (void) const | |
96 { return int8NDArray (dim_vector (1, 1), scalar); } | |
97 | |
98 int16NDArray | |
99 int16_array_value (void) const | |
100 { return int16NDArray (dim_vector (1, 1), scalar); } | |
101 | |
102 int32NDArray | |
103 int32_array_value (void) const | |
104 { return int32NDArray (dim_vector (1, 1), scalar); } | |
105 | |
106 int64NDArray | |
107 int64_array_value (void) const | |
108 { return int64NDArray (dim_vector (1, 1), scalar); } | |
109 | |
110 uint8NDArray | |
111 uint8_array_value (void) const | |
112 { return uint8NDArray (dim_vector (1, 1), scalar); } | |
113 | |
114 uint16NDArray | |
115 uint16_array_value (void) const | |
116 { return uint16NDArray (dim_vector (1, 1), scalar); } | |
117 | |
118 uint32NDArray | |
119 uint32_array_value (void) const | |
120 { return uint32NDArray (dim_vector (1, 1), scalar); } | |
121 | |
122 uint64NDArray | |
123 uint64_array_value (void) const | |
124 { return uint64NDArray (dim_vector (1, 1), scalar); } | |
125 | |
2376 | 126 double double_value (bool = false) const { return scalar; } |
127 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
128 float float_value (bool = false) const { return static_cast<float> (scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
129 |
2916 | 130 double scalar_value (bool = false) const { return scalar; } |
131 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 float float_scalar_value (bool = false) const { return static_cast<float> (scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
133 |
3145 | 134 Matrix matrix_value (bool = false) const |
135 { return Matrix (1, 1, scalar); } | |
2376 | 136 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 FloatMatrix float_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
138 { return FloatMatrix (1, 1, scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
139 |
4569 | 140 NDArray array_value (bool = false) const |
4630 | 141 { return NDArray (dim_vector (1, 1), scalar); } |
4505 | 142 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
143 FloatNDArray float_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
144 { return FloatNDArray (dim_vector (1, 1), scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
145 |
5989 | 146 SparseMatrix sparse_matrix_value (bool = false) const |
147 { return SparseMatrix (Matrix (1, 1, scalar)); } | |
148 | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
149 // FIXME Need SparseComplexMatrix (Matrix) constructor!!! |
5989 | 150 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
151 { return SparseComplexMatrix (sparse_matrix_value ()); } | |
152 | |
5731 | 153 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 154 |
2376 | 155 Complex complex_value (bool = false) const { return scalar; } |
156 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
157 FloatComplex float_complex_value (bool = false) const { return scalar; } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
158 |
2376 | 159 ComplexMatrix complex_matrix_value (bool = false) const |
160 { return ComplexMatrix (1, 1, Complex (scalar)); } | |
161 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
162 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
163 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
164 |
4569 | 165 ComplexNDArray complex_array_value (bool = false) const |
4630 | 166 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } |
4569 | 167 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
168 FloatComplexNDArray float_complex_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
169 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
170 |
5533 | 171 charNDArray |
172 char_array_value (bool = false) const | |
173 { | |
174 charNDArray retval (dim_vector (1, 1)); | |
175 retval(0) = static_cast<char> (scalar); | |
176 return retval; | |
177 } | |
178 | |
5943 | 179 bool bool_value (bool warn = false) const |
180 { | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
181 if (xisnan (scalar)) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
182 error ("invalid conversion from NaN to logical"); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
183 else if (warn && scalar != 0 && scalar != 1) |
5943 | 184 gripe_logical_conversion (); |
185 | |
186 return scalar; | |
187 } | |
5533 | 188 |
5943 | 189 boolNDArray bool_array_value (bool warn = false) const |
190 { | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
191 if (xisnan (scalar)) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
192 error ("invalid conversion from NaN to logical"); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
193 else if (warn && scalar != 0 && scalar != 1) |
5943 | 194 gripe_logical_conversion (); |
195 | |
196 return boolNDArray (dim_vector (1, 1), scalar); | |
197 } | |
5533 | 198 |
5279 | 199 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
3223 | 200 |
2376 | 201 void increment (void) { ++scalar; } |
202 | |
203 void decrement (void) { --scalar; } | |
204 | |
6974 | 205 bool save_ascii (std::ostream& os); |
4687 | 206 |
207 bool load_ascii (std::istream& is); | |
208 | |
209 bool save_binary (std::ostream& os, bool& save_as_floats); | |
210 | |
211 bool load_binary (std::istream& is, bool swap, | |
212 oct_mach_info::float_format fmt); | |
213 | |
214 #if defined (HAVE_HDF5) | |
215 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
216 | |
217 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
218 #endif | |
219 | |
4944 | 220 int write (octave_stream& os, int block_size, |
221 oct_data_conv::data_type output_type, int skip, | |
222 oct_mach_info::float_format flt_fmt) const | |
223 { | |
224 return os.write (array_value (), block_size, output_type, | |
225 skip, flt_fmt); | |
226 } | |
227 | |
5900 | 228 mxArray *as_mxArray (void) const; |
229 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
230 octave_value erf (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
231 octave_value erfc (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
232 octave_value gamma (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
233 octave_value lgamma (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
234 octave_value abs (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
235 octave_value acos (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
236 octave_value acosh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
237 octave_value angle (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
238 octave_value arg (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
239 octave_value asin (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
240 octave_value asinh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
241 octave_value atan (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
242 octave_value atanh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
243 octave_value ceil (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
244 octave_value conj (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
245 octave_value cos (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
246 octave_value cosh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
247 octave_value exp (void) const; |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7636
diff
changeset
|
248 octave_value expm1 (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
249 octave_value fix (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
250 octave_value floor (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
251 octave_value imag (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
252 octave_value log (void) const; |
7740 | 253 octave_value log2 (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
254 octave_value log10 (void) const; |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7636
diff
changeset
|
255 octave_value log1p (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
256 octave_value real (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
257 octave_value round (void) const; |
7636
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7576
diff
changeset
|
258 octave_value roundb (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
259 octave_value signum (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
260 octave_value sin (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
261 octave_value sinh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
262 octave_value sqrt (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
263 octave_value tan (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
264 octave_value tanh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
265 octave_value finite (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
266 octave_value isinf (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
267 octave_value isna (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
268 octave_value isnan (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
269 |
2376 | 270 private: |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
271 octave_value map (double (*fcn) (double)) const; |
2376 | 272 |
4612 | 273 DECLARE_OCTAVE_ALLOCATOR |
2477 | 274 |
4612 | 275 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 276 }; |
277 | |
278 #endif | |
279 | |
280 /* | |
281 ;;; Local Variables: *** | |
282 ;;; mode: C++ *** | |
283 ;;; End: *** | |
284 */ |