GNU Octave  4.2.1
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-cx-diag.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2017 Jaroslav Hajek
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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "byte-swap.h"
28 
29 #include "ov-flt-cx-diag.h"
30 #include "ov-base-diag.cc"
31 #include "ov-flt-re-diag.h"
32 #include "ov-flt-complex.h"
33 #include "ov-flt-cx-mat.h"
34 #include "ls-utils.h"
35 
36 
38 
40  "float complex diagonal matrix", "single");
41 
42 static octave_base_value *
44 {
46  dynamic_cast<const octave_float_complex_diag_matrix&> (a);
47 
49 }
50 
53 {
56 }
57 
60 {
62 
63  if (matrix.nelem () == 1)
64  {
65  retval = new octave_float_complex (matrix (0, 0));
67  if (rv2)
68  {
69  delete retval;
70  retval = rv2;
71  }
72  }
73  else if (matrix.all_elements_are_real ())
74  {
75  return new octave_float_diag_matrix (::real (matrix));
76  }
77 
78  return retval;
79 }
80 
83 {
85 
86  if (! force_conversion)
87  warn_implicit_conversion ("Octave:imag-to-real",
88  type_name (), "real matrix");
89 
90  retval = ::real (matrix);
91 
92  return retval;
93 }
94 
97 {
99 
100  if (! force_conversion)
101  warn_implicit_conversion ("Octave:imag-to-real",
102  type_name (), "real matrix");
103 
104  retval = ::real (matrix);
105 
106  return retval;
107 }
108 
111 {
112  return ComplexDiagMatrix (matrix);
113 }
114 
117 {
118  return matrix;
119 }
120 
123 {
124  return ComplexDiagMatrix (matrix);
125 }
126 
129 {
130  return matrix;
131 }
132 
135 {
136  switch (umap)
137  {
138  case umap_abs:
139  return matrix.abs ();
140  case umap_real:
142  case umap_conj:
144  case umap_imag:
146  case umap_sqrt:
147  {
149  (std::sqrt);
151  retval.resize (matrix.rows (), matrix.columns ());
152  return retval;
153  }
154  default:
155  return to_dense ().map (umap);
156  }
157 }
158 
159 bool
161  bool& /* save_as_floats */)
162 {
163 
164  int32_t r = matrix.rows ();
165  int32_t c = matrix.cols ();
166  os.write (reinterpret_cast<char *> (&r), 4);
167  os.write (reinterpret_cast<char *> (&c), 4);
168 
170  save_type st = LS_FLOAT;
171  if (matrix.length () > 4096) // FIXME: make this configurable.
172  {
173  float max_val, min_val;
174  if (m.all_integers (max_val, min_val))
175  st = get_save_type (max_val, min_val);
176  }
177 
178  const FloatComplex *mtmp = m.data ();
179  write_floats (os, reinterpret_cast<const float *> (mtmp), st, 2 * m.numel ());
180 
181  return true;
182 }
183 
184 bool
187 {
188  int32_t r, c;
189  char tmp;
190  if (! (is.read (reinterpret_cast<char *> (&r), 4)
191  && is.read (reinterpret_cast<char *> (&c), 4)
192  && is.read (reinterpret_cast<char *> (&tmp), 1)))
193  return false;
194  if (swap)
195  {
196  swap_bytes<4> (&r);
197  swap_bytes<4> (&c);
198  }
199 
200  FloatComplexDiagMatrix m (r, c);
201  FloatComplex *re = m.fortran_vec ();
202  octave_idx_type len = m.length ();
203  read_floats (is, reinterpret_cast<float *> (re),
204  static_cast<save_type> (tmp), 2 * len, swap, fmt);
205 
206  if (! is)
207  return false;
208 
209  matrix = m;
210 
211  return true;
212 }
213 
214 bool
216  FloatComplex& x) const
217 {
218  bool retval = val.is_complex_scalar () || val.is_real_scalar ();
219  if (retval)
220  x = val.float_complex_value ();
221  return retval;
222 }
save_type
Definition: data-conv.h:85
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:936
const T * fortran_vec(void) const
Definition: DiagArray2.h:178
FloatDiagMatrix float_diag_matrix_value(bool=false) const
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
DiagMatrix diag_matrix_value(bool=false) const
octave_value map(unary_mapper_t umap) const
save_type get_save_type(double, double)
Definition: ls-utils.cc:35
octave_value as_single(void) const
bool is_complex_scalar(void) const
Definition: ov.h:557
octave_idx_type rows(void) const
Definition: DiagArray2.h:88
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1413
static octave_base_value * default_numeric_conversion_function(const octave_base_value &a)
octave_value as_double(void) const
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:169
void read_floats(std::istream &is, float *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
Definition: data-conv.cc:830
bool all_integers(float &max_val, float &min_val) const
Definition: fCNDArray.cc:520
ComplexDiagMatrix complex_diag_matrix_value(bool=false) const
type_conv_info numeric_conversion_function(void) const
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
bool swap
Definition: load-save.cc:725
std::string type_name(void) const
bool chk_valid_scalar(const octave_value &, FloatComplex &) const
ComplexColumnVector conj(const ComplexColumnVector &a)
Definition: CColVector.cc:216
virtual octave_base_value * try_narrowing_conversion(void)
Definition: ov-base.h:258
FloatComplexDiagMatrix float_complex_diag_matrix_value(bool=false) const
bool all_elements_are_real(void) const
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:60
octave_idx_type nelem(void) const
Definition: DiagArray2.h:95
bool is_real_scalar(void) const
Definition: ov.h:551
Array< U > map(F fcn) const
Apply function fcn to each element of the Array.
Definition: Array.h:760
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
FloatComplex float_complex_value(bool frc_str_conv=false) const
Definition: ov.h:802
const T * data(void) const
Definition: Array.h:582
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
bool save_binary(std::ostream &os, bool &save_as_floats)
FloatComplexColumnVector extract_diag(octave_idx_type k=0) const
Definition: fCDiagMatrix.h:138
octave_idx_type cols(void) const
Definition: DiagArray2.h:89
void warn_implicit_conversion(const char *id, const char *from, const char *to)
Definition: errwarn.cc:332
octave_idx_type columns(void) const
Definition: DiagArray2.h:90
FloatDiagMatrix abs(void) const
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:142
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
static int static_type_id(void)
octave_base_value * try_narrowing_conversion(void)
FloatComplexMatrix float_complex_matrix_value(bool=false) const
ColumnVector real(const ComplexColumnVector &a)
Definition: dColVector.cc:136
write the output to stdout if nargout is
Definition: load-save.cc:1576
octave_idx_type length(void) const
Definition: DiagArray2.h:94
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x