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-base-sparse.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2015 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 <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 
32 #include "str-vec.h"
33 
34 #include "error.h"
35 #include "oct-obj.h"
36 #include "ov-base.h"
37 #include "ov-typeinfo.h"
38 
39 #include "boolSparse.h"
40 #include "MatrixType.h"
41 
42 class tree_walker;
43 
45 
46 template <class T>
47 class
49 {
50 public:
51 
53  : octave_base_value (), matrix (), typ (MatrixType ())
54  { }
55 
56  octave_base_sparse (const T& a)
57  : octave_base_value (), matrix (a), typ (MatrixType ())
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 
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 
87  octave_value subsref (const std::string& type,
88  const std::list<octave_value_list>& idx);
89 
90  octave_value_list subsref (const std::string& type,
91  const std::list<octave_value_list>& idx, int)
92  { return subsref (type, idx); }
93 
94  octave_value subsasgn (const std::string& type,
95  const std::list<octave_value_list>& idx,
96  const octave_value& rhs);
97 
98  void assign (const octave_value_list& idx, const T& rhs);
99 
100  void delete_elements (const octave_value_list& idx);
101 
102  dim_vector dims (void) const { return matrix.dims (); }
103 
105  bool resize_ok = false);
106 
107  octave_value reshape (const dim_vector& new_dims) const
108  { return T (matrix.reshape (new_dims)); }
109 
110  octave_value permute (const Array<int>& vec, bool inv = false) const
111  { return T (matrix.permute (vec, inv)); }
112 
113  octave_value resize (const dim_vector& dv, bool = false) const;
114 
115  octave_value all (int dim = 0) const { return matrix.all (dim); }
116  octave_value any (int dim = 0) const { return matrix.any (dim); }
117 
119  { return octave_value (matrix.diag (k)); }
120 
122  { return octave_value (matrix.sort (dim, mode)); }
124  sortmode mode = ASCENDING) const
125  { return octave_value (matrix.sort (sidx, dim, mode)); }
126 
128  { return full_value ().is_sorted (mode); }
129 
130  MatrixType matrix_type (void) const { return typ; }
131  MatrixType matrix_type (const MatrixType& _typ) const
132  { MatrixType ret = typ; typ = _typ; return ret; }
133 
134  bool is_matrix_type (void) const { return true; }
135 
136  bool is_numeric_type (void) const { return true; }
137 
138  bool is_sparse_type (void) const { return true; }
139 
140  bool is_defined (void) const { return true; }
141 
142  bool is_constant (void) const { return true; }
143 
144  bool is_true (void) const;
145 
146  octave_idx_type capacity (void) const { return matrix.capacity (); }
147 
148  bool print_as_scalar (void) const;
149 
150  void print (std::ostream& os, bool pr_as_read_syntax = false);
151 
152  void print_info (std::ostream& os, const std::string& prefix) const;
153 
154  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
155 
156  bool save_ascii (std::ostream& os);
157 
158  bool load_ascii (std::istream& is);
159 
160  // Unsafe. These functions exists to support the MEX interface.
161  // You should not use them anywhere else.
162  void *mex_get_data (void) const { return matrix.mex_get_data (); }
163 
164  octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); }
165 
166  octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); }
167 
169 
170 protected:
171 
173 
175 
176  mutable MatrixType typ;
177 };
178 
179 #endif
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
bool is_true(const std::string &s)
Definition: mkoctfile.cc:373
boolMatrix matrix_value(void) const
Definition: boolSparse.cc:248
octave_value diag(octave_idx_type k=0) const
octave_value map(unary_mapper_t umap) 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
dim_vector dims(void) const
Definition: Sparse.h:283
sortmode
Definition: oct-sort.h:103
MatrixType matrix_type(const MatrixType &_typ) const
octave_base_sparse(const T &a)
bool is_constant(void) const
size_t byte_size(void) const
SparseBoolMatrix permute(const Array< octave_idx_type > &vec, bool inv=false) const
Definition: boolSparse.cc:312
octave_base_sparse(const T &a, const MatrixType &t)
octave_idx_type nzmax(void) const
sortmode is_sorted(sortmode mode=UNSORTED) const
SparseBoolMatrix reshape(const dim_vector &new_dims) const
Definition: boolSparse.cc:306
octave_idx_type nnz(void) const
Definition: Sparse.h:248
octave_idx_type nzmax(void) const
Definition: Sparse.h:246
sortmode is_sorted(sortmode mode=UNSORTED) const
Definition: ov.h:1138
void assign(const octave_value_list &idx, const SparseBoolMatrix &rhs)
SparseBoolMatrix all(int dim=-1) const
Definition: boolSparse.cc:138
octave_idx_type safe_numel(void) const
Definition: dim-vector.cc:93
octave_idx_type numel(void) const
Sparse< T > sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: Sparse.cc:2240
octave_idx_type ndims(void) const
Definition: Sparse.h:544
octave_idx_type * mex_get_ir(void) const
Definition: Sparse.h:567
bool is_defined(void) const
void resize(octave_idx_type r, octave_idx_type c)
Definition: Sparse.cc:944
octave_idx_type * mex_get_jc(void) const
Definition: Sparse.h:572
octave_value squeeze(void) const
size_t byte_size(void) const
Definition: Sparse.h:276
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
void print_info(std::ostream &os, const std::string &prefix) const
SparseBoolMatrix any(int dim=-1) const
Definition: boolSparse.cc:144
SparseBoolMatrix squeeze(void) const
Definition: boolSparse.cc:287
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
octave_idx_type capacity(void) const
Definition: Sparse.h:247
MatrixType matrix_type(void) const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
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
SparseBoolMatrix diag(octave_idx_type k=0) const
Definition: boolSparse.cc:242
octave_value any(int dim=0) const
void * mex_get_data(void) const
Definition: Sparse.h:565
bool is_matrix_type(void) const
octave_value full_value(void) const
octave_idx_type * mex_get_jc(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())? '\'': '"'))