5164
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2004, 2005, 2006, 2007 David Bateman |
7016
|
4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler |
|
5 |
|
6 This file is part of Octave. |
5164
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
5164
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
5164
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_base_sparse_h) |
|
25 #define octave_base_sparse_h 1 |
|
26 |
|
27 #include <cstdlib> |
|
28 |
|
29 #include <iostream> |
|
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" |
5785
|
40 #include "MatrixType.h" |
5164
|
41 |
|
42 class Octave_map; |
|
43 |
|
44 class tree_walker; |
|
45 |
|
46 class octave_sparse_bool_matrix; |
|
47 |
|
48 template <class T> |
|
49 class |
|
50 octave_base_sparse : public octave_base_value |
|
51 { |
|
52 public: |
|
53 |
5785
|
54 octave_base_sparse (void) : octave_base_value (), typ (MatrixType ()) { } |
5164
|
55 |
|
56 octave_base_sparse (const T& a) : octave_base_value (), matrix (a), |
5785
|
57 typ (MatrixType ()) |
5164
|
58 { |
|
59 if (matrix.ndims () == 0) |
|
60 matrix.resize (dim_vector (0, 0)); |
|
61 } |
|
62 |
5785
|
63 octave_base_sparse (const T& a, const MatrixType& t) : octave_base_value (), |
5164
|
64 matrix (a), typ (t) |
|
65 { |
|
66 if (matrix.ndims () == 0) |
|
67 matrix.resize (dim_vector (0, 0)); |
|
68 } |
|
69 |
|
70 octave_base_sparse (const octave_base_sparse& a) : |
|
71 octave_base_value (), matrix (a.matrix), typ (a.typ) { } |
|
72 |
|
73 ~octave_base_sparse (void) { } |
|
74 |
5759
|
75 octave_base_value *clone (void) const { return new octave_base_sparse (*this); } |
|
76 octave_base_value *empty_clone (void) const |
5164
|
77 { return new octave_base_sparse (); } |
|
78 |
5275
|
79 octave_idx_type nnz (void) const { return matrix.nnz (); } |
5604
|
80 |
|
81 octave_idx_type nzmax (void) const { return matrix.nzmax (); } |
5164
|
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 subsref (const std::string& type, |
|
88 const std::list<octave_value_list>& idx); |
|
89 |
|
90 octave_value_list subsref (const std::string&, |
|
91 const std::list<octave_value_list>&, int) |
|
92 { |
|
93 panic_impossible (); |
|
94 return octave_value_list (); |
|
95 } |
|
96 |
|
97 octave_value subsasgn (const std::string& type, |
|
98 const std::list<octave_value_list>& idx, |
|
99 const octave_value& rhs); |
|
100 |
|
101 void assign (const octave_value_list& idx, const T& rhs); |
|
102 |
|
103 dim_vector dims (void) const { return matrix.dims (); } |
|
104 |
5885
|
105 octave_value do_index_op (const octave_value_list& idx, |
|
106 bool resize_ok = false); |
5164
|
107 |
|
108 octave_value reshape (const dim_vector& new_dims) const |
|
109 { return T (matrix.reshape (new_dims)); } |
|
110 |
|
111 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
112 { return T (matrix.permute (vec, inv)); } |
|
113 |
5731
|
114 octave_value resize (const dim_vector& dv, bool = false) const; |
5164
|
115 |
|
116 octave_value all (int dim = 0) const { return matrix.all (dim); } |
|
117 octave_value any (int dim = 0) const { return matrix.any (dim); } |
|
118 |
7433
|
119 octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const |
|
120 { return octave_value (matrix.sort (dim, mode)); } |
|
121 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
|
122 sortmode mode = UNDEFINED) const |
|
123 { return octave_value (matrix.sort (sidx, dim, mode)); } |
|
124 |
5785
|
125 MatrixType matrix_type (void) const { return typ; } |
|
126 MatrixType matrix_type (const MatrixType& _typ) const |
|
127 { MatrixType ret = typ; typ = _typ; return ret; } |
5322
|
128 |
5164
|
129 bool is_matrix_type (void) const { return true; } |
|
130 |
|
131 bool is_numeric_type (void) const { return true; } |
|
132 |
5631
|
133 bool is_sparse_type (void) const { return true; } |
|
134 |
5164
|
135 bool is_defined (void) const { return true; } |
|
136 |
|
137 bool is_constant (void) const { return true; } |
|
138 |
|
139 bool is_true (void) const; |
|
140 |
5275
|
141 octave_idx_type capacity (void) const { return matrix.capacity (); } |
5164
|
142 |
|
143 bool print_as_scalar (void) const; |
|
144 |
|
145 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
146 |
|
147 void print_info (std::ostream& os, const std::string& prefix) const; |
|
148 |
|
149 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
150 |
6974
|
151 bool save_ascii (std::ostream& os); |
5164
|
152 |
|
153 bool load_ascii (std::istream& is); |
|
154 |
5900
|
155 // Unsafe. These functions exists to support the MEX interface. |
|
156 // You should not use them anywhere else. |
|
157 void *mex_get_data (void) const { return matrix.mex_get_data (); } |
|
158 |
|
159 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); } |
|
160 |
|
161 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); } |
|
162 |
5164
|
163 protected: |
|
164 |
|
165 T matrix; |
|
166 |
5785
|
167 mutable MatrixType typ; |
5164
|
168 }; |
|
169 |
|
170 #endif |
|
171 |
|
172 /* |
|
173 ;;; Local Variables: *** |
|
174 ;;; mode: C++ *** |
|
175 ;;; End: *** |
|
176 */ |