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-re-mat.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 "str-vec.h"
34 
35 #include "error.h"
36 #include "oct-stream.h"
37 #include "ov-base.h"
38 #include "ov-base-mat.h"
39 #include "ov-typeinfo.h"
40 
41 #include "MatrixType.h"
42 
43 class octave_value_list;
44 
45 class tree_walker;
46 
47 // Real matrix values.
48 
49 class
52 {
53 public:
54 
56  : octave_base_matrix<NDArray> () { }
57 
58  octave_matrix (const Matrix& m)
59  : octave_base_matrix<NDArray> (m) { }
60 
61  octave_matrix (const Matrix& m, const MatrixType& t)
62  : octave_base_matrix<NDArray> (m, t) { }
63 
64  octave_matrix (const NDArray& nda)
65  : octave_base_matrix<NDArray> (nda) { }
66 
69 
71  : octave_base_matrix<NDArray> (Matrix (d)) { }
72 
74  : octave_base_matrix<NDArray> (Matrix (v)) { }
75 
77  : octave_base_matrix<NDArray> (Matrix (v)) { }
78 
80  : octave_base_matrix<NDArray> (m) { }
81 
83  bool zero_based = false, bool cache_index = false)
84  : octave_base_matrix<NDArray> (NDArray (idx, zero_based))
85  {
86  // Auto-create cache to speed up subsequent indexing.
87  if (zero_based && cache_index)
88  set_idx_cache (idx_vector (idx));
89  }
90 
91  octave_matrix (const NDArray& nda, const idx_vector& cache)
93  {
94  set_idx_cache (cache);
95  }
96 
97  ~octave_matrix (void) { }
98 
99  octave_base_value *clone (void) const { return new octave_matrix (*this); }
100  octave_base_value *empty_clone (void) const { return new octave_matrix (); }
101 
102  type_conv_info numeric_demotion_function (void) const;
103 
104  octave_base_value *try_narrowing_conversion (void);
105 
106  idx_vector index_vector (bool /* require_integers */ = false) const
107  { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
108 
109  builtin_type_t builtin_type (void) const { return btyp_double; }
110 
111  bool is_real_matrix (void) const { return true; }
112 
113  bool is_real_type (void) const { return true; }
114 
115  bool is_double_type (void) const { return true; }
116 
117  bool is_float_type (void) const { return true; }
118 
120  int8_array_value (void) const { return int8NDArray (matrix); }
121 
123  int16_array_value (void) const { return int16NDArray (matrix); }
124 
126  int32_array_value (void) const { return int32NDArray (matrix); }
127 
129  int64_array_value (void) const { return int64NDArray (matrix); }
130 
132  uint8_array_value (void) const { return uint8NDArray (matrix); }
133 
135  uint16_array_value (void) const { return uint16NDArray (matrix); }
136 
138  uint32_array_value (void) const { return uint32NDArray (matrix); }
139 
141  uint64_array_value (void) const { return uint64NDArray (matrix); }
142 
143  double double_value (bool = false) const;
144 
145  float float_value (bool = false) const;
146 
147  double scalar_value (bool frc_str_conv = false) const
148  { return double_value (frc_str_conv); }
149 
150  Matrix matrix_value (bool = false) const;
151 
152  FloatMatrix float_matrix_value (bool = false) const;
153 
154  Complex complex_value (bool = false) const;
155 
156  FloatComplex float_complex_value (bool = false) const;
157 
158  ComplexMatrix complex_matrix_value (bool = false) const;
159 
160  FloatComplexMatrix float_complex_matrix_value (bool = false) const;
161 
162  ComplexNDArray complex_array_value (bool = false) const;
163 
164  FloatComplexNDArray float_complex_array_value (bool = false) const;
165 
166  boolNDArray bool_array_value (bool warn = false) const;
167 
168  charNDArray char_array_value (bool = false) const;
169 
170  NDArray array_value (bool = false) const { return matrix; }
171 
172  FloatNDArray float_array_value (bool = false) const { return matrix; }
173 
174  SparseMatrix sparse_matrix_value (bool = false) const;
175 
176  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
177 
178  octave_value diag (octave_idx_type k = 0) const;
179 
180  octave_value diag (octave_idx_type m, octave_idx_type n) const;
181 
182  octave_value reshape (const dim_vector& new_dims) const;
183 
184  octave_value squeeze (void) const;
185 
186  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
188  sortmode mode = ASCENDING) const;
189 
190  sortmode is_sorted (sortmode mode = UNSORTED) const;
191 
192  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
193 
194  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
195 
196  // Use matrix_ref here to clear index cache.
197  void increment (void) { matrix_ref () += 1.0; }
198 
199  void decrement (void) { matrix_ref () -= 1.0; }
200 
201  void changesign (void) { matrix_ref ().changesign (); }
202 
203  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
204 
205  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
206 
207  bool save_ascii (std::ostream& os);
208 
209  bool load_ascii (std::istream& is);
210 
211  bool save_binary (std::ostream& os, bool& save_as_floats);
212 
213  bool load_binary (std::istream& is, bool swap,
215 
216  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
217 
218  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
219 
220  int write (octave_stream& os, int block_size,
221  oct_data_conv::data_type output_type, int skip,
222  oct_mach_info::float_format flt_fmt) const
223  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
224 
225  // Unsafe. This function exists to support the MEX interface.
226  // You should not use it anywhere else.
227  void *mex_get_data (void) const { return matrix.mex_get_data (); }
228 
229  mxArray *as_mxArray (void) const;
230 
231  octave_value map (unary_mapper_t umap) const;
232 
233 private:
234 
236 };
237 
238 #endif
octave_matrix(const Matrix &m, const MatrixType &t)
Definition: ov-re-mat.h:61
octave_base_value * empty_clone(void) const
Definition: ov-re-mat.h:100
octave_matrix(const Array< octave_idx_type > &idx, bool zero_based=false, bool cache_index=false)
Definition: ov-re-mat.h:82
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:31
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
Definition: ov-re-mat.h:220
double scalar_value(bool frc_str_conv=false) const
Definition: ov-re-mat.h:147
NDArray array_value(bool=false) const
Definition: ov-re-mat.h:170
int64NDArray int64_array_value(void) const
Definition: ov-re-mat.h:129
~octave_matrix(void)
Definition: ov-re-mat.h:97
sortmode
Definition: oct-sort.h:103
FloatNDArray float_array_value(bool=false) const
Definition: ov-re-mat.h:172
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:31
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:31
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:31
uint16NDArray uint16_array_value(void) const
Definition: ov-re-mat.h:135
octave_matrix(const DiagMatrix &d)
Definition: ov-re-mat.h:70
octave_matrix(const Matrix &m)
Definition: ov-re-mat.h:58
octave_matrix(void)
Definition: ov-re-mat.h:55
uint32NDArray uint32_array_value(void) const
Definition: ov-re-mat.h:138
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:31
bool is_double_type(void) const
Definition: ov-re-mat.h:115
builtin_type_t
Definition: ov-base.h:59
uint64NDArray uint64_array_value(void) const
Definition: ov-re-mat.h:141
octave_matrix(const RowVector &v)
Definition: ov-re-mat.h:73
F77_RET_T const double const double double * d
int16NDArray int16_array_value(void) const
Definition: ov-re-mat.h:123
bool is_real_matrix(void) const
Definition: ov-re-mat.h:111
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
bool is_real_type(void) const
Definition: ov-re-mat.h:113
#define OCTINTERP_API
Definition: mexproto.h:66
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:31
octave_matrix(const ColumnVector &v)
Definition: ov-re-mat.h:76
void decrement(void)
Definition: ov-re-mat.h:199
octave_matrix(const Array< double > &m)
Definition: ov-re-mat.h:67
static void cache(const std::string key, str_llist_type *value)
Definition: kpse.cc:2105
Definition: dMatrix.h:35
void * mex_get_data(void) const
Definition: ov-re-mat.h:227
octave_matrix(const octave_matrix &m)
Definition: ov-re-mat.h:79
int32NDArray int32_array_value(void) const
Definition: ov-re-mat.h:126
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:31
int8NDArray int8_array_value(void) const
Definition: ov-re-mat.h:120
void increment(void)
Definition: ov-re-mat.h:197
void changesign(void)
Definition: ov-re-mat.h:201
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, oct_mach_info::float_format flt_fmt)
Definition: oct-stream.cc:3546
octave_matrix(const NDArray &nda)
Definition: ov-re-mat.h:64
octave_matrix(const NDArray &nda, const idx_vector &cache)
Definition: ov-re-mat.h:91
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
octave_base_value * clone(void) const
Definition: ov-re-mat.h:99
uint8NDArray uint8_array_value(void) const
Definition: ov-re-mat.h:132
bool is_float_type(void) const
Definition: ov-re-mat.h:117
std::complex< double > Complex
Definition: oct-cmplx.h:29
builtin_type_t builtin_type(void) const
Definition: ov-re-mat.h:109
idx_vector index_vector(bool=false) const
Definition: ov-re-mat.h:106
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:31