GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-flt-complex.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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 "mx-base.h"
37#include "str-vec.h"
38
39#include "errwarn.h"
40#include "error.h"
41#include "ov-base.h"
42#include "ov-flt-cx-mat.h"
43#include "ov-base-scalar.h"
44#include "ov-typeinfo.h"
45
47
48// Complex scalar values.
49
50extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<FloatComplex>;
51
53{
54public:
55
58
61
64
66
68 { return new octave_float_complex (*this); }
69
70 // We return an octave_float_complex_matrix object here instead of an
71 // octave_float_complex object so that in expressions like A(2,2,2) = 2
72 // (for A previously undefined), A will be empty instead of a 1x1
73 // object.
76
77 octave_base_value * try_narrowing_conversion ();
78
79 octave_value do_index_op (const octave_value_list& idx,
80 bool resize_ok = false);
81
82 octave_value any (int = 0) const
83 {
84 return (scalar != FloatComplex (0, 0)
85 && ! (octave::math::isnan (scalar.real ())
86 || octave::math::isnan (scalar.imag ())));
87 }
88
90
91 bool is_complex_scalar () const { return true; }
92
93 bool iscomplex () const { return true; }
94
95 bool is_single_type () const { return true; }
96
97 bool isfloat () const { return true; }
98
99 double double_value (bool = false) const;
100
101 float float_value (bool = false) const;
102
103 double scalar_value (bool frc_str_conv = false) const
104 { return double_value (frc_str_conv); }
105
106 float float_scalar_value (bool frc_str_conv = false) const
107 { return float_value (frc_str_conv); }
108
109 Matrix matrix_value (bool = false) const;
110
111 FloatMatrix float_matrix_value (bool = false) const;
112
113 NDArray array_value (bool = false) const;
114
115 FloatNDArray float_array_value (bool = false) const;
116
118 { return SparseMatrix (matrix_value ()); }
119
121 { return SparseComplexMatrix (complex_matrix_value ()); }
122
123 octave_value resize (const dim_vector& dv, bool fill = false) const;
124
125 Complex complex_value (bool = false) const;
126
127 FloatComplex float_complex_value (bool = false) const;
128
129 ComplexMatrix complex_matrix_value (bool = false) const;
130
131 FloatComplexMatrix float_complex_matrix_value (bool = false) const;
132
133 ComplexNDArray complex_array_value (bool = false) const;
134
135 FloatComplexNDArray float_complex_array_value (bool = false) const;
136
137 bool bool_value (bool warn = false) const
138 {
139 if (octave::math::isnan (scalar))
140 octave::err_nan_to_logical_conversion ();
141 if (warn && scalar != 0.0f && scalar != 1.0f)
143
144 return scalar != 0.0f;
145 }
146
147 boolNDArray bool_array_value (bool warn = false) const
148 {
149 if (octave::math::isnan (scalar))
150 octave::err_nan_to_logical_conversion ();
151 if (warn && scalar != 0.0f && scalar != 1.0f)
153
154 return boolNDArray (dim_vector (1, 1), scalar != 1.0f);
155 }
156
157 octave_value as_double () const;
158 octave_value as_single () const;
159
160 // We don't need to override both forms of the diag method. The using
161 // declaration will avoid warnings about partially-overloaded virtual
162 // functions.
163 using octave_base_scalar<FloatComplex>::diag;
164
166
167 void increment () { scalar += 1.0; }
168
169 void decrement () { scalar -= 1.0; }
170
171 bool save_ascii (std::ostream& os);
172
173 bool load_ascii (std::istream& is);
174
175 bool save_binary (std::ostream& os, bool save_as_floats);
176
177 bool load_binary (std::istream& is, bool swap,
178 octave::mach_info::float_format fmt);
179
180 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
181
182 bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
183
184 int write (octave::stream& os, int block_size,
185 oct_data_conv::data_type output_type, int skip,
186 octave::mach_info::float_format flt_fmt) const
187 {
188 // Yes, for compatibility, we drop the imaginary part here.
189 return os.write (array_value (true), block_size, output_type,
190 skip, flt_fmt);
191 }
192
193 mxArray * as_mxArray (bool interleaved) const;
194
195 octave_value map (unary_mapper_t umap) const;
196
197private:
198
200};
201
203
204#endif
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
bool is_complex_scalar() const
octave_base_value * clone() const
bool bool_value(bool warn=false) const
octave_base_value * empty_clone() const
SparseMatrix sparse_matrix_value(bool=false) const
double scalar_value(bool frc_str_conv=false) const
builtin_type_t builtin_type() const
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
bool is_single_type() const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
boolNDArray bool_array_value(bool warn=false) const
~octave_float_complex()=default
float float_scalar_value(bool frc_str_conv=false) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition ovl.h:115
Array< octave_value > array_value() const
Definition ovl.h:88
void warn_logical_conversion()
Definition errwarn.cc:365
std::complex< double > Complex
Definition oct-cmplx.h:33
std::complex< float > FloatComplex
Definition oct-cmplx.h:34
int64_t octave_hdf5_id
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA_API(API)
Definition ov-base.h:185
builtin_type_t
Definition ov-base.h:83
@ btyp_float_complex
Definition ov-base.h:87
octave_float_complex octave_float_complex_scalar