00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_scalar_h)
00025 #define octave_scalar_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031
00032 #include "lo-ieee.h"
00033 #include "lo-mappers.h"
00034 #include "lo-utils.h"
00035 #include "mx-base.h"
00036 #include "oct-alloc.h"
00037 #include "str-vec.h"
00038
00039 #include "gripes.h"
00040 #include "ov-base.h"
00041 #include "ov-re-mat.h"
00042 #include "ov-base-scalar.h"
00043 #include "ov-typeinfo.h"
00044
00045 class Octave_map;
00046 class octave_value_list;
00047
00048 class tree_walker;
00049
00050
00051
00052 class
00053 OCTINTERP_API
00054 octave_scalar : public octave_base_scalar<double>
00055 {
00056 public:
00057
00058 octave_scalar (void)
00059 : octave_base_scalar<double> (0.0) { }
00060
00061 octave_scalar (double d)
00062 : octave_base_scalar<double> (d) { }
00063
00064 octave_scalar (const octave_scalar& s)
00065 : octave_base_scalar<double> (s) { }
00066
00067 ~octave_scalar (void) { }
00068
00069 octave_base_value *clone (void) const { return new octave_scalar (*this); }
00070
00071
00072
00073
00074 octave_base_value *empty_clone (void) const { return new octave_matrix (); }
00075
00076 octave_value do_index_op (const octave_value_list& idx,
00077 bool resize_ok = false);
00078
00079 type_conv_info numeric_demotion_function (void) const;
00080
00081 idx_vector index_vector (void) const { return idx_vector (scalar); }
00082
00083 octave_value any (int = 0) const
00084 { return (scalar != 0 && ! lo_ieee_isnan (scalar)); }
00085
00086 builtin_type_t builtin_type (void) const { return btyp_double; }
00087
00088 bool is_real_scalar (void) const { return true; }
00089
00090 bool is_real_type (void) const { return true; }
00091
00092 bool is_double_type (void) const { return true; }
00093
00094 bool is_float_type (void) const { return true; }
00095
00096 int8NDArray
00097 int8_array_value (void) const
00098 { return int8NDArray (dim_vector (1, 1), scalar); }
00099
00100 int16NDArray
00101 int16_array_value (void) const
00102 { return int16NDArray (dim_vector (1, 1), scalar); }
00103
00104 int32NDArray
00105 int32_array_value (void) const
00106 { return int32NDArray (dim_vector (1, 1), scalar); }
00107
00108 int64NDArray
00109 int64_array_value (void) const
00110 { return int64NDArray (dim_vector (1, 1), scalar); }
00111
00112 uint8NDArray
00113 uint8_array_value (void) const
00114 { return uint8NDArray (dim_vector (1, 1), scalar); }
00115
00116 uint16NDArray
00117 uint16_array_value (void) const
00118 { return uint16NDArray (dim_vector (1, 1), scalar); }
00119
00120 uint32NDArray
00121 uint32_array_value (void) const
00122 { return uint32NDArray (dim_vector (1, 1), scalar); }
00123
00124 uint64NDArray
00125 uint64_array_value (void) const
00126 { return uint64NDArray (dim_vector (1, 1), scalar); }
00127
00128 #define DEFINE_INT_SCALAR_VALUE(TYPE) \
00129 octave_ ## TYPE \
00130 TYPE ## _scalar_value (void) const \
00131 { return octave_ ## TYPE (scalar); }
00132
00133 DEFINE_INT_SCALAR_VALUE (int8)
00134 DEFINE_INT_SCALAR_VALUE (int16)
00135 DEFINE_INT_SCALAR_VALUE (int32)
00136 DEFINE_INT_SCALAR_VALUE (int64)
00137 DEFINE_INT_SCALAR_VALUE (uint8)
00138 DEFINE_INT_SCALAR_VALUE (uint16)
00139 DEFINE_INT_SCALAR_VALUE (uint32)
00140 DEFINE_INT_SCALAR_VALUE (uint64)
00141
00142 #undef DEFINE_INT_SCALAR_VALUE
00143
00144 double double_value (bool = false) const { return scalar; }
00145
00146 float float_value (bool = false) const { return static_cast<float> (scalar); }
00147
00148 double scalar_value (bool = false) const { return scalar; }
00149
00150 float float_scalar_value (bool = false) const { return static_cast<float> (scalar); }
00151
00152 Matrix matrix_value (bool = false) const
00153 { return Matrix (1, 1, scalar); }
00154
00155 FloatMatrix float_matrix_value (bool = false) const
00156 { return FloatMatrix (1, 1, scalar); }
00157
00158 NDArray array_value (bool = false) const
00159 { return NDArray (dim_vector (1, 1), scalar); }
00160
00161 FloatNDArray float_array_value (bool = false) const
00162 { return FloatNDArray (dim_vector (1, 1), scalar); }
00163
00164 SparseMatrix sparse_matrix_value (bool = false) const
00165 { return SparseMatrix (Matrix (1, 1, scalar)); }
00166
00167
00168 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
00169 { return SparseComplexMatrix (sparse_matrix_value ()); }
00170
00171 octave_value resize (const dim_vector& dv, bool fill = false) const;
00172
00173 Complex complex_value (bool = false) const { return scalar; }
00174
00175 FloatComplex float_complex_value (bool = false) const { return scalar; }
00176
00177 ComplexMatrix complex_matrix_value (bool = false) const
00178 { return ComplexMatrix (1, 1, Complex (scalar)); }
00179
00180 FloatComplexMatrix float_complex_matrix_value (bool = false) const
00181 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
00182
00183 ComplexNDArray complex_array_value (bool = false) const
00184 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
00185
00186 FloatComplexNDArray float_complex_array_value (bool = false) const
00187 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
00188
00189 charNDArray
00190 char_array_value (bool = false) const
00191 {
00192 charNDArray retval (dim_vector (1, 1));
00193 retval(0) = static_cast<char> (scalar);
00194 return retval;
00195 }
00196
00197 bool bool_value (bool warn = false) const
00198 {
00199 if (xisnan (scalar))
00200 error ("invalid conversion from NaN to logical");
00201 else if (warn && scalar != 0 && scalar != 1)
00202 gripe_logical_conversion ();
00203
00204 return scalar;
00205 }
00206
00207 boolNDArray bool_array_value (bool warn = false) const
00208 {
00209 if (xisnan (scalar))
00210 error ("invalid conversion from NaN to logical");
00211 else if (warn && scalar != 0 && scalar != 1)
00212 gripe_logical_conversion ();
00213
00214 return boolNDArray (dim_vector (1, 1), scalar);
00215 }
00216
00217 octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00218
00219 void increment (void) { ++scalar; }
00220
00221 void decrement (void) { --scalar; }
00222
00223 bool save_ascii (std::ostream& os);
00224
00225 bool load_ascii (std::istream& is);
00226
00227 bool save_binary (std::ostream& os, bool& save_as_floats);
00228
00229 bool load_binary (std::istream& is, bool swap,
00230 oct_mach_info::float_format fmt);
00231
00232 #if defined (HAVE_HDF5)
00233 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00234
00235 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug);
00236 #endif
00237
00238 int write (octave_stream& os, int block_size,
00239 oct_data_conv::data_type output_type, int skip,
00240 oct_mach_info::float_format flt_fmt) const
00241 {
00242 return os.write (array_value (), block_size, output_type,
00243 skip, flt_fmt);
00244 }
00245
00246 mxArray *as_mxArray (void) const;
00247
00248 octave_value erf (void) const;
00249 octave_value erfc (void) const;
00250 octave_value gamma (void) const;
00251 octave_value lgamma (void) const;
00252 octave_value abs (void) const;
00253 octave_value acos (void) const;
00254 octave_value acosh (void) const;
00255 octave_value angle (void) const;
00256 octave_value arg (void) const;
00257 octave_value asin (void) const;
00258 octave_value asinh (void) const;
00259 octave_value atan (void) const;
00260 octave_value atanh (void) const;
00261 octave_value ceil (void) const;
00262 octave_value conj (void) const;
00263 octave_value cos (void) const;
00264 octave_value cosh (void) const;
00265 octave_value exp (void) const;
00266 octave_value expm1 (void) const;
00267 octave_value fix (void) const;
00268 octave_value floor (void) const;
00269 octave_value imag (void) const;
00270 octave_value log (void) const;
00271 octave_value log2 (void) const;
00272 octave_value log10 (void) const;
00273 octave_value log1p (void) const;
00274 octave_value real (void) const;
00275 octave_value round (void) const;
00276 octave_value roundb (void) const;
00277 octave_value signum (void) const;
00278 octave_value sin (void) const;
00279 octave_value sinh (void) const;
00280 octave_value sqrt (void) const;
00281 octave_value tan (void) const;
00282 octave_value tanh (void) const;
00283 octave_value finite (void) const;
00284 octave_value isinf (void) const;
00285 octave_value isna (void) const;
00286 octave_value isnan (void) const;
00287
00288 private:
00289 octave_value map (double (*fcn) (double)) const;
00290
00291 DECLARE_OCTAVE_ALLOCATOR
00292
00293 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00294 };
00295
00296 #endif
00297
00298
00299
00300
00301
00302