GNU Octave  4.2.1
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-mat.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1998-2017 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_base_mat_h)
25 #define octave_ov_base_mat_h 1
26 
27 #include "octave-config.h"
28 
29 #include <cstdlib>
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "mx-base.h"
35 #include "str-vec.h"
36 #include "MatrixType.h"
37 
38 #include "error.h"
39 #include "ovl.h"
40 #include "ov-base.h"
41 #include "ov-typeinfo.h"
42 
43 class tree_walker;
44 
45 // Real matrix values.
46 
47 template <typename MT>
48 class
50 {
51 public:
52 
54  : octave_base_value (), matrix (), typ (), idx_cache () { }
55 
56  octave_base_matrix (const MT& m, const MatrixType& t = MatrixType ())
57  : octave_base_value (), matrix (m),
58  typ (t.is_known () ? new MatrixType (t) : 0), idx_cache ()
59  {
60  if (matrix.ndims () == 0)
61  matrix.resize (dim_vector (0, 0));
62  }
63 
66  typ (m.typ ? new MatrixType (*m.typ) : 0),
67  idx_cache (m.idx_cache ? new idx_vector (*m.idx_cache) : 0)
68  { }
69 
70  ~octave_base_matrix (void) { clear_cached_info (); }
71 
72  size_t byte_size (void) const { return matrix.byte_size (); }
73 
74  octave_value squeeze (void) const { return MT (matrix.squeeze ()); }
75 
76  octave_value full_value (void) const { return matrix; }
77 
78  void maybe_economize (void) { matrix.maybe_economize (); }
79 
81  const std::list<octave_value_list>& idx);
82 
84  const std::list<octave_value_list>& idx, int)
85  { return subsref (type, idx); }
86 
88  const std::list<octave_value_list>& idx,
89  const octave_value& rhs);
90 
91  octave_value do_index_op (const octave_value_list& idx,
92  bool resize_ok = false);
93 
95  { return do_index_op (idx); }
96 
97  // FIXME: should we import the functions from the base class and
98  // overload them here, or should we use a different name so we don't
99  // have to do this? Without the using declaration or a name change,
100  // the base class functions will be hidden. That may be OK, but it
101  // can also cause some confusion.
103 
104  void assign (const octave_value_list& idx, const MT& rhs);
105 
106  void assign (const octave_value_list& idx, typename MT::element_type rhs);
107 
108  void delete_elements (const octave_value_list& idx);
109 
110  dim_vector dims (void) const { return matrix.dims (); }
111 
112  octave_idx_type numel (void) const { return matrix.numel (); }
113 
114  int ndims (void) const { return matrix.ndims (); }
115 
116  octave_idx_type nnz (void) const { return matrix.nnz (); }
117 
118  octave_value reshape (const dim_vector& new_dims) const
119  { return MT (matrix.reshape (new_dims)); }
120 
121  octave_value permute (const Array<int>& vec, bool inv = false) const
122  { return MT (matrix.permute (vec, inv)); }
123 
124  octave_value resize (const dim_vector& dv, bool fill = false) const;
125 
126  octave_value all (int dim = 0) const { return matrix.all (dim); }
127  octave_value any (int dim = 0) const { return matrix.any (dim); }
128 
129  MatrixType matrix_type (void) const { return typ ? *typ : MatrixType (); }
130  MatrixType matrix_type (const MatrixType& _typ) const;
131 
133  { return octave_value (matrix.diag (k)); }
134 
136  { return octave_value (matrix.diag (m, n)); }
137 
139  { return octave_value (matrix.sort (dim, mode)); }
141  sortmode mode = ASCENDING) const
142  { return octave_value (matrix.sort (sidx, dim, mode)); }
143 
145  { return matrix.is_sorted (mode); }
146 
148  { return matrix.sort_rows_idx (mode); }
149 
151  { return matrix.is_sorted_rows (mode); }
152 
153  bool is_matrix_type (void) const { return true; }
154 
155  bool is_numeric_type (void) const { return true; }
156 
157  bool is_defined (void) const { return true; }
158 
159  bool is_constant (void) const { return true; }
160 
161  bool is_true (void) const;
162 
163  bool print_as_scalar (void) const;
164 
165  void print (std::ostream& os, bool pr_as_read_syntax = false);
166 
167  void print_info (std::ostream& os, const std::string& prefix) const;
168 
169  void short_disp (std::ostream& os) const;
170 
171  MT& matrix_ref (void)
172  {
173  clear_cached_info ();
174  return matrix;
175  }
176 
177  const MT& matrix_ref (void) const
178  {
179  return matrix;
180  }
181 
183  fast_elem_extract (octave_idx_type n) const;
184 
185  bool
186  fast_elem_insert (octave_idx_type n, const octave_value& x);
187 
188 protected:
189 
190  MT matrix;
191 
193  {
194  delete idx_cache;
195  idx_cache = idx ? new idx_vector (idx) : 0;
196  return idx;
197  }
198 
199  void clear_cached_info (void) const
200  {
201  delete typ; typ = 0;
202  delete idx_cache; idx_cache = 0;
203  }
204 
205  mutable MatrixType *typ;
207 
208 private:
209 
210  // No assignment.
211 
213 };
214 
215 #endif
octave_value all(int dim=0) const
Definition: ov-base-mat.h:126
bool is_true(const std::string &s)
Definition: mkoctfile.cc:398
octave_value squeeze(void) const
Definition: ov-base-mat.h:74
sortmode is_sorted(sortmode mode=UNSORTED) const
Definition: ov-base-mat.h:144
sortmode
Definition: oct-sort.h:105
size_t byte_size(void) const
Definition: ov-base-mat.h:72
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:6386
idx subsref(val, idx) esult
Definition: ov.cc:3080
void maybe_economize(void)
Definition: ov-base-mat.h:78
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:296
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-base-mat.h:150
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-base-mat.h:121
for large enough k
Definition: lu.cc:606
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the then the first element defines the pivoting tolerance for the unsymmetric the values defined such that for full matrix
Definition: lu.cc:138
octave_idx_type numel(void) const
Definition: ov-base-mat.h:112
octave_value diag(octave_idx_type k=0) const
Definition: ov-base-mat.h:132
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
Definition: ov-base-mat.h:83
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
bool is_constant(void) const
Definition: ov-base-mat.h:159
bool is_matrix_type(void) const
Definition: ov-base-mat.h:153
~octave_base_matrix(void)
Definition: ov-base-mat.h:70
MatrixType matrix_type(void) const
Definition: ov-base-mat.h:129
const MT & matrix_ref(void) const
Definition: ov-base-mat.h:177
octave_base_matrix(const octave_base_matrix &m)
Definition: ov-base-mat.h:64
MatrixType * typ
Definition: ov-base-mat.h:205
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:140
void clear_cached_info(void) const
Definition: ov-base-mat.h:199
idx_vector set_idx_cache(const idx_vector &idx) const
Definition: ov-base-mat.h:192
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-base-mat.h:118
idx type
Definition: ov.cc:3129
int ndims(void) const
Definition: ov-base-mat.h:114
octave_base_matrix(const MT &m, const MatrixType &t=MatrixType())
Definition: ov-base-mat.h:56
dim_vector dims(void) const
Definition: ov-base-mat.h:110
bool is_numeric_type(void) const
Definition: ov-base-mat.h:155
MT & matrix_ref(void)
Definition: ov-base-mat.h:171
idx_vector * idx_cache
Definition: ov-base-mat.h:206
octave_idx_type nnz(void) const
Definition: ov-base-mat.h:116
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
octave_value_list do_multi_index_op(int, const octave_value_list &idx)
Definition: ov-base-mat.h:94
octave_value any(int dim=0) const
Definition: ov-base-mat.h:127
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:138
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:147
octave_value diag(octave_idx_type m, octave_idx_type n) const
Definition: ov-base-mat.h:135
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_base_matrix(void)
Definition: ov-base-mat.h:53
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:854
octave_value full_value(void) const
Definition: ov-base-mat.h:76
dim_vector dv
Definition: sub2ind.cc:263
tree_walker & operator=(const tree_walker &)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
bool is_defined(void) const
Definition: ov-base-mat.h:157