Mercurial > hg > octave-nkf
annotate src/ov-base-sparse.h @ 10811:e38c071bbc41
allow user query the maximum array size
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 21 Jul 2010 08:47:34 +0200 |
parents | d9e57045b9e1 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 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 | |
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: | |
51 | |
5785 | 52 octave_base_sparse (void) : octave_base_value (), typ (MatrixType ()) { } |
5164 | 53 |
54 octave_base_sparse (const T& a) : octave_base_value (), matrix (a), | |
10313 | 55 typ (MatrixType ()) |
5164 | 56 { |
57 if (matrix.ndims () == 0) | |
58 matrix.resize (dim_vector (0, 0)); | |
59 } | |
60 | |
5785 | 61 octave_base_sparse (const T& a, const MatrixType& t) : octave_base_value (), |
10313 | 62 matrix (a), typ (t) |
5164 | 63 { |
64 if (matrix.ndims () == 0) | |
65 matrix.resize (dim_vector (0, 0)); | |
66 } | |
67 | |
68 octave_base_sparse (const octave_base_sparse& a) : | |
69 octave_base_value (), matrix (a.matrix), typ (a.typ) { } | |
70 | |
71 ~octave_base_sparse (void) { } | |
72 | |
5275 | 73 octave_idx_type nnz (void) const { return matrix.nnz (); } |
5604 | 74 |
75 octave_idx_type nzmax (void) const { return matrix.nzmax (); } | |
5164 | 76 |
77 size_t byte_size (void) const { return matrix.byte_size (); } | |
78 | |
79 octave_value squeeze (void) const { return matrix.squeeze (); } | |
80 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
81 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
|
82 |
5164 | 83 octave_value subsref (const std::string& type, |
10313 | 84 const std::list<octave_value_list>& idx); |
5164 | 85 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
86 octave_value_list subsref (const std::string& type, |
10313 | 87 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
|
88 { return subsref (type, idx); } |
5164 | 89 |
90 octave_value subsasgn (const std::string& type, | |
10313 | 91 const std::list<octave_value_list>& idx, |
92 const octave_value& rhs); | |
5164 | 93 |
94 void assign (const octave_value_list& idx, const T& rhs); | |
95 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
96 void delete_elements (const octave_value_list& idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
97 |
5164 | 98 dim_vector dims (void) const { return matrix.dims (); } |
99 | |
5885 | 100 octave_value do_index_op (const octave_value_list& idx, |
10313 | 101 bool resize_ok = false); |
5164 | 102 |
103 octave_value reshape (const dim_vector& new_dims) const | |
104 { return T (matrix.reshape (new_dims)); } | |
105 | |
106 octave_value permute (const Array<int>& vec, bool inv = false) const | |
107 { return T (matrix.permute (vec, inv)); } | |
108 | |
5731 | 109 octave_value resize (const dim_vector& dv, bool = false) const; |
5164 | 110 |
111 octave_value all (int dim = 0) const { return matrix.all (dim); } | |
112 octave_value any (int dim = 0) const { return matrix.any (dim); } | |
113 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
114 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
|
115 { return octave_value (matrix.diag (k)); } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
116 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
117 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 118 { return octave_value (matrix.sort (dim, mode)); } |
119 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | |
10313 | 120 sortmode mode = ASCENDING) const |
7433 | 121 { return octave_value (matrix.sort (sidx, dim, mode)); } |
122 | |
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
|
123 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
|
124 { return full_value ().is_sorted (mode); } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
125 |
5785 | 126 MatrixType matrix_type (void) const { return typ; } |
127 MatrixType matrix_type (const MatrixType& _typ) const | |
128 { MatrixType ret = typ; typ = _typ; return ret; } | |
5322 | 129 |
5164 | 130 bool is_matrix_type (void) const { return true; } |
131 | |
132 bool is_numeric_type (void) const { return true; } | |
133 | |
5631 | 134 bool is_sparse_type (void) const { return true; } |
135 | |
5164 | 136 bool is_defined (void) const { return true; } |
137 | |
138 bool is_constant (void) const { return true; } | |
139 | |
140 bool is_true (void) const; | |
141 | |
5275 | 142 octave_idx_type capacity (void) const { return matrix.capacity (); } |
5164 | 143 |
144 bool print_as_scalar (void) const; | |
145 | |
146 void print (std::ostream& os, bool pr_as_read_syntax = false) const; | |
147 | |
148 void print_info (std::ostream& os, const std::string& prefix) const; | |
149 | |
150 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; | |
151 | |
6974 | 152 bool save_ascii (std::ostream& os); |
5164 | 153 |
154 bool load_ascii (std::istream& is); | |
155 | |
5900 | 156 // Unsafe. These functions exists to support the MEX interface. |
157 // You should not use them anywhere else. | |
158 void *mex_get_data (void) const { return matrix.mex_get_data (); } | |
159 | |
160 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); } | |
161 | |
162 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); } | |
163 | |
5164 | 164 protected: |
165 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
166 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
|
167 |
5164 | 168 T matrix; |
169 | |
5785 | 170 mutable MatrixType typ; |
5164 | 171 }; |
172 | |
173 #endif |