4904
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #include <cstdlib> |
|
24 |
|
25 #include <iostream> |
|
26 #include <string> |
|
27 |
|
28 #include "mx-base.h" |
|
29 #include "oct-alloc.h" |
|
30 #include "so-array.h" |
|
31 #include "str-vec.h" |
|
32 |
|
33 #include "error.h" |
4944
|
34 #include "oct-stream.h" |
4904
|
35 #include "ov-base.h" |
|
36 #include "ov-base-int.h" |
|
37 #include "ov-typeinfo.h" |
|
38 |
|
39 class |
|
40 OCTAVE_VALUE_INT_MATRIX_T |
|
41 : public octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> |
|
42 { |
|
43 public: |
|
44 |
|
45 OCTAVE_VALUE_INT_MATRIX_T (void) |
|
46 : octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> () { } |
|
47 |
|
48 OCTAVE_VALUE_INT_MATRIX_T (const OCTAVE_INT_NDARRAY_T& nda) |
|
49 : octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> (nda) { } |
|
50 |
|
51 ~OCTAVE_VALUE_INT_MATRIX_T (void) { } |
|
52 |
|
53 octave_value * |
|
54 clone (void) const |
|
55 { return new OCTAVE_VALUE_INT_MATRIX_T (*this); } |
|
56 |
|
57 octave_value * |
|
58 empty_clone (void) const |
|
59 { return new OCTAVE_VALUE_INT_MATRIX_T (); } |
|
60 |
|
61 OCTAVE_INT_NDARRAY_T |
4910
|
62 OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const |
4904
|
63 { return matrix; } |
|
64 |
4915
|
65 NDArray |
|
66 array_value (bool = false) const |
|
67 { |
|
68 NDArray retval (matrix.dims ()); |
|
69 int nel = matrix.numel (); |
|
70 for (int i = 0; i < nel; i++) |
4963
|
71 retval(i) = double (matrix(i)); |
|
72 return retval; |
|
73 } |
|
74 |
|
75 ComplexNDArray |
|
76 complex_array_value (bool = false) const |
|
77 { |
|
78 ComplexNDArray retval (matrix.dims ()); |
|
79 int nel = matrix.numel (); |
|
80 for (int i = 0; i < nel; i++) |
|
81 retval(i) = Complex (matrix(i)); |
4915
|
82 return retval; |
|
83 } |
|
84 |
4938
|
85 idx_vector index_vector (void) const { return idx_vector (matrix); } |
|
86 |
4944
|
87 int write (octave_stream& os, int block_size, |
|
88 oct_data_conv::data_type output_type, int skip, |
|
89 oct_mach_info::float_format flt_fmt) const |
|
90 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
91 |
4904
|
92 private: |
|
93 |
|
94 DECLARE_OCTAVE_ALLOCATOR |
|
95 |
|
96 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
97 }; |
|
98 |
|
99 class |
|
100 OCTAVE_VALUE_INT_SCALAR_T |
|
101 : public octave_base_int_scalar<OCTAVE_INT_T> |
|
102 { |
|
103 public: |
|
104 |
|
105 OCTAVE_VALUE_INT_SCALAR_T (void) |
|
106 : octave_base_int_scalar<OCTAVE_INT_T> () { } |
|
107 |
|
108 OCTAVE_VALUE_INT_SCALAR_T (const OCTAVE_INT_T& nda) |
|
109 : octave_base_int_scalar<OCTAVE_INT_T> (nda) { } |
|
110 |
|
111 ~OCTAVE_VALUE_INT_SCALAR_T (void) { } |
|
112 |
|
113 octave_value * |
|
114 clone (void) const |
|
115 { return new OCTAVE_VALUE_INT_SCALAR_T (*this); } |
|
116 |
|
117 octave_value * |
|
118 empty_clone (void) const |
|
119 { return new OCTAVE_VALUE_INT_SCALAR_T (); } |
|
120 |
4964
|
121 octave_value do_index_op (const octave_value_list& idx, int resize_ok) |
|
122 { |
|
123 octave_value retval; |
|
124 |
|
125 if (idx.valid_scalar_indices ()) |
|
126 retval = scalar; |
|
127 else |
|
128 { |
|
129 // XXX FIXME XXX -- this doesn't solve the problem of |
|
130 // |
|
131 // a = 1; a([1,1], [1,1], [1,1]) |
|
132 // |
|
133 // and similar constructions. Hmm... |
|
134 |
|
135 // XXX FIXME XXX -- using this constructor avoids narrowing the |
|
136 // 1x1 matrix back to a scalar value. Need a better solution |
|
137 // to this problem. |
|
138 |
|
139 octave_value tmp (new OCTAVE_VALUE_INT_MATRIX_T ( |
|
140 OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION ())); |
|
141 retval = tmp.do_index_op (idx, resize_ok); |
|
142 } |
|
143 |
|
144 return retval; |
|
145 } |
|
146 |
4904
|
147 OCTAVE_INT_T |
4910
|
148 OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (void) const |
4904
|
149 { return scalar; } |
|
150 |
|
151 OCTAVE_INT_NDARRAY_T |
4910
|
152 OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const |
|
153 { return OCTAVE_INT_NDARRAY_T (dim_vector (1, 1), scalar); } |
4904
|
154 |
4915
|
155 octave_value resize (const dim_vector& dv) const |
|
156 { OCTAVE_INT_NDARRAY_T retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } |
|
157 |
|
158 NDArray |
|
159 array_value (bool = false) const |
|
160 { |
|
161 NDArray retval (dim_vector (1,1)); |
4963
|
162 retval(0) = double (scalar); |
|
163 return retval; |
|
164 } |
|
165 |
|
166 ComplexNDArray |
|
167 complex_array_value (bool = false) const |
|
168 { |
|
169 ComplexNDArray retval (dim_vector (1,1)); |
|
170 retval(0) = Complex (scalar); |
4915
|
171 return retval; |
|
172 } |
|
173 |
4938
|
174 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
175 |
4944
|
176 int write (octave_stream& os, int block_size, |
|
177 oct_data_conv::data_type output_type, int skip, |
|
178 oct_mach_info::float_format flt_fmt) const |
|
179 { |
|
180 return os.write (OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (), |
|
181 block_size, output_type, skip, flt_fmt); |
|
182 } |
|
183 |
4904
|
184 private: |
|
185 |
|
186 DECLARE_OCTAVE_ALLOCATOR |
|
187 |
|
188 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
189 }; |
|
190 |
|
191 /* |
|
192 ;;; Local Variables: *** |
|
193 ;;; mode: C++ *** |
|
194 ;;; End: *** |
|
195 */ |