comparison src/ov-re-mat.cc @ 5956:cdef72fcd206

[project @ 2006-08-22 20:36:56 by jwe]
author jwe
date Tue, 22 Aug 2006 20:36:57 +0000
parents c038c2947ee1
children 85c7dc4afe6b
comparison
equal deleted inserted replaced
5955:fc46f9c99028 5956:cdef72fcd206
252 retval = octave_value (chm, true, type); 252 retval = octave_value (chm, true, type);
253 253
254 return retval; 254 return retval;
255 } 255 }
256 256
257 static Matrix
258 strip_infnan (const Matrix& m)
259 {
260 octave_idx_type nr = m.rows ();
261 octave_idx_type nc = m.columns ();
262
263 Matrix retval (nr, nc);
264
265 octave_idx_type k = 0;
266 for (octave_idx_type i = 0; i < nr; i++)
267 {
268 for (octave_idx_type j = 0; j < nc; j++)
269 {
270 double d = m (i, j);
271 if (xisnan (d))
272 goto next_row;
273 else
274 retval (k, j) = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d;
275 }
276 k++;
277
278 next_row:
279 continue;
280 }
281
282 if (k > 0)
283 retval.resize (k, nc);
284
285 return retval;
286 }
287
288 bool 257 bool
289 octave_matrix::save_ascii (std::ostream& os, bool& infnan_warned, 258 octave_matrix::save_ascii (std::ostream& os, bool& infnan_warned,
290 bool strip_nan_and_inf) 259 int strip_nan_and_inf)
291 { 260 {
292 dim_vector d = dims (); 261 dim_vector d = dims ();
293 if (d.length () > 2) 262 if (d.length () > 2)
294 { 263 {
295 NDArray tmp = array_value (); 264 NDArray tmp = array_value ();
320 os << "# rows: " << rows () << "\n" 289 os << "# rows: " << rows () << "\n"
321 << "# columns: " << columns () << "\n"; 290 << "# columns: " << columns () << "\n";
322 291
323 Matrix tmp = matrix_value (); 292 Matrix tmp = matrix_value ();
324 293
325 if (strip_nan_and_inf) 294 tmp.save_ascii (os, infnan_warned, strip_nan_and_inf);
326 tmp = strip_infnan (tmp);
327 else if (! infnan_warned && tmp.any_element_is_inf_or_nan ())
328 {
329 warning ("save: Inf or NaN values may not be reloadable");
330 infnan_warned = true;
331 }
332
333 os << tmp;
334 } 295 }
335 296
336 return true; 297 return true;
337 } 298 }
338 299