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-re-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-re-diag.h"
30 #include "ov-base-diag.cc"
31 #include "ov-float.h"
32 #include "ov-flt-re-mat.h"
33 #include "ls-utils.h"
34 
35 
37 
39  "float diagonal matrix", "single");
40 
41 static octave_base_value *
43 {
44  const octave_float_diag_matrix& v =
45  dynamic_cast<const octave_float_diag_matrix&> (a);
46 
47  return new octave_float_matrix (v.float_matrix_value ());
48 }
49 
52 {
55 }
56 
59 {
61 
62  if (matrix.nelem () == 1)
63  retval = new octave_float_scalar (matrix (0, 0));
64 
65  return retval;
66 }
67 
70 {
71  return DiagMatrix (matrix);
72 }
73 
76 {
77  return matrix;
78 }
79 
82 {
83  return ComplexDiagMatrix (matrix);
84 }
85 
88 {
90 }
91 
94 {
95  return DiagMatrix (matrix);
96 }
97 
100 {
101  return matrix;
102 }
103 
106 {
107  return int8_array_value ();
108 }
109 
112 {
113  return int16_array_value ();
114 }
115 
118 {
119  return int32_array_value ();
120 }
121 
124 {
125  return int64_array_value ();
126 }
127 
130 {
131  return uint8_array_value ();
132 }
133 
136 {
137  return uint16_array_value ();
138 }
139 
142 {
143  return uint32_array_value ();
144 }
145 
148 {
149  return uint64_array_value ();
150 }
151 
154 {
155  switch (umap)
156  {
157  case umap_abs:
158  return matrix.abs ();
159  case umap_real:
160  case umap_conj:
161  return matrix;
162  case umap_imag:
163  return DiagMatrix (matrix.rows (), matrix.cols (), 0.0);
164  case umap_sqrt:
165  {
169  retval.resize (matrix.rows (), matrix.columns ());
170  return retval;
171  }
172  default:
173  return to_dense ().map (umap);
174  }
175 }
176 
177 bool
179  bool& /* save_as_floats*/)
180 {
181 
182  int32_t r = matrix.rows ();
183  int32_t c = matrix.cols ();
184  os.write (reinterpret_cast<char *> (&r), 4);
185  os.write (reinterpret_cast<char *> (&c), 4);
186 
188  save_type st = LS_FLOAT;
189  if (matrix.length () > 8192) // FIXME: make this configurable.
190  {
191  float max_val, min_val;
192  if (m.all_integers (max_val, min_val))
193  st = get_save_type (max_val, min_val);
194  }
195 
196  const float *mtmp = m.data ();
197  write_floats (os, mtmp, st, m.numel ());
198 
199  return true;
200 }
201 
202 bool
205 {
206  int32_t r, c;
207  char tmp;
208  if (! (is.read (reinterpret_cast<char *> (&r), 4)
209  && is.read (reinterpret_cast<char *> (&c), 4)
210  && is.read (reinterpret_cast<char *> (&tmp), 1)))
211  return false;
212  if (swap)
213  {
214  swap_bytes<4> (&r);
215  swap_bytes<4> (&c);
216  }
217 
218  FloatDiagMatrix m (r, c);
219  float *re = m.fortran_vec ();
220  octave_idx_type len = m.length ();
221  read_floats (is, re, static_cast<save_type> (tmp), len, swap, fmt);
222 
223  if (! is)
224  return false;
225 
226  matrix = m;
227 
228  return true;
229 }
230 
231 bool
233  float& x) const
234 {
235  bool retval = val.is_real_scalar ();
236  if (retval)
237  x = val.float_value ();
238  return retval;
239 }
save_type
Definition: data-conv.h:85
type_conv_info numeric_conversion_function(void) const
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:936
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
const T * fortran_vec(void) const
Definition: DiagArray2.h:178
FloatDiagMatrix float_diag_matrix_value(bool=false) const
Complex rc_sqrt(double x)
Definition: lo-mappers.cc:551
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
FloatComplexDiagMatrix float_complex_diag_matrix_value(bool=false) const
save_type get_save_type(double, double)
Definition: ls-utils.cc:35
octave_value as_int64(void) const
FloatDiagMatrix abs(void) const
Definition: fDiagMatrix.cc:127
float float_value(bool frc_str_conv=false) const
Definition: ov.h:778
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
#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
octave_value as_uint16(void) const
ComplexDiagMatrix complex_diag_matrix_value(bool=false) 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
octave_value as_single(void) const
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:60
octave_value as_int8(void) const
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
bool chk_valid_scalar(const octave_value &, float &) const
octave_value map(unary_mapper_t umap) const
const T * data(void) const
Definition: Array.h:582
octave_value as_uint64(void) const
double tmp
Definition: data.cc:6300
octave_value as_uint8(void) const
octave_value retval
Definition: data.cc:6294
static octave_base_value * default_numeric_conversion_function(const octave_base_value &a)
FloatColumnVector extract_diag(octave_idx_type k=0) const
Definition: fDiagMatrix.h:105
DiagMatrix diag_matrix_value(bool=false) const
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
octave_idx_type cols(void) const
Definition: DiagArray2.h:89
octave_value as_int32(void) const
FloatMatrix float_matrix_value(bool=false) const
bool save_binary(std::ostream &os, bool &save_as_floats)
octave_idx_type columns(void) const
Definition: DiagArray2.h:90
bool all_integers(float &max_val, float &min_val) const
Definition: fNDArray.cc:540
static int static_type_id(void)
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
octave_base_value * try_narrowing_conversion(void)
octave_value as_int16(void) const
write the output to stdout if nargout is
Definition: load-save.cc:1576
octave_value as_double(void) const
octave_value as_uint32(void) const
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