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-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_complex_h)
24 #define octave_ov_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-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 
55  : octave_base_scalar<Complex> () { }
56 
58  : octave_base_scalar<Complex> (c) { }
59 
61  : octave_base_scalar<Complex> (c) { }
62 
63  ~octave_complex (void) { }
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  error ("attempted to use a complex scalar as an index\n"
85  " (forgot to initialize i or j?)");
86  return idx_vector ();
87  }
88 
89  octave_value any (int = 0) const
90  {
91  return (scalar != Complex (0, 0)
94  }
95 
96  builtin_type_t builtin_type (void) const { return btyp_complex; }
97 
98  bool is_complex_scalar (void) const { return true; }
99 
100  bool is_complex_type (void) const { return true; }
101 
102  bool is_double_type (void) const { return true; }
103 
104  bool is_float_type (void) const { return true; }
105 
106  double double_value (bool = false) const;
107 
108  float float_value (bool = false) const;
109 
110  double scalar_value (bool frc_str_conv = false) const
111  { return double_value (frc_str_conv); }
112 
113  float float_scalar_value (bool frc_str_conv = false) const
114  { return float_value (frc_str_conv); }
115 
116  Matrix matrix_value (bool = false) const;
117 
118  FloatMatrix float_matrix_value (bool = false) const;
119 
120  NDArray array_value (bool = false) const;
121 
122  FloatNDArray float_array_value (bool = false) const;
123 
124  SparseMatrix sparse_matrix_value (bool = false) const
125  { return SparseMatrix (matrix_value ()); }
126 
128  { return SparseComplexMatrix (complex_matrix_value ()); }
129 
130  octave_value resize (const dim_vector& dv, bool fill = false) const;
131 
132  Complex complex_value (bool = false) const;
133 
134  FloatComplex float_complex_value (bool = false) const;
135 
136  ComplexMatrix complex_matrix_value (bool = false) const;
137 
138  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
139 
140  ComplexNDArray complex_array_value (bool = false) const;
141 
142  FloatComplexNDArray float_complex_array_value (bool = false) const;
143 
144  bool bool_value (bool warn = false) const
145  {
146  if (xisnan (scalar))
148  else if (warn && scalar != 0.0 && scalar != 1.0)
150 
151  return scalar != 0.0;
152  }
153 
154  boolNDArray bool_array_value (bool warn = false) const
155  {
156  if (xisnan (scalar))
158  else if (warn && scalar != 0.0 && scalar != 1.0)
160 
161  return boolNDArray (dim_vector (1, 1), scalar != 0.0);
162  }
163 
164  octave_value diag (octave_idx_type m, octave_idx_type n) const;
165 
166  void increment (void) { scalar += 1.0; }
167 
168  void decrement (void) { scalar -= 1.0; }
169 
170  bool save_ascii (std::ostream& os);
171 
172  bool load_ascii (std::istream& is);
173 
174  bool save_binary (std::ostream& os, bool& save_as_floats);
175 
176  bool load_binary (std::istream& is, bool swap,
178 
179  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
180 
181  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
182 
183  int write (octave_stream& os, int block_size,
184  oct_data_conv::data_type output_type, int skip,
185  oct_mach_info::float_format flt_fmt) const
186  {
187  // Yes, for compatibility, we drop the imaginary part here.
188  return os.write (array_value (true), block_size, output_type,
189  skip, flt_fmt);
190  }
191 
192  mxArray *as_mxArray (void) const;
193 
194  octave_value map (unary_mapper_t umap) const;
195 
196 private:
197 
198 
200 };
201 
203 
204 #endif
boolNDArray bool_array_value(bool warn=false) const
Definition: ov-complex.h:154
idx_vector index_vector(bool=false) const
Definition: ov-complex.h:82
~octave_complex(void)
Definition: ov-complex.h:63
bool xisnan(double x)
Definition: lo-mappers.cc:144
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-complex.h:124
octave_base_value * clone(void) const
Definition: ov-complex.h:65
bool bool_value(bool warn=false) const
Definition: ov-complex.h:144
double scalar_value(bool frc_str_conv=false) const
Definition: ov-complex.h:110
float float_scalar_value(bool frc_str_conv=false) const
Definition: ov-complex.h:113
void error(const char *fmt,...)
Definition: error.cc:476
bool is_complex_scalar(void) const
Definition: ov-complex.h:98
builtin_type_t
Definition: ov-base.h:59
builtin_type_t builtin_type(void) const
Definition: ov-complex.h:96
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-complex.h:127
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:101
octave_value any(int=0) const
Definition: ov-complex.h:89
octave_complex(void)
Definition: ov-complex.h:54
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
void increment(void)
Definition: ov-complex.h:166
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
Definition: ov-complex.h:183
#define OCTINTERP_API
Definition: mexproto.h:66
octave_complex(const Complex &c)
Definition: ov-complex.h:57
bool is_complex_type(void) const
Definition: ov-complex.h:100
void gripe_nan_to_logical_conversion(void)
octave_complex(const octave_complex &c)
Definition: ov-complex.h:60
void decrement(void)
Definition: ov-complex.h:168
Definition: dMatrix.h:35
bool is_float_type(void) const
Definition: ov-complex.h:104
bool is_double_type(void) const
Definition: ov-complex.h:102
octave_base_value * empty_clone(void) const
Definition: ov-complex.h:71
void gripe_logical_conversion(void)
Definition: gripes.cc:201
octave_complex octave_complex_scalar
Definition: ov-complex.h:202
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
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:162
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
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