GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base-sparse.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2018 David Bateman
4 Copyright (C) 1998-2004 Andy Adler
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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_ov_base_sparse_h)
25 #define octave_ov_base_sparse_h 1
26 
27 #include "octave-config.h"
28 
29 #include <cstdlib>
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "str-vec.h"
35 
36 #include "error.h"
37 #include "ovl.h"
38 #include "ov-base.h"
39 #include "ov-typeinfo.h"
40 
41 #include "boolSparse.h"
42 #include "MatrixType.h"
43 
45 
46 template <typename T>
47 class
49 {
50 public:
51 
53  : octave_base_value (), matrix (), typ (MatrixType ())
54  { }
55 
56  octave_base_sparse (const T& a)
58  {
59  if (matrix.ndims () == 0)
60  matrix.resize (dim_vector (0, 0));
61  }
62 
63  octave_base_sparse (const T& a, const MatrixType& t)
64  : octave_base_value (), matrix (a), typ (t)
65  {
66  if (matrix.ndims () == 0)
67  matrix.resize (dim_vector (0, 0));
68  }
69 
71  : octave_base_value (), matrix (a.matrix), typ (a.typ) { }
72 
73  ~octave_base_sparse (void) = default;
74 
75  octave_idx_type numel (void) const { return dims ().safe_numel (); }
76 
77  octave_idx_type nnz (void) const { return matrix.nnz (); }
78 
79  octave_idx_type nzmax (void) const { return matrix.nzmax (); }
80 
81  size_t byte_size (void) const { return matrix.byte_size (); }
82 
83  octave_value squeeze (void) const { return matrix.squeeze (); }
84 
85  octave_value full_value (void) const { return matrix.matrix_value (); }
86 
88  const std::list<octave_value_list>& idx);
89 
91  const std::list<octave_value_list>& idx, int)
92  { return subsref (type, idx); }
93 
95  const std::list<octave_value_list>& idx,
96  const octave_value& rhs);
97 
98  // FIXME: should we import the functions from the base class and
99  // overload them here, or should we use a different name so we don't
100  // have to do this? Without the using declaration or a name change,
101  // the base class functions will be hidden. That may be OK, but it
102  // can also cause some confusion.
104 
105  void assign (const octave_value_list& idx, const T& rhs);
106 
107  void delete_elements (const octave_value_list& idx);
108 
109  dim_vector dims (void) const { return matrix.dims (); }
110 
112  bool resize_ok = false);
113 
114  octave_value reshape (const dim_vector& new_dims) const
115  { return T (matrix.reshape (new_dims)); }
116 
117  octave_value permute (const Array<int>& vec, bool inv = false) const
118  { return T (matrix.permute (vec, inv)); }
119 
120  octave_value resize (const dim_vector& dv, bool = false) const;
121 
122  octave_value all (int dim = 0) const { return matrix.all (dim); }
123  octave_value any (int dim = 0) const { return matrix.any (dim); }
124 
126  { return octave_value (matrix.diag (k)); }
127 
129  { return octave_value (matrix.sort (dim, mode)); }
131  sortmode mode = ASCENDING) const
132  { return octave_value (matrix.sort (sidx, dim, mode)); }
133 
135  { return full_value ().issorted (mode); }
136 
137  MatrixType matrix_type (void) const { return typ; }
138  MatrixType matrix_type (const MatrixType& _typ) const
139  { MatrixType ret = typ; typ = _typ; return ret; }
140 
141  bool is_matrix_type (void) const { return true; }
142 
143  bool isnumeric (void) const { return true; }
144 
145  bool issparse (void) const { return true; }
146 
147  bool is_defined (void) const { return true; }
148 
149  bool is_constant (void) const { return true; }
150 
151  bool is_true (void) const;
152 
153  OCTAVE_DEPRECATED (4.4, "use 'nzmax' instead")
154  octave_idx_type capacity (void) const { return nzmax (); }
155 
156  bool print_as_scalar (void) const;
157 
158  void print (std::ostream& os, bool pr_as_read_syntax = false);
159 
160  void print_info (std::ostream& os, const std::string& prefix) const;
161 
162  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
163 
164  bool save_ascii (std::ostream& os);
165 
166  bool load_ascii (std::istream& is);
167 
169 
172 
173  // Unsafe. These functions exists to support the MEX interface.
174  // You should not use them anywhere else.
175  void * mex_get_data (void) const { return matrix.mex_get_data (); }
176 
177  octave_idx_type * mex_get_ir (void) const { return matrix.mex_get_ir (); }
178 
179  octave_idx_type * mex_get_jc (void) const { return matrix.mex_get_jc (); }
180 
182 
183 protected:
184 
186 
188 
189  mutable MatrixType typ;
190 };
191 
192 #endif
octave_value diag(octave_idx_type k=0) const
octave_value squeeze(void) const
octave_base_sparse(const octave_base_sparse &a)
characters Given a string matrix
Definition: hex2num.cc:155
octave_idx_type nnz(void) const
sortmode
Definition: oct-sort.h:105
octave_value reshape(const dim_vector &new_dims) const
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:6348
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
idx subsref(val, idx) esult
Definition: ov.cc:3065
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:300
dim_vector dims(void) const
bool is_defined(void) const
for large enough k
Definition: lu.cc:617
octave_base_sparse(const T &a)
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
octave_base_sparse(const T &a, const MatrixType &t)
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:997
bool is_matrix_type(void) const
octave_idx_type * mex_get_ir(void) const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
void assign(const octave_value_list &idx, const SparseBoolMatrix &rhs)
octave_value resize(const dim_vector &dv, bool=false) const
bool issparse(void) const
void * mex_get_data(void) const
octave_value permute(const Array< int > &vec, bool inv=false) const
sortmode issorted(sortmode mode=UNSORTED) const
MatrixType matrix_type(const MatrixType &_typ) const
bool is_true(const std::string &s)
void print_info(std::ostream &os, const std::string &prefix) const
MatrixType matrix_type(void) const
size_t byte_size(void) const
idx type
Definition: ov.cc:3114
void print(std::ostream &os, bool pr_as_read_syntax=false)
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
bool isnumeric(void) const
void delete_elements(const octave_value_list &idx)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
octave_value all(int dim=0) const
octave_idx_type numel(void) const
octave_idx_type * mex_get_jc(void) const
octave_map map(dims)
octave_idx_type nzmax(void) const
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3114
octave_value full_value(void) const
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
octave_value fast_elem_extract(octave_idx_type n) const
bool is_constant(void) const
for i
Definition: data.cc:5264
write the output to stdout if nargout is
Definition: load-save.cc:1612
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov.h:1380
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
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:888
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
octave_value any(int dim=0) const
octave_idx_type capacity(void) const
static float_display_format get_edit_display_format(const octave_value &val)