GNU Octave  3.8.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-2013 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) const;
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 
168 protected:
169 
171 
173 
174  mutable MatrixType typ;
175 };
176 
177 #endif