GNU Octave  3.8.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-2013 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; }
97  MatrixType matrix_type (const MatrixType&) const
98  { return matrix_type (); }
99 
100  octave_value diag (octave_idx_type k = 0) const;
101 
102  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
103  { return to_dense ().sort (dim, mode); }
105  sortmode mode = ASCENDING) const
106  { return to_dense ().sort (sidx, dim, mode); }
107 
108  sortmode is_sorted (sortmode mode = UNSORTED) const
109  { return to_dense ().is_sorted (mode); }
110 
111  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
112  { return to_dense ().sort_rows_idx (mode); }
113 
114  sortmode is_sorted_rows (sortmode mode = UNSORTED) const
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 (void) 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) const;
207 
208  void print_info (std::ostream& os, const std::string& prefix) const;
209 
210 protected:
211 
212  DMT matrix;
213 
214  octave_value to_dense (void) const;
215 
216  virtual bool chk_valid_scalar (const octave_value&,
217  typename DMT::element_type&) const = 0;
218 
219 private:
220 
222 
223 };
224 
225 #endif