| | 643 | } |
| | 644 | |
| | 645 | |
| | 646 | /*--------------------------------------------------------------------------*/ |
| | 647 | |
| | 648 | |
| | 649 | void _convertToDecimalVector( UArray* arr ) |
| | 650 | { |
| | 651 | int32_t* it = arr->ptr.i; |
| | 652 | int32_t* end = it + arr->used; |
| | 653 | |
| | 654 | while( it != end ) |
| | 655 | { |
| | 656 | *((float*) it) = (float) *it; |
| | 657 | ++it; |
| | 658 | } |
| | 659 | } |
| | 660 | |
| | 661 | |
| | 662 | // Returns zero if make failed. |
| | 663 | UIndex ur_makeVector( const UCell* from, UCell* res ) |
| | 664 | { |
| | 665 | UIndex binN = 0; |
| | 666 | int vtype = UT_INT; |
| | 667 | |
| | 668 | if( ur_is(from, UT_BLOCK) ) |
| | 669 | { |
| | 670 | UBinary* bin; |
| | 671 | UBlock* blk; |
| | 672 | UCell* it; |
| | 673 | UCell* end; |
| | 674 | |
| | 675 | blk = ur_block( from ); |
| | 676 | UR_ITER_BLOCK( it, end, blk, from ) |
| | 677 | |
| | 678 | binN = ur_makeBinary( (end - it) * sizeof(int32_t) ); |
| | 679 | bin = ur_binPtr( binN ); |
| | 680 | |
| | 681 | while( it != end ) |
| | 682 | { |
| | 683 | if( ur_is(it, UT_INT) ) |
| | 684 | { |
| | 685 | bin->ptr.i[ bin->used ] = ur_int(it); |
| | 686 | ++bin->used; |
| | 687 | } |
| | 688 | else if( ur_is(it, UT_DECIMAL) ) |
| | 689 | { |
| | 690 | goto decimal; |
| | 691 | } |
| | 692 | ++it; |
| | 693 | } |
| | 694 | goto init; |
| | 695 | |
| | 696 | decimal: |
| | 697 | |
| | 698 | vtype = UT_DECIMAL; |
| | 699 | _convertToDecimalVector( bin ); |
| | 700 | |
| | 701 | while( it != end ) |
| | 702 | { |
| | 703 | if( ur_is(it, UT_DECIMAL) ) |
| | 704 | { |
| | 705 | bin->ptr.f[ bin->used ] = (float) ur_decimal(it); |
| | 706 | ++bin->used; |
| | 707 | } |
| | 708 | else if( ur_is(it, UT_INT) ) |
| | 709 | { |
| | 710 | bin->ptr.f[ bin->used ] = (float) ur_int(it); |
| | 711 | ++bin->used; |
| | 712 | } |
| | 713 | ++it; |
| | 714 | } |
| | 715 | } |
| | 716 | else if( ur_is(from, UT_INT) ) |
| | 717 | { |
| | 718 | binN = ur_makeBinary( ur_int(from) * sizeof(int32_t) ); |
| | 719 | } |
| | 720 | |
| | 721 | if( binN ) |
| | 722 | { |
| | 723 | init: |
| | 724 | ur_initType(res, UT_VECTOR); |
| | 725 | ur_arrayDT(res) = vtype; |
| | 726 | ur_setSeries(res, binN, 0); |
| | 727 | return binN; |
| | 728 | } |
| | 729 | |
| | 730 | return 0; |