GNU Octave  4.4.1
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-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_flt_complex_h)
24 #define octave_ov_flt_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-flt-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 
56 
59 
62 
63  ~octave_float_complex (void) = default;
64 
65  octave_base_value * clone (void) const
66  { return new octave_float_complex (*this); }
67 
68  // We return an octave_float_complex_matrix object here instead of an
69  // octave_float_complex object so that in expressions like A(2,2,2) = 2
70  // (for A previously undefined), A will be empty instead of a 1x1
71  // object.
73  { return new octave_float_complex_matrix (); }
74 
75  octave_base_value * try_narrowing_conversion (void);
76 
77  octave_value do_index_op (const octave_value_list& idx,
78  bool resize_ok = false);
79 
80  octave_value any (int = 0) const
81  {
82  return (scalar != FloatComplex (0, 0)
83  && ! (lo_ieee_isnan (scalar.real ())
84  || lo_ieee_isnan (scalar.imag ())));
85  }
86 
88 
89  bool is_complex_scalar (void) const { return true; }
90 
91  bool iscomplex (void) const { return true; }
92 
93  bool is_single_type (void) const { return true; }
94 
95  bool isfloat (void) const { return true; }
96 
97  double double_value (bool = false) const;
98 
99  float float_value (bool = false) const;
100 
101  double scalar_value (bool frc_str_conv = false) const
102  { return double_value (frc_str_conv); }
103 
104  float float_scalar_value (bool frc_str_conv = false) const
105  { return float_value (frc_str_conv); }
106 
107  Matrix matrix_value (bool = false) const;
108 
109  FloatMatrix float_matrix_value (bool = false) const;
110 
111  NDArray array_value (bool = false) const;
112 
113  FloatNDArray float_array_value (bool = false) const;
114 
115  SparseMatrix sparse_matrix_value (bool = false) const
116  { return SparseMatrix (matrix_value ()); }
117 
119  { return SparseComplexMatrix (complex_matrix_value ()); }
120 
121  octave_value resize (const dim_vector& dv, bool fill = false) const;
122 
123  Complex complex_value (bool = false) const;
124 
125  FloatComplex float_complex_value (bool = false) const;
126 
127  ComplexMatrix complex_matrix_value (bool = false) const;
128 
129  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
130 
131  ComplexNDArray complex_array_value (bool = false) const;
132 
133  FloatComplexNDArray float_complex_array_value (bool = false) const;
134 
135  bool bool_value (bool warn = false) const
136  {
139  if (warn && scalar != 0.0f && scalar != 1.0f)
141 
142  return scalar != 0.0f;
143  }
144 
145  boolNDArray bool_array_value (bool warn = false) const
146  {
149  if (warn && scalar != 0.0f && scalar != 1.0f)
151 
152  return boolNDArray (dim_vector (1, 1), scalar != 1.0f);
153  }
154 
155  octave_value as_double (void) const;
156  octave_value as_single (void) const;
157 
158  octave_value diag (octave_idx_type m, octave_idx_type n) const;
159 
160  void increment (void) { scalar += 1.0; }
161 
162  void decrement (void) { scalar -= 1.0; }
163 
164  bool save_ascii (std::ostream& os);
165 
166  bool load_ascii (std::istream& is);
167 
168  bool save_binary (std::ostream& os, bool& save_as_floats);
169 
170  bool load_binary (std::istream& is, bool swap,
172 
173  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
174 
175  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
176 
177  int write (octave::stream& os, int block_size,
178  oct_data_conv::data_type output_type, int skip,
180  {
181  // Yes, for compatibility, we drop the imaginary part here.
182  return os.write (array_value (true), block_size, output_type,
183  skip, flt_fmt);
184  }
185 
186  mxArray * as_mxArray (void) const;
187 
188  octave_value map (unary_mapper_t umap) const;
189 
190 private:
191 
193 };
194 
196 
197 #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
builtin_type_t builtin_type(void) const
bool is_single_type(void) const
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5264
void warn_logical_conversion(void)
Definition: errwarn.cc:359
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
bool isnan(bool)
Definition: lo-mappers.h:187
double scalar_value(bool frc_str_conv=false) const
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
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
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
builtin_type_t
Definition: ov-base.h:71
void err_nan_to_logical_conversion(void)
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:105
bool iscomplex(void) const
static double as_double(time_t sec, long usec)
Definition: oct-time.h:34
bool swap
Definition: load-save.cc:738
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
nd deftypefn *std::string name
Definition: sysdep.cc:647
octave_float_complex(const octave_float_complex &c)
Array< octave_value > array_value(void) const
Definition: ovl.h:86
octave_float_complex(const FloatComplex &c)
bool save_as_floats
Definition: load-save.cc:1617
boolNDArray bool_array_value(bool warn=false) const
int64_t octave_hdf5_id
Definition: dMatrix.h:36
octave_base_value * clone(void) const
bool is_complex_scalar(void) const
octave_map map(dims)
bool bool_value(bool warn=false) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
octave_float_complex octave_float_complex_scalar
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
std::complex< double > Complex
Definition: oct-cmplx.h:31
octave_base_value * empty_clone(void) const
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
octave_value any(int=0) const
dim_vector dv
Definition: sub2ind.cc:263
SparseMatrix sparse_matrix_value(bool=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
octave::stream os
Definition: file-io.cc:627
bool isfloat(void) const