Mercurial > hg > octave-nkf
annotate src/ov-base-sparse.h @ 14626:f947d2922feb stable rc-3-6-2-0
3.6.2-rc0 release candidate
* configure.ac (AC_INIT): Version is now 3.6.2-rc0.
(OCTAVE_RELEASE_DATE): Now 2012-05-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 May 2012 13:46:18 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2004-2012 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
7016 | 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 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
5164 | 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 tree_walker; | |
43 | |
44 class octave_sparse_bool_matrix; | |
45 | |
46 template <class T> | |
47 class | |
48 octave_base_sparse : public octave_base_value | |
49 { | |
50 public: | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
51 |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
52 octave_base_sparse (void) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
53 : octave_base_value (), matrix (), typ (MatrixType ()) |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
54 { } |
5164 | 55 |
56 octave_base_sparse (const T& a) : octave_base_value (), matrix (a), | |
10313 | 57 typ (MatrixType ()) |
5164 | 58 { |
59 if (matrix.ndims () == 0) | |
60 matrix.resize (dim_vector (0, 0)); | |
61 } | |
62 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
63 octave_base_sparse (const T& a, const MatrixType& t) : octave_base_value (), |
10313 | 64 matrix (a), typ (t) |
5164 | 65 { |
66 if (matrix.ndims () == 0) | |
67 matrix.resize (dim_vector (0, 0)); | |
68 } | |
69 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
70 octave_base_sparse (const octave_base_sparse& a) : |
5164 | 71 octave_base_value (), matrix (a.matrix), typ (a.typ) { } |
72 | |
73 ~octave_base_sparse (void) { } | |
74 | |
5275 | 75 octave_idx_type nnz (void) const { return matrix.nnz (); } |
5604 | 76 |
77 octave_idx_type nzmax (void) const { return matrix.nzmax (); } | |
5164 | 78 |
79 size_t byte_size (void) const { return matrix.byte_size (); } | |
80 | |
81 octave_value squeeze (void) const { return matrix.squeeze (); } | |
82 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
83 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
|
84 |
5164 | 85 octave_value subsref (const std::string& type, |
10313 | 86 const std::list<octave_value_list>& idx); |
5164 | 87 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
88 octave_value_list subsref (const std::string& type, |
10313 | 89 const std::list<octave_value_list>& idx, int) |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
90 { return subsref (type, idx); } |
5164 | 91 |
92 octave_value subsasgn (const std::string& type, | |
10313 | 93 const std::list<octave_value_list>& idx, |
94 const octave_value& rhs); | |
5164 | 95 |
96 void assign (const octave_value_list& idx, const T& rhs); | |
97 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
98 void delete_elements (const octave_value_list& idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
99 |
5164 | 100 dim_vector dims (void) const { return matrix.dims (); } |
101 | |
5885 | 102 octave_value do_index_op (const octave_value_list& idx, |
10313 | 103 bool resize_ok = false); |
5164 | 104 |
105 octave_value reshape (const dim_vector& new_dims) const | |
106 { return T (matrix.reshape (new_dims)); } | |
107 | |
108 octave_value permute (const Array<int>& vec, bool inv = false) const | |
109 { return T (matrix.permute (vec, inv)); } | |
110 | |
5731 | 111 octave_value resize (const dim_vector& dv, bool = false) const; |
5164 | 112 |
113 octave_value all (int dim = 0) const { return matrix.all (dim); } | |
114 octave_value any (int dim = 0) const { return matrix.any (dim); } | |
115 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
116 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
|
117 { return octave_value (matrix.diag (k)); } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
118 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
119 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 120 { return octave_value (matrix.sort (dim, mode)); } |
121 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | |
10313 | 122 sortmode mode = ASCENDING) const |
7433 | 123 { return octave_value (matrix.sort (sidx, dim, mode)); } |
124 | |
8734
767ed8cc6634
rename internal issorted and issorted_rows functions to is_sorted and is_sorted_rows
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
125 sortmode is_sorted (sortmode mode = UNSORTED) const |
767ed8cc6634
rename internal issorted and issorted_rows functions to is_sorted and is_sorted_rows
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
126 { return full_value ().is_sorted (mode); } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
127 |
5785 | 128 MatrixType matrix_type (void) const { return typ; } |
129 MatrixType matrix_type (const MatrixType& _typ) const | |
130 { MatrixType ret = typ; typ = _typ; return ret; } | |
5322 | 131 |
5164 | 132 bool is_matrix_type (void) const { return true; } |
133 | |
134 bool is_numeric_type (void) const { return true; } | |
135 | |
5631 | 136 bool is_sparse_type (void) const { return true; } |
137 | |
5164 | 138 bool is_defined (void) const { return true; } |
139 | |
140 bool is_constant (void) const { return true; } | |
141 | |
142 bool is_true (void) const; | |
143 | |
5275 | 144 octave_idx_type capacity (void) const { return matrix.capacity (); } |
5164 | 145 |
146 bool print_as_scalar (void) const; | |
147 | |
148 void print (std::ostream& os, bool pr_as_read_syntax = false) const; | |
149 | |
150 void print_info (std::ostream& os, const std::string& prefix) const; | |
151 | |
152 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; | |
153 | |
6974 | 154 bool save_ascii (std::ostream& os); |
5164 | 155 |
156 bool load_ascii (std::istream& is); | |
157 | |
5900 | 158 // Unsafe. These functions exists to support the MEX interface. |
159 // You should not use them anywhere else. | |
160 void *mex_get_data (void) const { return matrix.mex_get_data (); } | |
161 | |
162 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); } | |
163 | |
164 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); } | |
165 | |
5164 | 166 protected: |
167 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
168 octave_value map (octave_base_value::unary_mapper_t umap) const; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
169 |
5164 | 170 T matrix; |
171 | |
5785 | 172 mutable MatrixType typ; |
5164 | 173 }; |
174 | |
175 #endif |