GNU Octave  4.0.0
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-2015 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 <cstdlib>
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "mx-base.h"
32 #include "str-vec.h"
33 
34 #include "oct-obj.h"
35 #include "ov-base.h"
36 #include "ov-typeinfo.h"
37 
38 class tree_walker;
39 
40 // Real matrix values.
41 
42 template <class DMT, class 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) { }
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 
67  octave_value subsref (const std::string& type,
68  const std::list<octave_value_list>& idx);
69 
70  octave_value_list subsref (const std::string& type,
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 
77  octave_value subsasgn (const std::string& type,
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  { return to_dense ().permute (vec, inv); }
90 
91  octave_value resize (const dim_vector& dv, bool fill = false) const;
92 
93  octave_value all (int dim = 0) const { return MT (matrix).all (dim); }
94  octave_value any (int dim = 0) const { return MT (matrix).any (dim); }
95 
96  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
98  { return matrix_type (); }
99 
100  octave_value diag (octave_idx_type k = 0) const;
101 
103  { return to_dense ().sort (dim, mode); }
105  sortmode mode = ASCENDING) const
106  { return to_dense ().sort (sidx, dim, mode); }
107 
109  { return to_dense ().is_sorted (mode); }
110 
112  { return to_dense ().sort_rows_idx (mode); }
113 
115  { return to_dense ().is_sorted_rows (mode); }
116 
117  bool is_matrix_type (void) const { return true; }
118 
119  bool is_numeric_type (void) const { return true; }
120 
121  bool is_defined (void) const { return true; }
122 
123  bool is_constant (void) const { return true; }
124 
125  bool is_true (void) const;
126 
127  bool is_diag_matrix (void) const { return true; }
128 
129  double double_value (bool = false) const;
130 
131  float float_value (bool = false) const;
132 
133  double scalar_value (bool frc_str_conv = false) const
134  { return double_value (frc_str_conv); }
135 
136  idx_vector index_vector (bool /* require_integers */ = false) const;
137 
138  Matrix matrix_value (bool = false) const;
139 
140  FloatMatrix float_matrix_value (bool = false) const;
141 
142  Complex complex_value (bool = false) const;
143 
144  FloatComplex float_complex_value (bool = false) const;
145 
146  ComplexMatrix complex_matrix_value (bool = false) const;
147 
148  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
149 
150  ComplexNDArray complex_array_value (bool = false) const;
151 
152  FloatComplexNDArray float_complex_array_value (bool = false) const;
153 
154  boolNDArray bool_array_value (bool warn = false) const;
155 
156  charNDArray char_array_value (bool = false) const;
157 
158  NDArray array_value (bool = false) const;
159 
160  FloatNDArray float_array_value (bool = false) const;
161 
162  SparseMatrix sparse_matrix_value (bool = false) const;
163 
164  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
165 
167  int8_array_value (void) const { return to_dense ().int8_array_value (); }
168 
170  int16_array_value (void) const { return to_dense ().int16_array_value (); }
171 
173  int32_array_value (void) const { return to_dense ().int32_array_value (); }
174 
176  int64_array_value (void) const { return to_dense ().int64_array_value (); }
177 
179  uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
180 
182  uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
183 
185  uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
186 
188  uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
189 
190  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
191 
192  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
193 
194  bool save_ascii (std::ostream& os);
195 
196  bool load_ascii (std::istream& is);
197 
198  int write (octave_stream& os, int block_size,
199  oct_data_conv::data_type output_type, int skip,
200  oct_mach_info::float_format flt_fmt) const;
201 
202  mxArray *as_mxArray (void) const;
203 
204  bool print_as_scalar (void) const;
205 
206  void print (std::ostream& os, bool pr_as_read_syntax = false);
207 
208  void print_info (std::ostream& os, const std::string& prefix) const;
209 
210  octave_value fast_elem_extract (octave_idx_type n) const;
211 
212 protected:
213 
214  DMT matrix;
215 
216  octave_value to_dense (void) const;
217 
218  virtual bool chk_valid_scalar (const octave_value&,
219  typename DMT::element_type&) const = 0;
220 
221 private:
222 
224 
225 };
226 
227 #endif
int64NDArray int64_array_value(void) const
Definition: ov-base-diag.h:176
bool is_true(const std::string &s)
Definition: mkoctfile.cc:373
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:104
uint64NDArray uint64_array_value(void) const
Definition: ov-base-diag.h:188
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:498
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:501
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array.cc:2086
octave_value squeeze(void) const
Definition: ov-base-diag.h:63
int32NDArray int32_array_value(void) const
Definition: ov-base-diag.h:173
sortmode
Definition: oct-sort.h:103
dim_vector dims(void) const
Definition: ov-base-diag.h:81
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-base-diag.h:88
bool is_diag_matrix(void) const
Definition: ov-base-diag.h:127
size_t byte_size(void) const
Definition: ov-base-diag.h:61
octave_idx_type nnz(void) const
Definition: ov-base-diag.h:83
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:111
octave_value any(int dim=0) const
Definition: ov.h:600
sortmode is_sorted(sortmode mode=UNSORTED) const
Definition: ov-base-diag.h:108
bool is_numeric_type(void) const
Definition: ov-base-diag.h:119
octave_base_diag(void)
Definition: ov-base-diag.h:49
uint16NDArray uint16_array_value(void) const
Definition: ov-base-diag.h:182
octave_value dense_cache
Definition: ov-base-diag.h:223
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-base-diag.h:114
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-base-diag.h:70
Definition: dMatrix.h:35
octave_value all(int dim=0) const
Definition: ov.h:597
int16NDArray int16_array_value(void) const
Definition: ov-base-diag.h:170
uint8NDArray uint8_array_value(void) const
Definition: ov-base-diag.h:179
bool is_defined(void) const
Definition: ov-base-diag.h:121
bool is_matrix_type(void) const
Definition: ov-base-diag.h:117
octave_value any(int dim=0) const
Definition: ov-base-diag.h:94
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1132
double scalar_value(bool frc_str_conv=false) const
Definition: ov-base-diag.h:133
MatrixType matrix_type(const MatrixType &) const
Definition: ov-base-diag.h:97
int8NDArray int8_array_value(void) const
Definition: ov-base-diag.h:167
octave_base_diag(const DMT &m)
Definition: ov-base-diag.h:52
bool is_constant(void) const
Definition: ov-base-diag.h:123
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
MatrixType matrix_type(void) const
Definition: ov-base-diag.h:96
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-base-diag.h:85
std::complex< double > Complex
Definition: oct-cmplx.h:29
octave_base_diag(const octave_base_diag &m)
Definition: ov-base-diag.h:56
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-diag.h:102
octave_value full_value(void) const
Definition: ov-base-diag.h:65
uint32NDArray uint32_array_value(void) const
Definition: ov-base-diag.h:185
octave_value all(int dim=0) const
Definition: ov-base-diag.h:93
~octave_base_diag(void)
Definition: ov-base-diag.h:59