Mercurial > hg > octave-lojdl
annotate src/ov-bool-mat.h @ 9812:f80c566bc751
improve unary mapper system
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 12 Nov 2009 15:47:58 +0100 |
parents | e793865ede63 |
children | 6f1ea8241c99 |
rev | line source |
---|---|
2871 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008 John W. Eaton |
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_map; |
45 class octave_value_list; | |
46 | |
47 class tree_walker; | |
48 | |
49 // Character matrix values. | |
50 | |
51 class | |
4513 | 52 octave_bool_matrix : public octave_base_matrix<boolNDArray> |
2871 | 53 { |
54 public: | |
55 | |
56 octave_bool_matrix (void) | |
4513 | 57 : octave_base_matrix<boolNDArray> () { } |
58 | |
59 octave_bool_matrix (const boolNDArray& bnda) | |
60 : octave_base_matrix<boolNDArray> (bnda) { } | |
2871 | 61 |
62 octave_bool_matrix (const boolMatrix& bm) | |
4513 | 63 : octave_base_matrix<boolNDArray> (bm) { } |
2871 | 64 |
5785 | 65 octave_bool_matrix (const boolMatrix& bm, const MatrixType& t) |
66 : octave_base_matrix<boolNDArray> (bm, t) { } | |
67 | |
2871 | 68 octave_bool_matrix (const octave_bool_matrix& bm) |
4513 | 69 : octave_base_matrix<boolNDArray> (bm) { } |
2871 | 70 |
71 ~octave_bool_matrix (void) { } | |
72 | |
5759 | 73 octave_base_value *clone (void) const { return new octave_bool_matrix (*this); } |
74 octave_base_value *empty_clone (void) const { return new octave_bool_matrix (); } | |
2871 | 75 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
76 type_conv_info numeric_conversion_function (void) const; |
2871 | 77 |
5759 | 78 octave_base_value *try_narrowing_conversion (void); |
2871 | 79 |
9350
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
80 idx_vector index_vector (void) const |
16a5f9e1fdb3
cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
81 { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); } |
2871 | 82 |
9685 | 83 builtin_type_t builtin_type (void) const { return btyp_bool; } |
84 | |
2871 | 85 bool is_bool_matrix (void) const { return true; } |
86 | |
3209 | 87 bool is_bool_type (void) const { return true; } |
88 | |
2871 | 89 bool is_real_type (void) const { return true; } |
90 | |
5533 | 91 int8NDArray |
92 int8_array_value (void) const { return int8NDArray (matrix); } | |
93 | |
94 int16NDArray | |
95 int16_array_value (void) const { return int16NDArray (matrix); } | |
96 | |
97 int32NDArray | |
98 int32_array_value (void) const { return int32NDArray (matrix); } | |
99 | |
100 int64NDArray | |
101 int64_array_value (void) const { return int64NDArray (matrix); } | |
102 | |
103 uint8NDArray | |
104 uint8_array_value (void) const { return uint8NDArray (matrix); } | |
105 | |
106 uint16NDArray | |
107 uint16_array_value (void) const { return uint16NDArray (matrix); } | |
108 | |
109 uint32NDArray | |
110 uint32_array_value (void) const { return uint32NDArray (matrix); } | |
111 | |
112 uint64NDArray | |
113 uint64_array_value (void) const { return uint64NDArray (matrix); } | |
114 | |
2871 | 115 double double_value (bool = false) const; |
116 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
117 float float_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
118 |
3145 | 119 double scalar_value (bool frc_str_conv = false) const |
120 { return double_value (frc_str_conv); } | |
2916 | 121 |
4513 | 122 Matrix matrix_value (bool = false) const |
123 { return Matrix (matrix.matrix_value ()); } | |
2871 | 124 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
125 FloatMatrix float_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
126 { return FloatMatrix (matrix.matrix_value ()); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 |
4569 | 128 NDArray array_value (bool = false) const |
4650 | 129 { return NDArray (matrix); } |
4569 | 130 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
131 FloatNDArray float_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 { return FloatNDArray (matrix); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
133 |
2871 | 134 Complex complex_value (bool = false) const; |
135 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 FloatComplex float_complex_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 |
3145 | 138 ComplexMatrix complex_matrix_value (bool = false) const |
4513 | 139 { return ComplexMatrix (matrix.matrix_value ( )); } |
2871 | 140 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
141 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
142 { return FloatComplexMatrix (matrix.matrix_value ( )); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
143 |
4569 | 144 ComplexNDArray complex_array_value (bool = false) const |
4901 | 145 { return ComplexNDArray (matrix); } |
4569 | 146 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
147 FloatComplexNDArray float_complex_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
148 { return FloatComplexNDArray (matrix); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 |
5533 | 150 charNDArray |
151 char_array_value (bool = false) const | |
152 { | |
153 charNDArray retval (dims ()); | |
154 | |
155 octave_idx_type nel = numel (); | |
156 | |
157 for (octave_idx_type i = 0; i < nel; i++) | |
158 retval(i) = static_cast<char>(matrix(i)); | |
159 | |
160 return retval; | |
161 } | |
162 | |
5944 | 163 boolMatrix bool_matrix_value (bool = false) const |
4513 | 164 { return matrix.matrix_value (); } |
2871 | 165 |
5944 | 166 boolNDArray bool_array_value (bool = false) const |
4543 | 167 { return matrix; } |
168 | |
5164 | 169 SparseMatrix sparse_matrix_value (bool = false) const |
170 { return SparseMatrix (Matrix (matrix.matrix_value ())); } | |
171 | |
172 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const | |
173 { return SparseComplexMatrix (ComplexMatrix (matrix.matrix_value ())); } | |
174 | |
175 SparseBoolMatrix sparse_bool_matrix_value (bool = false) const | |
176 { return SparseBoolMatrix (matrix.matrix_value ()); } | |
177 | |
5279 | 178 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871 | 179 |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
180 // Use matrix_ref here to clear index cache. |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
181 void invert (void) { matrix_ref ().invert (); } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9358
diff
changeset
|
182 |
4643 | 183 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
184 | |
6974 | 185 bool save_ascii (std::ostream& os); |
4687 | 186 |
187 bool load_ascii (std::istream& is); | |
188 | |
189 bool save_binary (std::ostream& os, bool& save_as_floats); | |
190 | |
191 bool load_binary (std::istream& is, bool swap, | |
192 oct_mach_info::float_format fmt); | |
193 | |
194 #if defined (HAVE_HDF5) | |
195 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
196 | |
197 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
198 #endif | |
199 | |
4970 | 200 int write (octave_stream& os, int block_size, |
201 oct_data_conv::data_type output_type, int skip, | |
202 oct_mach_info::float_format flt_fmt) const | |
203 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } | |
204 | |
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
|
205 // 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
|
206 // 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
|
207 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
|
208 |
5900 | 209 mxArray *as_mxArray (void) const; |
210 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
211 // Mapper functions are converted to double for treatment |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
212 octave_value map (unary_mapper_t umap) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
213 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
214 octave_matrix m (array_value ()); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
215 return m.map (umap); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
216 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
217 |
2871 | 218 protected: |
219 | |
3219 | 220 DECLARE_OCTAVE_ALLOCATOR |
2871 | 221 |
3219 | 222 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871 | 223 }; |
224 | |
225 #endif | |
226 | |
227 /* | |
228 ;;; Local Variables: *** | |
229 ;;; mode: C++ *** | |
230 ;;; End: *** | |
231 */ |