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-base-diag.h
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 (octave_ov_base_diag_h)
24 #define octave_ov_base_diag_h 1
25 
26 #include "octave-config.h"
27 
28 #include <cstdlib>
29 
30 #include <iosfwd>
31 #include <string>
32 
33 #include "mx-base.h"
34 #include "str-vec.h"
35 
36 #include "ovl.h"
37 #include "ov-base.h"
38 #include "ov-typeinfo.h"
39 
40 class tree_walker;
41 
42 // Real matrix values.
43 
44 template <typename DMT, typename MT>
45 class
47 {
48 
49 public:
50 
52  : octave_base_value (), matrix (), dense_cache () { }
53 
54  octave_base_diag (const DMT& m)
55  : octave_base_value (), matrix (m), dense_cache ()
56  { }
57 
59  : octave_base_value (), matrix (m.matrix), dense_cache () { }
60 
61  ~octave_base_diag (void) { }
62 
63  size_t byte_size (void) const { return matrix.byte_size (); }
64 
65  octave_value squeeze (void) const { return matrix; }
66 
67  octave_value full_value (void) const { return to_dense (); }
68 
70  const std::list<octave_value_list>& idx);
71 
73  const std::list<octave_value_list>& idx, int)
74  { return subsref (type, idx); }
75 
76  octave_value do_index_op (const octave_value_list& idx,
77  bool resize_ok = false);
78 
80  const std::list<octave_value_list>& idx,
81  const octave_value& rhs);
82 
83  dim_vector dims (void) const { return matrix.dims (); }
84 
85  octave_idx_type nnz (void) const { return to_dense ().nnz (); }
86 
87  octave_value reshape (const dim_vector& new_dims) const
88  { return to_dense ().reshape (new_dims); }
89 
90  octave_value permute (const Array<int>& vec, bool inv = false) const
91  {
92  if (vec.numel () == 2
93  && ((vec.xelem (0) == 1 && vec.xelem (1) == 0)
94  || (vec.xelem (0) == 0 && vec.xelem (1) == 1)))
95  return DMT (matrix);
96  else
97  return to_dense ().permute (vec, inv);
98  }
99 
100  octave_value resize (const dim_vector& dv, bool fill = false) const;
101 
102  octave_value all (int dim = 0) const { return MT (matrix).all (dim); }
103  octave_value any (int dim = 0) const { return MT (matrix).any (dim); }
104 
105  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
107  { return matrix_type (); }
108 
109  octave_value diag (octave_idx_type k = 0) const;
110 
112  { return to_dense ().sort (dim, mode); }
114  sortmode mode = ASCENDING) const
115  { return to_dense ().sort (sidx, dim, mode); }
116 
118  { return to_dense ().is_sorted (mode); }
119 
121  { return to_dense ().sort_rows_idx (mode); }
122 
124  { return to_dense ().is_sorted_rows (mode); }
125 
126  bool is_matrix_type (void) const { return true; }
127 
128  bool is_numeric_type (void) const { return true; }
129 
130  bool is_defined (void) const { return true; }
131 
132  bool is_constant (void) const { return true; }
133 
134  bool is_true (void) const;
135 
136  bool is_diag_matrix (void) const { return true; }
137 
138  double double_value (bool = false) const;
139 
140  float float_value (bool = false) const;
141 
142  double scalar_value (bool frc_str_conv = false) const
143  { return double_value (frc_str_conv); }
144 
145  idx_vector index_vector (bool /* require_integers */ = false) const;
146 
147  Matrix matrix_value (bool = false) const;
148 
149  FloatMatrix float_matrix_value (bool = false) const;
150 
151  Complex complex_value (bool = false) const;
152 
153  FloatComplex float_complex_value (bool = false) const;
154 
155  ComplexMatrix complex_matrix_value (bool = false) const;
156 
157  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
158 
159  ComplexNDArray complex_array_value (bool = false) const;
160 
161  FloatComplexNDArray float_complex_array_value (bool = false) const;
162 
163  boolNDArray bool_array_value (bool warn = false) const;
164 
165  charNDArray char_array_value (bool = false) const;
166 
167  NDArray array_value (bool = false) const;
168 
169  FloatNDArray float_array_value (bool = false) const;
170 
171  SparseMatrix sparse_matrix_value (bool = false) const;
172 
173  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
174 
176  int8_array_value (void) const { return to_dense ().int8_array_value (); }
177 
179  int16_array_value (void) const { return to_dense ().int16_array_value (); }
180 
182  int32_array_value (void) const { return to_dense ().int32_array_value (); }
183 
185  int64_array_value (void) const { return to_dense ().int64_array_value (); }
186 
188  uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
189 
191  uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
192 
194  uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
195 
197  uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
198 
199  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
200 
201  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
202 
203  bool save_ascii (std::ostream& os);
204 
205  bool load_ascii (std::istream& is);
206 
207  int write (octave_stream& os, int block_size,
208  oct_data_conv::data_type output_type, int skip,
210 
211  mxArray *as_mxArray (void) const;
212 
213  bool print_as_scalar (void) const;
214 
215  void print (std::ostream& os, bool pr_as_read_syntax = false);
216 
217  void print_info (std::ostream& os, const std::string& prefix) const;
218 
219  octave_value fast_elem_extract (octave_idx_type n) const;
220 
221 protected:
222 
223  DMT matrix;
224 
225  octave_value to_dense (void) const;
226 
227  virtual bool chk_valid_scalar (const octave_value&,
228  typename DMT::element_type&) const = 0;
229 
230 private:
231 
233 
234 };
235 
236 #endif
int64NDArray int64_array_value(void) const
Definition: ov-base-diag.h:185
bool is_true(const std::string &s)
Definition: mkoctfile.cc:398
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:113
uint64NDArray uint64_array_value(void) const
Definition: ov-base-diag.h:197
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:515
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:518
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array.cc:2087
octave_value squeeze(void) const
Definition: ov-base-diag.h:65
int32NDArray int32_array_value(void) const
Definition: ov-base-diag.h:182
sortmode
Definition: oct-sort.h:105
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6386
idx subsref(val, idx) esult
Definition: ov.cc:3080
dim_vector dims(void) const
Definition: ov-base-diag.h:83
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-base-diag.h:90
for large enough k
Definition: lu.cc:606
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the then the first element defines the pivoting tolerance for the unsymmetric the values defined such that for full matrix
Definition: lu.cc:138
bool is_diag_matrix(void) const
Definition: ov-base-diag.h:136
size_t byte_size(void) const
Definition: ov-base-diag.h:63
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
octave_idx_type nnz(void) const
Definition: ov-base-diag.h:85
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:120
octave_value any(int dim=0) const
Definition: ov.h:616
sortmode is_sorted(sortmode mode=UNSORTED) const
Definition: ov-base-diag.h:117
bool is_numeric_type(void) const
Definition: ov-base-diag.h:128
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
octave_base_diag(void)
Definition: ov-base-diag.h:51
uint16NDArray uint16_array_value(void) const
Definition: ov-base-diag.h:191
octave_value dense_cache
Definition: ov-base-diag.h:232
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-base-diag.h:123
idx type
Definition: ov.cc:3129
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-base-diag.h:72
Definition: dMatrix.h:37
octave_value all(int dim=0) const
Definition: ov.h:613
int16NDArray int16_array_value(void) const
Definition: ov-base-diag.h:179
uint8NDArray uint8_array_value(void) const
Definition: ov-base-diag.h:188
bool is_defined(void) const
Definition: ov-base-diag.h:130
T & xelem(octave_idx_type n)
Definition: Array.h:455
bool is_matrix_type(void) const
Definition: ov-base-diag.h:126
octave_value any(int dim=0) const
Definition: ov-base-diag.h:103
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1317
double scalar_value(bool frc_str_conv=false) const
Definition: ov-base-diag.h:142
MatrixType matrix_type(const MatrixType &) const
Definition: ov-base-diag.h:106
int8NDArray int8_array_value(void) const
Definition: ov-base-diag.h:176
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
octave_base_diag(const DMT &m)
Definition: ov-base-diag.h:54
bool is_constant(void) const
Definition: ov-base-diag.h:132
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
MatrixType matrix_type(void) const
Definition: ov-base-diag.h:105
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-base-diag.h:87
std::complex< double > Complex
Definition: oct-cmplx.h:31
write the output to stdout if nargout is
Definition: load-save.cc:1576
octave_base_diag(const octave_base_diag &m)
Definition: ov-base-diag.h:58
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
dim_vector dv
Definition: sub2ind.cc:263
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:111
octave_value full_value(void) const
Definition: ov-base-diag.h:67
uint32NDArray uint32_array_value(void) const
Definition: ov-base-diag.h:194
octave_value all(int dim=0) const
Definition: ov-base-diag.h:102
~octave_base_diag(void)
Definition: ov-base-diag.h:61