GNU Octave  3.8.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-2013 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 "oct-alloc.h"
34 #include "str-vec.h"
35 
36 #include "gripes.h"
37 #include "error.h"
38 #include "ov-base.h"
39 #include "ov-flt-cx-mat.h"
40 #include "ov-base-scalar.h"
41 #include "ov-typeinfo.h"
42 
43 class octave_value_list;
44 
45 class tree_walker;
46 
47 // Complex scalar values.
48 
49 class
52 {
53 public:
54 
57 
60 
63 
65 
66  octave_base_value *clone (void) const
67  { return new octave_float_complex (*this); }
68 
69  // We return an octave_float_complex_matrix object here instead of an
70  // octave_float_complex object so that in expressions like A(2,2,2) = 2
71  // (for A previously undefined), A will be empty instead of a 1x1
72  // object.
73  octave_base_value *empty_clone (void) const
74  { return new octave_float_complex_matrix (); }
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  octave_value any (int = 0) const
82  {
83  return (scalar != FloatComplex (0, 0)
86  }
87 
89 
90  bool is_complex_scalar (void) const { return true; }
91 
92  bool is_complex_type (void) const { return true; }
93 
94  bool is_single_type (void) const { return true; }
95 
96  bool is_float_type (void) const { return true; }
97 
98  double double_value (bool = false) const;
99 
100  float float_value (bool = false) const;
101 
102  double scalar_value (bool frc_str_conv = false) const
103  { return double_value (frc_str_conv); }
104 
105  float float_scalar_value (bool frc_str_conv = false) const
106  { return float_value (frc_str_conv); }
107 
108  Matrix matrix_value (bool = false) const;
109 
110  FloatMatrix float_matrix_value (bool = false) const;
111 
112  NDArray array_value (bool = false) const;
113 
114  FloatNDArray float_array_value (bool = false) const;
115 
116  SparseMatrix sparse_matrix_value (bool = false) const
117  { return SparseMatrix (matrix_value ()); }
118 
119  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
120  { return SparseComplexMatrix (complex_matrix_value ()); }
121 
122  octave_value resize (const dim_vector& dv, bool fill = false) const;
123 
124  Complex complex_value (bool = false) const;
125 
126  FloatComplex float_complex_value (bool = false) const;
127 
128  ComplexMatrix complex_matrix_value (bool = false) const;
129 
130  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
131 
132  ComplexNDArray complex_array_value (bool = false) const;
133 
134  FloatComplexNDArray float_complex_array_value (bool = false) const;
135 
136  bool bool_value (bool warn = false) const
137  {
138  if (xisnan (scalar))
140  else if (warn && scalar != 0.0f && scalar != 1.0f)
142 
143  return scalar != 0.0f;
144  }
145 
146  boolNDArray bool_array_value (bool warn = false) const
147  {
148  if (xisnan (scalar))
150  else if (warn && scalar != 0.0f && scalar != 1.0f)
152 
153  return boolNDArray (dim_vector (1, 1), scalar != 1.0f);
154  }
155 
156  octave_value diag (octave_idx_type m, octave_idx_type n) const;
157 
158  void increment (void) { scalar += 1.0; }
159 
160  void decrement (void) { scalar -= 1.0; }
161 
162  bool save_ascii (std::ostream& os);
163 
164  bool load_ascii (std::istream& is);
165 
166  bool save_binary (std::ostream& os, bool& save_as_floats);
167 
168  bool load_binary (std::istream& is, bool swap,
170 
171 #if defined (HAVE_HDF5)
172  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
173 
174  bool load_hdf5 (hid_t loc_id, const char *name);
175 #endif
176 
177  int write (octave_stream& os, int block_size,
178  oct_data_conv::data_type output_type, int skip,
179  oct_mach_info::float_format flt_fmt) const
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 
195 };
196 
198 
199 #endif