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-sparse.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2017 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 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_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 
44 class tree_walker;
45 
47 
48 template <typename T>
49 class
51 {
52 public:
53 
55  : octave_base_value (), matrix (), typ (MatrixType ())
56  { }
57 
58  octave_base_sparse (const T& a)
59  : octave_base_value (), matrix (a), typ (MatrixType ())
60  {
61  if (matrix.ndims () == 0)
62  matrix.resize (dim_vector (0, 0));
63  }
64 
65  octave_base_sparse (const T& a, const MatrixType& t)
66  : octave_base_value (), matrix (a), typ (t)
67  {
68  if (matrix.ndims () == 0)
69  matrix.resize (dim_vector (0, 0));
70  }
71 
73  : octave_base_value (), matrix (a.matrix), typ (a.typ) { }
74 
76 
77  octave_idx_type numel (void) const { return dims ().safe_numel (); }
78 
79  octave_idx_type nnz (void) const { return matrix.nnz (); }
80 
81  octave_idx_type nzmax (void) const { return matrix.nzmax (); }
82 
83  size_t byte_size (void) const { return matrix.byte_size (); }
84 
85  octave_value squeeze (void) const { return matrix.squeeze (); }
86 
87  octave_value full_value (void) const { return matrix.matrix_value (); }
88 
90  const std::list<octave_value_list>& idx);
91 
93  const std::list<octave_value_list>& idx, int)
94  { return subsref (type, idx); }
95 
97  const std::list<octave_value_list>& idx,
98  const octave_value& rhs);
99 
100  // FIXME: should we import the functions from the base class and
101  // overload them here, or should we use a different name so we don't
102  // have to do this? Without the using declaration or a name change,
103  // the base class functions will be hidden. That may be OK, but it
104  // can also cause some confusion.
106 
107  void assign (const octave_value_list& idx, const T& rhs);
108 
109  void delete_elements (const octave_value_list& idx);
110 
111  dim_vector dims (void) const { return matrix.dims (); }
112 
114  bool resize_ok = false);
115 
116  octave_value reshape (const dim_vector& new_dims) const
117  { return T (matrix.reshape (new_dims)); }
118 
119  octave_value permute (const Array<int>& vec, bool inv = false) const
120  { return T (matrix.permute (vec, inv)); }
121 
122  octave_value resize (const dim_vector& dv, bool = false) const;
123 
124  octave_value all (int dim = 0) const { return matrix.all (dim); }
125  octave_value any (int dim = 0) const { return matrix.any (dim); }
126 
128  { return octave_value (matrix.diag (k)); }
129 
131  { return octave_value (matrix.sort (dim, mode)); }
133  sortmode mode = ASCENDING) const
134  { return octave_value (matrix.sort (sidx, dim, mode)); }
135 
137  { return full_value ().is_sorted (mode); }
138 
139  MatrixType matrix_type (void) const { return typ; }
140  MatrixType matrix_type (const MatrixType& _typ) const
141  { MatrixType ret = typ; typ = _typ; return ret; }
142 
143  bool is_matrix_type (void) const { return true; }
144 
145  bool is_numeric_type (void) const { return true; }
146 
147  bool is_sparse_type (void) const { return true; }
148 
149  bool is_defined (void) const { return true; }
150 
151  bool is_constant (void) const { return true; }
152 
153  bool is_true (void) const;
154 
155  OCTAVE_DEPRECATED ("use 'nzmax' instead")
156  octave_idx_type capacity (void) const { return nzmax (); }
157 
158  bool print_as_scalar (void) const;
159 
160  void print (std::ostream& os, bool pr_as_read_syntax = false);
161 
162  void print_info (std::ostream& os, const std::string& prefix) const;
163 
164  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
165 
166  bool save_ascii (std::ostream& os);
167 
168  bool load_ascii (std::istream& is);
169 
170  // Unsafe. These functions exists to support the MEX interface.
171  // You should not use them anywhere else.
172  void *mex_get_data (void) const { return matrix.mex_get_data (); }
173 
174  octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); }
175 
176  octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); }
177 
179 
180 protected:
181 
183 
185 
186  mutable MatrixType typ;
187 };
188 
189 #endif
bool is_true(const std::string &s)
Definition: mkoctfile.cc:398
octave_value diag(octave_idx_type k=0) const
octave_base_sparse(const octave_base_sparse &a)
octave_value all(int dim=0) const
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
sortmode
Definition: oct-sort.h:105
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
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:296
MatrixType matrix_type(const MatrixType &_typ) const
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_base_sparse(const T &a)
bool is_constant(void) const
size_t byte_size(void) 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:935
octave_idx_type nzmax(void) const
sortmode is_sorted(sortmode mode=UNSORTED) 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:398
sortmode is_sorted(sortmode mode=UNSORTED) const
Definition: ov.h:1323
void assign(const octave_value_list &idx, const SparseBoolMatrix &rhs)
octave_idx_type numel(void) const
bool is_defined(void) const
octave_value squeeze(void) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
idx type
Definition: ov.cc:3129
void print(std::ostream &os, bool pr_as_read_syntax=false)
void print_info(std::ostream &os, const std::string &prefix) const
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
void delete_elements(const octave_value_list &idx)
octave_value fast_elem_extract(octave_idx_type n) const
octave_value resize(const dim_vector &dv, bool=false) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
octave_idx_type capacity(void) const
octave_value reshape(const dim_vector &new_dims) const
MatrixType matrix_type(void) const
octave_map map(dims)
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
void * mex_get_data(void) const
bool is_numeric_type(void) const
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
bool is_sparse_type(void) const
octave_value permute(const Array< int > &vec, bool inv=false) const
octave_value any(int dim=0) const
bool is_matrix_type(void) const
octave_value full_value(void) const
write the output to stdout if nargout is
Definition: load-save.cc:1576
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:854
octave_idx_type * mex_get_jc(void) const
dim_vector dv
Definition: sub2ind.cc:263
dim_vector dims(void) const
octave_idx_type nnz(void) const
octave_idx_type * mex_get_ir(void) const
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))