Check if indexes are all equal. If they are not of the same type or they do not implement this check, check if their coordinate variables are all equal instead.
(
elements: Sequence[tuple[Index, dict[Hashable, Variable]]],
exclude_dims: frozenset[Hashable],
)
| 2107 | |
| 2108 | |
| 2109 | def indexes_all_equal( |
| 2110 | elements: Sequence[tuple[Index, dict[Hashable, Variable]]], |
| 2111 | exclude_dims: frozenset[Hashable], |
| 2112 | ) -> bool: |
| 2113 | """Check if indexes are all equal. |
| 2114 | |
| 2115 | If they are not of the same type or they do not implement this check, check |
| 2116 | if their coordinate variables are all equal instead. |
| 2117 | |
| 2118 | """ |
| 2119 | |
| 2120 | def check_variables(): |
| 2121 | variables = [e[1] for e in elements] |
| 2122 | return any( |
| 2123 | not variables[0][k].equals(other_vars[k]) |
| 2124 | for other_vars in variables[1:] |
| 2125 | for k in variables[0] |
| 2126 | ) |
| 2127 | |
| 2128 | indexes = [e[0] for e in elements] |
| 2129 | |
| 2130 | same_objects = all(indexes[0] is other_idx for other_idx in indexes[1:]) |
| 2131 | if same_objects: |
| 2132 | return True |
| 2133 | |
| 2134 | same_type = all(type(indexes[0]) is type(other_idx) for other_idx in indexes[1:]) |
| 2135 | if same_type: |
| 2136 | index_equals_func = _wrap_index_equals(indexes[0]) |
| 2137 | try: |
| 2138 | not_equal = any( |
| 2139 | not index_equals_func(other_idx, exclude_dims) |
| 2140 | for other_idx in indexes[1:] |
| 2141 | ) |
| 2142 | except NotImplementedError: |
| 2143 | not_equal = check_variables() |
| 2144 | else: |
| 2145 | not_equal = check_variables() |
| 2146 | |
| 2147 | return not not_equal |
| 2148 | |
| 2149 | |
| 2150 | def _apply_indexes_fast(indexes: Indexes[Index], args: Mapping[Any, Any], func: str): |
no test coverage detected
searching dependent graphs…