GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-flt-complex.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_ov_flt_complex_h)
27#define octave_ov_flt_complex_h 1
28
29#include "octave-config.h"
30
31#include <cstdlib>
32
33#include <iosfwd>
34#include <string>
35
36#include "lo-ieee.h"
37#include "mx-base.h"
38#include "str-vec.h"
39
40#include "errwarn.h"
41#include "error.h"
42#include "ov-base.h"
43#include "ov-flt-cx-mat.h"
44#include "ov-base-scalar.h"
45#include "ov-typeinfo.h"
46
48
49// Complex scalar values.
50
51class
52OCTINTERP_API
54{
55public:
56
59
62
65
66 ~octave_float_complex (void) = default;
67
68 octave_base_value * clone (void) const
69 { return new octave_float_complex (*this); }
70
71 // We return an octave_float_complex_matrix object here instead of an
72 // octave_float_complex object so that in expressions like A(2,2,2) = 2
73 // (for A previously undefined), A will be empty instead of a 1x1
74 // object.
76 { return new octave_float_complex_matrix (); }
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 octave_value any (int = 0) const
84 {
85 return (scalar != FloatComplex (0, 0)
86 && ! (lo_ieee_isnan (scalar.real ())
87 || lo_ieee_isnan (scalar.imag ())));
88 }
89
91
92 bool is_complex_scalar (void) const { return true; }
93
94 bool iscomplex (void) const { return true; }
95
96 bool is_single_type (void) const { return true; }
97
98 bool isfloat (void) const { return true; }
99
100 double double_value (bool = false) const;
101
102 float float_value (bool = false) const;
103
104 double scalar_value (bool frc_str_conv = false) const
105 { return double_value (frc_str_conv); }
106
107 float float_scalar_value (bool frc_str_conv = false) const
108 { return float_value (frc_str_conv); }
109
110 Matrix matrix_value (bool = false) const;
111
112 FloatMatrix float_matrix_value (bool = false) const;
113
114 NDArray array_value (bool = false) const;
115
116 FloatNDArray float_array_value (bool = false) const;
117
119 { return SparseMatrix (matrix_value ()); }
120
122 { return SparseComplexMatrix (complex_matrix_value ()); }
123
124 octave_value resize (const dim_vector& dv, bool fill = false) const;
125
126 Complex complex_value (bool = false) const;
127
128 FloatComplex float_complex_value (bool = false) const;
129
130 ComplexMatrix complex_matrix_value (bool = false) const;
131
132 FloatComplexMatrix float_complex_matrix_value (bool = false) const;
133
134 ComplexNDArray complex_array_value (bool = false) const;
135
136 FloatComplexNDArray float_complex_array_value (bool = false) const;
137
138 bool bool_value (bool warn = false) const
139 {
142 if (warn && scalar != 0.0f && scalar != 1.0f)
144
145 return scalar != 0.0f;
146 }
147
148 boolNDArray bool_array_value (bool warn = false) const
149 {
152 if (warn && scalar != 0.0f && scalar != 1.0f)
154
155 return boolNDArray (dim_vector (1, 1), scalar != 1.0f);
156 }
157
158 octave_value as_double (void) const;
159 octave_value as_single (void) const;
160
161 // We don't need to override both forms of the diag method. The using
162 // declaration will avoid warnings about partially-overloaded virtual
163 // functions.
164 using octave_base_scalar<FloatComplex>::diag;
165
167
168 void increment (void) { scalar += 1.0; }
169
170 void decrement (void) { scalar -= 1.0; }
171
172 bool save_ascii (std::ostream& os);
173
174 bool load_ascii (std::istream& is);
175
176 bool save_binary (std::ostream& os, bool save_as_floats);
177
178 bool load_binary (std::istream& is, bool swap,
180
181 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
182
183 bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
184
185 int write (octave::stream& os, int block_size,
186 oct_data_conv::data_type output_type, int skip,
188 {
189 // Yes, for compatibility, we drop the imaginary part here.
190 return os.write (array_value (true), block_size, output_type,
191 skip, flt_fmt);
192 }
193
194 mxArray * as_mxArray (bool interleaved) const;
195
196 octave_value map (unary_mapper_t umap) const;
197
198private:
199
201};
202
204
205#endif
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
OCTINTERP_API 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:6773
bool is_complex_scalar(void) const
bool isfloat(void) const
bool bool_value(bool warn=false) const
bool is_single_type(void) const
SparseMatrix sparse_matrix_value(bool=false) const
double scalar_value(bool frc_str_conv=false) const
~octave_float_complex(void)=default
octave_float_complex(const octave_float_complex &c)
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
octave_float_complex(const FloatComplex &c)
octave_value any(int=0) const
builtin_type_t builtin_type(void) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
boolNDArray bool_array_value(bool warn=false) const
octave_base_value * empty_clone(void) const
bool iscomplex(void) const
octave_base_value * clone(void) const
float float_scalar_value(bool frc_str_conv=false) const
Array< octave_value > array_value(void) const
Definition: ovl.h:90
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:117
void warn_logical_conversion(void)
Definition: errwarn.cc:365
QString name
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:100
class OCTAVE_API boolNDArray
Definition: mx-fwd.h:42
class OCTAVE_API SparseMatrix
Definition: mx-fwd.h:55
class OCTAVE_API SparseComplexMatrix
Definition: mx-fwd.h:56
bool isnan(bool)
Definition: lo-mappers.h:178
void err_nan_to_logical_conversion(void)
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
int64_t octave_hdf5_id
static double as_double(OCTAVE_TIME_T sec, long usec)
Definition: oct-time.h:35
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:173
builtin_type_t
Definition: ov-base.h:75
@ btyp_float_complex
Definition: ov-base.h:79
octave_float_complex octave_float_complex_scalar
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:679