Returns the stride between the fields, or None if the stride is not constant. The values in "counts" designate the lengths of subarrays. Subarrays are treated as many contiguous fields, with always positive stride.
(offsets, counts, itemsize)
| 888 | return fields |
| 889 | |
| 890 | def _common_stride(offsets, counts, itemsize): |
| 891 | """ |
| 892 | Returns the stride between the fields, or None if the stride is not |
| 893 | constant. The values in "counts" designate the lengths of |
| 894 | subarrays. Subarrays are treated as many contiguous fields, with |
| 895 | always positive stride. |
| 896 | """ |
| 897 | if len(offsets) <= 1: |
| 898 | return itemsize |
| 899 | |
| 900 | negative = offsets[1] < offsets[0] # negative stride |
| 901 | if negative: |
| 902 | # reverse, so offsets will be ascending |
| 903 | it = zip(reversed(offsets), reversed(counts)) |
| 904 | else: |
| 905 | it = zip(offsets, counts) |
| 906 | |
| 907 | prev_offset = None |
| 908 | stride = None |
| 909 | for offset, count in it: |
| 910 | if count != 1: # subarray: always c-contiguous |
| 911 | if negative: |
| 912 | return None # subarrays can never have a negative stride |
| 913 | if stride is None: |
| 914 | stride = itemsize |
| 915 | if stride != itemsize: |
| 916 | return None |
| 917 | end_offset = offset + (count - 1) * itemsize |
| 918 | else: |
| 919 | end_offset = offset |
| 920 | |
| 921 | if prev_offset is not None: |
| 922 | new_stride = offset - prev_offset |
| 923 | if stride is None: |
| 924 | stride = new_stride |
| 925 | if stride != new_stride: |
| 926 | return None |
| 927 | |
| 928 | prev_offset = end_offset |
| 929 | |
| 930 | if negative: |
| 931 | return -stride |
| 932 | return stride |
| 933 | |
| 934 | |
| 935 | def _structured_to_unstructured_dispatcher(arr, dtype=None, copy=None, |
no outgoing calls
no test coverage detected
searching dependent graphs…