Mercurial > octave-nkf
comparison libinterp/corefcn/matrix_type.cc @ 20617:ba2b07c13913
use new string_value method to handle value extraction errors
* __dispatch__.cc, balance.cc, colloc.cc, conv2.cc, data.cc, debug.cc,
graphics.cc, input.cc, matrix_type.cc, oct-hist.cc, schur.cc,
spparms.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc:
Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Oct 2015 10:06:39 -0400 |
parents | b10432a40432 |
children |
comparison
equal
deleted
inserted
replaced
20616:fd0efcdb3718 | 20617:ba2b07c13913 |
---|---|
212 retval = octave_value ("Unknown"); | 212 retval = octave_value ("Unknown"); |
213 } | 213 } |
214 else | 214 else |
215 { | 215 { |
216 // Ok, we're changing the matrix type | 216 // Ok, we're changing the matrix type |
217 if (! args(1).is_string ()) | 217 |
218 error ("matrix_type: TYPE must be a string"); | 218 std::string str_typ = args(1).string_value ("matrix_type: TYPE must be a string"); |
219 else | 219 |
220 { | 220 // FIXME: why do I have to explicitly call the constructor? |
221 std::string str_typ = args(1).string_value (); | 221 MatrixType mattyp = MatrixType (); |
222 | 222 |
223 // FIXME: why do I have to explicitly call the constructor? | 223 octave_idx_type nl = 0; |
224 MatrixType mattyp = MatrixType (); | 224 octave_idx_type nu = 0; |
225 | 225 |
226 octave_idx_type nl = 0; | 226 // Use STL function to convert to lower case |
227 octave_idx_type nu = 0; | 227 std::transform (str_typ.begin (), str_typ.end (), |
228 | 228 str_typ.begin (), tolower); |
229 // Use STL function to convert to lower case | 229 |
230 std::transform (str_typ.begin (), str_typ.end (), | 230 if (str_typ == "diagonal") |
231 str_typ.begin (), tolower); | 231 mattyp.mark_as_diagonal (); |
232 | 232 if (str_typ == "permuted diagonal") |
233 if (str_typ == "diagonal") | 233 mattyp.mark_as_permuted_diagonal (); |
234 mattyp.mark_as_diagonal (); | 234 else if (str_typ == "upper") |
235 if (str_typ == "permuted diagonal") | 235 mattyp.mark_as_upper_triangular (); |
236 mattyp.mark_as_permuted_diagonal (); | 236 else if (str_typ == "lower") |
237 else if (str_typ == "upper") | 237 mattyp.mark_as_lower_triangular (); |
238 mattyp.mark_as_upper_triangular (); | 238 else if (str_typ == "banded" |
239 else if (str_typ == "lower") | 239 || str_typ == "banded positive definite") |
240 mattyp.mark_as_lower_triangular (); | 240 { |
241 else if (str_typ == "banded" | 241 if (nargin != 4) |
242 || str_typ == "banded positive definite") | 242 error ("matrix_type: banded matrix type requires 4 arguments"); |
243 { | 243 else |
244 if (nargin != 4) | 244 { |
245 error ("matrix_type: banded matrix type requires 4 arguments"); | 245 nl = args(2).nint_value (); |
246 nu = args(3).nint_value (); | |
247 | |
248 if (error_state) | |
249 error ("matrix_type: band size NL, NU must be integers"); | |
246 else | 250 else |
247 { | 251 { |
248 nl = args(2).nint_value (); | 252 if (nl == 1 && nu == 1) |
249 nu = args(3).nint_value (); | 253 mattyp.mark_as_tridiagonal (); |
250 | |
251 if (error_state) | |
252 error ("matrix_type: band size NL, NU must be integers"); | |
253 else | 254 else |
254 { | 255 mattyp.mark_as_banded (nu, nl); |
255 if (nl == 1 && nu == 1) | 256 |
256 mattyp.mark_as_tridiagonal (); | 257 if (str_typ == "banded positive definite") |
257 else | 258 mattyp.mark_as_symmetric (); |
258 mattyp.mark_as_banded (nu, nl); | 259 } |
259 | 260 } |
260 if (str_typ == "banded positive definite") | 261 } |
261 mattyp.mark_as_symmetric (); | 262 else if (str_typ == "positive definite") |
262 } | 263 { |
263 } | 264 mattyp.mark_as_full (); |
264 } | 265 mattyp.mark_as_symmetric (); |
265 else if (str_typ == "positive definite") | 266 } |
266 { | 267 else if (str_typ == "singular") |
267 mattyp.mark_as_full (); | 268 mattyp.mark_as_rectangular (); |
268 mattyp.mark_as_symmetric (); | 269 else if (str_typ == "full") |
269 } | 270 mattyp.mark_as_full (); |
270 else if (str_typ == "singular") | 271 else if (str_typ == "unknown") |
271 mattyp.mark_as_rectangular (); | 272 mattyp.invalidate_type (); |
272 else if (str_typ == "full") | 273 else |
273 mattyp.mark_as_full (); | 274 error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); |
274 else if (str_typ == "unknown") | 275 |
275 mattyp.invalidate_type (); | 276 if (nargin == 3 |
276 else | 277 && (str_typ == "upper" || str_typ == "lower")) |
277 error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); | 278 { |
278 | 279 const ColumnVector perm = |
279 if (nargin == 3 | 280 ColumnVector (args(2).vector_value ()); |
280 && (str_typ == "upper" || str_typ == "lower")) | 281 |
281 { | 282 if (error_state) |
282 const ColumnVector perm = | 283 error ("matrix_type: Invalid permutation vector PERM"); |
283 ColumnVector (args(2).vector_value ()); | 284 else |
284 | 285 { |
285 if (error_state) | 286 octave_idx_type len = perm.numel (); |
287 dim_vector dv = args(0).dims (); | |
288 | |
289 if (len != dv(0)) | |
286 error ("matrix_type: Invalid permutation vector PERM"); | 290 error ("matrix_type: Invalid permutation vector PERM"); |
287 else | 291 else |
288 { | 292 { |
289 octave_idx_type len = perm.numel (); | 293 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); |
290 dim_vector dv = args(0).dims (); | 294 |
291 | 295 for (octave_idx_type i = 0; i < len; i++) |
292 if (len != dv(0)) | 296 p[i] = static_cast<octave_idx_type> (perm (i)) - 1; |
293 error ("matrix_type: Invalid permutation vector PERM"); | 297 |
294 else | 298 mattyp.mark_as_permuted (len, p); |
295 { | 299 } |
296 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); | 300 } |
297 | 301 } |
298 for (octave_idx_type i = 0; i < len; i++) | 302 else if (nargin != 2 |
299 p[i] = static_cast<octave_idx_type> | 303 && str_typ != "banded positive definite" |
300 (perm (i)) | 304 && str_typ != "banded") |
301 - 1; | 305 error ("matrix_type: Invalid number of arguments"); |
302 | 306 |
303 mattyp.mark_as_permuted (len, p); | 307 // Set the matrix type |
304 } | 308 if (args(0).is_complex_type ()) |
305 } | 309 retval = octave_value (args(0).sparse_complex_matrix_value (), |
306 } | 310 mattyp); |
307 else if (nargin != 2 | 311 else |
308 && str_typ != "banded positive definite" | 312 retval = octave_value (args(0).sparse_matrix_value (), |
309 && str_typ != "banded") | 313 mattyp); |
310 error ("matrix_type: Invalid number of arguments"); | |
311 | |
312 // Set the matrix type | |
313 if (args(0).is_complex_type ()) | |
314 retval = octave_value (args(0).sparse_complex_matrix_value (), | |
315 mattyp); | |
316 else | |
317 retval = octave_value (args(0).sparse_matrix_value (), | |
318 mattyp); | |
319 } | |
320 } | 314 } |
321 } | 315 } |
322 else | 316 else |
323 { | 317 { |
324 if (nargin == 1) | 318 if (nargin == 1) |
396 retval = octave_value ("Unknown"); | 390 retval = octave_value ("Unknown"); |
397 } | 391 } |
398 else | 392 else |
399 { | 393 { |
400 // Ok, we're changing the matrix type | 394 // Ok, we're changing the matrix type |
401 if (! args(1).is_string ()) | 395 |
402 error ("matrix_type: TYPE must be a string"); | 396 std::string str_typ = args(1).string_value ("matrix_type: TYPE must be a string"); |
403 else | 397 |
404 { | 398 // FIXME: why do I have to explicitly call the constructor? |
405 std::string str_typ = args(1).string_value (); | 399 MatrixType mattyp = MatrixType (MatrixType::Unknown, true); |
406 | 400 |
407 // FIXME: why do I have to explicitly call the constructor? | 401 // Use STL function to convert to lower case |
408 MatrixType mattyp = MatrixType (MatrixType::Unknown, true); | 402 std::transform (str_typ.begin (), str_typ.end (), |
409 | 403 str_typ.begin (), tolower); |
410 // Use STL function to convert to lower case | 404 |
411 std::transform (str_typ.begin (), str_typ.end (), | 405 if (str_typ == "upper") |
412 str_typ.begin (), tolower); | 406 mattyp.mark_as_upper_triangular (); |
413 | 407 else if (str_typ == "lower") |
414 if (str_typ == "upper") | 408 mattyp.mark_as_lower_triangular (); |
415 mattyp.mark_as_upper_triangular (); | 409 else if (str_typ == "positive definite") |
416 else if (str_typ == "lower") | 410 { |
417 mattyp.mark_as_lower_triangular (); | 411 mattyp.mark_as_full (); |
418 else if (str_typ == "positive definite") | 412 mattyp.mark_as_symmetric (); |
419 { | 413 } |
420 mattyp.mark_as_full (); | 414 else if (str_typ == "singular") |
421 mattyp.mark_as_symmetric (); | 415 mattyp.mark_as_rectangular (); |
422 } | 416 else if (str_typ == "full") |
423 else if (str_typ == "singular") | 417 mattyp.mark_as_full (); |
424 mattyp.mark_as_rectangular (); | 418 else if (str_typ == "unknown") |
425 else if (str_typ == "full") | 419 mattyp.invalidate_type (); |
426 mattyp.mark_as_full (); | 420 else |
427 else if (str_typ == "unknown") | 421 error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); |
428 mattyp.invalidate_type (); | 422 |
429 else | 423 if (nargin == 3 && (str_typ == "upper" || str_typ == "lower")) |
430 error ("matrix_type: Unknown matrix type %s", | 424 { |
431 str_typ.c_str ()); | 425 const ColumnVector perm = |
432 | 426 ColumnVector (args(2).vector_value ()); |
433 if (nargin == 3 && (str_typ == "upper" | 427 |
434 || str_typ == "lower")) | 428 if (error_state) |
435 { | 429 error ("matrix_type: Invalid permutation vector PERM"); |
436 const ColumnVector perm = | 430 else |
437 ColumnVector (args(2).vector_value ()); | 431 { |
438 | 432 octave_idx_type len = perm.numel (); |
439 if (error_state) | 433 dim_vector dv = args(0).dims (); |
434 | |
435 if (len != dv(0)) | |
440 error ("matrix_type: Invalid permutation vector PERM"); | 436 error ("matrix_type: Invalid permutation vector PERM"); |
441 else | 437 else |
442 { | 438 { |
443 octave_idx_type len = perm.numel (); | 439 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); |
444 dim_vector dv = args(0).dims (); | 440 |
445 | 441 for (octave_idx_type i = 0; i < len; i++) |
446 if (len != dv(0)) | 442 p[i] = static_cast<octave_idx_type> (perm (i)) - 1; |
447 error ("matrix_type: Invalid permutation vector PERM"); | 443 |
448 else | 444 mattyp.mark_as_permuted (len, p); |
449 { | 445 } |
450 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); | 446 } |
451 | 447 } |
452 for (octave_idx_type i = 0; i < len; i++) | 448 else if (nargin != 2) |
453 p[i] = static_cast<octave_idx_type> | 449 error ("matrix_type: Invalid number of arguments"); |
454 (perm (i)) | 450 |
455 - 1; | 451 // Set the matrix type |
456 | 452 if (args(0).is_single_type ()) |
457 mattyp.mark_as_permuted (len, p); | 453 { |
458 } | 454 if (args(0).is_complex_type ()) |
459 } | 455 retval = octave_value (args(0).float_complex_matrix_value (), |
460 } | 456 mattyp); |
461 else if (nargin != 2) | 457 else |
462 error ("matrix_type: Invalid number of arguments"); | 458 retval = octave_value (args(0).float_matrix_value (), |
463 | 459 mattyp); |
464 // Set the matrix type | 460 } |
465 if (args(0).is_single_type ()) | 461 else |
466 { | 462 { |
467 if (args(0).is_complex_type ()) | 463 if (args(0).is_complex_type ()) |
468 retval = octave_value (args(0).float_complex_matrix_value (), | 464 retval = octave_value (args(0).complex_matrix_value (), |
469 mattyp); | 465 mattyp); |
470 else | 466 else |
471 retval = octave_value (args(0).float_matrix_value (), | 467 retval = octave_value (args(0).matrix_value (), mattyp); |
472 mattyp); | |
473 } | |
474 else | |
475 { | |
476 if (args(0).is_complex_type ()) | |
477 retval = octave_value (args(0).complex_matrix_value (), | |
478 mattyp); | |
479 else | |
480 retval = octave_value (args(0).matrix_value (), | |
481 mattyp); | |
482 } | |
483 } | 468 } |
484 } | 469 } |
485 } | 470 } |
486 } | 471 } |
487 | 472 |