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" |
|
39 #include "SparseType.h" |
|
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 |
|
53 octave_base_sparse (void) : octave_base_value (), typ (SparseType ()) { } |
|
54 |
|
55 octave_base_sparse (const T& a) : octave_base_value (), matrix (a), |
|
56 typ (SparseType ()) |
|
57 { |
|
58 if (matrix.ndims () == 0) |
|
59 matrix.resize (dim_vector (0, 0)); |
|
60 } |
|
61 |
|
62 octave_base_sparse (const T& a, const SparseType& t) : octave_base_value (), |
|
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 |
|
74 octave_value *clone (void) const { return new octave_base_sparse (*this); } |
|
75 octave_value *empty_clone (void) const |
|
76 { return new octave_base_sparse (); } |
|
77 |
5275
|
78 octave_idx_type nnz (void) const { return matrix.nnz (); } |
|
79 octave_idx_type nonzero (void) const { return matrix.nonzero (); } |
5164
|
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 subsref (const std::string& type, |
|
86 const std::list<octave_value_list>& idx); |
|
87 |
|
88 octave_value_list subsref (const std::string&, |
|
89 const std::list<octave_value_list>&, int) |
|
90 { |
|
91 panic_impossible (); |
|
92 return octave_value_list (); |
|
93 } |
|
94 |
|
95 octave_value subsasgn (const std::string& type, |
|
96 const std::list<octave_value_list>& idx, |
|
97 const octave_value& rhs); |
|
98 |
|
99 void assign (const octave_value_list& idx, const T& rhs); |
|
100 |
|
101 dim_vector dims (void) const { return matrix.dims (); } |
|
102 |
|
103 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
|
104 |
|
105 octave_value do_index_op (const octave_value_list& idx) |
|
106 { return do_index_op (idx, 0); } |
|
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 |
|
114 octave_value resize (const dim_vector& dv) const |
|
115 { T retval (matrix); retval.resize (dv); return retval; } |
|
116 |
|
117 octave_value all (int dim = 0) const { return matrix.all (dim); } |
|
118 octave_value any (int dim = 0) const { return matrix.any (dim); } |
|
119 |
|
120 bool is_matrix_type (void) const { return true; } |
|
121 |
|
122 bool is_numeric_type (void) const { return true; } |
|
123 |
|
124 bool is_defined (void) const { return true; } |
|
125 |
|
126 bool is_constant (void) const { return true; } |
|
127 |
|
128 bool is_true (void) const; |
|
129 |
5275
|
130 octave_idx_type capacity (void) const { return matrix.capacity (); } |
5164
|
131 |
|
132 bool print_as_scalar (void) const; |
|
133 |
|
134 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
135 |
|
136 void print_info (std::ostream& os, const std::string& prefix) const; |
|
137 |
|
138 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
139 |
|
140 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
141 bool strip_nan_and_inf); |
|
142 |
|
143 bool load_ascii (std::istream& is); |
|
144 |
|
145 protected: |
|
146 |
|
147 T matrix; |
|
148 |
|
149 SparseType typ; |
|
150 }; |
|
151 |
|
152 #endif |
|
153 |
|
154 /* |
|
155 ;;; Local Variables: *** |
|
156 ;;; mode: C++ *** |
|
157 ;;; End: *** |
|
158 */ |