(*rows, device=None)
| 40 | # Helpers for constructing transformation matrices. |
| 41 | |
| 42 | def matrix(*rows, device=None): |
| 43 | assert all(len(row) == len(rows[0]) for row in rows) |
| 44 | elems = [x for row in rows for x in row] |
| 45 | ref = [x for x in elems if isinstance(x, torch.Tensor)] |
| 46 | if len(ref) == 0: |
| 47 | return misc.constant(np.asarray(rows), device=device) |
| 48 | assert device is None or device == ref[0].device |
| 49 | elems = [x if isinstance(x, torch.Tensor) else misc.constant(x, shape=ref[0].shape, device=ref[0].device) for x in elems] |
| 50 | return torch.stack(elems, dim=-1).reshape(ref[0].shape + (len(rows), -1)) |
| 51 | |
| 52 | def translate2d(tx, ty, **kwargs): |
| 53 | return matrix( |
no outgoing calls
no test coverage detected