GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-flt-re-diag.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 {
60  octave_base_value *retval = nullptr;
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  {
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
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6704
bool all_integers(float &max_val, float &min_val) const
Definition: fNDArray.cc:538
FloatColumnVector extract_diag(octave_idx_type k=0) const
Definition: fDiagMatrix.h:105
FloatComplexDiagMatrix float_complex_diag_matrix_value(bool=false) const
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1473
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:937
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
const T * data(void) const
Definition: Array.h:582
Complex rc_sqrt(double x)
Definition: lo-mappers.cc:322
bool chk_valid_scalar(const octave_value &, float &) const
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
save_type get_save_type(double, double)
Definition: ls-utils.cc:35
octave_value as_uint16(void) const
FloatMatrix float_matrix_value(bool=false) const
const T * fortran_vec(void) const
Definition: DiagArray2.h:169
octave_value as_uint8(void) const
octave_value as_single(void) const
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:180
octave_value as_uint64(void) const
octave_value as_int32(void) const
octave_idx_type rows(void) const
Definition: DiagArray2.h:87
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
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:831
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:511
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:400
bool swap
Definition: load-save.cc:738
FloatDiagMatrix abs(void) const
Definition: fDiagMatrix.cc:126
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:60
octave_idx_type length(void) const
Definition: DiagArray2.h:93
octave_idx_type cols(void) const
Definition: DiagArray2.h:88
double tmp
Definition: data.cc:6252
octave_value map(unary_mapper_t umap) const
octave_value retval
Definition: data.cc:6246
static octave_base_value * default_numeric_conversion_function(const octave_base_value &a)
octave_idx_type nelem(void) const
Definition: DiagArray2.h:94
ComplexDiagMatrix complex_diag_matrix_value(bool=false) const
octave_value as_int16(void) const
octave_value as_uint32(void) const
FloatDiagMatrix float_diag_matrix_value(bool=false) const
Array< U > map(F fcn) const
Apply function fcn to each element of the Array<T>.
Definition: Array.h:764
bool save_binary(std::ostream &os, bool &save_as_floats)
octave_idx_type columns(void) const
Definition: DiagArray2.h:89
static int static_type_id(void)
type_conv_info numeric_conversion_function(void) const
DiagMatrix diag_matrix_value(bool=false) const
octave_value as_int64(void) const
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
octave_base_value * try_narrowing_conversion(void)
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
write the output to stdout if nargout is
Definition: load-save.cc:1612
octave_value as_int8(void) const
octave_value as_double(void) const
octave::stream os
Definition: file-io.cc:627
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x