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-re-mat.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_ov_re_mat_h)
25 #define octave_ov_re_mat_h 1
26 
27 #include <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 
32 #include "mx-base.h"
33 #include "oct-alloc.h"
34 #include "str-vec.h"
35 
36 #include "error.h"
37 #include "oct-stream.h"
38 #include "ov-base.h"
39 #include "ov-base-mat.h"
40 #include "ov-typeinfo.h"
41 
42 #include "MatrixType.h"
43 
44 class octave_value_list;
45 
46 class tree_walker;
47 
48 // Real matrix values.
49 
50 class
53 {
54 public:
55 
57  : octave_base_matrix<NDArray> () { }
58 
59  octave_matrix (const Matrix& m)
60  : octave_base_matrix<NDArray> (m) { }
61 
62  octave_matrix (const Matrix& m, const MatrixType& t)
63  : octave_base_matrix<NDArray> (m, t) { }
64 
65  octave_matrix (const NDArray& nda)
66  : octave_base_matrix<NDArray> (nda) { }
67 
70 
72  : octave_base_matrix<NDArray> (Matrix (d)) { }
73 
75  : octave_base_matrix<NDArray> (Matrix (v)) { }
76 
78  : octave_base_matrix<NDArray> (Matrix (v)) { }
79 
81  : octave_base_matrix<NDArray> (m) { }
82 
84  bool zero_based = false, bool cache_index = false)
85  : octave_base_matrix<NDArray> (NDArray (idx, zero_based))
86  {
87  // Auto-create cache to speed up subsequent indexing.
88  if (zero_based && cache_index)
89  set_idx_cache (idx_vector (idx));
90  }
91 
92  octave_matrix (const NDArray& nda, const idx_vector& cache)
94  {
95  set_idx_cache (cache);
96  }
97 
98  ~octave_matrix (void) { }
99 
100  octave_base_value *clone (void) const { return new octave_matrix (*this); }
101  octave_base_value *empty_clone (void) const { return new octave_matrix (); }
102 
103  type_conv_info numeric_demotion_function (void) const;
104 
105  octave_base_value *try_narrowing_conversion (void);
106 
107  idx_vector index_vector (void) const
108  { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
109 
110  builtin_type_t builtin_type (void) const { return btyp_double; }
111 
112  bool is_real_matrix (void) const { return true; }
113 
114  bool is_real_type (void) const { return true; }
115 
116  bool is_double_type (void) const { return true; }
117 
118  bool is_float_type (void) const { return true; }
119 
121  int8_array_value (void) const { return int8NDArray (matrix); }
122 
124  int16_array_value (void) const { return int16NDArray (matrix); }
125 
127  int32_array_value (void) const { return int32NDArray (matrix); }
128 
130  int64_array_value (void) const { return int64NDArray (matrix); }
131 
133  uint8_array_value (void) const { return uint8NDArray (matrix); }
134 
136  uint16_array_value (void) const { return uint16NDArray (matrix); }
137 
139  uint32_array_value (void) const { return uint32NDArray (matrix); }
140 
142  uint64_array_value (void) const { return uint64NDArray (matrix); }
143 
144  double double_value (bool = false) const;
145 
146  float float_value (bool = false) const;
147 
148  double scalar_value (bool frc_str_conv = false) const
149  { return double_value (frc_str_conv); }
150 
151  Matrix matrix_value (bool = false) const;
152 
153  FloatMatrix float_matrix_value (bool = false) const;
154 
155  Complex complex_value (bool = false) const;
156 
157  FloatComplex float_complex_value (bool = false) const;
158 
159  ComplexMatrix complex_matrix_value (bool = false) const;
160 
161  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
162 
163  ComplexNDArray complex_array_value (bool = false) const;
164 
165  FloatComplexNDArray float_complex_array_value (bool = false) const;
166 
167  boolNDArray bool_array_value (bool warn = false) const;
168 
169  charNDArray char_array_value (bool = false) const;
170 
171  NDArray array_value (bool = false) const { return matrix; }
172 
173  FloatNDArray float_array_value (bool = false) const { return matrix; }
174 
175  SparseMatrix sparse_matrix_value (bool = false) const;
176 
177  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
178 
179  octave_value diag (octave_idx_type k = 0) const;
180 
181  octave_value diag (octave_idx_type m, octave_idx_type n) const;
182 
183  octave_value reshape (const dim_vector& new_dims) const;
184 
185  octave_value squeeze (void) const;
186 
187  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
189  sortmode mode = ASCENDING) const;
190 
191  sortmode is_sorted (sortmode mode = UNSORTED) const;
192 
193  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
194 
195  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
196 
197  // Use matrix_ref here to clear index cache.
198  void increment (void) { matrix_ref () += 1.0; }
199 
200  void decrement (void) { matrix_ref () -= 1.0; }
201 
202  void changesign (void) { matrix_ref ().changesign (); }
203 
204  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
205 
206  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
207 
208  bool save_ascii (std::ostream& os);
209 
210  bool load_ascii (std::istream& is);
211 
212  bool save_binary (std::ostream& os, bool& save_as_floats);
213 
214  bool load_binary (std::istream& is, bool swap,
216 
217 #if defined (HAVE_HDF5)
218  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
219 
220  bool load_hdf5 (hid_t loc_id, const char *name);
221 #endif
222 
223  int write (octave_stream& os, int block_size,
224  oct_data_conv::data_type output_type, int skip,
225  oct_mach_info::float_format flt_fmt) const
226  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
227 
228  // Unsafe. This function exists to support the MEX interface.
229  // You should not use it anywhere else.
230  void *mex_get_data (void) const { return matrix.mex_get_data (); }
231 
232  mxArray *as_mxArray (void) const;
233 
234  octave_value map (unary_mapper_t umap) const;
235 
236 private:
238 
240 };
241 
242 #endif