Mercurial > hg > octave-nkf
annotate src/ov-base-mat.h @ 12438:ab4c6bbff14a
use correct type for std::string length
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 Feb 2011 14:27:26 -0500 |
parents | e0e50f48df37 |
children | d6118a2c0644 |
rev | line source |
---|---|
3219 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1998-2011 John W. Eaton |
4 Copyright (C) 2009-2010 VZLU Prague | |
3219 | 5 |
6 This file is part of Octave. | |
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. | |
3219 | 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/>. | |
3219 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_base_matrix_h) | |
25 #define octave_base_matrix_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> |
3219 | 30 #include <string> |
31 | |
32 #include "mx-base.h" | |
33 #include "str-vec.h" | |
6376 | 34 #include "MatrixType.h" |
3219 | 35 |
36 #include "error.h" | |
4649 | 37 #include "oct-obj.h" |
3219 | 38 #include "ov-base.h" |
39 #include "ov-typeinfo.h" | |
40 | |
41 class tree_walker; | |
42 | |
43 // Real matrix values. | |
44 | |
3223 | 45 template <class MT> |
46 class | |
3219 | 47 octave_base_matrix : public octave_base_value |
48 { | |
49 public: | |
50 | |
51 octave_base_matrix (void) | |
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_value (), matrix (), typ (), idx_cache () { } |
3219 | 53 |
6376 | 54 octave_base_matrix (const MT& m, const MatrixType& t = MatrixType ()) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
55 : octave_base_value (), matrix (m), |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
56 typ (t.is_known () ? new MatrixType(t) : 0), idx_cache () |
4676 | 57 { |
58 if (matrix.ndims () == 0) | |
59 matrix.resize (dim_vector (0, 0)); | |
60 } | |
3219 | 61 |
62 octave_base_matrix (const octave_base_matrix& m) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
63 : octave_base_value (), matrix (m.matrix), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
64 typ (m.typ ? new MatrixType (*m.typ) : 0), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
65 idx_cache (m.idx_cache ? new idx_vector (*m.idx_cache) : 0) |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
66 { } |
3219 | 67 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
68 ~octave_base_matrix (void) { clear_cached_info (); } |
3219 | 69 |
4901 | 70 size_t byte_size (void) const { return matrix.byte_size (); } |
71 | |
5147 | 72 octave_value squeeze (void) const { return MT (matrix.squeeze ()); } |
4532 | 73 |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
74 octave_value full_value (void) const { return matrix; } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
75 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
76 void maybe_economize (void) { matrix.maybe_economize (); } |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
77 |
4247 | 78 octave_value subsref (const std::string& type, |
10313 | 79 const std::list<octave_value_list>& idx); |
3219 | 80 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
81 octave_value_list subsref (const std::string& type, |
10313 | 82 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
|
83 { return subsref (type, idx); } |
4271 | 84 |
4247 | 85 octave_value subsasgn (const std::string& type, |
10313 | 86 const std::list<octave_value_list>& idx, |
87 const octave_value& rhs); | |
3933 | 88 |
5885 | 89 octave_value do_index_op (const octave_value_list& idx, |
10313 | 90 bool resize_ok = false); |
3220 | 91 |
3928 | 92 void assign (const octave_value_list& idx, const MT& rhs); |
93 | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
94 void assign (const octave_value_list& idx, typename MT::element_type rhs); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
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 |
4513 | 98 dim_vector dims (void) const { return matrix.dims (); } |
99 | |
8994 | 100 octave_idx_type numel (void) const { return matrix.numel (); } |
101 | |
10653
ec5fa46e0e45
override ndims and numel for scalars and matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
102 int ndims (void) const { return matrix.ndims (); } |
ec5fa46e0e45
override ndims and numel for scalars and matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
103 |
5602 | 104 octave_idx_type nnz (void) const { return matrix.nnz (); } |
105 | |
4567 | 106 octave_value reshape (const dim_vector& new_dims) const |
107 { return MT (matrix.reshape (new_dims)); } | |
108 | |
4593 | 109 octave_value permute (const Array<int>& vec, bool inv = false) const |
110 { return MT (matrix.permute (vec, inv)); } | |
111 | |
5731 | 112 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 113 |
4017 | 114 octave_value all (int dim = 0) const { return matrix.all (dim); } |
115 octave_value any (int dim = 0) const { return matrix.any (dim); } | |
3221 | 116 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
117 MatrixType matrix_type (void) const { return typ ? *typ : MatrixType (); } |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
118 MatrixType matrix_type (const MatrixType& _typ) const; |
5785 | 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, | |
10313 | 126 sortmode mode = ASCENDING) const |
7433 | 127 { return octave_value (matrix.sort (sidx, dim, mode)); } |
128 | |
8734
767ed8cc6634
rename internal issorted and issorted_rows functions to is_sorted and is_sorted_rows
John W. Eaton <jwe@octave.org>
parents:
8733
diff
changeset
|
129 sortmode is_sorted (sortmode mode = UNSORTED) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
130 { return matrix.is_sorted (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
131 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
132 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
133 { return matrix.sort_rows_idx (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
134 |
8734
767ed8cc6634
rename internal issorted and issorted_rows functions to is_sorted and is_sorted_rows
John W. Eaton <jwe@octave.org>
parents:
8733
diff
changeset
|
135 sortmode is_sorted_rows (sortmode mode = UNSORTED) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
136 { return matrix.is_sorted_rows (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
137 |
3221 | 138 bool is_matrix_type (void) const { return true; } |
139 | |
140 bool is_numeric_type (void) const { return true; } | |
141 | |
3219 | 142 bool is_defined (void) const { return true; } |
143 | |
144 bool is_constant (void) const { return true; } | |
145 | |
3220 | 146 bool is_true (void) const; |
147 | |
4604 | 148 bool print_as_scalar (void) const; |
3219 | 149 |
3523 | 150 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3219 | 151 |
3933 | 152 void print_info (std::ostream& os, const std::string& prefix) const; |
153 | |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
154 MT& matrix_ref (void) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
155 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
156 clear_cached_info (); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
157 return matrix; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
158 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
159 |
10665
0f310fce905d
implement octave_base_matrix::matrix_ref const
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
160 const MT& matrix_ref (void) const |
0f310fce905d
implement octave_base_matrix::matrix_ref const
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
161 { |
0f310fce905d
implement octave_base_matrix::matrix_ref const
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
162 return matrix; |
0f310fce905d
implement octave_base_matrix::matrix_ref const
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
163 } |
0f310fce905d
implement octave_base_matrix::matrix_ref const
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
164 |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10665
diff
changeset
|
165 octave_value |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10665
diff
changeset
|
166 fast_elem_extract (octave_idx_type n) const; |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10665
diff
changeset
|
167 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10665
diff
changeset
|
168 bool |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10665
diff
changeset
|
169 fast_elem_insert (octave_idx_type n, const octave_value& x); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10665
diff
changeset
|
170 |
3219 | 171 protected: |
172 | |
173 MT matrix; | |
5785 | 174 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
175 idx_vector set_idx_cache (const idx_vector& idx) const |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
176 { |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
177 delete idx_cache; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
178 idx_cache = idx ? new idx_vector (idx) : 0; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
179 return idx; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
180 } |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
181 |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
182 void clear_cached_info (void) const |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
183 { |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
184 delete typ; typ = 0; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
185 delete idx_cache; idx_cache = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
186 } |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
187 |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
188 mutable MatrixType *typ; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
189 mutable idx_vector *idx_cache; |
12153
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
190 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
191 private: |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
192 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
193 // No assignment. |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
194 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
195 octave_base_matrix& operator = (const octave_base_matrix&); |
3219 | 196 }; |
197 | |
198 #endif |