2871
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2871
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2871
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_bool_matrix_h) |
|
24 #define octave_bool_matrix_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
3503
|
28 #include <iostream> |
2871
|
29 #include <string> |
|
30 |
|
31 #include "mx-base.h" |
|
32 #include "oct-alloc.h" |
|
33 |
|
34 #include "error.h" |
4970
|
35 #include "oct-stream.h" |
2871
|
36 #include "ov-base.h" |
3219
|
37 #include "ov-base-mat.h" |
2871
|
38 #include "ov-typeinfo.h" |
|
39 |
5785
|
40 #include "MatrixType.h" |
|
41 |
2871
|
42 class Octave_map; |
|
43 class octave_value_list; |
|
44 |
|
45 class tree_walker; |
|
46 |
|
47 // Character matrix values. |
|
48 |
|
49 class |
4513
|
50 octave_bool_matrix : public octave_base_matrix<boolNDArray> |
2871
|
51 { |
|
52 public: |
|
53 |
|
54 octave_bool_matrix (void) |
4513
|
55 : octave_base_matrix<boolNDArray> () { } |
|
56 |
|
57 octave_bool_matrix (const boolNDArray& bnda) |
|
58 : octave_base_matrix<boolNDArray> (bnda) { } |
2871
|
59 |
|
60 octave_bool_matrix (const boolMatrix& bm) |
4513
|
61 : octave_base_matrix<boolNDArray> (bm) { } |
2871
|
62 |
5785
|
63 octave_bool_matrix (const boolMatrix& bm, const MatrixType& t) |
|
64 : octave_base_matrix<boolNDArray> (bm, t) { } |
|
65 |
3225
|
66 octave_bool_matrix (const Array2<bool>& a) |
4513
|
67 : octave_base_matrix<boolNDArray> (a) { } |
3225
|
68 |
2871
|
69 octave_bool_matrix (const octave_bool_matrix& bm) |
4513
|
70 : octave_base_matrix<boolNDArray> (bm) { } |
2871
|
71 |
|
72 ~octave_bool_matrix (void) { } |
|
73 |
5759
|
74 octave_base_value *clone (void) const { return new octave_bool_matrix (*this); } |
|
75 octave_base_value *empty_clone (void) const { return new octave_bool_matrix (); } |
2871
|
76 |
|
77 type_conv_fcn numeric_conversion_function (void) const; |
|
78 |
5759
|
79 octave_base_value *try_narrowing_conversion (void); |
2871
|
80 |
4650
|
81 idx_vector index_vector (void) const { return idx_vector (matrix); } |
2871
|
82 |
|
83 bool is_bool_matrix (void) const { return true; } |
|
84 |
3209
|
85 bool is_bool_type (void) const { return true; } |
|
86 |
2871
|
87 bool is_real_type (void) const { return true; } |
|
88 |
|
89 bool valid_as_scalar_index (void) const; |
|
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 |
3145
|
117 double scalar_value (bool frc_str_conv = false) const |
|
118 { return double_value (frc_str_conv); } |
2916
|
119 |
4513
|
120 Matrix matrix_value (bool = false) const |
|
121 { return Matrix (matrix.matrix_value ()); } |
2871
|
122 |
4569
|
123 NDArray array_value (bool = false) const |
4650
|
124 { return NDArray (matrix); } |
4569
|
125 |
2871
|
126 Complex complex_value (bool = false) const; |
|
127 |
3145
|
128 ComplexMatrix complex_matrix_value (bool = false) const |
4513
|
129 { return ComplexMatrix (matrix.matrix_value ( )); } |
2871
|
130 |
4569
|
131 ComplexNDArray complex_array_value (bool = false) const |
4901
|
132 { return ComplexNDArray (matrix); } |
4569
|
133 |
5533
|
134 charNDArray |
|
135 char_array_value (bool = false) const |
|
136 { |
|
137 charNDArray retval (dims ()); |
|
138 |
|
139 octave_idx_type nel = numel (); |
|
140 |
|
141 for (octave_idx_type i = 0; i < nel; i++) |
|
142 retval(i) = static_cast<char>(matrix(i)); |
|
143 |
|
144 return retval; |
|
145 } |
|
146 |
5944
|
147 boolMatrix bool_matrix_value (bool = false) const |
4513
|
148 { return matrix.matrix_value (); } |
2871
|
149 |
5944
|
150 boolNDArray bool_array_value (bool = false) const |
4543
|
151 { return matrix; } |
|
152 |
5164
|
153 SparseMatrix sparse_matrix_value (bool = false) const |
|
154 { return SparseMatrix (Matrix (matrix.matrix_value ())); } |
|
155 |
|
156 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
|
157 { return SparseComplexMatrix (ComplexMatrix (matrix.matrix_value ())); } |
|
158 |
|
159 SparseBoolMatrix sparse_bool_matrix_value (bool = false) const |
|
160 { return SparseBoolMatrix (matrix.matrix_value ()); } |
|
161 |
5279
|
162 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871
|
163 |
4643
|
164 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
165 |
6974
|
166 bool save_ascii (std::ostream& os); |
4687
|
167 |
|
168 bool load_ascii (std::istream& is); |
|
169 |
|
170 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
171 |
|
172 bool load_binary (std::istream& is, bool swap, |
|
173 oct_mach_info::float_format fmt); |
|
174 |
|
175 #if defined (HAVE_HDF5) |
|
176 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
177 |
|
178 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
179 #endif |
|
180 |
4970
|
181 int write (octave_stream& os, int block_size, |
|
182 oct_data_conv::data_type output_type, int skip, |
|
183 oct_mach_info::float_format flt_fmt) const |
|
184 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
185 |
5900
|
186 mxArray *as_mxArray (void) const; |
|
187 |
2871
|
188 protected: |
|
189 |
3219
|
190 DECLARE_OCTAVE_ALLOCATOR |
2871
|
191 |
3219
|
192 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871
|
193 }; |
|
194 |
|
195 #endif |
|
196 |
|
197 /* |
|
198 ;;; Local Variables: *** |
|
199 ;;; mode: C++ *** |
|
200 ;;; End: *** |
|
201 */ |