Mercurial > hg > octave-nkf
annotate src/ov-base-sparse.h @ 8721:e9cb742df9eb
imported patch sort3.diff
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 11 Feb 2009 15:25:53 +0100 |
parents | d254a21e0120 |
children | 767ed8cc6634 |
rev | line source |
---|---|
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 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
87 octave_value full_value (void) const { return matrix.matrix_value (); } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
88 |
5164 | 89 octave_value subsref (const std::string& type, |
90 const std::list<octave_value_list>& idx); | |
91 | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
92 octave_value_list subsref (const std::string& type, |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
93 const std::list<octave_value_list>& idx, int) |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
94 { return subsref (type, idx); } |
5164 | 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 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
102 void delete_elements (const octave_value_list& idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
103 |
5164 | 104 dim_vector dims (void) const { return matrix.dims (); } |
105 | |
5885 | 106 octave_value do_index_op (const octave_value_list& idx, |
107 bool resize_ok = false); | |
5164 | 108 |
109 octave_value reshape (const dim_vector& new_dims) const | |
110 { return T (matrix.reshape (new_dims)); } | |
111 | |
112 octave_value permute (const Array<int>& vec, bool inv = false) const | |
113 { return T (matrix.permute (vec, inv)); } | |
114 | |
5731 | 115 octave_value resize (const dim_vector& dv, bool = false) const; |
5164 | 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 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
120 octave_value diag (octave_idx_type k = 0) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
121 { return octave_value (matrix.diag (k)); } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
122 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
123 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 124 { return octave_value (matrix.sort (dim, mode)); } |
125 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
126 sortmode mode = ASCENDING) const |
7433 | 127 { return octave_value (matrix.sort (sidx, dim, mode)); } |
128 | |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
129 sortmode issorted (sortmode mode = UNSORTED) const |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
130 { return full_value ().issorted (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
131 |
5785 | 132 MatrixType matrix_type (void) const { return typ; } |
133 MatrixType matrix_type (const MatrixType& _typ) const | |
134 { MatrixType ret = typ; typ = _typ; return ret; } | |
5322 | 135 |
5164 | 136 bool is_matrix_type (void) const { return true; } |
137 | |
138 bool is_numeric_type (void) const { return true; } | |
139 | |
5631 | 140 bool is_sparse_type (void) const { return true; } |
141 | |
5164 | 142 bool is_defined (void) const { return true; } |
143 | |
144 bool is_constant (void) const { return true; } | |
145 | |
146 bool is_true (void) const; | |
147 | |
5275 | 148 octave_idx_type capacity (void) const { return matrix.capacity (); } |
5164 | 149 |
150 bool print_as_scalar (void) const; | |
151 | |
152 void print (std::ostream& os, bool pr_as_read_syntax = false) const; | |
153 | |
154 void print_info (std::ostream& os, const std::string& prefix) const; | |
155 | |
156 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; | |
157 | |
6974 | 158 bool save_ascii (std::ostream& os); |
5164 | 159 |
160 bool load_ascii (std::istream& is); | |
161 | |
5900 | 162 // Unsafe. These functions exists to support the MEX interface. |
163 // You should not use them anywhere else. | |
164 void *mex_get_data (void) const { return matrix.mex_get_data (); } | |
165 | |
166 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); } | |
167 | |
168 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); } | |
169 | |
5164 | 170 protected: |
171 | |
172 T matrix; | |
173 | |
5785 | 174 mutable MatrixType typ; |
5164 | 175 }; |
176 | |
177 #endif | |
178 | |
179 /* | |
180 ;;; Local Variables: *** | |
181 ;;; mode: C++ *** | |
182 ;;; End: *** | |
183 */ |