(array, roffset, coffset, rows, cols, format)
| 667 | |
| 668 | |
| 669 | def array_to_xml(array, roffset, coffset, rows, cols, format): |
| 670 | xml = "" |
| 671 | rows = min(rows, MAXIMUM_ARRAY_SIZE) |
| 672 | cols = min(cols, MAXIMUM_ARRAY_SIZE) |
| 673 | |
| 674 | # there is no obvious rule for slicing (at least 5 choices) |
| 675 | if len(array) == 1 and (rows > 1 or cols > 1): |
| 676 | array = array[0] |
| 677 | if array.size > len(array): |
| 678 | array = array[roffset:, coffset:] |
| 679 | rows = min(rows, len(array)) |
| 680 | cols = min(cols, len(array[0])) |
| 681 | if len(array) == 1: |
| 682 | array = array[0] |
| 683 | elif array.size == len(array): |
| 684 | if roffset == 0 and rows == 1: |
| 685 | array = array[coffset:] |
| 686 | cols = min(cols, len(array)) |
| 687 | elif coffset == 0 and cols == 1: |
| 688 | array = array[roffset:] |
| 689 | rows = min(rows, len(array)) |
| 690 | |
| 691 | xml += '<arraydata rows="%s" cols="%s"/>' % (rows, cols) |
| 692 | for row in range(rows): |
| 693 | xml += '<row index="%s"/>' % to_string(row) |
| 694 | for col in range(cols): |
| 695 | value = array |
| 696 | if rows == 1 or cols == 1: |
| 697 | if rows == 1 and cols == 1: |
| 698 | value = array[0] |
| 699 | else: |
| 700 | if rows == 1: |
| 701 | dim = col |
| 702 | else: |
| 703 | dim = row |
| 704 | value = array[dim] |
| 705 | if "ndarray" in str(type(value)): |
| 706 | value = value[0] |
| 707 | else: |
| 708 | value = array[row][col] |
| 709 | value = format % value |
| 710 | xml += var_to_xml(value, "") |
| 711 | return xml |
| 712 | |
| 713 | |
| 714 | def array_to_meta_xml(array, name, format): |
no test coverage detected