GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base-diag.h
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 (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 // Real matrix values.
41 
42 template <typename DMT, typename MT>
43 class
45 {
46 
47 public:
48 
50  : octave_base_value (), matrix (), dense_cache () { }
51 
52  octave_base_diag (const DMT& m)
53  : octave_base_value (), matrix (m), dense_cache ()
54  { }
55 
57  : octave_base_value (), matrix (m.matrix), dense_cache () { }
58 
59  ~octave_base_diag (void) = default;
60 
61  size_t byte_size (void) const { return matrix.byte_size (); }
62 
63  octave_value squeeze (void) const { return matrix; }
64 
65  octave_value full_value (void) const { return to_dense (); }
66 
68  const std::list<octave_value_list>& idx);
69 
71  const std::list<octave_value_list>& idx, int)
72  { return subsref (type, idx); }
73 
74  octave_value do_index_op (const octave_value_list& idx,
75  bool resize_ok = false);
76 
78  const std::list<octave_value_list>& idx,
79  const octave_value& rhs);
80 
81  dim_vector dims (void) const { return matrix.dims (); }
82 
83  octave_idx_type nnz (void) const { return to_dense ().nnz (); }
84 
85  octave_value reshape (const dim_vector& new_dims) const
86  { return to_dense ().reshape (new_dims); }
87 
88  octave_value permute (const Array<int>& vec, bool inv = false) const
89  {
90  if (vec.numel () == 2
91  && ((vec.xelem (0) == 1 && vec.xelem (1) == 0)
92  || (vec.xelem (0) == 0 && vec.xelem (1) == 1)))
93  return DMT (matrix);
94  else
95  return to_dense ().permute (vec, inv);
96  }
97 
98  octave_value resize (const dim_vector& dv, bool fill = false) const;
99 
100  octave_value all (int dim = 0) const { return MT (matrix).all (dim); }
101  octave_value any (int dim = 0) const { return MT (matrix).any (dim); }
102 
103  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
105  { return matrix_type (); }
106 
107  octave_value diag (octave_idx_type k = 0) const;
108 
110  { return to_dense ().sort (dim, mode); }
112  sortmode mode = ASCENDING) const
113  { return to_dense ().sort (sidx, dim, mode); }
114 
116  { return to_dense ().issorted (mode); }
117 
119  { return to_dense ().sort_rows_idx (mode); }
120 
122  { return to_dense ().is_sorted_rows (mode); }
123 
124  bool is_matrix_type (void) const { return true; }
125 
126  bool isnumeric (void) const { return true; }
127 
128  bool is_defined (void) const { return true; }
129 
130  bool is_constant (void) const { return true; }
131 
132  bool is_true (void) const;
133 
134  bool is_diag_matrix (void) const { return true; }
135 
136  double double_value (bool = false) const;
137 
138  float float_value (bool = false) const;
139 
140  double scalar_value (bool frc_str_conv = false) const
141  { return double_value (frc_str_conv); }
142 
143  idx_vector index_vector (bool /* require_integers */ = false) const;
144 
145  Matrix matrix_value (bool = false) const;
146 
147  FloatMatrix float_matrix_value (bool = false) const;
148 
149  Complex complex_value (bool = false) const;
150 
151  FloatComplex float_complex_value (bool = false) const;
152 
153  ComplexMatrix complex_matrix_value (bool = false) const;
154 
155  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
156 
157  ComplexNDArray complex_array_value (bool = false) const;
158 
159  FloatComplexNDArray float_complex_array_value (bool = false) const;
160 
161  boolNDArray bool_array_value (bool warn = false) const;
162 
163  charNDArray char_array_value (bool = false) const;
164 
165  NDArray array_value (bool = false) const;
166 
167  FloatNDArray float_array_value (bool = false) const;
168 
169  SparseMatrix sparse_matrix_value (bool = false) const;
170 
171  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
172 
174  int8_array_value (void) const { return to_dense ().int8_array_value (); }
175 
177  int16_array_value (void) const { return to_dense ().int16_array_value (); }
178 
180  int32_array_value (void) const { return to_dense ().int32_array_value (); }
181 
183  int64_array_value (void) const { return to_dense ().int64_array_value (); }
184 
186  uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
187 
189  uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
190 
192  uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
193 
195  uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
196 
197  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
198 
199  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
200 
202 
203  std::string edit_display (const float_display_format& fmt,
205 
206  bool save_ascii (std::ostream& os);
207 
208  bool load_ascii (std::istream& is);
209 
210  int write (octave::stream& os, int block_size,
211  oct_data_conv::data_type output_type, int skip,
213 
214  mxArray * as_mxArray (void) const;
215 
216  bool print_as_scalar (void) const;
217 
218  void print (std::ostream& os, bool pr_as_read_syntax = false);
219 
220  void print_info (std::ostream& os, const std::string& prefix) const;
221 
222  void short_disp (std::ostream& os) const;
223 
224  octave_value fast_elem_extract (octave_idx_type n) const;
225 
226 protected:
227 
228  DMT matrix;
229 
230  octave_value to_dense (void) const;
231 
232  virtual bool chk_valid_scalar (const octave_value&,
233  typename DMT::element_type&) const = 0;
234 
235 private:
236 
238 
239 };
240 
241 #endif
MatrixType matrix_type(const MatrixType &) const
Definition: ov-base-diag.h:104
bool is_matrix_type(void) const
Definition: ov-base-diag.h:124
characters Given a string matrix
Definition: hex2num.cc:155
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-base-diag.h:85
sortmode
Definition: oct-sort.h:105
octave_value all(int dim=0) const
Definition: ov-base-diag.h:100
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:6348
size_t byte_size(void) const
Definition: ov-base-diag.h:61
idx subsref(val, idx) esult
Definition: ov.cc:3065
for large enough k
Definition: lu.cc:617
double scalar_value(bool frc_str_conv=false) const
Definition: ov-base-diag.h:140
octave_value all(int dim=0) const
Definition: ov.h:637
octave_value full_value(void) const
Definition: ov-base-diag.h:65
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array.cc:2068
bool is_diag_matrix(void) const
Definition: ov-base-diag.h:134
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-base-diag.h:88
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-base-diag.h:115
uint16NDArray uint16_array_value(void) const
Definition: ov-base-diag.h:189
bool is_defined(void) const
Definition: ov-base-diag.h:128
dim_vector dims(void) const
Definition: ov-base-diag.h:81
int8NDArray int8_array_value(void) const
Definition: ov-base-diag.h:174
int16NDArray int16_array_value(void) const
Definition: ov-base-diag.h:177
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1374
bool isnumeric(void) const
Definition: ov-base-diag.h:126
octave_value any(int dim=0) const
Definition: ov-base-diag.h:101
octave_base_diag(void)
Definition: ov-base-diag.h:49
octave_value any(int dim=0) const
Definition: ov.h:640
octave_idx_type nnz(void) const
Definition: ov-base-diag.h:83
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:505
octave_value dense_cache
Definition: ov-base-diag.h:237
bool is_true(const std::string &s)
idx type
Definition: ov.cc:3114
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-base-diag.h:70
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:118
Definition: dMatrix.h:36
T & xelem(octave_idx_type n)
Definition: Array.h:458
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:502
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:109
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:111
uint32NDArray uint32_array_value(void) const
Definition: ov-base-diag.h:192
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3114
uint8NDArray uint8_array_value(void) const
Definition: ov-base-diag.h:186
octave_base_diag(const DMT &m)
Definition: ov-base-diag.h:52
for i
Definition: data.cc:5264
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
octave_value squeeze(void) const
Definition: ov-base-diag.h:63
uint64NDArray uint64_array_value(void) const
Definition: ov-base-diag.h:195
std::complex< double > Complex
Definition: oct-cmplx.h:31
bool is_constant(void) const
Definition: ov-base-diag.h:130
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_base_diag(const octave_base_diag &m)
Definition: ov-base-diag.h:56
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-base-diag.h:121
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:888
int32NDArray int32_array_value(void) const
Definition: ov-base-diag.h:180
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
static float_display_format get_edit_display_format(const octave_value &val)
MatrixType matrix_type(void) const
Definition: ov-base-diag.h:103
int64NDArray int64_array_value(void) const
Definition: ov-base-diag.h:183