(spatial_dims: int, coefs: Sequence[float] | float, eye_func=np.eye)
| 984 | |
| 985 | |
| 986 | def _create_shear(spatial_dims: int, coefs: Sequence[float] | float, eye_func=np.eye) -> NdarrayOrTensor: |
| 987 | if spatial_dims == 2: |
| 988 | coefs = ensure_tuple_size(coefs, dim=2, pad_val=0.0) |
| 989 | rank = 3 |
| 990 | shear_indices = [(0, 1, coefs[0]), (1, 0, coefs[1])] |
| 991 | elif spatial_dims == 3: |
| 992 | coefs = ensure_tuple_size(coefs, dim=6, pad_val=0.0) |
| 993 | rank = 4 |
| 994 | shear_indices = [ |
| 995 | (0, 1, coefs[0]), |
| 996 | (0, 2, coefs[1]), |
| 997 | (1, 0, coefs[2]), |
| 998 | (1, 2, coefs[3]), |
| 999 | (2, 0, coefs[4]), |
| 1000 | (2, 1, coefs[5]), |
| 1001 | ] |
| 1002 | else: |
| 1003 | raise NotImplementedError("Currently only spatial_dims in [2, 3] are supported.") |
| 1004 | # Compose individual single-axis shear matrices so that the result is a |
| 1005 | # proper (area/volume-preserving) shear with determinant 1. Each elementary |
| 1006 | # shear is pre-multiplied, so the first coefficient is applied first. |
| 1007 | out = eye_func(rank) |
| 1008 | for i, j, c in shear_indices: |
| 1009 | s = eye_func(rank) |
| 1010 | s[i, j] = c |
| 1011 | out = s @ out |
| 1012 | return out # type: ignore |
| 1013 | |
| 1014 | |
| 1015 | def create_scale( |
no test coverage detected
searching dependent graphs…