Mercurial > hg > octave-lojdl
annotate src/ov-base-mat.h @ 9358:d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Jun 2009 21:11:41 -0400 |
parents | 16a5f9e1fdb3 |
children | 1beb23d2b892 |
rev | line source |
---|---|
3219 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
7017 | 4 John W. Eaton |
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 Octave_map; | |
42 | |
43 class tree_walker; | |
44 | |
45 // Real matrix values. | |
46 | |
3223 | 47 template <class MT> |
48 class | |
3219 | 49 octave_base_matrix : public octave_base_value |
50 { | |
51 public: | |
52 | |
53 octave_base_matrix (void) | |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
54 : octave_base_value (), typ (), idx_cache () { } |
3219 | 55 |
6376 | 56 octave_base_matrix (const MT& m, const MatrixType& t = MatrixType ()) |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
57 : octave_base_value (), matrix (m), |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
58 typ (t.is_known () ? new MatrixType(t) : 0), idx_cache () |
4676 | 59 { |
60 if (matrix.ndims () == 0) | |
61 matrix.resize (dim_vector (0, 0)); | |
62 } | |
3219 | 63 |
64 octave_base_matrix (const octave_base_matrix& m) | |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
65 : octave_base_value (), matrix (m.matrix), |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
66 typ (m.typ ? new MatrixType (*m.typ) : 0), |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
67 idx_cache (m.idx_cache ? new idx_vector (*m.idx_cache) : 0) |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
68 { } |
3219 | 69 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
70 ~octave_base_matrix (void) { clear_cached_info (); } |
3219 | 71 |
5759 | 72 octave_base_value *clone (void) const { return new octave_base_matrix (*this); } |
73 octave_base_value *empty_clone (void) const { return new octave_base_matrix (); } | |
3933 | 74 |
4901 | 75 size_t byte_size (void) const { return matrix.byte_size (); } |
76 | |
5147 | 77 octave_value squeeze (void) const { return MT (matrix.squeeze ()); } |
4532 | 78 |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
79 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
|
80 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
81 void maybe_economize (void) { matrix.maybe_economize (); } |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
82 |
4247 | 83 octave_value subsref (const std::string& type, |
4219 | 84 const std::list<octave_value_list>& idx); |
3219 | 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, |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
87 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
|
88 { return subsref (type, idx); } |
4271 | 89 |
4247 | 90 octave_value subsasgn (const std::string& type, |
4219 | 91 const std::list<octave_value_list>& idx, |
3933 | 92 const octave_value& rhs); |
93 | |
5885 | 94 octave_value do_index_op (const octave_value_list& idx, |
95 bool resize_ok = false); | |
3220 | 96 |
3928 | 97 void assign (const octave_value_list& idx, const MT& rhs); |
98 | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
99 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
|
100 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
101 void delete_elements (const octave_value_list& idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
102 |
4513 | 103 dim_vector dims (void) const { return matrix.dims (); } |
104 | |
8994 | 105 octave_idx_type numel (void) const { return matrix.numel (); } |
106 | |
5602 | 107 octave_idx_type nnz (void) const { return matrix.nnz (); } |
108 | |
4567 | 109 octave_value reshape (const dim_vector& new_dims) const |
110 { return MT (matrix.reshape (new_dims)); } | |
111 | |
4593 | 112 octave_value permute (const Array<int>& vec, bool inv = false) const |
113 { return MT (matrix.permute (vec, inv)); } | |
114 | |
5731 | 115 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 116 |
4017 | 117 octave_value all (int dim = 0) const { return matrix.all (dim); } |
118 octave_value any (int dim = 0) const { return matrix.any (dim); } | |
3221 | 119 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
120 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
|
121 MatrixType matrix_type (const MatrixType& _typ) const; |
5785 | 122 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
123 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
|
124 { return octave_value (matrix.diag (k)); } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
125 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
126 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 127 { return octave_value (matrix.sort (dim, mode)); } |
128 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
|
129 sortmode mode = ASCENDING) const |
7433 | 130 { return octave_value (matrix.sort (sidx, dim, mode)); } |
131 | |
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
|
132 sortmode is_sorted (sortmode mode = UNSORTED) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
133 { return matrix.is_sorted (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
134 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
135 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
|
136 { return matrix.sort_rows_idx (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
137 |
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
|
138 sortmode is_sorted_rows (sortmode mode = UNSORTED) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
139 { return matrix.is_sorted_rows (mode); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8679
diff
changeset
|
140 |
3221 | 141 bool is_matrix_type (void) const { return true; } |
142 | |
143 bool is_numeric_type (void) const { return true; } | |
144 | |
3219 | 145 bool is_defined (void) const { return true; } |
146 | |
147 bool is_constant (void) const { return true; } | |
148 | |
3220 | 149 bool is_true (void) const; |
150 | |
4604 | 151 bool print_as_scalar (void) const; |
3219 | 152 |
3523 | 153 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3219 | 154 |
3933 | 155 void print_info (std::ostream& os, const std::string& prefix) const; |
156 | |
3219 | 157 protected: |
158 | |
159 MT matrix; | |
5785 | 160 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
161 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
|
162 { |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
163 delete idx_cache; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
164 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
|
165 return idx; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
166 } |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
167 |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
168 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
|
169 { |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
170 delete typ; typ = 0; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
171 delete idx_cache; idx_cache = 0; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
172 } |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
173 |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
174 mutable MatrixType *typ; |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8994
diff
changeset
|
175 mutable idx_vector *idx_cache; |
3219 | 176 }; |
177 | |
178 #endif | |
179 | |
180 /* | |
181 ;;; Local Variables: *** | |
182 ;;; mode: C++ *** | |
183 ;;; End: *** | |
184 */ |