Mercurial > octave-nkf
comparison src/ov-re-sparse.cc @ 5282:5bdc3f24cd5f
[project @ 2005-04-14 22:17:26 by dbateman]
author | dbateman |
---|---|
date | Thu, 14 Apr 2005 22:17:27 +0000 |
parents | 23b37da9fd5b |
children | 4c8a2e4e0717 |
comparison
equal
deleted
inserted
replaced
5281:f3266e7dbb99 | 5282:5bdc3f24cd5f |
---|---|
45 | 45 |
46 DEFINE_OCTAVE_ALLOCATOR (octave_sparse_matrix); | 46 DEFINE_OCTAVE_ALLOCATOR (octave_sparse_matrix); |
47 | 47 |
48 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_sparse_matrix, "sparse matrix", "sparse"); | 48 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_sparse_matrix, "sparse matrix", "sparse"); |
49 | 49 |
50 idx_vector | |
51 octave_sparse_matrix::index_vector (void) const | |
52 { | |
53 if (matrix.numel () == matrix.nonzero ()) | |
54 return idx_vector (array_value ()); | |
55 else | |
56 { | |
57 std::string nm = type_name (); | |
58 error ("%s type invalid as index value", nm.c_str ()); | |
59 return idx_vector (); | |
60 } | |
61 } | |
62 | |
50 octave_value * | 63 octave_value * |
51 octave_sparse_matrix::try_narrowing_conversion (void) | 64 octave_sparse_matrix::try_narrowing_conversion (void) |
52 { | 65 { |
53 octave_value *retval = 0; | 66 octave_value *retval = 0; |
54 | 67 |
144 | 157 |
145 streamoff_array | 158 streamoff_array |
146 octave_sparse_matrix::streamoff_array_value (void) const | 159 octave_sparse_matrix::streamoff_array_value (void) const |
147 { | 160 { |
148 streamoff_array retval (dims ()); | 161 streamoff_array retval (dims ()); |
149 int nc = matrix.cols (); | 162 octave_idx_type nc = matrix.cols (); |
150 int nr = matrix.rows (); | 163 octave_idx_type nr = matrix.rows (); |
151 | 164 |
152 for (int j = 0; j < nc; j++) | 165 for (octave_idx_type j = 0; j < nc; j++) |
153 for (int i = matrix.cidx(i); i < matrix.cidx(i+1); i++) | 166 for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) |
154 { | 167 { |
155 double d = matrix.data(i); | 168 double d = matrix.data(i); |
156 | 169 |
157 if (D_NINT (d) == d) | 170 if (D_NINT (d) == d) |
158 { | 171 { |
167 } | 180 } |
168 | 181 |
169 return retval; | 182 return retval; |
170 } | 183 } |
171 | 184 |
185 octave_value | |
186 octave_sparse_matrix::convert_to_str_internal (bool, bool) const | |
187 { | |
188 octave_value retval; | |
189 dim_vector dv = dims (); | |
190 octave_idx_type nel = dv.numel (); | |
191 | |
192 if (nel == 0) | |
193 { | |
194 char s = '\0'; | |
195 retval = octave_value (&s); | |
196 } | |
197 else | |
198 { | |
199 octave_idx_type nr = matrix.rows (); | |
200 octave_idx_type nc = matrix.cols (); | |
201 charNDArray chm (dv, static_cast<char> (0)); | |
202 | |
203 bool warned = false; | |
204 | |
205 for (octave_idx_type j = 0; j < nc; j++) | |
206 for (octave_idx_type i = matrix.cidx(j); | |
207 i < matrix.cidx(j+1); i++) | |
208 { | |
209 OCTAVE_QUIT; | |
210 | |
211 double d = matrix.data (i); | |
212 | |
213 if (xisnan (d)) | |
214 { | |
215 ::error ("invalid conversion from NaN to character"); | |
216 return retval; | |
217 } | |
218 else | |
219 { | |
220 int ival = NINT (d); | |
221 | |
222 if (ival < 0 || ival > UCHAR_MAX) | |
223 { | |
224 // XXX FIXME XXX -- is there something | |
225 // better we could do? | |
226 | |
227 ival = 0; | |
228 | |
229 if (! warned) | |
230 { | |
231 ::warning ("range error for conversion to character value"); | |
232 warned = true; | |
233 } | |
234 } | |
235 | |
236 chm (matrix.ridx(i) + j * nr) = | |
237 static_cast<char> (ival); | |
238 } | |
239 } | |
240 retval = octave_value (chm, 1); | |
241 } | |
242 | |
243 return retval; | |
244 } | |
245 | |
172 bool | 246 bool |
173 octave_sparse_matrix::save_binary (std::ostream& os, bool&save_as_floats) | 247 octave_sparse_matrix::save_binary (std::ostream& os, bool&save_as_floats) |
174 { | 248 { |
175 dim_vector d = this->dims (); | 249 dim_vector d = this->dims (); |
176 if (d.length() < 1) | 250 if (d.length() < 1) |