comparison libinterp/corefcn/bsxfun.cc @ 20587:f90c8372b7ba

eliminate many more simple uses of error_state * Cell.cc, __ichol__.cc, __ilu__.cc, balance.cc, bsxfun.cc, colloc.cc, det.cc, dlmread.cc, dynamic-ld.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, hess.cc, input.cc, levenshtein.cc, load-path.cc, lookup.cc, ls-mat-ascii.cc, ls-mat4.cc, lsode.cc, lu.cc, max.cc, md5sum.cc, mex.cc, pager.cc, pinv.cc, pr-output.cc, qz.cc, schur.cc, sparse.cc, sqrtm.cc, str2double.cc, strfns.cc, sub2ind.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc, amd.cc, audiodevinfo.cc, dmperm.cc, fftw.cc, symrcm.cc, ov-base-diag.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-sparse.cc, ov-builtin.cc, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, op-bm-b.cc, op-bm-bm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-str-m.cc, op-str-s.cc, oct-parse.in.yy, pt-cbinop.cc, pt-colon.cc, pt-decl.cc, pt-exp.cc, pt-id.cc, pt-misc.cc, pt-select.cc, pt-unop.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 19:29:36 -0400
parents e914b5399c67
children
comparison
equal deleted inserted replaced
20586:b7ac1e94266e 20587:f90c8372b7ba
372 if (tmp.is_defined ()) 372 if (tmp.is_defined ())
373 retval(0) = tmp; 373 retval(0) = tmp;
374 } 374 }
375 } 375 }
376 376
377 if (! error_state && retval.empty ()) 377 if (retval.empty ())
378 { 378 {
379 dim_vector dva = A.dims (); 379 dim_vector dva = A.dims ();
380 octave_idx_type nda = dva.length (); 380 octave_idx_type nda = dva.length ();
381 dim_vector dvb = B.dims (); 381 dim_vector dvb = B.dims ();
382 octave_idx_type ndb = dvb.length (); 382 octave_idx_type ndb = dvb.length ();
395 { 395 {
396 error ("bsxfun: dimensions of A and B must match"); 396 error ("bsxfun: dimensions of A and B must match");
397 break; 397 break;
398 } 398 }
399 399
400 if (!error_state) 400 // Find the size of the output
401 dim_vector dvc;
402 dvc.resize (nd);
403
404 for (octave_idx_type i = 0; i < nd; i++)
405 dvc(i) = (dva(i) < 1 ? dva(i)
406 : (dvb(i) < 1 ? dvb(i)
407 : (dva(i) > dvb(i)
408 ? dva(i) : dvb(i))));
409
410 if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1)
401 { 411 {
402 // Find the size of the output 412 octave_value_list inputs;
403 dim_vector dvc; 413 inputs (0) = A;
404 dvc.resize (nd); 414 inputs (1) = B;
405 415 retval = func.do_multi_index_op (1, inputs);
406 for (octave_idx_type i = 0; i < nd; i++) 416 }
407 dvc(i) = (dva(i) < 1 ? dva(i) 417 else if (dvc.numel () < 1)
408 : (dvb(i) < 1 ? dvb(i) 418 {
409 : (dva(i) > dvb(i) 419 octave_value_list inputs;
410 ? dva(i) : dvb(i)))); 420 inputs (0) = A.resize (dvc);
411 421 inputs (1) = B.resize (dvc);
412 if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1) 422 retval = func.do_multi_index_op (1, inputs);
423 }
424 else
425 {
426 octave_idx_type ncount = 1;
427 for (octave_idx_type i = 1; i < nd; i++)
428 ncount *= dvc(i);
429
430 #define BSXDEF(T) \
431 T result_ ## T; \
432 bool have_ ## T = false;
433
434 BSXDEF(NDArray);
435 BSXDEF(ComplexNDArray);
436 BSXDEF(FloatNDArray);
437 BSXDEF(FloatComplexNDArray);
438 BSXDEF(boolNDArray);
439 BSXDEF(int8NDArray);
440 BSXDEF(int16NDArray);
441 BSXDEF(int32NDArray);
442 BSXDEF(int64NDArray);
443 BSXDEF(uint8NDArray);
444 BSXDEF(uint16NDArray);
445 BSXDEF(uint32NDArray);
446 BSXDEF(uint64NDArray);
447
448 octave_value Ac ;
449 octave_value_list idxA;
450 octave_value Bc;
451 octave_value_list idxB;
452 octave_value C;
453 octave_value_list inputs;
454 Array<int> ra_idx (dim_vector (dvc.length (), 1), 0);
455
456
457 for (octave_idx_type i = 0; i < ncount; i++)
413 { 458 {
414 octave_value_list inputs; 459 if (maybe_update_column (Ac, A, dva, dvc, i, idxA))
415 inputs (0) = A; 460 inputs (0) = Ac;
416 inputs (1) = B; 461
417 retval = func.do_multi_index_op (1, inputs); 462 if (maybe_update_column (Bc, B, dvb, dvc, i, idxB))
418 } 463 inputs (1) = Bc;
419 else if (dvc.numel () < 1) 464
420 { 465 octave_value_list tmp = func.do_multi_index_op (1,
421 octave_value_list inputs; 466 inputs);
422 inputs (0) = A.resize (dvc); 467
423 inputs (1) = B.resize (dvc); 468 #define BSXINIT(T, CLS, EXTRACTOR) \
424 retval = func.do_multi_index_op (1, inputs); 469 (result_type == CLS) \
425 } 470 { \
426 else 471 have_ ## T = true; \
427 { 472 result_ ## T = tmp (0). EXTRACTOR ## _array_value (); \
428 octave_idx_type ncount = 1; 473 result_ ## T .resize (dvc); \
429 for (octave_idx_type i = 1; i < nd; i++) 474 }
430 ncount *= dvc(i); 475
431 476 if (i == 0)
432 #define BSXDEF(T) \
433 T result_ ## T; \
434 bool have_ ## T = false;
435
436 BSXDEF(NDArray);
437 BSXDEF(ComplexNDArray);
438 BSXDEF(FloatNDArray);
439 BSXDEF(FloatComplexNDArray);
440 BSXDEF(boolNDArray);
441 BSXDEF(int8NDArray);
442 BSXDEF(int16NDArray);
443 BSXDEF(int32NDArray);
444 BSXDEF(int64NDArray);
445 BSXDEF(uint8NDArray);
446 BSXDEF(uint16NDArray);
447 BSXDEF(uint32NDArray);
448 BSXDEF(uint64NDArray);
449
450 octave_value Ac ;
451 octave_value_list idxA;
452 octave_value Bc;
453 octave_value_list idxB;
454 octave_value C;
455 octave_value_list inputs;
456 Array<int> ra_idx (dim_vector (dvc.length (), 1), 0);
457
458
459 for (octave_idx_type i = 0; i < ncount; i++)
460 { 477 {
461 if (maybe_update_column (Ac, A, dva, dvc, i, idxA)) 478 if (! tmp(0).is_sparse_type ())
462 inputs (0) = Ac;
463
464 if (maybe_update_column (Bc, B, dvb, dvc, i, idxB))
465 inputs (1) = Bc;
466
467 octave_value_list tmp = func.do_multi_index_op (1,
468 inputs);
469
470 if (error_state)
471 break;
472
473 #define BSXINIT(T, CLS, EXTRACTOR) \
474 (result_type == CLS) \
475 { \
476 have_ ## T = true; \
477 result_ ## T = \
478 tmp (0). EXTRACTOR ## _array_value (); \
479 result_ ## T .resize (dvc); \
480 }
481
482 if (i == 0)
483 { 479 {
484 if (! tmp(0).is_sparse_type ()) 480 std::string result_type = tmp(0).class_name ();
481 if (result_type == "double")
485 { 482 {
486 std::string result_type = tmp(0).class_name (); 483 if (tmp(0).is_real_type ())
487 if (result_type == "double")
488 { 484 {
489 if (tmp(0).is_real_type ()) 485 have_NDArray = true;
490 { 486 result_NDArray = tmp(0).array_value ();
491 have_NDArray = true; 487 result_NDArray.resize (dvc);
492 result_NDArray = tmp(0).array_value ();
493 result_NDArray.resize (dvc);
494 }
495 else
496 {
497 have_ComplexNDArray = true;
498 result_ComplexNDArray =
499 tmp(0).complex_array_value ();
500 result_ComplexNDArray.resize (dvc);
501 }
502 } 488 }
503 else if (result_type == "single")
504 {
505 if (tmp(0).is_real_type ())
506 {
507 have_FloatNDArray = true;
508 result_FloatNDArray
509 = tmp(0).float_array_value ();
510 result_FloatNDArray.resize (dvc);
511 }
512 else
513 {
514 have_ComplexNDArray = true;
515 result_ComplexNDArray =
516 tmp(0).complex_array_value ();
517 result_ComplexNDArray.resize (dvc);
518 }
519 }
520 else if BSXINIT(boolNDArray, "logical", bool)
521 else if BSXINIT(int8NDArray, "int8", int8)
522 else if BSXINIT(int16NDArray, "int16", int16)
523 else if BSXINIT(int32NDArray, "int32", int32)
524 else if BSXINIT(int64NDArray, "int64", int64)
525 else if BSXINIT(uint8NDArray, "uint8", uint8)
526 else if BSXINIT(uint16NDArray, "uint16", uint16)
527 else if BSXINIT(uint32NDArray, "uint32", uint32)
528 else if BSXINIT(uint64NDArray, "uint64", uint64)
529 else 489 else
530 { 490 {
531 C = tmp (0); 491 have_ComplexNDArray = true;
532 C = C.resize (dvc); 492 result_ComplexNDArray =
493 tmp(0).complex_array_value ();
494 result_ComplexNDArray.resize (dvc);
533 } 495 }
534 } 496 }
535 } 497 else if (result_type == "single")
536 else
537 {
538 update_index (ra_idx, dvc, i);
539
540 if (have_FloatNDArray
541 || have_FloatComplexNDArray)
542 { 498 {
543 if (! tmp(0).is_float_type ()) 499 if (tmp(0).is_real_type ())
544 { 500 {
545 if (have_FloatNDArray) 501 have_FloatNDArray = true;
546 { 502 result_FloatNDArray
547 have_FloatNDArray = false; 503 = tmp(0).float_array_value ();
548 C = result_FloatNDArray; 504 result_FloatNDArray.resize (dvc);
549 }
550 else
551 {
552 have_FloatComplexNDArray = false;
553 C = result_FloatComplexNDArray;
554 }
555 C = do_cat_op (C, tmp(0), ra_idx);
556 } 505 }
557 else if (tmp(0).is_double_type ())
558 {
559 if (tmp(0).is_complex_type ()
560 && have_FloatNDArray)
561 {
562 result_ComplexNDArray =
563 ComplexNDArray (result_FloatNDArray);
564 result_ComplexNDArray.insert
565 (tmp(0).complex_array_value (), ra_idx);
566 have_FloatComplexNDArray = false;
567 have_ComplexNDArray = true;
568 }
569 else
570 {
571 result_NDArray =
572 NDArray (result_FloatNDArray);
573 result_NDArray.insert
574 (tmp(0).array_value (), ra_idx);
575 have_FloatNDArray = false;
576 have_NDArray = true;
577 }
578 }
579 else if (tmp(0).is_real_type ())
580 result_FloatNDArray.insert
581 (tmp(0).float_array_value (), ra_idx);
582 else 506 else
583 { 507 {
584 result_FloatComplexNDArray = 508 have_ComplexNDArray = true;
585 FloatComplexNDArray (result_FloatNDArray); 509 result_ComplexNDArray =
586 result_FloatComplexNDArray.insert 510 tmp(0).complex_array_value ();
587 (tmp(0).float_complex_array_value (), 511 result_ComplexNDArray.resize (dvc);
588 ra_idx);
589 have_FloatNDArray = false;
590 have_FloatComplexNDArray = true;
591 } 512 }
592 } 513 }
593 else if (have_NDArray) 514 else if BSXINIT(boolNDArray, "logical", bool)
515 else if BSXINIT(int8NDArray, "int8", int8)
516 else if BSXINIT(int16NDArray, "int16", int16)
517 else if BSXINIT(int32NDArray, "int32", int32)
518 else if BSXINIT(int64NDArray, "int64", int64)
519 else if BSXINIT(uint8NDArray, "uint8", uint8)
520 else if BSXINIT(uint16NDArray, "uint16", uint16)
521 else if BSXINIT(uint32NDArray, "uint32", uint32)
522 else if BSXINIT(uint64NDArray, "uint64", uint64)
523 else
594 { 524 {
595 if (! tmp(0).is_float_type ()) 525 C = tmp (0);
526 C = C.resize (dvc);
527 }
528 }
529 }
530 else
531 {
532 update_index (ra_idx, dvc, i);
533
534 if (have_FloatNDArray
535 || have_FloatComplexNDArray)
536 {
537 if (! tmp(0).is_float_type ())
538 {
539 if (have_FloatNDArray)
596 { 540 {
597 have_NDArray = false; 541 have_FloatNDArray = false;
598 C = result_NDArray; 542 C = result_FloatNDArray;
599 C = do_cat_op (C, tmp(0), ra_idx);
600 } 543 }
601 else if (tmp(0).is_real_type ())
602 result_NDArray.insert (tmp(0).array_value (),
603 ra_idx);
604 else 544 else
605 { 545 {
546 have_FloatComplexNDArray = false;
547 C = result_FloatComplexNDArray;
548 }
549 C = do_cat_op (C, tmp(0), ra_idx);
550 }
551 else if (tmp(0).is_double_type ())
552 {
553 if (tmp(0).is_complex_type ()
554 && have_FloatNDArray)
555 {
606 result_ComplexNDArray = 556 result_ComplexNDArray =
607 ComplexNDArray (result_NDArray); 557 ComplexNDArray (result_FloatNDArray);
608 result_ComplexNDArray.insert 558 result_ComplexNDArray.insert
609 (tmp(0).complex_array_value (), ra_idx); 559 (tmp(0).complex_array_value (), ra_idx);
610 have_NDArray = false; 560 have_FloatComplexNDArray = false;
611 have_ComplexNDArray = true; 561 have_ComplexNDArray = true;
612 } 562 }
563 else
564 {
565 result_NDArray =
566 NDArray (result_FloatNDArray);
567 result_NDArray.insert
568 (tmp(0).array_value (), ra_idx);
569 have_FloatNDArray = false;
570 have_NDArray = true;
571 }
613 } 572 }
573 else if (tmp(0).is_real_type ())
574 result_FloatNDArray.insert
575 (tmp(0).float_array_value (), ra_idx);
576 else
577 {
578 result_FloatComplexNDArray =
579 FloatComplexNDArray (result_FloatNDArray);
580 result_FloatComplexNDArray.insert
581 (tmp(0).float_complex_array_value (),
582 ra_idx);
583 have_FloatNDArray = false;
584 have_FloatComplexNDArray = true;
585 }
586 }
587 else if (have_NDArray)
588 {
589 if (! tmp(0).is_float_type ())
590 {
591 have_NDArray = false;
592 C = result_NDArray;
593 C = do_cat_op (C, tmp(0), ra_idx);
594 }
595 else if (tmp(0).is_real_type ())
596 result_NDArray.insert (tmp(0).array_value (),
597 ra_idx);
598 else
599 {
600 result_ComplexNDArray =
601 ComplexNDArray (result_NDArray);
602 result_ComplexNDArray.insert
603 (tmp(0).complex_array_value (), ra_idx);
604 have_NDArray = false;
605 have_ComplexNDArray = true;
606 }
607 }
614 608
615 #define BSXLOOP(T, CLS, EXTRACTOR) \ 609 #define BSXLOOP(T, CLS, EXTRACTOR) \
616 (have_ ## T) \ 610 (have_ ## T) \
617 { \ 611 { \
618 if (tmp (0).class_name () != CLS) \ 612 if (tmp (0).class_name () != CLS) \
619 { \ 613 { \
620 have_ ## T = false; \ 614 have_ ## T = false; \
621 C = result_ ## T; \ 615 C = result_ ## T; \
622 C = do_cat_op (C, tmp (0), ra_idx); \ 616 C = do_cat_op (C, tmp (0), ra_idx); \
623 } \ 617 } \
624 else \ 618 else \
625 result_ ## T .insert \ 619 result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \
626 (tmp(0). EXTRACTOR ## _array_value (), \ 620 }
627 ra_idx); \ 621
628 } 622 else if BSXLOOP(ComplexNDArray, "double", complex)
629 623 else if BSXLOOP(boolNDArray, "logical", bool)
630 else if BSXLOOP(ComplexNDArray, "double", complex) 624 else if BSXLOOP(int8NDArray, "int8", int8)
631 else if BSXLOOP(boolNDArray, "logical", bool) 625 else if BSXLOOP(int16NDArray, "int16", int16)
632 else if BSXLOOP(int8NDArray, "int8", int8) 626 else if BSXLOOP(int32NDArray, "int32", int32)
633 else if BSXLOOP(int16NDArray, "int16", int16) 627 else if BSXLOOP(int64NDArray, "int64", int64)
634 else if BSXLOOP(int32NDArray, "int32", int32) 628 else if BSXLOOP(uint8NDArray, "uint8", uint8)
635 else if BSXLOOP(int64NDArray, "int64", int64) 629 else if BSXLOOP(uint16NDArray, "uint16", uint16)
636 else if BSXLOOP(uint8NDArray, "uint8", uint8) 630 else if BSXLOOP(uint32NDArray, "uint32", uint32)
637 else if BSXLOOP(uint16NDArray, "uint16", uint16) 631 else if BSXLOOP(uint64NDArray, "uint64", uint64)
638 else if BSXLOOP(uint32NDArray, "uint32", uint32) 632 else
639 else if BSXLOOP(uint64NDArray, "uint64", uint64) 633 C = do_cat_op (C, tmp(0), ra_idx);
640 else
641 C = do_cat_op (C, tmp(0), ra_idx);
642 }
643 } 634 }
635 }
644 636
645 #define BSXEND(T) \ 637 #define BSXEND(T) \
646 (have_ ## T) \ 638 (have_ ## T) \
647 retval(0) = result_ ## T; 639 retval(0) = result_ ## T;
648 640
649 if BSXEND(NDArray) 641 if BSXEND(NDArray)
650 else if BSXEND(ComplexNDArray) 642 else if BSXEND(ComplexNDArray)
651 else if BSXEND(FloatNDArray) 643 else if BSXEND(FloatNDArray)
652 else if BSXEND(FloatComplexNDArray) 644 else if BSXEND(FloatComplexNDArray)
653 else if BSXEND(boolNDArray) 645 else if BSXEND(boolNDArray)
654 else if BSXEND(int8NDArray) 646 else if BSXEND(int8NDArray)
655 else if BSXEND(int16NDArray) 647 else if BSXEND(int16NDArray)
656 else if BSXEND(int32NDArray) 648 else if BSXEND(int32NDArray)
657 else if BSXEND(int64NDArray) 649 else if BSXEND(int64NDArray)
658 else if BSXEND(uint8NDArray) 650 else if BSXEND(uint8NDArray)
659 else if BSXEND(uint16NDArray) 651 else if BSXEND(uint16NDArray)
660 else if BSXEND(uint32NDArray) 652 else if BSXEND(uint32NDArray)
661 else if BSXEND(uint64NDArray) 653 else if BSXEND(uint64NDArray)
662 else 654 else
663 retval(0) = C; 655 retval(0) = C;
664 }
665 } 656 }
666 } 657 }
667 } 658 }
668 659
669 return retval; 660 return retval;