GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-complex.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 // Complex scalar values.
47 
48 class
49 OCTINTERP_API
51 {
52 public:
53 
55  : octave_base_scalar<Complex> () { }
56 
59 
62 
63  ~octave_complex (void) = default;
64 
65  octave_base_value * clone (void) const { return new octave_complex (*this); }
66 
67  // We return an octave_complex_matrix object here instead of an
68  // octave_complex object so that in expressions like A(2,2,2) = 2
69  // (for A previously undefined), A will be empty instead of a 1x1
70  // object.
72  { return new octave_complex_matrix (); }
73 
74  type_conv_info numeric_demotion_function (void) const;
75 
76  octave_base_value * try_narrowing_conversion (void);
77 
78  octave_value do_index_op (const octave_value_list& idx,
79  bool resize_ok = false);
80 
81  // Use this to give a more specific error message.
82  idx_vector index_vector (bool /* require_integers */ = false) const;
83 
84  octave_value any (int = 0) const
85  {
86  return (scalar != Complex (0, 0)
87  && ! (lo_ieee_isnan (scalar.real ())
88  || lo_ieee_isnan (scalar.imag ())));
89  }
90 
91  builtin_type_t builtin_type (void) const { return btyp_complex; }
92 
93  bool is_complex_scalar (void) const { return true; }
94 
95  bool iscomplex (void) const { return true; }
96 
97  bool is_double_type (void) const { return true; }
98 
99  bool isfloat (void) const { return true; }
100 
101  double double_value (bool = false) const;
102 
103  float float_value (bool = false) const;
104 
105  double scalar_value (bool frc_str_conv = false) const
106  { return double_value (frc_str_conv); }
107 
108  float float_scalar_value (bool frc_str_conv = false) const
109  { return float_value (frc_str_conv); }
110 
111  Matrix matrix_value (bool = false) const;
112 
113  FloatMatrix float_matrix_value (bool = false) const;
114 
115  NDArray array_value (bool = false) const;
116 
117  FloatNDArray float_array_value (bool = false) const;
118 
119  SparseMatrix sparse_matrix_value (bool = false) const
120  { return SparseMatrix (matrix_value ()); }
121 
123  { return SparseComplexMatrix (complex_matrix_value ()); }
124 
125  octave_value resize (const dim_vector& dv, bool fill = false) const;
126 
127  Complex complex_value (bool = false) const;
128 
129  FloatComplex float_complex_value (bool = false) const;
130 
131  ComplexMatrix complex_matrix_value (bool = false) const;
132 
133  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
134 
135  ComplexNDArray complex_array_value (bool = false) const;
136 
137  FloatComplexNDArray float_complex_array_value (bool = false) const;
138 
139  bool bool_value (bool warn = false) const
140  {
143  if (warn && scalar != 0.0 && scalar != 1.0)
145 
146  return scalar != 0.0;
147  }
148 
149  boolNDArray bool_array_value (bool warn = false) const
150  {
153  if (warn && scalar != 0.0 && scalar != 1.0)
155 
156  return boolNDArray (dim_vector (1, 1), scalar != 0.0);
157  }
158 
159  octave_value as_double (void) const;
160  octave_value as_single (void) const;
161 
162  octave_value diag (octave_idx_type m, octave_idx_type n) const;
163 
164  void increment (void) { scalar += 1.0; }
165 
166  void decrement (void) { scalar -= 1.0; }
167 
168  bool save_ascii (std::ostream& os);
169 
170  bool load_ascii (std::istream& is);
171 
172  bool save_binary (std::ostream& os, bool& save_as_floats);
173 
174  bool load_binary (std::istream& is, bool swap,
176 
177  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
178 
179  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
180 
181  int write (octave::stream& os, int block_size,
182  oct_data_conv::data_type output_type, int skip,
184  {
185  // Yes, for compatibility, we drop the imaginary part here.
186  return os.write (array_value (true), block_size, output_type,
187  skip, flt_fmt);
188  }
189 
190  mxArray * as_mxArray (void) const;
191 
192  octave_value map (unary_mapper_t umap) const;
193 
194 private:
195 
197 };
198 
200 
201 #endif
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6704
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-complex.h:122
bool iscomplex(void) const
Definition: ov-complex.h:95
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5264
octave_base_value * empty_clone(void) const
Definition: ov-complex.h:71
void warn_logical_conversion(void)
Definition: errwarn.cc:359
bool isnan(bool)
Definition: lo-mappers.h:187
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
float float_scalar_value(bool frc_str_conv=false) const
Definition: ov-complex.h:108
builtin_type_t
Definition: ov-base.h:71
void err_nan_to_logical_conversion(void)
double scalar_value(bool frc_str_conv=false) const
Definition: ov-complex.h:105
bool isfloat(void) const
Definition: ov-complex.h:99
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:105
bool bool_value(bool warn=false) const
Definition: ov-complex.h:139
static double as_double(time_t sec, long usec)
Definition: oct-time.h:34
bool swap
Definition: load-save.cc:738
octave_complex(void)
Definition: ov-complex.h:54
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
octave_value any(int=0) const
Definition: ov-complex.h:84
void increment(void)
Definition: ov-complex.h:164
nd deftypefn *std::string name
Definition: sysdep.cc:647
octave_complex(const Complex &c)
Definition: ov-complex.h:57
octave_complex(const octave_complex &c)
Definition: ov-complex.h:60
Array< octave_value > array_value(void) const
Definition: ovl.h:86
bool save_as_floats
Definition: load-save.cc:1617
int64_t octave_hdf5_id
void decrement(void)
Definition: ov-complex.h:166
bool is_complex_scalar(void) const
Definition: ov-complex.h:93
octave_base_value * clone(void) const
Definition: ov-complex.h:65
Definition: dMatrix.h:36
octave_complex octave_complex_scalar
Definition: ov-complex.h:199
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-complex.h:119
octave_map map(dims)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
builtin_type_t builtin_type(void) const
Definition: ov-complex.h:91
std::complex< double > Complex
Definition: oct-cmplx.h:31
write the output to stdout if nargout is
Definition: load-save.cc:1612
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
boolNDArray bool_array_value(bool warn=false) const
Definition: ov-complex.h:149
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:181
bool is_double_type(void) const
Definition: ov-complex.h:97