Mercurial > hg > octave-nkf
annotate src/ov-bool-mat.h @ 12386:c1ea9b90a272 release-3-4-x
Added tag ss-3-3-92 for changeset c468c5b902b3
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 06 Feb 2011 07:30:27 -0500 |
parents | 12df7854fa7c |
children | 72c96de7a403 |
rev | line source |
---|---|
2871 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
4 Copyright (C) 2009-2010 VZLU Prague | |
2871 | 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. | |
2871 | 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/>. | |
2871 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_bool_matrix_h) | |
25 #define octave_bool_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> |
2871 | 30 #include <string> |
31 | |
32 #include "mx-base.h" | |
33 #include "oct-alloc.h" | |
34 | |
35 #include "error.h" | |
4970 | 36 #include "oct-stream.h" |
2871 | 37 #include "ov-base.h" |
3219 | 38 #include "ov-base-mat.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
39 #include "ov-re-mat.h" |
2871 | 40 #include "ov-typeinfo.h" |
41 | |
5785 | 42 #include "MatrixType.h" |
43 | |
2871 | 44 class octave_value_list; |
45 | |
46 class tree_walker; | |
47 | |
48 // Character matrix values. | |
49 | |
50 class | |
4513 | 51 octave_bool_matrix : public octave_base_matrix<boolNDArray> |
2871 | 52 { |
53 public: | |
54 | |
55 octave_bool_matrix (void) | |
4513 | 56 : octave_base_matrix<boolNDArray> () { } |
57 | |
58 octave_bool_matrix (const boolNDArray& bnda) | |
59 : octave_base_matrix<boolNDArray> (bnda) { } | |
2871 | 60 |
10351
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
61 octave_bool_matrix (const Array<bool>& bnda) |
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
62 : octave_base_matrix<boolNDArray> (bnda) { } |
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
63 |
2871 | 64 octave_bool_matrix (const boolMatrix& bm) |
4513 | 65 : octave_base_matrix<boolNDArray> (bm) { } |
2871 | 66 |
5785 | 67 octave_bool_matrix (const boolMatrix& bm, const MatrixType& t) |
68 : octave_base_matrix<boolNDArray> (bm, t) { } | |
69 | |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
70 octave_bool_matrix (const boolNDArray& bm, const idx_vector& cache) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
71 : octave_base_matrix<boolNDArray> (bm) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
72 { |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
73 set_idx_cache (cache); |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
74 } |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
75 |
2871 | 76 octave_bool_matrix (const octave_bool_matrix& bm) |
4513 | 77 : octave_base_matrix<boolNDArray> (bm) { } |
2871 | 78 |
79 ~octave_bool_matrix (void) { } | |
80 | |
5759 | 81 octave_base_value *clone (void) const { return new octave_bool_matrix (*this); } |
82 octave_base_value *empty_clone (void) const { return new octave_bool_matrix (); } | |
2871 | 83 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
84 type_conv_info numeric_conversion_function (void) const; |
2871 | 85 |
5759 | 86 octave_base_value *try_narrowing_conversion (void); |
2871 | 87 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 idx_vector index_vector (void) const |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
89 { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); } |
2871 | 90 |
9685 | 91 builtin_type_t builtin_type (void) const { return btyp_bool; } |
92 | |
2871 | 93 bool is_bool_matrix (void) const { return true; } |
94 | |
3209 | 95 bool is_bool_type (void) const { return true; } |
96 | |
2871 | 97 bool is_real_type (void) const { return true; } |
98 | |
9841
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
99 bool is_numeric_type (void) const { return false; } |
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
100 |
5533 | 101 int8NDArray |
102 int8_array_value (void) const { return int8NDArray (matrix); } | |
103 | |
104 int16NDArray | |
105 int16_array_value (void) const { return int16NDArray (matrix); } | |
106 | |
107 int32NDArray | |
108 int32_array_value (void) const { return int32NDArray (matrix); } | |
109 | |
110 int64NDArray | |
111 int64_array_value (void) const { return int64NDArray (matrix); } | |
112 | |
113 uint8NDArray | |
114 uint8_array_value (void) const { return uint8NDArray (matrix); } | |
115 | |
116 uint16NDArray | |
117 uint16_array_value (void) const { return uint16NDArray (matrix); } | |
118 | |
119 uint32NDArray | |
120 uint32_array_value (void) const { return uint32NDArray (matrix); } | |
121 | |
122 uint64NDArray | |
123 uint64_array_value (void) const { return uint64NDArray (matrix); } | |
124 | |
2871 | 125 double double_value (bool = false) const; |
126 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 float float_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
128 |
3145 | 129 double scalar_value (bool frc_str_conv = false) const |
130 { return double_value (frc_str_conv); } | |
2916 | 131 |
4513 | 132 Matrix matrix_value (bool = false) const |
133 { return Matrix (matrix.matrix_value ()); } | |
2871 | 134 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
135 FloatMatrix float_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 { return FloatMatrix (matrix.matrix_value ()); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 |
4569 | 138 NDArray array_value (bool = false) const |
4650 | 139 { return NDArray (matrix); } |
4569 | 140 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
141 FloatNDArray float_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
142 { return FloatNDArray (matrix); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
143 |
2871 | 144 Complex complex_value (bool = false) const; |
145 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
146 FloatComplex float_complex_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
147 |
3145 | 148 ComplexMatrix complex_matrix_value (bool = false) const |
4513 | 149 { return ComplexMatrix (matrix.matrix_value ( )); } |
2871 | 150 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
151 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
152 { return FloatComplexMatrix (matrix.matrix_value ( )); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
153 |
4569 | 154 ComplexNDArray complex_array_value (bool = false) const |
4901 | 155 { return ComplexNDArray (matrix); } |
4569 | 156 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
157 FloatComplexNDArray float_complex_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
158 { return FloatComplexNDArray (matrix); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
159 |
5533 | 160 charNDArray |
161 char_array_value (bool = false) const | |
162 { | |
163 charNDArray retval (dims ()); | |
164 | |
165 octave_idx_type nel = numel (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
166 |
5533 | 167 for (octave_idx_type i = 0; i < nel; i++) |
168 retval(i) = static_cast<char>(matrix(i)); | |
169 | |
170 return retval; | |
171 } | |
172 | |
5944 | 173 boolMatrix bool_matrix_value (bool = false) const |
4513 | 174 { return matrix.matrix_value (); } |
2871 | 175 |
5944 | 176 boolNDArray bool_array_value (bool = false) const |
4543 | 177 { return matrix; } |
178 | |
5164 | 179 SparseMatrix sparse_matrix_value (bool = false) const |
180 { return SparseMatrix (Matrix (matrix.matrix_value ())); } | |
181 | |
182 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const | |
183 { return SparseComplexMatrix (ComplexMatrix (matrix.matrix_value ())); } | |
184 | |
185 SparseBoolMatrix sparse_bool_matrix_value (bool = false) const | |
186 { return SparseBoolMatrix (matrix.matrix_value ()); } | |
187 | |
5279 | 188 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871 | 189 |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
190 // Use matrix_ref here to clear index cache. |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
191 void invert (void) { matrix_ref ().invert (); } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
192 |
4643 | 193 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
194 | |
6974 | 195 bool save_ascii (std::ostream& os); |
4687 | 196 |
197 bool load_ascii (std::istream& is); | |
198 | |
199 bool save_binary (std::ostream& os, bool& save_as_floats); | |
200 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
201 bool load_binary (std::istream& is, bool swap, |
10313 | 202 oct_mach_info::float_format fmt); |
4687 | 203 |
204 #if defined (HAVE_HDF5) | |
205 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
206 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9841
diff
changeset
|
207 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 208 #endif |
209 | |
4970 | 210 int write (octave_stream& os, int block_size, |
10313 | 211 oct_data_conv::data_type output_type, int skip, |
212 oct_mach_info::float_format flt_fmt) const | |
4970 | 213 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
214 | |
9358
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9350
diff
changeset
|
215 // Unsafe. This function exists to support the MEX interface. |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9350
diff
changeset
|
216 // You should not use it anywhere else. |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9350
diff
changeset
|
217 void *mex_get_data (void) const { return matrix.mex_get_data (); } |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9350
diff
changeset
|
218 |
5900 | 219 mxArray *as_mxArray (void) const; |
220 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
221 // Mapper functions are converted to double for treatment |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
222 octave_value map (unary_mapper_t umap) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
223 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
224 octave_matrix m (array_value ()); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
225 return m.map (umap); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
226 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
227 |
2871 | 228 protected: |
229 | |
3219 | 230 DECLARE_OCTAVE_ALLOCATOR |
2871 | 231 |
3219 | 232 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871 | 233 }; |
234 | |
235 #endif |