(*rows, device=None)
| 72 | # Helpers for constructing transformation matrices (unchanged). |
| 73 | |
| 74 | def matrix(*rows, device=None): |
| 75 | assert all(len(row) == len(rows[0]) for row in rows) |
| 76 | elems = [x for row in rows for x in row] |
| 77 | ref = [x for x in elems if isinstance(x, torch.Tensor)] |
| 78 | if len(ref) == 0: |
| 79 | return constant(np.asarray(rows), device=device) |
| 80 | assert device is None or device == ref[0].device |
| 81 | elems = [x if isinstance(x, torch.Tensor) else constant(x, shape=ref[0].shape, device=ref[0].device) for x in elems] |
| 82 | return torch.stack(elems, dim=-1).reshape(ref[0].shape + (len(rows), -1)) |
| 83 | |
| 84 | def translate2d(tx, ty, **kwargs): |
| 85 | return matrix( |
no test coverage detected