GNU Octave  4.0.0
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-flt-complex.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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_flt_complex_h)
24 #define octave_ov_flt_complex_h 1
25 
26 #include <cstdlib>
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "lo-ieee.h"
32 #include "mx-base.h"
33 #include "str-vec.h"
34 
35 #include "gripes.h"
36 #include "error.h"
37 #include "ov-base.h"
38 #include "ov-flt-cx-mat.h"
39 #include "ov-base-scalar.h"
40 #include "ov-typeinfo.h"
41 
42 class octave_value_list;
43 
44 class tree_walker;
45 
46 // Complex scalar values.
47 
48 class
51 {
52 public:
53 
56 
59 
62 
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)
85  }
86 
88 
89  bool is_complex_scalar (void) const { return true; }
90 
91  bool is_complex_type (void) const { return true; }
92 
93  bool is_single_type (void) const { return true; }
94 
95  bool is_float_type (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  {
137  if (xisnan (scalar))
139  else 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  {
147  if (xisnan (scalar))
149  else if (warn && scalar != 0.0f && scalar != 1.0f)
151 
152  return boolNDArray (dim_vector (1, 1), scalar != 1.0f);
153  }
154 
155  octave_value diag (octave_idx_type m, octave_idx_type n) const;
156 
157  void increment (void) { scalar += 1.0; }
158 
159  void decrement (void) { scalar -= 1.0; }
160 
161  bool save_ascii (std::ostream& os);
162 
163  bool load_ascii (std::istream& is);
164 
165  bool save_binary (std::ostream& os, bool& save_as_floats);
166 
167  bool load_binary (std::istream& is, bool swap,
169 
170  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
171 
172  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
173 
174  int write (octave_stream& os, int block_size,
175  oct_data_conv::data_type output_type, int skip,
176  oct_mach_info::float_format flt_fmt) const
177  {
178  // Yes, for compatibility, we drop the imaginary part here.
179  return os.write (array_value (true), block_size, output_type,
180  skip, flt_fmt);
181  }
182 
183  mxArray *as_mxArray (void) const;
184 
185  octave_value map (unary_mapper_t umap) const;
186 
187 private:
188 
189 
191 };
192 
194 
195 #endif
float float_scalar_value(bool frc_str_conv=false) const
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
bool xisnan(double x)
Definition: lo-mappers.cc:144
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
octave_base_value * empty_clone(void) const
bool is_single_type(void) const
builtin_type_t
Definition: ov-base.h:59
boolNDArray bool_array_value(bool warn=false) const
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:101
octave_base_value * clone(void) const
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
octave_value any(int=0) const
double scalar_value(bool frc_str_conv=false) const
F77_RET_T const double const double * f
#define OCTINTERP_API
Definition: mexproto.h:66
bool bool_value(bool warn=false) const
octave_float_complex(const octave_float_complex &c)
bool is_complex_type(void) const
void gripe_nan_to_logical_conversion(void)
bool is_complex_scalar(void) const
octave_float_complex(const FloatComplex &c)
Definition: dMatrix.h:35
builtin_type_t builtin_type(void) const
bool is_float_type(void) const
void gripe_logical_conversion(void)
Definition: gripes.cc:201
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, oct_mach_info::float_format flt_fmt)
Definition: oct-stream.cc:3546
octave_float_complex octave_float_complex_scalar
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:162
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
SparseMatrix sparse_matrix_value(bool=false) const
std::complex< double > Complex
Definition: oct-cmplx.h:29
ColumnVector real(const ComplexColumnVector &a)
Definition: dColVector.cc:156
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:736