GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-complex.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_ov_complex_h)
24 #define octave_ov_complex_h 1
25 
26 #include "octave-config.h"
27 
28 #include <cstdlib>
29 
30 #include <iosfwd>
31 #include <string>
32 
33 #include "lo-ieee.h"
34 #include "mx-base.h"
35 #include "str-vec.h"
36 
37 #include "errwarn.h"
38 #include "error.h"
39 #include "ov-base.h"
40 #include "ov-cx-mat.h"
41 #include "ov-base-scalar.h"
42 #include "ov-typeinfo.h"
43 
44 class octave_value_list;
45 
46 class tree_walker;
47 
48 // Complex scalar values.
49 
50 class
53 {
54 public:
55 
57  : octave_base_scalar<Complex> () { }
58 
60  : octave_base_scalar<Complex> (c) { }
61 
63  : octave_base_scalar<Complex> (c) { }
64 
65  ~octave_complex (void) { }
66 
67  octave_base_value *clone (void) const { return new octave_complex (*this); }
68 
69  // We return an octave_complex_matrix object here instead of an
70  // octave_complex object so that in expressions like A(2,2,2) = 2
71  // (for A previously undefined), A will be empty instead of a 1x1
72  // object.
74  { return new octave_complex_matrix (); }
75 
76  type_conv_info numeric_demotion_function (void) const;
77 
78  octave_base_value *try_narrowing_conversion (void);
79 
80  octave_value do_index_op (const octave_value_list& idx,
81  bool resize_ok = false);
82 
83  // Use this to give a more specific error message.
84  idx_vector index_vector (bool /* require_integers */ = false) const;
85 
86  octave_value any (int = 0) const
87  {
88  return (scalar != Complex (0, 0)
89  && ! (lo_ieee_isnan (scalar.real ())
90  || lo_ieee_isnan (scalar.imag ())));
91  }
92 
93  builtin_type_t builtin_type (void) const { return btyp_complex; }
94 
95  bool is_complex_scalar (void) const { return true; }
96 
97  bool is_complex_type (void) const { return true; }
98 
99  bool is_double_type (void) const { return true; }
100 
101  bool is_float_type (void) const { return true; }
102 
103  double double_value (bool = false) const;
104 
105  float float_value (bool = false) const;
106 
107  double scalar_value (bool frc_str_conv = false) const
108  { return double_value (frc_str_conv); }
109 
110  float float_scalar_value (bool frc_str_conv = false) const
111  { return float_value (frc_str_conv); }
112 
113  Matrix matrix_value (bool = false) const;
114 
115  FloatMatrix float_matrix_value (bool = false) const;
116 
117  NDArray array_value (bool = false) const;
118 
119  FloatNDArray float_array_value (bool = false) const;
120 
121  SparseMatrix sparse_matrix_value (bool = false) const
122  { return SparseMatrix (matrix_value ()); }
123 
125  { return SparseComplexMatrix (complex_matrix_value ()); }
126 
127  octave_value resize (const dim_vector& dv, bool fill = false) const;
128 
129  Complex complex_value (bool = false) const;
130 
131  FloatComplex float_complex_value (bool = false) const;
132 
133  ComplexMatrix complex_matrix_value (bool = false) const;
134 
135  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
136 
137  ComplexNDArray complex_array_value (bool = false) const;
138 
139  FloatComplexNDArray float_complex_array_value (bool = false) const;
140 
141  bool bool_value (bool warn = false) const
142  {
145  if (warn && scalar != 0.0 && scalar != 1.0)
147 
148  return scalar != 0.0;
149  }
150 
151  boolNDArray bool_array_value (bool warn = false) const
152  {
155  if (warn && scalar != 0.0 && scalar != 1.0)
157 
158  return boolNDArray (dim_vector (1, 1), scalar != 0.0);
159  }
160 
161  octave_value as_double (void) const;
162  octave_value as_single (void) const;
163 
165 
166  void increment (void) { scalar += 1.0; }
167 
168  void decrement (void) { scalar -= 1.0; }
169 
170  bool save_ascii (std::ostream& os);
171 
172  bool load_ascii (std::istream& is);
173 
174  bool save_binary (std::ostream& os, bool& save_as_floats);
175 
176  bool load_binary (std::istream& is, bool swap,
178 
179  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
180 
181  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
182 
183  int write (octave_stream& os, int block_size,
184  oct_data_conv::data_type output_type, int skip,
186  {
187  // Yes, for compatibility, we drop the imaginary part here.
188  return os.write (array_value (true), block_size, output_type,
189  skip, flt_fmt);
190  }
191 
192  mxArray *as_mxArray (void) const;
193 
194  octave_value map (unary_mapper_t umap) const;
195 
196 private:
197 
199 };
200 
202 
203 #endif
boolNDArray bool_array_value(bool warn=false) const
Definition: ov-complex.h:151
~octave_complex(void)
Definition: ov-complex.h:65
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5342
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-complex.h:121
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, octave::mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6647
octave_base_value * clone(void) const
Definition: ov-complex.h:67
void warn_logical_conversion(void)
Definition: errwarn.cc:353
bool bool_value(bool warn=false) const
Definition: ov-complex.h:141
double scalar_value(bool frc_str_conv=false) const
Definition: ov-complex.h:107
bool isnan(double x)
Definition: lo-mappers.cc:347
float float_scalar_value(bool frc_str_conv=false) const
Definition: ov-complex.h:110
bool is_complex_scalar(void) const
Definition: ov-complex.h:95
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
builtin_type_t
Definition: ov-base.h:61
void err_nan_to_logical_conversion(void)
builtin_type_t builtin_type(void) const
Definition: ov-complex.h:93
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-complex.h:124
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:103
octave_value any(int=0) const
Definition: ov-complex.h:86
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
Definition: ov-complex.h:183
bool swap
Definition: load-save.cc:725
octave_complex(void)
Definition: ov-complex.h:56
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:148
void increment(void)
Definition: ov-complex.h:166
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
#define OCTINTERP_API
Definition: mexproto.h:69
octave_complex(const Complex &c)
Definition: ov-complex.h:59
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
bool is_complex_type(void) const
Definition: ov-complex.h:97
octave_complex(const octave_complex &c)
Definition: ov-complex.h:62
bool save_as_floats
Definition: load-save.cc:1581
int64_t octave_hdf5_id
void decrement(void)
Definition: ov-complex.h:168
Definition: dMatrix.h:37
bool is_float_type(void) const
Definition: ov-complex.h:101
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
bool is_double_type(void) const
Definition: ov-complex.h:99
octave_base_value * empty_clone(void) const
Definition: ov-complex.h:73
octave_complex octave_complex_scalar
Definition: ov-complex.h:201
octave_map map(dims)
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
std::complex< double > Complex
Definition: oct-cmplx.h:31
write the output to stdout if nargout is
Definition: load-save.cc:1576
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
dim_vector dv
Definition: sub2ind.cc:263