5164
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
|
4 Copyright (C) 1998-2004 Andy Adler |
|
5 |
|
6 Octave is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License as published by the |
|
8 Free Software Foundation; either version 2, or (at your option) any |
|
9 later version. |
|
10 |
|
11 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
5307
|
17 along with this program; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 Boston, MA 02110-1301, USA. |
5164
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_base_sparse_h) |
|
24 #define octave_base_sparse_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
|
28 #include <iostream> |
|
29 #include <string> |
|
30 |
|
31 #include "str-vec.h" |
|
32 |
|
33 #include "error.h" |
|
34 #include "oct-obj.h" |
|
35 #include "ov-base.h" |
|
36 #include "ov-typeinfo.h" |
|
37 |
|
38 #include "boolSparse.h" |
5785
|
39 #include "MatrixType.h" |
5164
|
40 |
|
41 class Octave_map; |
|
42 |
|
43 class tree_walker; |
|
44 |
|
45 class octave_sparse_bool_matrix; |
|
46 |
|
47 template <class T> |
|
48 class |
|
49 octave_base_sparse : public octave_base_value |
|
50 { |
|
51 public: |
|
52 |
5785
|
53 octave_base_sparse (void) : octave_base_value (), typ (MatrixType ()) { } |
5164
|
54 |
|
55 octave_base_sparse (const T& a) : octave_base_value (), matrix (a), |
5785
|
56 typ (MatrixType ()) |
5164
|
57 { |
|
58 if (matrix.ndims () == 0) |
|
59 matrix.resize (dim_vector (0, 0)); |
|
60 } |
|
61 |
5785
|
62 octave_base_sparse (const T& a, const MatrixType& t) : octave_base_value (), |
5164
|
63 matrix (a), typ (t) |
|
64 { |
|
65 if (matrix.ndims () == 0) |
|
66 matrix.resize (dim_vector (0, 0)); |
|
67 } |
|
68 |
|
69 octave_base_sparse (const octave_base_sparse& a) : |
|
70 octave_base_value (), matrix (a.matrix), typ (a.typ) { } |
|
71 |
|
72 ~octave_base_sparse (void) { } |
|
73 |
5759
|
74 octave_base_value *clone (void) const { return new octave_base_sparse (*this); } |
|
75 octave_base_value *empty_clone (void) const |
5164
|
76 { return new octave_base_sparse (); } |
|
77 |
5275
|
78 octave_idx_type nnz (void) const { return matrix.nnz (); } |
5604
|
79 |
|
80 octave_idx_type nzmax (void) const { return matrix.nzmax (); } |
5164
|
81 |
|
82 size_t byte_size (void) const { return matrix.byte_size (); } |
|
83 |
|
84 octave_value squeeze (void) const { return matrix.squeeze (); } |
|
85 |
|
86 octave_value subsref (const std::string& type, |
|
87 const std::list<octave_value_list>& idx); |
|
88 |
|
89 octave_value_list subsref (const std::string&, |
|
90 const std::list<octave_value_list>&, int) |
|
91 { |
|
92 panic_impossible (); |
|
93 return octave_value_list (); |
|
94 } |
|
95 |
|
96 octave_value subsasgn (const std::string& type, |
|
97 const std::list<octave_value_list>& idx, |
|
98 const octave_value& rhs); |
|
99 |
|
100 void assign (const octave_value_list& idx, const T& rhs); |
|
101 |
|
102 dim_vector dims (void) const { return matrix.dims (); } |
|
103 |
5885
|
104 octave_value do_index_op (const octave_value_list& idx, |
|
105 bool resize_ok = false); |
5164
|
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 |
5731
|
113 octave_value resize (const dim_vector& dv, bool = false) const; |
5164
|
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 |
5785
|
118 MatrixType matrix_type (void) const { return typ; } |
|
119 MatrixType matrix_type (const MatrixType& _typ) const |
|
120 { MatrixType ret = typ; typ = _typ; return ret; } |
5322
|
121 |
5164
|
122 bool is_matrix_type (void) const { return true; } |
|
123 |
|
124 bool is_numeric_type (void) const { return true; } |
|
125 |
5631
|
126 bool is_sparse_type (void) const { return true; } |
|
127 |
5164
|
128 bool is_defined (void) const { return true; } |
|
129 |
|
130 bool is_constant (void) const { return true; } |
|
131 |
|
132 bool is_true (void) const; |
|
133 |
5275
|
134 octave_idx_type capacity (void) const { return matrix.capacity (); } |
5164
|
135 |
|
136 bool print_as_scalar (void) const; |
|
137 |
|
138 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
139 |
|
140 void print_info (std::ostream& os, const std::string& prefix) const; |
|
141 |
|
142 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
143 |
|
144 bool save_ascii (std::ostream& os, bool& infnan_warned, |
5956
|
145 int strip_nan_and_inf); |
5164
|
146 |
|
147 bool load_ascii (std::istream& is); |
|
148 |
5900
|
149 // Unsafe. These functions exists to support the MEX interface. |
|
150 // You should not use them anywhere else. |
|
151 void *mex_get_data (void) const { return matrix.mex_get_data (); } |
|
152 |
|
153 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); } |
|
154 |
|
155 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); } |
|
156 |
5164
|
157 protected: |
|
158 |
|
159 T matrix; |
|
160 |
5785
|
161 mutable MatrixType typ; |
5164
|
162 }; |
|
163 |
|
164 #endif |
|
165 |
|
166 /* |
|
167 ;;; Local Variables: *** |
|
168 ;;; mode: C++ *** |
|
169 ;;; End: *** |
|
170 */ |